using System;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Robust.Shared.Physics
{
///
/// A physics shape that represents an Axis-Aligned Bounding Box.
/// This box does not rotate with the entity, and will always be offset from the
/// entity origin in world space.
///
[Serializable, NetSerializable]
[DataDefinition]
public class PhysShapeAabb : IPhysShape
{
[DataFieldWithFlag("layer", typeof(CollisionLayer))]
private int _collisionLayer;
[DataFieldWithFlag("mask", typeof(CollisionMask))]
private int _collisionMask;
[DataField("bounds")]
private Box2 _localBounds = Box2.UnitCentered;
///
/// Local AABB bounds of this shape.
///
[ViewVariables(VVAccess.ReadWrite)]
public Box2 LocalBounds
{
get => _localBounds;
set
{
_localBounds = value;
OnDataChanged?.Invoke();
}
}
///
[ViewVariables(VVAccess.ReadWrite)]
public int CollisionLayer
{
get => _collisionLayer;
set
{
_collisionLayer = value;
OnDataChanged?.Invoke();
}
}
///
[ViewVariables(VVAccess.ReadWrite)]
public int CollisionMask
{
get => _collisionMask;
set
{
_collisionMask = value;
OnDataChanged?.Invoke();
}
}
///
public void ApplyState() { }
public void DebugDraw(DebugDrawingHandle handle, in Matrix3 modelMatrix, in Box2 worldViewport,
float sleepPercent)
{
var m = Matrix3.Identity;
m.R0C2 = modelMatrix.R0C2;
m.R1C2 = modelMatrix.R1C2;
handle.SetTransform(m);
handle.DrawRect(LocalBounds, handle.CalcWakeColor(handle.RectFillColor, sleepPercent));
handle.SetTransform(Matrix3.Identity);
}
[field: NonSerialized]
public event Action? OnDataChanged;
///
public Box2 CalculateLocalBounds(Angle rotation)
{
return _localBounds;
}
}
}