diff --git a/.gitignore b/.gitignore index 5ed3d3e..f768bd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bin/ obj/ -.vscode \ No newline at end of file +.vscode +.vs diff --git a/Structs/Transform2D.cs b/Structs/Transform2D.cs index aab7338..6f71c52 100644 --- a/Structs/Transform2D.cs +++ b/Structs/Transform2D.cs @@ -16,7 +16,7 @@ namespace MoonTools.Core.Structs private float _rotation; private Vector2 _scale; - public Matrix4x4 TransformMatrix { get; private set; } + public Matrix3x2 TransformMatrix { get; private set; } public Position2D Position { @@ -119,11 +119,11 @@ namespace MoonTools.Core.Structs return new Transform2D(Position + other.Position, Rotation + other.Rotation, Scale * other.Scale); } - private static Matrix4x4 CreateTransformMatrix(Position2D translation, float rotation, Vector2 scale) + private static Matrix3x2 CreateTransformMatrix(Position2D translation, float rotation, Vector2 scale) { - return Matrix4x4.CreateScale(scale.X, scale.Y, 1) * - Matrix4x4.CreateRotationZ(rotation) * - Matrix4x4.CreateTranslation(translation.X, translation.Y, 0); + return Matrix3x2.CreateScale(scale.X, scale.Y) * + Matrix3x2.CreateRotation(rotation) * + Matrix3x2.CreateTranslation(translation.X, translation.Y); } public override bool Equals(Object other) diff --git a/Tests/Transform2DTest.cs b/Tests/Transform2DTest.cs index cb323e2..065f085 100644 --- a/Tests/Transform2DTest.cs +++ b/Tests/Transform2DTest.cs @@ -14,7 +14,7 @@ namespace Tests var transformA = new Transform2D(new Position2D(0, 1), 4f, new Vector2(2, 1)); var transformB = new Transform2D(new Position2D(0, 1), 4f, new Vector2(2, 1)); - transformA.Should().BeEquivalentTo(transformB); + transformA.Equals(transformB).Should().BeTrue(); } [Test] @@ -23,7 +23,7 @@ namespace Tests var transformA = new Transform2D(new Position2D(2, 3)); var transformB = new Transform2D(new Position2D(5, 1)); - transformA.Should().NotBeEquivalentTo(transformB); + transformA.Equals(transformB).Should().BeFalse(); } [Test] @@ -52,5 +52,17 @@ namespace Tests transformA.Compose(transformB).Should().BeEquivalentTo(new Transform2D(new Position2D(19, 3), 3 * (float)System.Math.PI / 4, new Vector2(3, 2))); } + + [Test] + public void Transform() + { + var transformA = new Transform2D(Position2D.Zero, (float)System.Math.PI / 2, Vector2.One); + var transformB = new Transform2D(new Vector2(0, 2), (float)System.Math.PI, Vector2.One); + var transformC = new Transform2D(new Vector2(-2, 0), (float)System.Math.PI * 2, new Vector2(3, 1)); + + Vector2.Transform(new Vector2(-1, 0), transformA.TransformMatrix).Should().Be(new Vector2(0, -1)); + Vector2.Transform(new Vector2(-1, 0), transformB.TransformMatrix).Should().Be(new Vector2(1, 2)); + Vector2.Transform(new Vector2(-1, 0), transformC.TransformMatrix).Should().Be(new Vector2(-5, 0)); + } } } \ No newline at end of file