Beispiel #1
0
        public void TestMethods()
        {
            {
                // test identity
                Matrix4x4 managedMatrix = new Matrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
                managedMatrix.SetIdentity();
                Assert.IsTrue(managedMatrix == Matrix4x4.Identity, "Managed matrix fails identity");
            }

            {
                //test zero
                Matrix4x4 managedMatrix = new Matrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
                managedMatrix.SetZero();
                Matrix4x4 zeroMatrix = new Matrix4x4(0, 0, 0, 0,
                                                     0, 0, 0, 0,
                                                     0, 0, 0, 0,
                                                     0, 0, 0, 0);
                Assert.IsTrue(managedMatrix == zeroMatrix, "Managed matrix fails zero");
            }

            {
                //test transpose
                Matrix4x4 managedMatrix = new Matrix4x4(1, 1, 1, 0,
                                                        0, 3, 1, 2,
                                                        2, 3, 1, 0,
                                                        1, 0, 2, 1);
                Matrix4x4 transposedManagedMatrix = new Matrix4x4(1, 0, 2, 1,
                                                                  1, 3, 3, 0,
                                                                  1, 1, 1, 2,
                                                                  0, 2, 0, 1);
                Matrix4x4 transposedMatrix = managedMatrix.GetTransposed();
                Assert.IsTrue(transposedMatrix == transposedManagedMatrix, "Managed matrix fails transpose 1: Expected " + transposedManagedMatrix.ToString() + " Actual :" + transposedManagedMatrix.ToString());
                Assert.IsTrue(transposedManagedMatrix == transposedMatrix, "Managed matrix fails transpose 2");
            }
            {
                //test inversion
                Matrix4x4 matrix4x4 = new Matrix4x4(1, 1, 1, 0,
                                                    0, 3, 1, 2,
                                                    2, 3, 1, 0,
                                                    1, 0, 2, 1);
                //inversed will be
                Matrix4x4 inverseMatrixExpected = new Matrix4x4(-3, -1f / 2, 3f / 2, 1f,
                                                                1f, 1f / 4, -1f / 4, -1f / 2,
                                                                3f, 1f / 4, -5f / 4, -1f / 2,
                                                                -3, 0, 1, 1);

                Matrix4x4 inverseMatrixCalculated = matrix4x4.GetInverted();
                Assert.IsTrue(inverseMatrixCalculated == inverseMatrixExpected, "Matrix4x4 inversion failed : Expected " + inverseMatrixExpected.ToString() + " Actual :" + inverseMatrixCalculated.ToString());

                Matrix44 matrixNative44 = new Matrix44(1, 1, 1, 0,
                                                       0, 3, 1, 2,
                                                       2, 3, 1, 0,
                                                       1, 0, 2, 1);

                //inversed will be
                Matrix44 inverseMatrix44Expected = new Matrix44(-3, -1f / 2, 3f / 2, 1f,
                                                                1f, 1f / 4, -1f / 4, -1f / 2,
                                                                3f, 1f / 4, -5f / 4, -1f / 2,
                                                                -3, 0, 1, 1);

                Matrix44  inverseMatrixNative44Calculated  = matrixNative44.GetInverted();
                Matrix4x4 inverseMatrixManaged44Expected   = inverseMatrix44Expected;
                Matrix4x4 inverseMatrixManaged44Calculated = inverseMatrixNative44Calculated;
                Assert.IsTrue(inverseMatrixManaged44Expected == inverseMatrixManaged44Calculated, "Matrix4x4 inversion failed : Expected " + inverseMatrix44Expected.PrintString() + " Actual :" + inverseMatrixNative44Calculated.PrintString());
            }
            {
                //test Determinant
                Matrix4x4 matrix4x4 = new Matrix4x4(1, 1, 1, 0,
                                                    0, 3, 1, 2,
                                                    2, 3, 1, 0,
                                                    1, 0, 2, 1);

                float    determinant1   = matrix4x4.Determinant();
                Matrix44 nativeMatrix44 = new Matrix44(1, 1, 1, 0,
                                                       0, 3, 1, 2,
                                                       2, 3, 1, 0,
                                                       1, 0, 2, 1);

                float determinant2 = nativeMatrix44.Determinant();
                Assert.IsTrue(determinant1 == determinant2, "Determinants are not equal ");
            }
        }