mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
90 lines
2.6 KiB
C#
90 lines
2.6 KiB
C#
using System;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Shared.Physics
|
|
{
|
|
/// <summary>
|
|
/// A physics shape that represents a circle. The circle cannot be rotated,
|
|
/// and it's origin is always the same as the entity position.
|
|
/// </summary>
|
|
[Serializable, NetSerializable]
|
|
public class PhysShapeCircle : IPhysShape
|
|
{
|
|
private const float DefaultRadius = 0.5f;
|
|
|
|
private int _collisionLayer;
|
|
private int _collisionMask;
|
|
private float _radius = DefaultRadius;
|
|
|
|
/// <inheritdoc />
|
|
[field: NonSerialized]
|
|
public event Action? OnDataChanged;
|
|
|
|
/// <inheritdoc />
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public int CollisionLayer
|
|
{
|
|
get => _collisionLayer;
|
|
set
|
|
{
|
|
_collisionLayer = value;
|
|
OnDataChanged?.Invoke();
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public int CollisionMask
|
|
{
|
|
get => _collisionMask;
|
|
set
|
|
{
|
|
_collisionMask = value;
|
|
OnDataChanged?.Invoke();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The radius of this circle.
|
|
/// </summary>
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public float Radius
|
|
{
|
|
get => _radius;
|
|
set
|
|
{
|
|
_radius = value;
|
|
OnDataChanged?.Invoke();
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
void IExposeData.ExposeData(ObjectSerializer serializer)
|
|
{
|
|
serializer.DataField(ref _collisionLayer, "layer", 0, WithFormat.Flags<CollisionLayer>());
|
|
serializer.DataField(ref _collisionMask, "mask", 0, WithFormat.Flags<CollisionMask>());
|
|
serializer.DataField(ref _radius, "radius", DefaultRadius);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Box2 CalculateLocalBounds(Angle rotation)
|
|
{
|
|
return new(-_radius, -_radius, _radius, _radius);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void ApplyState() { }
|
|
|
|
/// <inheritdoc />
|
|
public void DebugDraw(DebugDrawingHandle handle, in Matrix3 modelMatrix, in Box2 worldViewport,
|
|
float sleepPercent)
|
|
{
|
|
handle.SetTransform(in modelMatrix);
|
|
handle.DrawCircle(Vector2.Zero, _radius, handle.CalcWakeColor(handle.RectFillColor, sleepPercent));
|
|
handle.SetTransform(in Matrix3.Identity);
|
|
}
|
|
}
|
|
}
|