Ejemplo n.º 1
0
        public void SetRotationQuaternion()
        {
            var qat = new Quaternion(0.7071067811865476f, 0f, 0f, 0.7071067811865476f);
            var mat = new Matrix4X4();

            mat.SetRotation(qat);
            var expectedValue = new[, ] {
                { 1f, 0f, 0f, 0f },
                { 0f, 0f, -1f, 0f },
                { 0f, 1f, 0f, 0f },
                { 0f, 0f, 0f, 1f },
            };

            mat.AssertValues(expectedValue);


            mat = new Matrix4X4();
            mat.SetRotation(0f, 0f, 90f);
            var expectedResultRotationOnlyMatrix = new[, ] {
                { 0f, -1f, 0f, 0f },
                { 1f, 0f, 0f, 0f },
                { 0f, 0f, 1f, 0f },
                { 0f, 0f, 0f, 1f },
            };

            mat.AssertValues(expectedResultRotationOnlyMatrix);
        }
Ejemplo n.º 2
0
        public void SetRotationEuler()
        {
            var mat = new Matrix4X4();

            mat.SetRotation(90f, 0f, 0f);
            var expectedValue = new[, ] {
                { 1f, 0f, 0f, 0f },
                { 0f, 0f, -1f, 0f },
                { 0f, 1f, 0f, 0f },
                { 0f, 0f, 0f, 1f },
            };

            mat.AssertValues(expectedValue);
            mat = new Matrix4X4();
            mat.SetRotation(0f, 90f, 0f);
            expectedValue = new[, ] {
                { 0f, 0f, 1f, 0f },
                { 0f, 1f, 0f, 0f },
                { -1f, 0f, 0f, 0f },
                { 0f, 0f, 0f, 1f },
            };
            mat.AssertValues(expectedValue);
            mat = new Matrix4X4();
            mat.SetRotation(0f, 0f, 90f);
            expectedValue = new[, ] {
                { 0f, -1f, 0f, 0f },
                { 1f, 0f, 0f, 0f },
                { 0f, 0f, 1f, 0f },
                { 0f, 0f, 0f, 1f },
            };
            mat.AssertValues(expectedValue);
            mat = new Matrix4X4();
            mat.SetRotation(0f, 90f, 90f);
            expectedValue = new[, ] {
                { 0f, 0f, 1f, 0f },
                { 1f, 0f, 0f, 0f },
                { 0f, 1f, 0f, 0f },
                { 0f, 0f, 0f, 1f },
            };
            mat.AssertValues(expectedValue);
            mat = new Matrix4X4();
            mat.SetRotation(0f, 90f, -90f);
            expectedValue = new[, ] {
                { 0f, 0f, 1f, 0f },
                { -1f, 0f, 0f, 0f },
                { 0f, -1f, 0f, 0f },
                { 0f, 0f, 0f, 1f },
            };
            mat.AssertValues(expectedValue);
        }
Ejemplo n.º 3
0
        public void SetRotationAngleAxis()
        {
            var mat = new Matrix4X4();

            mat.SetRotation(90f, new Vector3(1, 0, 0));
            var expectedValue = new[, ] {
                { 1f, 0f, 0f, 0f },
                { 0f, 0f, -1f, 0f },
                { 0f, 1f, 0f, 0f },
                { 0f, 0f, 0f, 1f },
            };

            mat.AssertValues(expectedValue);
        }
Ejemplo n.º 4
0
        public void CompositingMatrix()
        {
            var mat = new Matrix4X4();

            mat.SetRotation(0f, 0f, 90f);
            mat.SetScale(new Vector3(3f, 3f, 3f));
            mat.SetTranslation(new Vector3(20f, 0f, 0f));
            var expectedResultMatrix = new[, ] {
                { 0f, -3f, 0f, 20f },
                { 3f, 0f, 0f, 0f },
                { 0f, 0f, 3f, 0f },
                { 0f, 0f, 0f, 1f },
            };

            mat.AssertValues(expectedResultMatrix);
        }
Ejemplo n.º 5
0
        public void SetScale()
        {
            var mat    = new Matrix4X4();
            var vertex = new Vector3(10, 10, 10);
            var scale  = new Vector3(3, 4, 5);

            mat.SetScale(scale);
            var result = mat.Transform(vertex);

            result.AssertValues(30, 40, 50);

            mat = new Matrix4X4();
            mat.SetScale(new Vector3(3f, 3f, 3f));
            var expectedResultScaleOnlyMatrix = new[, ] {
                { 3f, 0f, 0f, 0f },
                { 0f, 3f, 0f, 0f },
                { 0f, 0f, 3f, 0f },
                { 0f, 0f, 0f, 1f },
            };

            mat.AssertValues(expectedResultScaleOnlyMatrix);
        }
Ejemplo n.º 6
0
        public void SetTranslation()
        {
            var mat               = new Matrix4X4();
            var vertex            = new Vector3(10, 10, 10);
            var translationOffset = new Vector3(3, 4, 5);

            mat.SetTranslation(translationOffset);
            var result = mat.Transform(vertex);

            result.AssertValues(13, 14, 15);

            mat = new Matrix4X4();
            mat.SetTranslation(new Vector3(20f, 0f, 0f));
            var expectedResultTranslationOnlyMatrix = new[, ] {
                { 1f, 0f, 0f, 20f },
                { 0f, 1f, 0f, 0f },
                { 0f, 0f, 1f, 0f },
                { 0f, 0f, 0f, 1f },
            };

            mat.AssertValues(expectedResultTranslationOnlyMatrix);
        }
Ejemplo n.º 7
0
 public static void AssertValues(this Matrix4X4 mat, float[,] val)
 {
     mat.AssertValues(val[0, 0], val[0, 1], val[0, 2], val[0, 3], val[1, 0], val[1, 1], val[1, 2], val[1, 3], val[2, 0], val[2, 1], val[2, 2], val[2, 3], val[3, 0], val[3, 1], val[3, 2], val[3, 3]);
 }