public void TestExistingOwnerMatrix() { var ownerModel = new TestModel { Position = new Vector3(2, 3, 4) }; var model = new TestModel { Owner = ownerModel, Scale = new Vector3(4, 3, 2) }; // The order is important, the matrix is cached and needs to get propagated. ownerModel.UpdateCurrentWorldMatrix(); model.UpdateCurrentWorldMatrix(); Matrix4 expected = MathTestHelpers.BuildMatrix(new float[, ] { { 4, 0, 0, 0 }, { 0, 3, 0, 0 }, { 0, 0, 2, 0 }, { 2, 3, 4, 1 }, }); AssertCurrentMatrixEqual(model, expected); }
public void MovesCorrectly() { var camera = new Camera { Orientation = new Vector3((float)(Math.PI / 2), (float)-(Math.PI / 3), 0), MouseSpeedPerMs = 1f / 10 }; camera.Move(10, 20, 30, 1); camera.UpdateCurrentFrameMatrix(); // The values were measured when it worked correctly. No way I'm calculating these. Matrix4 expected = MathTestHelpers.BuildMatrix(new [, ] { { 0, 0.866f, -0.5f, 0 }, { 0, 0.5f, 0.866f, 0 }, { 1, 0, 0, 0 }, { -0.0267f, -0.0534f, 0.0801f, 1 }, }); CompareResult result = MathTestHelpers.MatrixCompare(expected, camera.CurrentFrameViewMatrix, epsilon: 1e-3f); Assert.True(result.AreEqual, result.DifferenceString); }
public void TestScaleMatrix() { var model = new TestModel { Scale = new Vector3(2, 3, 4) }; model.UpdateCurrentWorldMatrix(); Matrix4 expected = MathTestHelpers.BuildMatrix(new float[, ] { { 2, 0, 0, 0 }, { 0, 3, 0, 0 }, { 0, 0, 4, 0 }, { 0, 0, 0, 1 }, }); AssertCurrentMatrixEqual(model, expected); }
public void TestTranslationMatrix() { var model = new TestModel { Position = new Vector3(2, 3, 4) }; model.UpdateCurrentWorldMatrix(); Matrix4 expected = MathTestHelpers.BuildMatrix(new float[, ] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 2, 3, 4, 1 }, }); AssertCurrentMatrixEqual(model, expected); }
public void TestRotationMatrix() { var model = new TestModel { Rotation = new Vector3((float)Math.PI, (float)(2 * Math.PI), (float)(3 * Math.PI)) }; model.UpdateCurrentWorldMatrix(); Matrix4 expected = MathTestHelpers.BuildMatrix(new float[, ] { { -1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, -1, 0 }, { 0, 0, 0, 1 }, }); AssertCurrentMatrixEqual(model, expected); }
public void TestCombinedMatrix() { var model = new TestModel { Rotation = new Vector3((float)Math.PI, (float)(2 * Math.PI), (float)(3 * Math.PI)), Position = new Vector3(2, 3, 4), Scale = new Vector3(2, 3, 4) }; model.UpdateCurrentWorldMatrix(); Matrix4 expected = MathTestHelpers.BuildMatrix(new float[, ] { { -2, 0, 0, 0 }, { 0, 3, 0, 0 }, { 0, 0, -4, 0 }, { 2, 3, 4, 1 }, }); AssertCurrentMatrixEqual(model, expected); }
public void CalculatesPickRay() { const int x = 100; const int y = 200; var cameraMock = new Mock <ICamera>(); cameraMock.Setup(c => c.CurrentFrameViewMatrix).Returns(MathTestHelpers.BuildMatrix(new float[, ] { { 1, 2, 3, 0 }, { 1, 2, 3, 0 }, { 1, 2, 3, 0 }, { 1, 2, 3, 1 } })); cameraMock.Setup(c => c.Position).Returns(new Vector3(10, 20, 30)); ICamera camera = cameraMock.Object; var viewSize = new Size(1000, 600); Matrix4 projectionMatrix = MathTestHelpers.BuildMatrix(new float[, ] { { 4, 3, 2, 0 }, { 4, 3, 2, 0 }, { 4, 3, 2, 0 }, { 4, 3, 2, 1 } }); PickRay ray = PickRay.Pick(x, y, camera, viewSize, projectionMatrix); var expectedDirection = new Vector3(-0.26726f, -0.53452f, -0.80178f); Assert.Equal(camera.Position, ray.Position); CompareResult result = MathTestHelpers.VectorCompare(expectedDirection, ray.Direction, 1e-05f); Assert.True(result.AreEqual, result.DifferenceString); }
public void GetsCorrectViewMatrix() { var camera = new Camera { Position = new Vector3(10, 100, 1000), Orientation = new Vector3((float)(Math.PI / 2), (float)-(Math.PI / 3), 0) }; camera.UpdateCurrentFrameMatrix(); // The values were measured when it worked correctly. No way I'm calculating these. Matrix4 expected = MathTestHelpers.BuildMatrix(new [, ] { { 0, 0.866f, -0.5f, 0 }, { 0, 0.5f, 0.866f, 0 }, { 1, 0, 0, 0 }, { -1000, -58.66f, -81.602f, 1 }, }); CompareResult result = MathTestHelpers.MatrixCompare(expected, camera.CurrentFrameViewMatrix, epsilon: 1e-3f); Assert.True(result.AreEqual, result.DifferenceString); }
public void RotatesCorrectly() { var camera = new Camera { MouseSpeedPerMs = 1f / 5000 }; camera.Rotate(10, 20, 1); camera.UpdateCurrentFrameMatrix(); // The values were measured when it worked correctly. No way I'm calculating these. Matrix4 expected = MathTestHelpers.BuildMatrix(new [, ] { { -1, 0, -0.002f, 0 }, { 0, 1, -0.004f, 0 }, { 0.002f, -0.004f, -1, 0 }, { 0, 0, 0, 1 }, }); CompareResult result = MathTestHelpers.MatrixCompare(expected, camera.CurrentFrameViewMatrix, epsilon: 1e-3f); Assert.True(result.AreEqual, result.DifferenceString); }
private static void AssertCurrentMatrixEqual(TestModel model, Matrix4 expected) { CompareResult result = MathTestHelpers.MatrixCompare(expected, model.CurrentWorldMatrix); Assert.True(result.AreEqual, result.DifferenceString); }