mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
GetHardAABB (#2514)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
@@ -38,4 +39,31 @@ public partial class SharedPhysicsSystem
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public Box2 GetHardAABB(PhysicsComponent body, TransformComponent? xform = null, FixturesComponent? fixtures = null)
|
||||
{
|
||||
if (!Resolve(body.Owner, ref xform, ref fixtures))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var (worldPos, worldRot) = xform.GetWorldPositionRotation();
|
||||
|
||||
var transform = new Transform(worldPos, (float) worldRot.Theta);
|
||||
|
||||
var bounds = new Box2(transform.Position, transform.Position);
|
||||
|
||||
foreach (var fixture in fixtures.Fixtures.Values)
|
||||
{
|
||||
if (!fixture.Hard) continue;
|
||||
|
||||
for (var i = 0; i < fixture.Shape.ChildCount; i++)
|
||||
{
|
||||
var boundy = fixture.Shape.ComputeAABB(transform, i);
|
||||
bounds = bounds.Union(boundy);
|
||||
}
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user