Beispiel #1
0
        public void Matrix3x2MultiplyTest3()
        {
            Matrix3x2 a = GenerateMatrixNumberFrom1To6();
            Matrix3x2 b = GenerateMatrixNumberFrom1To6();

            Matrix3x2 expected = new Matrix3x2();

            expected.M11 = a.M11 * b.M11 + a.M12 * b.M21;
            expected.M12 = a.M11 * b.M12 + a.M12 * b.M22;

            expected.M21 = a.M21 * b.M11 + a.M22 * b.M21;
            expected.M22 = a.M21 * b.M12 + a.M22 * b.M22;

            expected.M31 = a.M31 * b.M11 + a.M32 * b.M21 + b.M31;
            expected.M32 = a.M31 * b.M12 + a.M32 * b.M22 + b.M32;
            Matrix3x2 actual;

            actual = Matrix3x2.Multiply(a, b);

            Assert.Equal(expected, actual);

            // Sanity check by comparison with 4x4 multiply.
            a = Matrix3x2.CreateRotation(MathHelper.ToRadians(30)) * Matrix3x2.CreateTranslation(23, 42);
            b = Matrix3x2.CreateScale(3, 7) * Matrix3x2.CreateTranslation(666, -1);

            actual = Matrix3x2.Multiply(a, b);

            Matrix4x4 a44        = new Matrix4x4(a);
            Matrix4x4 b44        = new Matrix4x4(b);
            Matrix4x4 expected44 = Matrix4x4.Multiply(a44, b44);
            Matrix4x4 actual44   = new Matrix4x4(actual);

            Assert.True(MathHelper.Equal(expected44, actual44), "Matrix3x2.Multiply did not return the expected value.");
        }
Beispiel #2
0
        public void Matrix3x2CreateScaleTest2()
        {
            Single    scale    = 2.0f;
            Matrix3x2 expected = new Matrix3x2(
                2.0f, 0.0f,
                0.0f, 2.0f,
                0.0f, 0.0f);
            Matrix3x2 actual = Matrix3x2.CreateScale(scale);

            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void Matrix3x2CreateScaleTest1()
        {
            Vector2   scales   = new Vector2(2.0f, 3.0f);
            Matrix3x2 expected = new Matrix3x2(
                2.0f, 0.0f,
                0.0f, 3.0f,
                0.0f, 0.0f);
            Matrix3x2 actual = Matrix3x2.CreateScale(scales);

            Assert.Equal(expected, actual);
        }
Beispiel #4
0
        public void Matrix3x2CreateScaleTest3()
        {
            Single    xScale   = 2.0f;
            Single    yScale   = 3.0f;
            Matrix3x2 expected = new Matrix3x2(
                2.0f, 0.0f,
                0.0f, 3.0f,
                0.0f, 0.0f);
            Matrix3x2 actual = Matrix3x2.CreateScale(xScale, yScale);

            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public void Matrix3x2InvertScaleTest()
        {
            Matrix3x2 mtx = Matrix3x2.CreateScale(23, -42);

            Matrix3x2 actual;

            Assert.True(Matrix3x2.Invert(mtx, out actual));

            Matrix3x2 i = mtx * actual;

            Assert.True(MathHelper.Equal(i, Matrix3x2.Identity));
        }
Beispiel #6
0
        public void Matrix3x2InvertAffineTest()
        {
            Matrix3x2 mtx = Matrix3x2.CreateRotation(2) *
                            Matrix3x2.CreateScale(23, -42) *
                            Matrix3x2.CreateTranslation(17, 53);

            Matrix3x2 actual;

            Assert.True(Matrix3x2.Invert(mtx, out actual));

            Matrix3x2 i = mtx * actual;

            Assert.True(MathHelper.Equal(i, Matrix3x2.Identity));
        }
Beispiel #7
0
        public void Matrix3x2CreateScaleCenterTest3()
        {
            Vector2 scale  = new Vector2(3, 4);
            Vector2 center = new Vector2(23, 42);

            Matrix3x2 scaleAroundZero         = Matrix3x2.CreateScale(scale.X, scale.Y, Vector2.Zero);
            Matrix3x2 scaleAroundZeroExpected = Matrix3x2.CreateScale(scale.X, scale.Y);

            Assert.True(MathHelper.Equal(scaleAroundZero, scaleAroundZeroExpected));

            Matrix3x2 scaleAroundCenter         = Matrix3x2.CreateScale(scale.X, scale.Y, center);
            Matrix3x2 scaleAroundCenterExpected = Matrix3x2.CreateTranslation(-center) * Matrix3x2.CreateScale(scale.X, scale.Y) * Matrix3x2.CreateTranslation(center);

            Assert.True(MathHelper.Equal(scaleAroundCenter, scaleAroundCenterExpected));
        }
Beispiel #8
0
        public void Matrix3x2CreateScaleCenterTest2()
        {
            Single  scale  = 5;
            Vector2 center = new Vector2(23, 42);

            Matrix3x2 scaleAroundZero         = Matrix3x2.CreateScale(scale, Vector2.Zero);
            Matrix3x2 scaleAroundZeroExpected = Matrix3x2.CreateScale(scale);

            Assert.True(MathHelper.Equal(scaleAroundZero, scaleAroundZeroExpected));

            Matrix3x2 scaleAroundCenter         = Matrix3x2.CreateScale(scale, center);
            Matrix3x2 scaleAroundCenterExpected = Matrix3x2.CreateTranslation(-center) * Matrix3x2.CreateScale(scale) * Matrix3x2.CreateTranslation(center);

            Assert.True(MathHelper.Equal(scaleAroundCenter, scaleAroundCenterExpected));
        }