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."); }
static Matrix3x2 GenerateTestMatrix() { Matrix3x2 m = Matrix3x2.CreateRotation(MathHelper.ToRadians(30.0f)); m.Translation = new Vector2(111.0f, 222.0f); return(m); }
public void Matrix3x2CreateRotationRightAngleTest() { // 90 degree rotations must be exact! Matrix3x2 actual = Matrix3x2.CreateRotation(0); Assert.Equal(new Matrix3x2(1, 0, 0, 1, 0, 0), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi / 2); Assert.Equal(new Matrix3x2(0, 1, -1, 0, 0, 0), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi); Assert.Equal(new Matrix3x2(-1, 0, 0, -1, 0, 0), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi * 3 / 2); Assert.Equal(new Matrix3x2(0, -1, 1, 0, 0, 0), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi * 2); Assert.Equal(new Matrix3x2(1, 0, 0, 1, 0, 0), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi * 5 / 2); Assert.Equal(new Matrix3x2(0, 1, -1, 0, 0, 0), actual); actual = Matrix3x2.CreateRotation(-MathHelper.Pi / 2); Assert.Equal(new Matrix3x2(0, -1, 1, 0, 0, 0), actual); // But merely close-to-90 rotations should not be excessively clamped. Single delta = MathHelper.ToRadians(0.01f); actual = Matrix3x2.CreateRotation(MathHelper.Pi + delta); Assert.False(MathHelper.Equal(new Matrix3x2(-1, 0, 0, -1, 0, 0), actual)); actual = Matrix3x2.CreateRotation(MathHelper.Pi - delta); Assert.False(MathHelper.Equal(new Matrix3x2(-1, 0, 0, -1, 0, 0), actual)); }
public void Matrix3x2DeterminantTest() { Matrix3x2 target = Matrix3x2.CreateRotation(MathHelper.ToRadians(30.0f)); Single val = 1.0f; Single det = target.GetDeterminant(); Assert.True(MathHelper.Equal(val, det), "Matrix3x2.Determinant was not set correctly."); }
public void Matrix3x2InvertRotationTest() { Matrix3x2 mtx = Matrix3x2.CreateRotation(2); Matrix3x2 actual; Assert.True(Matrix3x2.Invert(mtx, out actual)); Matrix3x2 i = mtx * actual; Assert.True(MathHelper.Equal(i, Matrix3x2.Identity)); }
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)); }
public void Vector2TransformNormal3x2Test() { Vector2 v = new Vector2(1.0f, 2.0f); Matrix3x2 m = Matrix3x2.CreateRotation(MathHelper.ToRadians(30.0f)); m.M31 = 10.0f; m.M32 = 20.0f; Vector2 expected = new Vector2(-0.133974612f, 2.232051f); Vector2 actual; actual = Vector2.TransformNormal(v, m); Assert.True(MathHelper.Equal(expected, actual), "Vector2f.Transform did not return the expected value."); }
public void Matrix3x2CreateRotationCenterTest() { Single radians = MathHelper.ToRadians(30.0f); Vector2 center = new Vector2(23, 42); Matrix3x2 rotateAroundZero = Matrix3x2.CreateRotation(radians, Vector2.Zero); Matrix3x2 rotateAroundZeroExpected = Matrix3x2.CreateRotation(radians); Assert.True(MathHelper.Equal(rotateAroundZero, rotateAroundZeroExpected)); Matrix3x2 rotateAroundCenter = Matrix3x2.CreateRotation(radians, center); Matrix3x2 rotateAroundCenterExpected = Matrix3x2.CreateTranslation(-center) * Matrix3x2.CreateRotation(radians) * Matrix3x2.CreateTranslation(center); Assert.True(MathHelper.Equal(rotateAroundCenter, rotateAroundCenterExpected)); }
public void Matrix3x2CreateRotationTest() { Single radians = MathHelper.ToRadians(50.0f); Matrix3x2 expected = new Matrix3x2(); expected.M11 = 0.642787635f; expected.M12 = 0.766044438f; expected.M21 = -0.766044438f; expected.M22 = 0.642787635f; Matrix3x2 actual; actual = Matrix3x2.CreateRotation(radians); Assert.True(MathHelper.Equal(expected, actual), "Matrix3x2.CreateRotation did not return the expected value."); }
public void Matrix3x2InvertTest() { Matrix3x2 mtx = Matrix3x2.CreateRotation(MathHelper.ToRadians(30.0f)); Matrix3x2 expected = new Matrix3x2(); expected.M11 = 0.8660254f; expected.M12 = -0.5f; expected.M21 = 0.5f; expected.M22 = 0.8660254f; expected.M31 = 0; expected.M32 = 0; Matrix3x2 actual; Assert.True(Matrix3x2.Invert(mtx, out actual)); Assert.True(MathHelper.Equal(expected, actual), "Matrix3x2.Invert did not return the expected value."); Matrix3x2 i = mtx * actual; Assert.True(MathHelper.Equal(i, Matrix3x2.Identity), "Matrix3x2.Invert did not return the expected value."); }
public void Matrix3x2CreateRotationRightAngleCenterTest() { Vector2 center = new Vector2(3, 7); // 90 degree rotations must be exact! Matrix3x2 actual = Matrix3x2.CreateRotation(0, center); Assert.Equal(new Matrix3x2(1, 0, 0, 1, 0, 0), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi / 2, center); Assert.Equal(new Matrix3x2(0, 1, -1, 0, 10, 4), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi, center); Assert.Equal(new Matrix3x2(-1, 0, 0, -1, 6, 14), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi * 3 / 2, center); Assert.Equal(new Matrix3x2(0, -1, 1, 0, -4, 10), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi * 2, center); Assert.Equal(new Matrix3x2(1, 0, 0, 1, 0, 0), actual); actual = Matrix3x2.CreateRotation(MathHelper.Pi * 5 / 2, center); Assert.Equal(new Matrix3x2(0, 1, -1, 0, 10, 4), actual); actual = Matrix3x2.CreateRotation(-MathHelper.Pi / 2, center); Assert.Equal(new Matrix3x2(0, -1, 1, 0, -4, 10), actual); // But merely close-to-90 rotations should not be excessively clamped. Single delta = MathHelper.ToRadians(0.01f); actual = Matrix3x2.CreateRotation(MathHelper.Pi + delta, center); Assert.False(MathHelper.Equal(new Matrix3x2(-1, 0, 0, -1, 6, 14), actual)); actual = Matrix3x2.CreateRotation(MathHelper.Pi - delta, center); Assert.False(MathHelper.Equal(new Matrix3x2(-1, 0, 0, -1, 6, 14), actual)); }