예제 #1
0
        public void QuaternionFromRotationMatrixTest1()
        {
            Matrix4X4 <float> matrix = Matrix4X4 <float> .Identity;

            Quaternion <float> expected = new Quaternion <float>(0.0f, 0.0f, 0.0f, 1.0f);
            Quaternion <float> actual   = Quaternion <float> .CreateFromRotationMatrix(matrix);

            Assert.True(MathHelper.Equal(expected, actual),
                        $"Quaternion<float>.CreateFromRotationMatrix did not return the expected value: expected {expected} actual {actual}");

            // make sure convert back to matrix is same as we passed matrix.
            Matrix4X4 <float> m2 = Matrix4X4.CreateFromQuaternion <float>(actual);

            Assert.True(MathHelper.Equal(matrix, m2),
                        $"Quaternion<float>.CreateFromQuaternion did not return the expected value: matrix {matrix} m2 {m2}");
        }
예제 #2
0
        public void QuaternionFromRotationMatrixWithScaledMatrixTest3()
        {
            float             angle  = MathHelper.ToRadians(180.0f);
            Matrix4X4 <float> matrix = Matrix4X4.CreateRotationX <float>(angle) * Matrix4X4.CreateRotationY <float>(angle);

            Quaternion <float> expected = Quaternion <float> .CreateFromAxisAngle(Vector3D <float> .UnitY, angle) * Quaternion <float> .CreateFromAxisAngle(Vector3D <float> .UnitX, angle);

            Quaternion <float> actual = Quaternion <float> .CreateFromRotationMatrix(matrix);

            Assert.True(MathHelper.EqualRotation(expected, actual),
                        $"Quaternion<float>.CreateFromRotationMatrix did not return the expected value: expected {expected} actual {actual}");

            // make sure convert back to matrix is same as we passed matrix.
            Matrix4X4 <float> m2 = Matrix4X4.CreateFromQuaternion <float>(actual);

            Assert.True(MathHelper.Equal(matrix, m2),
                        $"Quaternion<float>.CreateFromQuaternion did not return the expected value: matrix {matrix} m2 {m2}");
        }
예제 #3
0
        public void QuaternionFromRotationMatrixTest4()
        {
            for (float angle = 0.0f; angle < 720.0f; angle += 10.0f)
            {
                Matrix4X4 <float> matrix = Matrix4X4.CreateRotationZ <float>(angle);

                Quaternion <float> expected = Quaternion <float> .CreateFromAxisAngle(Vector3D <float> .UnitZ, angle);

                Quaternion <float> actual = Quaternion <float> .CreateFromRotationMatrix(matrix);

                Assert.True(MathHelper.EqualRotation(expected, actual),
                            $"Quaternion<float>.CreateFromRotationMatrix angle:{angle} did not return the expected value: expected {expected} actual {actual}");

                // make sure convert back to matrix is same as we passed matrix.
                Matrix4X4 <float> m2 = Matrix4X4.CreateFromQuaternion <float>(actual);
                Assert.True(MathHelper.Equal(matrix, m2),
                            $"Quaternion<float>.CreateFromQuaternion angle:{angle} did not return the expected value: matrix {matrix} m2 {m2}");
            }
        }