public void RotationMatrix() { using (var obj = new SKTransformNode()) { var zero = new MatrixFloat3x3(); obj.RotationMatrix = zero; // In Swift, a rotated zero matrice also becomes the identity matrice. Asserts.AreEqual(MatrixFloat3x3.Identity, obj.RotationMatrix, "RotationMatrix"); // Changing XRotation (or YRotation for that matter), makes the RotationMatrix change too obj.XRotation = (nfloat)(Math.PI / 2); var rotatedMatrix = new MatrixFloat3x3( 1, 0, 0, 0, 0, -1, 0, 1, 0 ); Asserts.AreEqual(rotatedMatrix, obj.RotationMatrix, 0.000001f, "RotationMatrix a"); Asserts.AreEqual(rotatedMatrix, CFunctions.GetMatrixFloat3x3(obj, "rotationMatrix"), 0.000001f, "RotationMatrix native a"); // Got this matrix after setting both XRotation and YRotation to Pi/2 rotatedMatrix = new MatrixFloat3x3( 0, 1, 0, 0, 0, -1, -1, 0, 0 ); obj.RotationMatrix = rotatedMatrix; Asserts.AreEqual(rotatedMatrix, obj.RotationMatrix, 0.000001f, "RotationMatrix b"); Assert.AreEqual((nfloat)(Math.PI / 2), obj.XRotation, 0.000001f, "XRotation b"); Assert.AreEqual(0, obj.YRotation, 0.000001f, "YRotation b"); // Setting YRotation changes RotationMatrix, but setting RotationMatrix doesn't change YRotation. } }
public void RotationTest() { using (var obj = new GKAgent3D()) { var initial = new Matrix3(0, 0, 1, 0, 1, 0, 1, 0, 0); Asserts.AreEqual(initial, obj.Rotation, "Rotation"); Asserts.AreEqual((MatrixFloat3x3)initial, obj.Rotation3x3, "Rotation3x3"); var mat = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); var mat3x3 = (MatrixFloat3x3)mat; obj.Rotation = mat; Asserts.AreEqual(mat, obj.Rotation, "Rotation after setter"); var transposed3x3 = MatrixFloat3x3.Transpose((MatrixFloat3x3)mat); Asserts.AreEqual(transposed3x3, obj.Rotation3x3, "Rotation3x3 after setter"); Asserts.AreEqual(transposed3x3, CFunctions.GetMatrixFloat3x3(obj, "rotation"), "Rotation3x3 after setter native"); obj.Rotation3x3 = mat3x3; Asserts.AreEqual(mat3x3, obj.Rotation3x3, "Rotation3x3 after setter 3x3"); Asserts.AreEqual(mat3x3, CFunctions.GetMatrixFloat3x3(obj, "rotation"), "Rotation3x3 after setter native 3x3"); } }
public void Create() { var M2x2 = new MatrixFloat2x2(1, 2, 3, 4); var M3x3 = new MatrixFloat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9); var M4x4 = new MatrixFloat4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); using (var obj = SKUniform.Create("name", M2x2)) { Asserts.AreEqual(M2x2, obj.MatrixFloat2x2Value, "11 MatrixFloat2x2Value"); Asserts.AreEqual(M2x2, CFunctions.GetMatrixFloat2x2(obj, "matrixFloat2x2Value"), "11b MatrixFloat2x2Value"); var tmp2 = new MatrixFloat2x2(9, 8, 7, 6); obj.MatrixFloat2x2Value = tmp2; Asserts.AreEqual(tmp2, obj.MatrixFloat2x2Value, "11 MatrixFloat2x2Value second"); Asserts.AreEqual(tmp2, CFunctions.GetMatrixFloat2x2(obj, "matrixFloat2x2Value"), "11b MatrixFloat2x2Value second"); } using (var obj = SKUniform.Create("name", M3x3)) { Asserts.AreEqual(M3x3, obj.MatrixFloat3x3Value, "12 MatrixFloat3x3Value"); Asserts.AreEqual(M3x3, CFunctions.GetMatrixFloat3x3(obj, "matrixFloat3x3Value"), "12b MatrixFloat3x3Value"); var tmp3 = new MatrixFloat3x3(9, 8, 7, 6, 5, 4, 3, 2, 1); obj.MatrixFloat3x3Value = tmp3; Asserts.AreEqual(tmp3, obj.MatrixFloat3x3Value, "12 MatrixFloat3x3Value second"); Asserts.AreEqual(tmp3, CFunctions.GetMatrixFloat3x3(obj, "matrixFloat3x3Value"), "12b MatrixFloat3x3Value second"); } using (var obj = SKUniform.Create("name", M4x4)) { Asserts.AreEqual(M4x4, obj.MatrixFloat4x4Value, "13 MatrixFloat4x4Value"); Asserts.AreEqual(M4x4, CFunctions.GetMatrixFloat4x4(obj, "matrixFloat4x4Value"), "13b FloatMatrix4Value"); var tmp4 = new MatrixFloat4x4(9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6); obj.MatrixFloat4x4Value = tmp4; Asserts.AreEqual(tmp4, obj.MatrixFloat4x4Value, "13 MatrixFloat4x4Value second"); Asserts.AreEqual(tmp4, CFunctions.GetMatrixFloat4x4(obj, "matrixFloat4x4Value"), "13b MatrixFloat4x4Value second"); } }
public void ElementConstructor() { var expected = GetTestMatrix(); var actual = new MatrixFloat3x3(expected.R0C0, expected.R0C1, expected.R0C2, expected.R1C0, expected.R1C1, expected.R1C2, expected.R2C0, expected.R2C1, expected.R2C2); Asserts.AreEqual(expected, actual, "ctor 1"); }
public void Identity() { var identity = new MatrixFloat3x3 { R0C0 = 1f, R1C1 = 1f, R2C2 = 1f, }; Asserts.AreEqual(identity, MatrixFloat3x3.Identity, "identity"); Asserts.AreEqual(Matrix3.Identity, MatrixFloat3x3.Identity, "opentk identity"); }
public static void AreEqual(MatrixFloat3x3 expected, Matrix3 actual, string message) { AreEqual(expected.R0C0, actual.R0C0, message + " (R0C0)"); AreEqual(expected.R0C1, actual.R0C1, message + " (R0C1)"); AreEqual(expected.R0C2, actual.R0C2, message + " (R0C2)"); AreEqual(expected.R1C0, actual.R1C0, message + " (R1C0)"); AreEqual(expected.R1C1, actual.R1C1, message + " (R1C1)"); AreEqual(expected.R1C2, actual.R1C2, message + " (R1C2)"); AreEqual(expected.R2C0, actual.R2C0, message + " (R2C0)"); AreEqual(expected.R2C1, actual.R2C1, message + " (R2C1)"); AreEqual(expected.R2C2, actual.R2C2, message + " (R2C2)"); }
public void TransposeStatic_ByRef() { var input = GetTestMatrix(); var inputSimd = (MatrixFloat3x3)input; Matrix3 expected; MatrixFloat3x3 actual; Matrix3.Transpose(ref input, out expected); MatrixFloat3x3.Transpose(ref inputSimd, out actual); Asserts.AreEqual(expected, actual, "transpose out/ref"); }
public void Multiply() { var inputL = GetTestMatrix(); var inputR = GetTestMatrix(); var inputSimdL = (MatrixFloat3x3)inputL; var inputSimdR = (MatrixFloat3x3)inputR; Matrix3 expected; Matrix3.Multiply(ref inputR, ref inputL, out expected); // OpenTK.Matrix3 got left/right mixed up... var actual = MatrixFloat3x3.Multiply(inputSimdL, inputSimdR); Asserts.AreEqual(expected, actual, "multiply"); }
public void ToStringTest() { var actual = new MatrixFloat3x3(1, 2, 3, 4, 5, 6, 7, 8, 9); Assert.AreEqual("(1, 2, 3)\n(4, 5, 6)\n(7, 8, 9)", actual.ToString(), "tostring"); }
public void Ctors() { SKTexture texture; Vector2 V2; Vector3 V3; Vector4 V4; Matrix2 M2; Matrix3 M3; Matrix4 M4; MatrixFloat2x2 M2x2; MatrixFloat3x3 M3x3; MatrixFloat4x4 M4x4; using (var obj = new SKUniform("name")) { var M4Zero = new Matrix4(Vector4.Zero, Vector4.Zero, Vector4.Zero, Vector4.Zero); Assert.AreEqual("name", obj.Name, "1 Name"); Assert.AreEqual(SKUniformType.None, obj.UniformType, "1 UniformType"); Assert.IsNull(obj.TextureValue, "1 TextureValue"); Assert.AreEqual(0.0f, obj.FloatValue, "1 FloatValue"); Asserts.AreEqual(Vector2.Zero, obj.FloatVector2Value, "1 FloatVector2Value"); Asserts.AreEqual(Vector3.Zero, obj.FloatVector3Value, "1 FloatVector3Value"); Asserts.AreEqual(Vector4.Zero, obj.FloatVector4Value, "1 FloatVector4Value"); Asserts.AreEqual(Matrix2.Zero, obj.FloatMatrix2Value, "1 FloatMatrix2Value"); Asserts.AreEqual(Matrix3.Zero, obj.FloatMatrix3Value, "1 FloatMatrix3Value"); Asserts.AreEqual(M4Zero, obj.FloatMatrix4Value, "1 FloatMatrix4Value"); texture = SKTexture.FromImageNamed("basn3p08.png"); V2 = new Vector2(1, 2); V3 = new Vector3(3, 4, 5); V4 = new Vector4(6, 7, 8, 9); M2 = new Matrix2(1, 2, 3, 4); M3 = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); M4 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); M2x2 = (MatrixFloat2x2)M2; M3x3 = (MatrixFloat3x3)M3; M4x4 = (MatrixFloat4x4)M4; obj.TextureValue = texture; Assert.AreEqual(texture, obj.TextureValue, "2 TextureValue"); obj.FloatValue = 0.5f; Assert.AreEqual(0.5f, obj.FloatValue, "2 FloatValue"); obj.FloatVector2Value = V2; Asserts.AreEqual(V2, obj.FloatVector2Value, "2 FloatVector2Value"); obj.FloatVector3Value = V3; Asserts.AreEqual(V3, obj.FloatVector3Value, "2 FloatVector3Value"); obj.FloatVector4Value = V4; Asserts.AreEqual(V4, obj.FloatVector4Value, "2 FloatVector4Value"); obj.FloatMatrix2Value = M2; Asserts.AreEqual(M2, obj.FloatMatrix2Value, "2 FloatMatrix2Value"); obj.FloatMatrix3Value = M3; Asserts.AreEqual(M3, obj.FloatMatrix3Value, "2 FloatMatrix3Value"); obj.FloatMatrix4Value = M4; Asserts.AreEqual(M4, obj.FloatMatrix4Value, "2 FloatMatrix4Value"); } bool hasSimdConstructors = TestRuntime.CheckXcodeVersion(8, 0); using (var obj = new SKUniform("name", texture)) { Assert.AreEqual(texture, obj.TextureValue, "3 TextureValue"); } using (var obj = new SKUniform("name", 3.1415f)) { Assert.AreEqual(3.1415f, obj.FloatValue, "4 FloatValue"); } using (var obj = new SKUniform("name", V2)) { Asserts.AreEqual(V2, obj.FloatVector2Value, "5 FloatVector2Value"); } using (var obj = new SKUniform("name", V3)) { Asserts.AreEqual(V3, obj.FloatVector3Value, "6 FloatVector3Value"); } using (var obj = new SKUniform("name", V4)) { Asserts.AreEqual(V4, obj.FloatVector4Value, "7 FloatVector4Value"); } using (var obj = new SKUniform("name", M2)) { Asserts.AreEqual(M2, obj.FloatMatrix2Value, "8 FloatMatrix2Value"); Asserts.AreEqual(M2, MatrixFloat2x2.Transpose(CFunctions.GetMatrixFloat2x2(obj, "matrixFloat2x2Value")), "8b FloatMatrix2Value"); } using (var obj = new SKUniform("name", M3)) { Asserts.AreEqual(M3, obj.FloatMatrix3Value, "9 FloatMatrix3Value"); Asserts.AreEqual(M3, MatrixFloat3x3.Transpose(CFunctions.GetMatrixFloat3x3(obj, "matrixFloat3x3Value")), "9b FloatMatrix3Value"); } using (var obj = new SKUniform("name", M4)) { Asserts.AreEqual(M4, obj.FloatMatrix4Value, "10 FloatMatrix4Value"); Asserts.AreEqual(M4, MatrixFloat4x4.Transpose(CFunctions.GetMatrixFloat4x4(obj, "matrixFloat4x4Value")), "10b FloatMatrix4Value"); } using (var obj = new SKUniform("name", M2x2)) { Asserts.AreEqual(M2x2, obj.MatrixFloat2x2Value, "11 MatrixFloat2x2Value"); Asserts.AreEqual(M2x2, CFunctions.GetMatrixFloat2x2(obj, "matrixFloat2x2Value"), "11b MatrixFloat2x2Value"); var tmp2 = new MatrixFloat2x2(9, 8, 7, 6); obj.MatrixFloat2x2Value = tmp2; Asserts.AreEqual(tmp2, obj.MatrixFloat2x2Value, "11 MatrixFloat2x2Value second"); Asserts.AreEqual(tmp2, CFunctions.GetMatrixFloat2x2(obj, "matrixFloat2x2Value"), "11b MatrixFloat2x2Value second"); } using (var obj = new SKUniform("name", M3x3)) { Asserts.AreEqual(M3x3, obj.MatrixFloat3x3Value, "12 MatrixFloat3x3Value"); Asserts.AreEqual(M3x3, CFunctions.GetMatrixFloat3x3(obj, "matrixFloat3x3Value"), "12b MatrixFloat3x3Value"); var tmp3 = new MatrixFloat3x3(9, 8, 7, 6, 5, 4, 3, 2, 1); obj.MatrixFloat3x3Value = tmp3; Asserts.AreEqual(tmp3, obj.MatrixFloat3x3Value, "12 MatrixFloat3x3Value second"); Asserts.AreEqual(tmp3, CFunctions.GetMatrixFloat3x3(obj, "matrixFloat3x3Value"), "12b MatrixFloat3x3Value second"); } using (var obj = new SKUniform("name", M4x4)) { Asserts.AreEqual(M4x4, obj.MatrixFloat4x4Value, "13 MatrixFloat4x4Value"); Asserts.AreEqual(M4x4, CFunctions.GetMatrixFloat4x4(obj, "matrixFloat4x4Value"), "13b FloatMatrix4Value"); var tmp4 = new MatrixFloat4x4(9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6); obj.MatrixFloat4x4Value = tmp4; Asserts.AreEqual(tmp4, obj.MatrixFloat4x4Value, "13 MatrixFloat4x4Value second"); Asserts.AreEqual(tmp4, CFunctions.GetMatrixFloat4x4(obj, "matrixFloat4x4Value"), "13b MatrixFloat4x4Value second"); } }