diff --git a/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs b/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs index d3fab92634f..ddbe6904258 100644 --- a/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs +++ b/Robust.Client/GameObjects/Components/Renderable/SpriteComponent.cs @@ -480,6 +480,8 @@ public bool SnapCardinals [DataField("noRot")] public bool NoRotation; + // TODO SPRITE + // When refactoring, make this nullable and remove EnableDirectionOverride [DataField("overrideDir")] public Direction DirectionOverride = Direction.East; diff --git a/Robust.Client/GameObjects/EntitySystems/SpriteSystem.Render.cs b/Robust.Client/GameObjects/EntitySystems/SpriteSystem.Render.cs index 3597edae7ec..d7772cf6626 100644 --- a/Robust.Client/GameObjects/EntitySystems/SpriteSystem.Render.cs +++ b/Robust.Client/GameObjects/EntitySystems/SpriteSystem.Render.cs @@ -53,7 +53,7 @@ public void RenderSprite( // If we have a 1-directional sprite then snap it to try and always face it south if applicable. if (sprite.Comp is {NoRotation: false, SnapCardinals: true}) - cardinal = angle.GetCardinalDir().ToAngle(); + cardinal = angle.RoundToCardinalAngle(); // worldRotation + eyeRotation should be the angle of the entity on-screen. If no-rot is enabled this is just set to zero. // However, at some point later the eye-matrix is applied separately, so we subtract -eye rotation for now: @@ -70,14 +70,12 @@ public void RenderSprite( return; } - // TODO sprite optimize angle.GetCardinalDir().ToAngle() - //Default rendering (NoRotation = false) entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation); var transformDefault = Matrix3x2.Multiply(sprite.Comp.LocalMatrix, entityMatrix); //Snap to cardinals - entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation - angle.GetCardinalDir().ToAngle()); + entityMatrix = Matrix3Helpers.CreateTransform(worldPosition, worldRotation - angle.RoundToCardinalAngle()); var transformSnap = Matrix3x2.Multiply(sprite.Comp.LocalMatrix, entityMatrix); //No rotation diff --git a/Robust.Shared.Maths/Angle.cs b/Robust.Shared.Maths/Angle.cs index eb99fc5cea6..49cf7bb0b4e 100644 --- a/Robust.Shared.Maths/Angle.cs +++ b/Robust.Shared.Maths/Angle.cs @@ -104,6 +104,16 @@ public readonly Direction GetCardinalDir() return (Direction) (Math.Floor((ang + CardinalOffset) / CardinalSegment) * 2 % 8); } + /// + /// Rounds the angle to the nearest cardinal direction. This behaves similarly to a combination of + /// and Direction.ToAngle(), however this may return an angle outside of the range + /// returned by those methods (-pi to pi). + /// + public Angle RoundToCardinalAngle() + { + return new Angle(CardinalSegment * Math.Floor((Theta + CardinalOffset) / CardinalSegment)); + } + /// /// Rotates the vector counter-clockwise around its origin by the value of Theta. ///