예제 #1
0
        public void ShouldComposeIdentityMatrix()
        {
            var quaternion = Quaternion.Identity;
            var vector     = new Vector3D {
            };
            var expected   = Matrix3D.Identity;

            GeometryAssert.AreEqual(expected, vector.ComposeTransform(ref quaternion));
            GeometryAssert.AreEqual(expected, quaternion.ComposeTransform(ref vector));
        }
예제 #2
0
        public void ShouldDecomposeIdentityMatrix()
        {
            var expected_quaternion = Quaternion.Identity;
            var expected_vector     = new Vector3D {
            };
            var matrix = Matrix3D.Identity;

            var(result_vector, result_quaternion) = matrix.Decompose();

            GeometryAssert.AreEqual(expected_quaternion, result_quaternion);
            GeometryAssert.AreEqual(expected_vector, result_vector);
        }
예제 #3
0
        public void ShouldComposeTranslationMatrix()
        {
            var quaternion = Quaternion.Identity;
            var vector     = new Vector3D {
                X = 5, Y = 7, Z = -3
            };
            var expected = Matrix3D.Identity;

            expected.Translate(vector);

            GeometryAssert.AreEqual(expected, vector.ComposeTransform(ref quaternion));
            GeometryAssert.AreEqual(expected, quaternion.ComposeTransform(ref vector));
        }
예제 #4
0
        public void ShouldComposeRotationMatrix()
        {
            var quaternion = new Quaternion {
                X = 3, Y = 4, Z = 2, W = 0.5
            };
            var vector   = new Vector3D {
            };
            var expected = Matrix3D.Identity;

            expected.Rotate(quaternion);

            GeometryAssert.AreEqual(expected, vector.ComposeTransform(ref quaternion));
            GeometryAssert.AreEqual(expected, quaternion.ComposeTransform(ref vector));
        }
예제 #5
0
        public void ShouldDecomposeTranslationMatrix()
        {
            var expected_quaternion = Quaternion.Identity;
            var expected_vector     = new Vector3D {
                X = 5, Y = 7, Z = -3
            };
            var matrix = Matrix3D.Identity;

            matrix.Translate(expected_vector);

            var(result_vector, result_quaternion) = matrix.Decompose();

            GeometryAssert.AreEqual(expected_quaternion, result_quaternion);
            GeometryAssert.AreEqual(expected_vector, result_vector);
        }
예제 #6
0
        public void ShouldDecomposeRotationMatrix()
        {
            var expected_quaternion = new Quaternion {
                X = 0.5, Y = 1, Z = 0.3, W = 0.5
            };
            var expected_vector = new Vector3D {
            };
            var matrix          = Matrix3D.Identity;

            expected_quaternion.Normalize();
            matrix.Rotate(expected_quaternion);

            var(result_vector, result_quaternion) = matrix.Decompose();

            GeometryAssert.AreEqual(expected_quaternion, result_quaternion);
            GeometryAssert.AreEqual(expected_vector, result_vector);
        }
예제 #7
0
        public void ShouldConvertMatrixTransform3DToQuaternionAndPoint()
        {
            var point      = new Point3D(Random.Next(1000), Random.Next(1000), Random.Next(1000));
            var quaternion = new Quaternion(Random.Next(1000), Random.Next(1000), Random.Next(1000), Random.Next(1000));

            quaternion.Normalize();

            var transforms = new Transform3DGroup
            {
                Children = new Transform3DCollection
                {
                    new TranslateTransform3D(point.X, point.Y, point.Z),
                    new RotateTransform3D(new QuaternionRotation3D(quaternion), point)
                }
            };

            var(point_test, (quaternion_test, rest)) = Converter.ConvertBack(new MatrixTransform3D(transforms.Value), Converter.Types);

            GeometryAssert.AreEqual(quaternion, ((Hymperia.Model.Modeles.JsonObject.Quaternion)quaternion_test).Convert());
            GeometryAssert.AreEqual(point, ((Hymperia.Model.Modeles.JsonObject.Point)point_test).Convert());
        }
예제 #8
0
        public void ShouldConvertQuaternionAndPointToMatrixTransform3D()
        {
            var point      = new Point3D(Random.Next(1000), Random.Next(1000), Random.Next(1000));
            var quaternion = new Quaternion(Random.Next(1000), Random.Next(1000), Random.Next(1000), Random.Next(1000));

            quaternion.Normalize();

            var expected = new Transform3DGroup
            {
                Children = new Transform3DCollection
                {
                    new TranslateTransform3D(point.X, point.Y, point.Z),
                    new RotateTransform3D(new QuaternionRotation3D(quaternion), point)
                }
            }.Value;
            var test = Converter.Convert(
                new object[] { point.Convert(), quaternion.Convert() },
                typeof(MatrixTransform3D)) as MatrixTransform3D;

            Assert.IsNotNull(test);
            GeometryAssert.AreEqual(expected, test.Value);
        }