public void Setup() { if (!TestRuntime.CheckXcodeVersion(7, 0)) { Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+"); } if ( #if !MONOMAC Runtime.Arch == Arch.SIMULATOR && #endif IntPtr.Size == 4) { // There's a bug in the i386 version of objc_msgSend where it doesn't preserve SIMD arguments // when resizing the cache of method selectors for a type. So here we call all selectors we can // find, so that the subsequent tests don't end up producing any cache resize (radar #21630410). object dummy; using (var obj = new MDLTransform(Matrix4.Identity)) { dummy = obj.Matrix; dummy = obj.MaximumTime; dummy = obj.MinimumTime; dummy = obj.Rotation; obj.GetRotation(0); dummy = obj.Scale; obj.GetScale(0); obj.SetIdentity(); obj.SetLocalTransform(Matrix4.Identity); obj.SetRotation(Vector3.Zero, 0); obj.SetScale(Vector3.Zero, 0); obj.SetTranslation(Vector3.Zero, 0); dummy = obj.Translation; obj.GetTranslation(0); } } }
public void Ctors() { Matrix4 id = Matrix4.Identity; var V3 = new Vector3(1, 2, 3); using (var obj = new MDLTransform(id)) { Asserts.AreEqual(Vector3.Zero, obj.Translation, "Translation"); Asserts.AreEqual(Vector3.One, obj.Scale, "Scale"); Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation"); Asserts.AreEqual(id, obj.Matrix, "Matrix"); obj.Translation = V3; Asserts.AreEqual(V3, obj.Translation, "Translation 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Scale = V3; Asserts.AreEqual(V3, obj.Scale, "Scale 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } }
public void GetRotationMatrixTest() { #if NET var matrix = NMatrix4.Identity; #else var matrix = Matrix4.Identity; #endif var V3 = new Vector3(1, 0, 0); using (var obj = new MDLTransform(matrix)) { obj.SetRotation(V3, 0); var expected = new MatrixFloat4x4( 1, 0, 0, 0, 0, (float)Math.Cos(1.0f), (float)-Math.Sin(1.0f), 0, 0, (float)Math.Sin(1.0f), (float)Math.Cos(1.0f), 0, 0, 0, 0, 1 ); #if NET Asserts.AreEqual(expected, obj.GetRotationMatrix(0), 0.00001f, "GetRotationMatrix"); #else Asserts.AreEqual((Matrix4)MatrixFloat4x4.Transpose(expected), obj.GetRotationMatrix(0), 0.00001f, "GetRotationMatrix"); Asserts.AreEqual(expected, obj.GetRotationMatrix4x4(0), 0.00001f, "GetRotationMatrix4x4"); #endif Asserts.AreEqual(expected, CFunctions.MDLTransform_GetRotationMatrix(obj, 0), 0.00001f, "GetRotationMatrix4x4 native"); } }
public void RotationAtTimeTest() { var matrix = Matrix4.Identity; var V3 = new Vector3(1, 2, 3); using (var obj = new MDLTransform(matrix)) { obj.SetRotation(V3, 0); Asserts.AreEqual(V3, obj.GetRotation(0), "RotationAtTime"); } }
public void MatrixTest() { var m4 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); var m4x4 = (MatrixFloat4x4)m4; using (var obj = new MDLTransform()) { // identity Asserts.AreEqual(Matrix4.Identity, obj.Matrix, "Initial identity"); Asserts.AreEqual(MatrixFloat4x4.Identity, obj.GetMatrix4x4(), "Initial identity 4x4"); Asserts.AreEqual(MatrixFloat4x4.Identity, CFunctions.GetMatrixFloat4x4(obj, "matrix"), "Initial identity native"); // translate the transform somewhere obj.SetTranslation(new Vector3(2, 2, 2), 0); // the matrix should now be a translation matrix like this: // 1 0 0 0 2 // 0 1 0 0 2 // 0 0 1 0 2 // 0 0 0 1 0 // but since Matrix4 is transposed when compared to MatrixFloat4x4, we get this: Asserts.AreEqual(new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, 2, 1 ), obj.Matrix, "Translated"); // The 4x4 version is correct: Asserts.AreEqual(new Matrix4( 1, 0, 0, 2, 0, 1, 0, 2, 0, 0, 1, 2, 0, 0, 0, 1 ), obj.GetMatrix4x4(), "Translated 4x4"); // Let's set the matrix to something (different from the identity matrix) obj.Matrix = m4; // And the matrix resets to the identify matrix. Asserts.AreEqual(Matrix4.Identity, obj.Matrix, "After set_Matrix"); // Translate again obj.SetTranslation(new Vector3(3, 3, 3), 0); // Set the matrix using a 4x4 matrix obj.SetMatrix4x4(m4x4); // And we still get the identity matrix back Asserts.AreEqual(MatrixFloat4x4.Identity, obj.GetMatrix4x4(), "After set_Matrix 2"); } }
public void CreateGlobalTransformTest() { Matrix4 m4; MatrixFloat4x4 m4x4; using (var obj = new MDLObject()) { m4 = MDLTransform.CreateGlobalTransform(obj, 0); Asserts.AreEqual((Matrix4)MatrixFloat4x4.Transpose(CFunctions.MDLTransform_CreateGlobalTransform(obj, 0)), m4, "CreateGlobalTransform"); m4x4 = MDLTransform.CreateGlobalTransform4x4(obj, 0); Asserts.AreEqual(CFunctions.MDLTransform_CreateGlobalTransform(obj, 0), m4, "CreateGlobalTransform4x4"); } }
public void Ctors() { Matrix4 id = Matrix4.Identity; var V3 = new Vector3(1, 2, 3); using (var obj = new MDLTransform(id)) { Asserts.AreEqual(Vector3.Zero, obj.Translation, "Translation"); Asserts.AreEqual(Vector3.One, obj.Scale, "Scale"); Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation"); Asserts.AreEqual(id, obj.Matrix, "Matrix"); if (TestRuntime.CheckXcodeVersion(8, 0)) { Asserts.AreEqual(false, obj.ResetsTransform, "ResetsTransform"); } obj.Translation = V3; Asserts.AreEqual(V3, obj.Translation, "Translation 2"); } if (TestRuntime.CheckXcodeVersion(8, 0)) { using (var obj = new MDLTransform(id, true)) { Asserts.AreEqual(Vector3.Zero, obj.Translation, "Translation"); Asserts.AreEqual(Vector3.One, obj.Scale, "Scale"); Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation"); Asserts.AreEqual(id, obj.Matrix, "Matrix"); Asserts.AreEqual(true, obj.ResetsTransform, "ResetsTransform"); obj.Translation = V3; Asserts.AreEqual(V3, obj.Translation, "Translation 2"); } } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Scale = V3; Asserts.AreEqual(V3, obj.Scale, "Scale 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } }
public void TranslationAtTimeTest() { #if NET var matrix = NMatrix4.Identity; #else var matrix = Matrix4.Identity; #endif var V3 = new Vector3(1, 2, 3); using (var obj = new MDLTransform(matrix)) { obj.SetTranslation(V3, 0); Asserts.AreEqual(V3, obj.GetTranslation(0), "TranslationAtTime"); } }
public void MatrixTest() { #if NET var m4 = new NMatrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); #else var m4 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); var m4x4 = (MatrixFloat4x4)m4; #endif using (var obj = new MDLTransform()) { // identity Asserts.AreEqual(Matrix4.Identity, obj.Matrix, "Initial identity"); #if NET Asserts.AreEqual(MatrixFloat4x4.Identity, obj.Matrix, "Initial identity 4x4"); #else Asserts.AreEqual(MatrixFloat4x4.Identity, obj.GetMatrix4x4(), "Initial identity 4x4"); #endif Asserts.AreEqual(MatrixFloat4x4.Identity, CFunctions.GetMatrixFloat4x4(obj, "matrix"), "Initial identity native"); // translate the transform somewhere obj.SetTranslation(new Vector3(2, 2, 2), 0); // the matrix should now be a translation matrix like this: // 1 0 0 0 2 // 0 1 0 0 2 // 0 0 1 0 2 // 0 0 0 1 0 #if !NET // but since Matrix4 is transposed when compared to MatrixFloat4x4, we get this: Asserts.AreEqual(new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, 2, 1 ), obj.Matrix, "Translated"); // The 4x4 version is correct: #endif Asserts.AreEqual(new Matrix4( 1, 0, 0, 2, 0, 1, 0, 2, 0, 0, 1, 2, 0, 0, 0, 1 #if NET ), obj.Matrix, "Translated 4x4");
public void Ctors() { Matrix4 id = Matrix4.Identity; var V3 = new Vector3(1, 2, 3); using (var obj = new MDLTransform(id)) { Asserts.AreEqual(Vector3.Zero, obj.Translation, "Translation"); Asserts.AreEqual(Vector3.One, obj.Scale, "Scale"); Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation"); Asserts.AreEqual(id, obj.Matrix, "Matrix"); if (TestRuntime.CheckXcodeVersion(8, 0)) { Asserts.AreEqual(false, obj.ResetsTransform, "ResetsTransform"); } obj.Translation = V3; Asserts.AreEqual(V3, obj.Translation, "Translation 2"); } if (TestRuntime.CheckXcodeVersion(8, 0)) { using (var obj = new MDLTransform(id, true)) { Asserts.AreEqual(Vector3.Zero, obj.Translation, "Translation"); Asserts.AreEqual(Vector3.One, obj.Scale, "Scale"); Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation"); Asserts.AreEqual(id, obj.Matrix, "Matrix"); Asserts.AreEqual(true, obj.ResetsTransform, "ResetsTransform"); obj.Translation = V3; Asserts.AreEqual(V3, obj.Translation, "Translation 2"); } } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Scale = V3; Asserts.AreEqual(V3, obj.Scale, "Scale 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } using (var obj = new MDLTransform(id)) { V3 *= 2; obj.Rotation = V3; Asserts.AreEqual(V3, obj.Rotation, "Rotation 2"); } var m4 = new Matrix4( 4, 0, 0, 0, 0, 3, 0, 0, 0, 0, 2, 0, 2, 3, 4, 1); using (var obj = new MDLTransform(m4)) { Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation 3"); Asserts.AreEqual(new Vector3(4, 3, 2), obj.Scale, "Scale 3"); Asserts.AreEqual(new Vector3(2, 3, 4), obj.Translation, "Translation 3"); Asserts.AreEqual(m4, obj.Matrix, 0.0001f, "Matrix 3"); } var m4x4 = new MatrixFloat4x4( 4, 0, 0, 2, 0, 3, 0, 3, 0, 0, 2, 4, 0, 0, 0, 1); using (var obj = new MDLTransform(m4x4)) { Asserts.AreEqual(Vector3.Zero, obj.Rotation, "Rotation 4"); Asserts.AreEqual(new Vector3(4, 3, 2), obj.Scale, "Scale 4"); Asserts.AreEqual(new Vector3(2, 3, 4), obj.Translation, "Translation 4"); Asserts.AreEqual(m4x4, obj.GetMatrix4x4(), 0.0001f, "Matrix4x4 4"); Asserts.AreEqual(m4x4, CFunctions.GetMatrixFloat4x4(obj, "matrix"), 0.0001f, "Matrix4x4-native 4"); } }
public void LocalTransformTest() { var m4 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); var m4x4 = (MatrixFloat4x4)m4; using (var obj = new MDLTransform()) { var component = (IMDLTransformComponent)obj; // identity Asserts.AreEqual(Matrix4.Identity, component.GetLocalTransform(0), "Initial identity"); Asserts.AreEqual(MatrixFloat4x4.Identity, component.GetLocalTransform4x4(0), "Initial identity 4x4"); Asserts.AreEqual(MatrixFloat4x4.Identity, CFunctions.MDLTransformComponent_GetLocalTransform(component, 0), "Initial identity native"); // translate the transform somewhere obj.SetTranslation(new Vector3(2, 2, 2), 0); // the local transform should now be a translation matrix like this: // 1 0 0 0 2 // 0 1 0 0 2 // 0 0 1 0 2 // 0 0 0 1 0 // but since Matrix4 is transposed when compared to MatrixFloat4x4, we get this: Asserts.AreEqual(new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, 2, 1 ), component.GetLocalTransform(0), "Translated"); // The 4x4 version is correct: Asserts.AreEqual(new Matrix4( 1, 0, 0, 2, 0, 1, 0, 2, 0, 0, 1, 2, 0, 0, 0, 1 ), component.GetLocalTransform4x4(0), "Translated 4x4"); // Let's set the local transform at time 1 to something (different from the identity matrix) component.SetLocalTransform(m4, 1); // At time 1 the transform matrix is now the identity matrix Asserts.AreEqual(Matrix4.Identity, component.GetLocalTransform(1), "After SetLocalTransform at 1"); // At time 0.5 we get a middle ground Asserts.AreEqual(new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1 ), component.GetLocalTransform(0.5), 0.00001f, "AfterSetLocalTransform at 0.5"); // And at time 0 we still have the translated matrix. Asserts.AreEqual(new Matrix4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 2, 2, 1 ), component.GetLocalTransform(0), 0.00001f, "AfterSetLocalTransform at 0"); // Let's set the local transform at all times component.SetLocalTransform(m4); // And we get the identity matrix back at all times Asserts.AreEqual(Matrix4.Identity, component.GetLocalTransform(0), "Second identity at 0"); Asserts.AreEqual(Matrix4.Identity, component.GetLocalTransform(1), "Second identity at 1"); // Translate again obj.SetTranslation(new Vector3(3, 3, 3), 0); // Set the local transform using a 4x4 matrix component.SetLocalTransform4x4(m4x4, 1); // And at time 0.5 we still get a middle ground // The numbers are different now because the translation matrix was different, // and the matrix is correct because we're checking the 4x4 version. Asserts.AreEqual(new MatrixFloat4x4( 1, 0, 0, 1.5f, 0, 1, 0, 1.5f, 0, 0, 1, 1.5f, 0, 0, 0, 1 ), component.GetLocalTransform4x4(0.5), 0.00001f, "AfterSetLocalTransform4x4 at 0.5"); } }