public void PoseTest() { CameraInstance cameraInstance = new CameraInstance(new Camera(new PerspectiveProjection())); Assert.IsNotNull(cameraInstance.PoseWorld); Assert.AreEqual(Vector3F.Zero, cameraInstance.PoseWorld.Position); Assert.AreEqual(Matrix33F.Identity, cameraInstance.PoseWorld.Orientation); // Set new Pose Vector3F position = new Vector3F(1, 2, 3); QuaternionF orientation = QuaternionF.CreateRotation(new Vector3F(3, 4, 5), 0.123f); cameraInstance.PoseWorld = new Pose(position, orientation); Assert.AreEqual(position, cameraInstance.PoseWorld.Position); Assert.AreEqual(orientation.ToRotationMatrix33(), cameraInstance.PoseWorld.Orientation); Assert.IsTrue(Matrix44F.AreNumericallyEqual(cameraInstance.PoseWorld.ToMatrix44F(), cameraInstance.ViewInverse)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(cameraInstance.PoseWorld.Inverse.ToMatrix44F(), cameraInstance.View)); // Set Position and Orientation position = new Vector3F(5, 6, 7); orientation = QuaternionF.CreateRotation(new Vector3F(1, -1, 6), -0.123f); cameraInstance.PoseWorld = new Pose(position, orientation); Assert.AreEqual(position, cameraInstance.PoseWorld.Position); Assert.AreEqual(orientation.ToRotationMatrix33(), cameraInstance.PoseWorld.Orientation); Assert.IsTrue(Matrix44F.AreNumericallyEqual(cameraInstance.PoseWorld.Inverse.ToMatrix44F(), cameraInstance.View)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(cameraInstance.PoseWorld.ToMatrix44F(), cameraInstance.ViewInverse)); }
public void SetProjectionFieldOfViewTest() { PerspectiveProjection projection = new PerspectiveProjection(); projection.SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 10); PerspectiveProjection projection2 = new PerspectiveProjection(); projection2.SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f); projection2.Near = 1; projection2.Far = 10; Projection projection3 = new PerspectiveProjection { Left = -2.0528009f / 2.0f, Right = 2.0528009f / 2.0f, Bottom = -1.1547005f / 2.0f, Top = 1.1547005f / 2.0f, Near = 1, Far = 10, }; Matrix44F expected = Matrix44F.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection2)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection3.ToMatrix44F())); }
public void SetProjectionTest() { OrthographicProjection projection = new OrthographicProjection(); projection.Set(4, 3, 2, 10); OrthographicProjection camera2 = new OrthographicProjection(); camera2.Set(4, 3); camera2.Near = 2; camera2.Far = 10; OrthographicProjection camera3 = new OrthographicProjection { Left = -2, Right = 2, Bottom = -1.5f, Top = 1.5f, Near = 2, Far = 10, }; Matrix44F expected = Matrix44F.CreateOrthographic(4, 3, 2, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera2)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera3.ToMatrix44F())); }
public void SetProjectionOffCenterTest() { OrthographicProjection projection = new OrthographicProjection(); projection.SetOffCenter(0, 4, 1, 4, 2, 10); OrthographicProjection camera2 = new OrthographicProjection(); camera2.SetOffCenter(0, 4, 1, 4); camera2.Near = 2; camera2.Far = 10; Projection camera3 = new OrthographicProjection { Left = 0, Right = 4, Bottom = 1, Top = 4, Near = 2, Far = 10, }; Matrix44F expected = Matrix44F.CreateOrthographicOffCenter(0, 4, 1, 4, 2, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera2)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera3.ToMatrix44F())); }
public void SetProjectionTest() { PerspectiveProjection projection = new PerspectiveProjection(); projection.Set(4, 3, 2, 10); PerspectiveProjection projection2 = new PerspectiveProjection(); projection2.Set(4, 3); projection2.Near = 2; projection2.Far = 10; Projection projection3 = new PerspectiveProjection { Left = -2, Right = 2, Bottom = -1.5f, Top = 1.5f, Near = 2, Far = 10, }; Matrix44F expected = Matrix44F.CreatePerspective(4, 3, 2, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection2)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection3.ToMatrix44F())); }
public void RotationMatrix44() { float angle = -1.6f; Vector3F axis = new Vector3F(1.0f, 2.0f, -3.0f); QuaternionF q = QuaternionF.CreateRotation(axis, angle); Matrix44F m44 = Matrix44F.CreateRotation(axis, angle); Assert.IsTrue(Matrix44F.AreNumericallyEqual(q.ToRotationMatrix44(), m44)); }
public void Multiply() { var a = new SrtTransform(new Vector3F(1, 2, 7), new QuaternionF(1, 2, 3, 4).Normalized, new Vector3F(4, -5, 6)); var b = new SrtTransform(new Vector3F(-3, 9, -2), new QuaternionF(3, -2, 1, 9).Normalized, new Vector3F(7, -4, 2)); var result1 = SrtTransform.Multiply(a, b).ToMatrix44F(); var result2 = a * b; Assert.IsTrue(Matrix44F.AreNumericallyEqual(result1, result2)); }
public void MultiplyWithUniformScaleIsTheSameAsMatrixMultiply() { // Result is the same as Matrix mulitiplication without scale. var a = new SrtTransform(new Vector3F(7), new QuaternionF(1, 2, 3, 4).Normalized, new Vector3F(4, -5, 6)); var b = new SrtTransform(new Vector3F(-3), new QuaternionF(3, -2, 1, 9).Normalized, new Vector3F(7, -4, 2)); var result1 = (a * b).ToMatrix44F(); var result2 = a.ToMatrix44F() * b.ToMatrix44F(); Assert.IsTrue(Matrix44F.AreNumericallyEqual(result1, result2)); }
public void MultiplyWithoutRotationIsTheSameAsMatrixMultiply() { // Result is the same as Matrix mulitiplication without scale. var a = new SrtTransform(new Vector3F(1, 2, 3), QuaternionF.Identity, new Vector3F(4, -5, 6)); var b = new SrtTransform(new Vector3F(5, 6, -3), QuaternionF.Identity, new Vector3F(7, -4, 2)); var result1 = (a * b).ToMatrix44F(); var result2 = a.ToMatrix44F() * b.ToMatrix44F(); Assert.IsTrue(Matrix44F.AreNumericallyEqual(result1, result2)); }
public void SetProjectionOffCenterTest() { PerspectiveProjection projection = new PerspectiveProjection(); projection.SetOffCenter(0, 4, 1, 4, 2, 10); PerspectiveProjection projection2 = new PerspectiveProjection(); projection2.SetOffCenter(0, 4, 1, 4); projection2.Near = 2; projection2.Far = 10; Matrix44F expected = Matrix44F.CreatePerspectiveOffCenter(0, 4, 1, 4, 2, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection2.ToMatrix44F())); }
public void InverseViewTest() { CameraInstance cameraInstance = new CameraInstance(new Camera(new PerspectiveProjection())); Assert.AreEqual(Matrix44F.Identity, cameraInstance.View); Assert.AreEqual(Matrix44F.Identity, cameraInstance.ViewInverse); Vector3F position = new Vector3F(1, 2, 3); Vector3F target = new Vector3F(2, 5, 4); Vector3F upVector = new Vector3F(1, 1, 1); Matrix44F view = Matrix44F.CreateLookAt(position, target, upVector); cameraInstance.ViewInverse = view.Inverse; Assert.IsTrue(Matrix44F.AreNumericallyEqual(view, cameraInstance.View)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(view.Inverse, cameraInstance.ViewInverse)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(view.Inverse, cameraInstance.PoseWorld.ToMatrix44F())); }
public void SetProjectionTest() { Matrix44F projectionMatrix = Matrix44F.CreateOrthographicOffCenter(1, 4, 2, 5, 6, 11); OrthographicProjection orthographicProjection = new OrthographicProjection(); orthographicProjection.Set(projectionMatrix); CameraInstance cameraInstance = new CameraInstance(new Camera(orthographicProjection)); Assert.AreEqual(Vector3F.Zero, cameraInstance.PoseWorld.Position); Assert.AreEqual(Matrix33F.Identity, cameraInstance.PoseWorld.Orientation); Assert.That(Numeric.AreEqual(3, cameraInstance.Camera.Projection.Width)); Assert.That(Numeric.AreEqual(3, cameraInstance.Camera.Projection.Height)); Assert.That(Numeric.AreEqual(1f, cameraInstance.Camera.Projection.AspectRatio)); Assert.That(Numeric.AreEqual(6, cameraInstance.Camera.Projection.Near)); Assert.That(Numeric.AreEqual(11, cameraInstance.Camera.Projection.Far)); Assert.That(Numeric.AreEqual(1, cameraInstance.Camera.Projection.Left)); Assert.That(Numeric.AreEqual(4, cameraInstance.Camera.Projection.Right)); Assert.That(Numeric.AreEqual(2, cameraInstance.Camera.Projection.Bottom)); Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Top)); Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Depth)); Assert.That(Matrix44F.AreNumericallyEqual(orthographicProjection, cameraInstance.Camera.Projection)); Assert.That(Matrix44F.AreNumericallyEqual(orthographicProjection.Inverse, cameraInstance.Camera.Projection.Inverse)); Assert.IsNotNull(cameraInstance.BoundingShape); PerspectiveProjection perspectiveProjection = new PerspectiveProjection(); perspectiveProjection.Inverse = Matrix44F.CreatePerspectiveOffCenter(1, 5, 2, 5, 1, 10).Inverse; cameraInstance = new CameraInstance(new Camera(perspectiveProjection)); Assert.AreEqual(Vector3F.Zero, cameraInstance.PoseWorld.Position); Assert.AreEqual(Matrix33F.Identity, cameraInstance.PoseWorld.Orientation); Assert.That(Numeric.AreEqual(MathHelper.ToRadians(33.690067f), cameraInstance.Camera.Projection.FieldOfViewX)); Assert.That(Numeric.AreEqual(MathHelper.ToRadians(15.255119f), cameraInstance.Camera.Projection.FieldOfViewY)); Assert.That(Numeric.AreEqual(4, cameraInstance.Camera.Projection.Width)); Assert.That(Numeric.AreEqual(3, cameraInstance.Camera.Projection.Height)); Assert.That(Numeric.AreEqual(4.0f / 3.0f, cameraInstance.Camera.Projection.AspectRatio)); Assert.That(Numeric.AreEqual(1, cameraInstance.Camera.Projection.Left)); Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Right)); Assert.That(Numeric.AreEqual(2, cameraInstance.Camera.Projection.Bottom)); Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Top)); Assert.That(Numeric.AreEqual(1, cameraInstance.Camera.Projection.Near)); Assert.That(Numeric.AreEqual(10, cameraInstance.Camera.Projection.Far)); Assert.That(Numeric.AreEqual(9, cameraInstance.Camera.Projection.Depth)); Assert.IsNotNull(cameraInstance.BoundingShape); }
public void GetWidthAndHeightTest() { float width, height; PerspectiveViewVolume.GetWidthAndHeight(MathHelper.ToRadians(90), 1, 1, out width, out height); Assert.IsTrue(Numeric.AreEqual(2, width)); Assert.IsTrue(Numeric.AreEqual(2, height)); PerspectiveViewVolume.GetWidthAndHeight(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, out width, out height); Assert.IsTrue(Numeric.AreEqual(2.0528009f, width)); Assert.IsTrue(Numeric.AreEqual(1.1547005f, height)); // We are pretty confident that the Projection.CreateProjectionXxx() works. // Use Projection.CreateProjectionXxx() to test GetWidthAndHeight(). Matrix44F projection = Matrix44F.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 10); Matrix44F projection2 = Matrix44F.CreatePerspective(width, height, 1, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection, projection2)); }
public void FromToMatrixTest() { var t = new Vector3F(1, 2, 3); var r = new QuaternionF(1, 2, 3, 4).Normalized; var s = new Vector3F(2, 7, 9); var m = Matrix44F.CreateTranslation(t) * Matrix44F.CreateRotation(r) * Matrix44F.CreateScale(s); var srt = SrtTransform.FromMatrix(m); Assert.IsTrue(Vector3F.AreNumericallyEqual(t, srt.Translation)); Assert.IsTrue(QuaternionF.AreNumericallyEqual(r, srt.Rotation)); Assert.IsTrue(Vector3F.AreNumericallyEqual(s, srt.Scale)); // XNA: srt = SrtTransform.FromMatrix((Matrix)m); Assert.IsTrue(Vector3F.AreNumericallyEqual(t, srt.Translation)); Assert.IsTrue(QuaternionF.AreNumericallyEqual(r, srt.Rotation)); Assert.IsTrue(Vector3F.AreNumericallyEqual(s, srt.Scale)); // With negative scale, the decomposition is not unique (many possible combinations of // axis mirroring + rotation). t = new Vector3F(1, 2, 3); r = new QuaternionF(1, 2, 3, 4).Normalized; s = new Vector3F(2, -7, 9); m = Matrix44F.CreateTranslation(t) * Matrix44F.CreateRotation(r) * Matrix44F.CreateScale(s); srt = SrtTransform.FromMatrix(m); var m2 = (Matrix44F)srt; Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, m2)); m2 = srt.ToMatrix44F(); Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, m2)); m2 = srt; Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, m2)); Matrix mXna = srt.ToXna(); Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, (Matrix44F)mXna)); mXna = srt; Assert.IsTrue(Matrix44F.AreNumericallyEqual(m, (Matrix44F)mXna)); }
public void LookAtTest() { CameraInstance cameraInstance = new CameraInstance(new Camera(new PerspectiveProjection())); Vector3F position = new Vector3F(1, 2, 3); Vector3F target = new Vector3F(2, 5, 4); Vector3F upVector = new Vector3F(1, 1, 1); cameraInstance.PoseWorld = new Pose(new Vector3F(1, 2, 3)); Matrix44F expected = Matrix44F.CreateLookAt(position, target, upVector); cameraInstance.LookAt(target, upVector); Assert.That(Matrix44F.AreNumericallyEqual(expected, cameraInstance.View)); position = new Vector3F(-2, 3, -7.5f); expected = Matrix44F.CreateLookAt(position, target, upVector); cameraInstance.LookAt(position, target, upVector); Assert.That(Vector3F.AreNumericallyEqual(position, cameraInstance.PoseWorld.Position)); Assert.That(Matrix44F.AreNumericallyEqual(expected, cameraInstance.View)); }
public void OrthographicOffCenterTest() { Vector3F position = new Vector3F(1, 2, 3); QuaternionF orientation = QuaternionF.CreateRotation(new Vector3F(2, 3, 6), 0.123f); CameraInstance cameraInstance = new CameraInstance(new Camera(new OrthographicProjection())) { PoseLocal = new Pose(position, orientation), }; ((OrthographicProjection)cameraInstance.Camera.Projection).SetOffCenter(0, 16, 0, 9, 2, 10); Matrix44F projection = Matrix44F.CreateOrthographicOffCenter(0, 16, 0, 9, 2, 10); Assert.AreEqual(position, cameraInstance.PoseWorld.Position); Assert.AreEqual(orientation.ToRotationMatrix33(), cameraInstance.PoseWorld.Orientation); Assert.AreEqual(16, cameraInstance.Camera.Projection.Width); Assert.AreEqual(9, cameraInstance.Camera.Projection.Height); Assert.AreEqual(16.0f / 9.0f, cameraInstance.Camera.Projection.AspectRatio); Assert.AreEqual(2, cameraInstance.Camera.Projection.Near); Assert.AreEqual(10, cameraInstance.Camera.Projection.Far); Assert.AreEqual(0, cameraInstance.Camera.Projection.Left); Assert.AreEqual(16, cameraInstance.Camera.Projection.Right); Assert.AreEqual(0, cameraInstance.Camera.Projection.Bottom); Assert.AreEqual(9, cameraInstance.Camera.Projection.Top); Assert.AreEqual(8, cameraInstance.Camera.Projection.Depth); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection, cameraInstance.Camera.Projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection.Inverse, cameraInstance.Camera.Projection.Inverse)); Assert.IsNotNull(cameraInstance.BoundingShape); CollisionDetection collisionDetection = new CollisionDetection(); var point = new PointShape(); CollisionObject pointCollisionObject = new CollisionObject(new GeometricObject(point)); CollisionObject cameraCollisionObject = new CollisionObject(cameraInstance); // Test shape using collision detection. Remove rotation to simplify test. cameraInstance.PoseWorld = new Pose(cameraInstance.PoseWorld.Position); point.Position = position + new Vector3F(0, 0, -2); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-0.1f, -0.1f, -1.9f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(16, 9, -10); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(16.1f, 9.1f, -10.1f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); cameraInstance.Camera.Projection.Left = -2; cameraInstance.Camera.Projection.Right = 4; cameraInstance.Camera.Projection.Bottom = 10; cameraInstance.Camera.Projection.Top = 14; cameraInstance.Camera.Projection.Near = 15; cameraInstance.Camera.Projection.Far = 100; projection = Matrix44F.CreateOrthographicOffCenter(-2, 4, 10, 14, 15, 100); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection.Inverse, cameraInstance.Camera.Projection.Inverse)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection, cameraInstance.Camera.Projection)); // Test shape using collision detection. Remove rotation to simplify test. cameraInstance.PoseWorld = new Pose(cameraInstance.PoseWorld.Position); point.Position = position + new Vector3F(-2, 10, -15); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-2.1f, -10.1f, -14.9f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(4, 14, -100); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(4.1f, 14.1f, -100.1f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); }
public void PerspectiveTest() { Vector3F position = new Vector3F(1, 2, 3); QuaternionF orientation = QuaternionF.CreateRotation(new Vector3F(2, 3, 6), 0.123f); CameraInstance cameraInstance = new CameraInstance(new Camera(new PerspectiveProjection())) { PoseLocal = new Pose(position, orientation), }; ((PerspectiveProjection)cameraInstance.Camera.Projection).SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 10.0f, 1, 10); Matrix44F projection = Matrix44F.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16.0f / 10.0f, 1, 10); Assert.AreEqual(position, cameraInstance.PoseWorld.Position); Assert.AreEqual(orientation.ToRotationMatrix33(), cameraInstance.PoseWorld.Orientation); Assert.AreEqual(MathHelper.ToRadians(60), cameraInstance.Camera.Projection.FieldOfViewY); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(85.4601055f), cameraInstance.Camera.Projection.FieldOfViewX)); Assert.AreEqual(16.0f / 10.0f, cameraInstance.Camera.Projection.AspectRatio); Assert.IsTrue(Numeric.AreEqual(1.8475209f, cameraInstance.Camera.Projection.Width)); Assert.IsTrue(Numeric.AreEqual(1.1547005f, cameraInstance.Camera.Projection.Height)); Assert.AreEqual(1, cameraInstance.Camera.Projection.Near); Assert.AreEqual(10, cameraInstance.Camera.Projection.Far); Assert.IsTrue(Numeric.AreEqual(-0.9237604f, cameraInstance.Camera.Projection.Left)); Assert.IsTrue(Numeric.AreEqual(0.9237604f, cameraInstance.Camera.Projection.Right)); Assert.IsTrue(Numeric.AreEqual(-0.5773503f, cameraInstance.Camera.Projection.Bottom)); Assert.IsTrue(Numeric.AreEqual(0.5773503f, cameraInstance.Camera.Projection.Top)); Assert.AreEqual(9, cameraInstance.Camera.Projection.Depth); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection, cameraInstance.Camera.Projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection.Inverse, cameraInstance.Camera.Projection.Inverse)); Assert.IsNotNull(cameraInstance.BoundingShape); // Test shape using collision detection. Remove rotation to simplify test. cameraInstance.PoseWorld = new Pose(cameraInstance.PoseWorld.Position); CollisionDetection collisionDetection = new CollisionDetection(); var point = new PointShape(); CollisionObject pointCollisionObject = new CollisionObject(new GeometricObject(point)); CollisionObject cameraCollisionObject = new CollisionObject(cameraInstance); point.Position = position + new Vector3F(0, 0, -1); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(0, 0, -10); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(0, 0, -0.9f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(0, 0, -10.1f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-0.9237604f, -0.5773f, -1); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-0.924f, -0.5773f, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-0.9237604f, -0.58f, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(0.9237604f, 0.5773f, -1); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(0.924f, 0.5773f, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(0.9237604f, 0.58f, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-9.237604f, -5.773f, -10); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-9.24f, -5.773f, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(-9.237604f, -5.8f, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(9.237604f, 5.773f, -10); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(9.24f, 5.773f, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(9.237604f, 5.8f, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); }
public void PerspectiveOffCenterTest() { Vector3F position = new Vector3F(1, 2, 3); QuaternionF orientation = QuaternionF.CreateRotation(new Vector3F(2, 3, 6), 0.123f); CameraInstance cameraInstance = new CameraInstance(new Camera(new PerspectiveProjection())) { PoseLocal = new Pose(position, orientation), }; ((PerspectiveProjection)cameraInstance.Camera.Projection).SetOffCenter(1, 5, 2, 5, 1, 10); Matrix44F projection = Matrix44F.CreatePerspectiveOffCenter(1, 5, 2, 5, 1, 10); Assert.AreEqual(position, cameraInstance.PoseWorld.Position); Assert.AreEqual(orientation.ToRotationMatrix33(), cameraInstance.PoseWorld.Orientation); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(33.690067f), cameraInstance.Camera.Projection.FieldOfViewX)); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(15.255119f), cameraInstance.Camera.Projection.FieldOfViewY)); Assert.AreEqual(4.0f / 3.0f, cameraInstance.Camera.Projection.AspectRatio); Assert.AreEqual(4, cameraInstance.Camera.Projection.Width); Assert.AreEqual(3, cameraInstance.Camera.Projection.Height); Assert.AreEqual(1, cameraInstance.Camera.Projection.Left); Assert.AreEqual(5, cameraInstance.Camera.Projection.Right); Assert.AreEqual(2, cameraInstance.Camera.Projection.Bottom); Assert.AreEqual(5, cameraInstance.Camera.Projection.Top); Assert.AreEqual(1, cameraInstance.Camera.Projection.Near); Assert.AreEqual(10, cameraInstance.Camera.Projection.Far); Assert.AreEqual(9, cameraInstance.Camera.Projection.Depth); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection, cameraInstance.Camera.Projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection.Inverse, cameraInstance.Camera.Projection.Inverse)); Assert.IsNotNull(cameraInstance.BoundingShape); // Test shape using collision detection. Remove rotation to simplify test. cameraInstance.PoseWorld = new Pose(cameraInstance.PoseWorld.Position); CollisionDetection collisionDetection = new CollisionDetection(); var point = new PointShape(); CollisionObject pointCollisionObject = new CollisionObject(new GeometricObject(point)); CollisionObject cameraCollisionObject = new CollisionObject(cameraInstance); point.Position = position + new Vector3F(3, 3, -1); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(30, 30, -10); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(3, 3, -0.9f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(30, 30, -10.1f); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(1, 2, -1); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(0.9f, 2, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(1, 1.9f, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(5, 5, -1); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(5.1f, 5, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(5, 5.1f, -1); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(10, 20, -10); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(9.9f, 20, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(10, 19.9f, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(50, 50, -10); Assert.IsTrue(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(50.1f, 50, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); point.Position = position + new Vector3F(50, 50.1f, -10); Assert.IsFalse(collisionDetection.HaveContact(pointCollisionObject, cameraCollisionObject)); }