public void mul(Matrix44 other) { float []result; result = new float[16]; result[0 + 0*4] = Matrix44.vectorDot4(array[0 + 0*4], array[1 + 0*4], array[2 + 0*4], array[3 + 0*4], other.array[0 + 0*4], other.array[0 + 1*4], other.array[0 + 2*4], other.array[0 + 3*4]); result[1 + 0*4] = Matrix44.vectorDot4(array[0 + 0*4], array[1 + 0*4], array[2 + 0*4], array[3 + 0*4], other.array[1 + 0*4], other.array[1 + 1*4], other.array[1 + 2*4], other.array[1 + 3*4]); result[2 + 0*4] = Matrix44.vectorDot4(array[0 + 0*4], array[1 + 0*4], array[2 + 0*4], array[3 + 0*4], other.array[2 + 0*4], other.array[2 + 1*4], other.array[2 + 2*4], other.array[2 + 3*4]); result[3 + 0*4] = Matrix44.vectorDot4(array[0 + 0*4], array[1 + 0*4], array[2 + 0*4], array[3 + 0*4], other.array[3 + 0*4], other.array[3 + 1*4], other.array[3 + 2*4], other.array[3 + 3*4]); result[0 + 1*4] = Matrix44.vectorDot4(array[0 + 1*4], array[1 + 1*4], array[2 + 1*4], array[3 + 1*4], other.array[0 + 0*4], other.array[0 + 1*4], other.array[0 + 2*4], other.array[0 + 3*4]); result[1 + 1*4] = Matrix44.vectorDot4(array[0 + 1*4], array[1 + 1*4], array[2 + 1*4], array[3 + 1*4], other.array[1 + 0*4], other.array[1 + 1*4], other.array[1 + 2*4], other.array[1 + 3*4]); result[2 + 1*4] = Matrix44.vectorDot4(array[0 + 1*4], array[1 + 1*4], array[2 + 1*4], array[3 + 1*4], other.array[2 + 0*4], other.array[2 + 1*4], other.array[2 + 2*4], other.array[2 + 3*4]); result[3 + 1*4] = Matrix44.vectorDot4(array[0 + 1*4], array[1 + 1*4], array[2 + 1*4], array[3 + 1*4], other.array[3 + 0*4], other.array[3 + 1*4], other.array[3 + 2*4], other.array[3 + 3*4]); result[0 + 2*4] = Matrix44.vectorDot4(array[0 + 2*4], array[1 + 2*4], array[2 + 2*4], array[3 + 2*4], other.array[0 + 0*4], other.array[0 + 1*4], other.array[0 + 2*4], other.array[0 + 3*4]); result[1 + 2*4] = Matrix44.vectorDot4(array[0 + 2*4], array[1 + 2*4], array[2 + 2*4], array[3 + 2*4], other.array[1 + 0*4], other.array[1 + 1*4], other.array[1 + 2*4], other.array[1 + 3*4]); result[2 + 2*4] = Matrix44.vectorDot4(array[0 + 2*4], array[1 + 2*4], array[2 + 2*4], array[3 + 2*4], other.array[2 + 0*4], other.array[2 + 1*4], other.array[2 + 2*4], other.array[2 + 3*4]); result[3 + 2*4] = Matrix44.vectorDot4(array[0 + 2*4], array[1 + 2*4], array[2 + 2*4], array[3 + 2*4], other.array[3 + 0*4], other.array[3 + 1*4], other.array[3 + 2*4], other.array[3 + 3*4]); result[0 + 3*4] = Matrix44.vectorDot4(array[0 + 3*4], array[1 + 3*4], array[2 + 3*4], array[3 + 3*4], other.array[0 + 0*4], other.array[0 + 1*4], other.array[0 + 2*4], other.array[0 + 3*4]); result[1 + 3*4] = Matrix44.vectorDot4(array[0 + 3*4], array[1 + 3*4], array[2 + 3*4], array[3 + 3*4], other.array[1 + 0*4], other.array[1 + 1*4], other.array[1 + 2*4], other.array[1 + 3*4]); result[2 + 3*4] = Matrix44.vectorDot4(array[0 + 3*4], array[1 + 3*4], array[2 + 3*4], array[3 + 3*4], other.array[2 + 0*4], other.array[2 + 1*4], other.array[2 + 2*4], other.array[2 + 3*4]); result[3 + 3*4] = Matrix44.vectorDot4(array[0 + 3*4], array[1 + 3*4], array[2 + 3*4], array[3 + 3*4], other.array[3 + 0*4], other.array[3 + 1*4], other.array[3 + 2*4], other.array[3 + 3*4]); array = result; }
public void initialize(System.Windows.Media.Media3D.Matrix3D M_initial, System.Windows.Media.Media3D.Matrix3D M_target) { m1 = matrix3Dto44(M_initial); q1 = Quaternion.CreateFromRotationMatrix(m1); m2 = matrix3Dto44(M_target); q2 = Quaternion.CreateFromRotationMatrix(m2); bezierInterpolation.initialize(M_initial, M_target); }
public static Vector4 Transform(Vector4 v, Matrix44 m) { Vector4 vector4_1 = new Vector4(); for (int index = 0; index < 4; ++index) vector4_1[index] = (float)((double)v[0] * (double)m[0][index] + (double)v[1] * (double)m[1][index] + (double)v[2] * (double)m[2][index] + (double)v[3] * (double)m[3][index]); Vector4 vector4_2; (vector4_2 = vector4_1)[0] = vector4_2[0] / vector4_1[3]; Vector4 vector4_3; (vector4_3 = vector4_1)[1] = vector4_3[1] / vector4_1[3]; Vector4 vector4_4; (vector4_4 = vector4_1)[2] = vector4_4[2] / vector4_1[3]; return vector4_1; }
// Test Operator: Multiplication //-----------------------------------// /// <summary> /// Helper method for testing multiplication. /// </summary> void TestMultiplication (Matrix44 a, Matrix44 b, Matrix44 expected ) { // This test asserts the following: // a * b == expected Matrix44 result_1b; Matrix44.Multiply(ref a, ref b, out result_1b); Assert.That(result_1b, Is.EqualTo(expected)); #if (VARIANTS_ENABLED) var result_1a = a * b; Assert.That(result_1a, Is.EqualTo(expected)); #endif }
public void TestOperator_Negation_i () { Double r = 3432; Double s = -6218; Double t = -3432; Double u = 6218; var a = new Matrix44( r, s, t, u, r, s, t, u, r, s, t, u, r, s, t, u); var b = new Matrix44( u, t, s, r, u, t, s, r, u, t, s, r, u, t, s, r); var c = new Matrix44( t, u, r, s, t, u, r, s, t, u, r, s, t, u, r, s); var d = new Matrix44( s, r, u, t, s, r, u, t, s, r, u, t, s, r, u, t); this.TestNegation(a, c); this.TestNegation(b, d); }
public void TestOperator_Subtraction_iii () { for(Int32 i = 0; i < 100; ++i) { var a = GetNextRandomMatrix44(); var b = GetNextRandomMatrix44(); var expected = new Matrix44( a.R0C0 - b.R0C0, a.R0C1 - b.R0C1, a.R0C2 - b.R0C2, a.R0C3 - b.R0C3, a.R1C0 - b.R1C0, a.R1C1 - b.R1C1, a.R1C2 - b.R1C2, a.R1C3 - b.R1C3, a.R2C0 - b.R2C0, a.R2C1 - b.R2C1, a.R2C2 - b.R2C2, a.R2C3 - b.R2C3, a.R3C0 - b.R3C0, a.R3C1 - b.R3C1, a.R3C2 - b.R3C2, a.R3C3 - b.R3C3 ); this.TestSubtraction(a, b, expected); } }
// Test Operator: Subtraction //--------------------------------------// /// <summary> /// Helper method for testing subtraction. /// </summary> void TestSubtraction (Matrix44 a, Matrix44 b, Matrix44 expected ) { // This test asserts the following: // a - b == expected // b - a == -expected var result_1a = a - b; var result_2a = b - a; Matrix44 result_1b; Matrix44.Subtract(ref a, ref b, out result_1b); Matrix44 result_2b; Matrix44.Subtract(ref b, ref a, out result_2b); Assert.That(result_1a, Is.EqualTo(expected)); Assert.That(result_2a, Is.EqualTo(-expected)); Assert.That(result_1b, Is.EqualTo(expected)); Assert.That(result_2b, Is.EqualTo(-expected)); }
public void TestOperator_Addition_iii () { var i = Matrix44.Identity; var expected = new Matrix44( 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2); this.TestAddition(i, i, expected); }
public void TestOperator_Addition_i () { var a = new Matrix44( 3, - 6, 44, 11, 44, -34, -22, 11, 36, -34, -22, 34, 44, -34, - 3, 12); var b = new Matrix44( - 6, 12, 18, - 3, 44, -34, -22, 11, 44, -54, -34, 11, 34, -54, -22, 11); var expected = new Matrix44( - 3, 6, 62, 8, 88, -68, -44, 22, 80, -88, -56, 45, 78, -88, -25, 23); this.TestAddition(a, b, expected); }
extern private static void ICall_CameraComponent_GetViewProj(CameraComponent self, out Matrix44 viewProj);
private static extern void ICall_Material_SetGlobalMatrix(GlobalShaderMatrix index, ref Matrix44 value);
private Matrix44 CorrectCameraTransform(Matrix44 origin) { origin.Decompose(out var scale, out Matrix44 rotationMatrix, out var translation); var newRotation = rotationMatrix.Rotation * CameraPostRotation; return(Matrix44.CreateRotation(newRotation) * Matrix44.CreateScale(scale) * Matrix44.CreateTranslation(translation)); }
public override bool HandToolAllowIntersection(IGameObject objectToIntersect, Matrix44 testMatrix, bool bThisObjectShifted) { r_internal(_Actor); return(base.HandToolAllowIntersection(objectToIntersect, testMatrix, bThisObjectShifted)); }
public void Execute() { CommandContext c = new CommandContext(); c.MatrixMode(CommandContext.NDSMatrixMode.Position_Vector); while (Offset < Data.Length) { byte cmd = Data[Offset++]; switch (cmd & 0xF) { case 0: //NOP break; case 1: //RET return; case 2: //NODE { byte nodeid = Data[Offset++]; NodeVisible = Data[Offset++] == 1; break; } case 3: //MTX if (!NodeVisible) { Offset++; break; } c.RestoreMatrix(Data[Offset++]); break; case 4: //MAT { if (!NodeVisible) { Offset++; break; } byte matid = Data[Offset++]; MDL0.Model.MaterialSet.Material m = Model.materials.materials[matid]; GL.BindTexture(TextureTarget.Texture2D, matid + 1); //+ texoffset); GL.MatrixMode(MatrixMode.Texture); GL.LoadIdentity(); GL.Scale(1f / m.origWidth, 1f / m.origHeight, 1f); GL.MultMatrix(m.GetMatrix()); c.PolygonAttr(m.polyAttr); uint diff = 0; if ((m.flag & MDL0.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_DIFFUSE) != 0) { diff = m.diffAmb & 0x7FFF; } uint amb = 0x5294; if ((m.flag & MDL0.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_AMBIENT) != 0) { amb = (m.diffAmb >> 16) & 0x7FFF; } uint usevtx = 0; if ((m.diffAmb & 0x8000) != 0 && (m.flag & MDL0.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_VTXCOLOR) != 0) { usevtx = 0x8000; } c.MaterialColor0((uint)(amb << 16 | usevtx | diff)); uint spec = 0; if ((m.flag & MDL0.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_SPECULAR) != 0) { spec = m.specEmi & 0x7FFF; } uint emiss = 0; if ((m.flag & MDL0.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_EMISSION) != 0) { spec = (m.specEmi >> 16) & 0x7FFF; } c.MaterialColor1((uint)(emiss << 16 | m.specEmi & 0x8000 | spec)); GL.MatrixMode(MatrixMode.Modelview); GL.Disable(EnableCap.TextureGenS); GL.Disable(EnableCap.TextureGenT); break; } case 5: //SHP { if (!NodeVisible) { Offset++; break; } c.RunDL(Model.shapes.shape[Data[Offset++]].DL); c.End(); //to prevent errors if the display list is not correctly terminated break; } case 6: //NODEDESC { byte nodeid = Data[Offset++]; byte parentid = Data[Offset++]; byte segmentscale = Data[Offset++]; bool thisnodesegmentscale = (segmentscale & 1) == 1; bool parentnodesegmentscale = (segmentscale >> 1 & 1) == 1; bool MayaScale = thisnodesegmentscale; int StackID = ((cmd >> 5 & 0x1) == 1) ? Data[Offset++] : -1; int RestID = ((cmd >> 6 & 0x1) == 1) ? Data[Offset++] : -1; if (RestID != -1) { c.RestoreMatrix((uint)RestID); } Model.nodes.data[nodeid].ApplyMatrix(c, MayaScale); //c.MultMatrix44(new Matrix44(Model.nodes.data[nodeid].GetMatrix(MayaScale, 1))); if (StackID != -1) { c.StoreMatrix((uint)StackID); } break; } case 7: //BB { byte nodeid = Data[Offset++]; int StackID = ((cmd >> 5 & 0x1) == 1) ? Data[Offset++] : -1; int RestID = ((cmd >> 6 & 0x1) == 1) ? Data[Offset++] : -1; if (RestID != -1) { c.RestoreMatrix((uint)RestID); } float[] proj = new float[16]; GL.GetFloat(GetPName.ModelviewMatrix, proj); Matrix44 m = c.GetCurPosMtx(); m[3, 0] = m[3, 1] = m[3, 2] = 0; Matrix44 mtx = c.GetCurPosMtx(); mtx[0, 0] = proj[0]; mtx[1, 0] = proj[1]; mtx[2, 0] = proj[2]; mtx[0, 1] = proj[4]; mtx[1, 1] = proj[5]; mtx[2, 1] = proj[6]; mtx[0, 2] = proj[8]; mtx[1, 2] = proj[9]; mtx[2, 2] = proj[10]; c.LoadMatrix44(mtx * m); if (StackID != -1) { c.StoreMatrix((uint)StackID); } break; } case 8: //BBY { byte nodeid = Data[Offset++]; int StackID = ((cmd >> 5 & 0x1) == 1) ? Data[Offset++] : -1; int RestID = ((cmd >> 6 & 0x1) == 1) ? Data[Offset++] : -1; if (RestID != -1) { c.RestoreMatrix((uint)RestID); } float[] proj = new float[16]; GL.GetFloat(GetPName.ModelviewMatrix, proj); /* * Matrix33 mtx = new Matrix33(); * mtx[0, 0] = proj[0]; * mtx[2, 0] = proj[2]; * * mtx[0, 1] = proj[4]; * mtx[1, 1] = proj[5]; * mtx[2, 1] = proj[6]; * * mtx[0, 2] = proj[8]; * mtx[2, 2] = proj[10]; * * c.MultMatrix33(mtx);//c.LoadMatrix44(mtx); * */ Matrix44 m = c.GetCurPosMtx(); m[3, 0] = m[3, 1] = m[3, 2] = 0; Matrix44 mtx = c.GetCurPosMtx(); mtx[0, 0] = proj[0]; mtx[2, 0] = proj[2]; mtx[0, 1] = proj[4]; mtx[1, 1] = proj[5]; mtx[2, 1] = proj[6]; mtx[0, 2] = proj[8]; mtx[2, 2] = proj[10]; c.LoadMatrix44(mtx * m); if (StackID != -1) { c.StoreMatrix((uint)StackID); } break; } case 9: //NODEMIX { byte stackid = Data[Offset++]; byte nummatrices = Data[Offset++]; for (int i = 0; i < nummatrices; i++) { byte SrcIdx_N = Data[Offset++]; byte NodeID_N = Data[Offset++]; float Ratio_N = Data[Offset++] / 256f; } break; } case 10: //CALLDL { uint RelAddr = IOUtil.ReadU32LE(Data, Offset); Offset += 4; uint Size = IOUtil.ReadU32LE(Data, Offset); Offset += 4; byte[] DL = new byte[Size]; Array.Copy(Data, Offset - 9 + RelAddr, DL, 0, Size); c.RunDL(DL); break; } case 11: //POSSCALE { if (cmd >> 5 == 0) { c.Scale(new Vector3(Model.info.posScale, Model.info.posScale, Model.info.posScale)); } else { c.Scale(new Vector3(Model.info.invPosScale, Model.info.invPosScale, Model.info.invPosScale)); } break; } case 12: //ENVMAP { byte matid = Data[Offset++]; byte flag = Data[Offset++]; if (NodeVisible) { float[] proj = new float[16]; GL.GetFloat(GetPName.ModelviewMatrix, proj); GL.MatrixMode(MatrixMode.Texture); //Gl.glLoadIdentity(); MDL0.Model.MaterialSet.Material m = Model.materials.materials[matid]; GL.Scale(m.origWidth * 0.5f, m.origHeight * -0.5f, 1); GL.Translate(m.origWidth * 0.5f, m.origHeight * 0.5f, 0); //Gl.glTexCoord2f(m.origWidth * 0.5f, m.origHeight * 0.5f); //Gl.glScalef(m.origWidth, m.origHeight, 1f); if ((m.flag & MDL0.Model.MaterialSet.Material.NNS_G3D_MATFLAG.NNS_G3D_MATFLAG_EFFECTMTX) != 0) { GL.MultMatrix(m.effectMtx); } Matrix44 mvm = new Matrix44(proj); mvm[3, 0] = mvm[3, 1] = mvm[3, 2] = 0; Matrix44 curmtx = c.GetCurPosMtx(); curmtx[3, 0] = curmtx[3, 1] = curmtx[3, 2] = 0; mvm *= curmtx; mvm[12] = 0; mvm[13] = 0; mvm[14] = 0; GL.MultMatrix((float[])mvm); GL.MatrixMode(MatrixMode.Modelview); GL.TexGen(TextureCoordName.S, TextureGenParameter.TextureGenMode, (int)TextureGenMode.SphereMap); GL.TexGen(TextureCoordName.T, TextureGenParameter.TextureGenMode, (int)TextureGenMode.SphereMap); GL.Enable(EnableCap.TextureGenS); GL.Enable(EnableCap.TextureGenT); } break; } case 13: //PRJMAP { byte matid = Data[Offset++]; byte flag = Data[Offset++]; break; } } } }
public void TestOperator_Multiplication_ii () { for(Int32 i = 0; i < 100; ++i) { var a = GetNextRandomMatrix44(); var b = GetNextRandomMatrix44(); var c = new Matrix44( (a.R0C0 * b.R0C0) + (a.R0C1 * b.R1C0) + (a.R0C2 * b.R2C0) + (a.R0C3 * b.R3C0), (a.R0C0 * b.R0C1) + (a.R0C1 * b.R1C1) + (a.R0C2 * b.R2C1) + (a.R0C3 * b.R3C1), (a.R0C0 * b.R0C2) + (a.R0C1 * b.R1C2) + (a.R0C2 * b.R2C2) + (a.R0C3 * b.R3C2), (a.R0C0 * b.R0C3) + (a.R0C1 * b.R1C3) + (a.R0C2 * b.R2C3) + (a.R0C3 * b.R3C3), (a.R1C0 * b.R0C0) + (a.R1C1 * b.R1C0) + (a.R1C2 * b.R2C0) + (a.R1C3 * b.R3C0), (a.R1C0 * b.R0C1) + (a.R1C1 * b.R1C1) + (a.R1C2 * b.R2C1) + (a.R1C3 * b.R3C1), (a.R1C0 * b.R0C2) + (a.R1C1 * b.R1C2) + (a.R1C2 * b.R2C2) + (a.R1C3 * b.R3C2), (a.R1C0 * b.R0C3) + (a.R1C1 * b.R1C3) + (a.R1C2 * b.R2C3) + (a.R1C3 * b.R3C3), (a.R2C0 * b.R0C0) + (a.R2C1 * b.R1C0) + (a.R2C2 * b.R2C0) + (a.R2C3 * b.R3C0), (a.R2C0 * b.R0C1) + (a.R2C1 * b.R1C1) + (a.R2C2 * b.R2C1) + (a.R2C3 * b.R3C1), (a.R2C0 * b.R0C2) + (a.R2C1 * b.R1C2) + (a.R2C2 * b.R2C2) + (a.R2C3 * b.R3C2), (a.R2C0 * b.R0C3) + (a.R2C1 * b.R1C3) + (a.R2C2 * b.R2C3) + (a.R2C3 * b.R3C3), (a.R3C0 * b.R0C0) + (a.R3C1 * b.R1C0) + (a.R3C2 * b.R2C0) + (a.R3C3 * b.R3C0), (a.R3C0 * b.R0C1) + (a.R3C1 * b.R1C1) + (a.R3C2 * b.R2C1) + (a.R3C3 * b.R3C1), (a.R3C0 * b.R0C2) + (a.R3C1 * b.R1C2) + (a.R3C2 * b.R2C2) + (a.R3C3 * b.R3C2), (a.R3C0 * b.R0C3) + (a.R3C1 * b.R1C3) + (a.R3C2 * b.R2C3) + (a.R3C3 * b.R3C3)); this.TestMultiplication(a, b, c); } }
internal void Render(Graphics zGfx, String pass, Matrix44 zView, Matrix44 zProjection) { if (!passState.ContainsKey (pass)) return; zGfx.SetCullMode (CullMode.None); zGfx.SetActive ((VertexBuffer)null); zGfx.SetActive ((IndexBuffer)null); zGfx.SetActive ((Texture)null, 0); shader.SetVariable ("View", zView); shader.SetVariable ("Projection", zProjection); zGfx.SetActive (shader, VertexPositionTextureColour.Default.VertexDeclaration); _render_batch(zGfx, pass); }
private static extern void ICall_Material_SetValueMatrix44(MaterialInstance self, String paramName, ref Matrix44 value);
// Test Operator: Addition //-----------------------------------------// /// <summary> /// Helper method for testing addition. /// </summary> void TestAddition (Matrix44 a, Matrix44 b, Matrix44 expected ) { // This test asserts the following: // a + b == expected // b + a == expected var result_1a = a + b; var result_2a = b + a; Matrix44 result_1b; Matrix44.Add(ref a, ref b, out result_1b); Matrix44 result_2b; Matrix44.Add(ref b, ref a, out result_2b); Assert.That(result_1a, Is.EqualTo(expected)); Assert.That(result_2a, Is.EqualTo(expected)); Assert.That(result_1b, Is.EqualTo(expected)); Assert.That(result_2b, Is.EqualTo(expected)); }
/// <summary> /// Helper to encapsulate asserting that two Matrix44s are equal. /// </summary> internal static void AssertEqualWithinReason (Matrix44 a, Matrix44 b) { Double tolerance; MathsTests.TestTolerance(out tolerance); Assert.That(a.R0C0, Is.EqualTo(b.R0C0).Within(tolerance)); Assert.That(a.R0C1, Is.EqualTo(b.R0C1).Within(tolerance)); Assert.That(a.R0C2, Is.EqualTo(b.R0C2).Within(tolerance)); Assert.That(a.R0C3, Is.EqualTo(b.R0C3).Within(tolerance)); Assert.That(a.R1C0, Is.EqualTo(b.R1C0).Within(tolerance)); Assert.That(a.R1C1, Is.EqualTo(b.R1C1).Within(tolerance)); Assert.That(a.R1C2, Is.EqualTo(b.R1C2).Within(tolerance)); Assert.That(a.R1C3, Is.EqualTo(b.R1C3).Within(tolerance)); Assert.That(a.R2C0, Is.EqualTo(b.R2C0).Within(tolerance)); Assert.That(a.R2C1, Is.EqualTo(b.R2C1).Within(tolerance)); Assert.That(a.R2C2, Is.EqualTo(b.R2C2).Within(tolerance)); Assert.That(a.R2C3, Is.EqualTo(b.R2C3).Within(tolerance)); Assert.That(a.R3C0, Is.EqualTo(b.R3C0).Within(tolerance)); Assert.That(a.R3C1, Is.EqualTo(b.R3C1).Within(tolerance)); Assert.That(a.R3C2, Is.EqualTo(b.R3C2).Within(tolerance)); Assert.That(a.R3C3, Is.EqualTo(b.R3C3).Within(tolerance)); }
public void TestOperator_Addition_ii () { var a = new Matrix44( 3, - 6, 44, 11, 44, -34, -22, 11, 36, -34, -22, 34, 44, -34, - 3, 12); var expected = a; expected.R0C0++; expected.R1C1++; expected.R2C2++; expected.R3C3++; this.TestAddition(a, Matrix44.Identity, expected); }
public void Test_Constructors () { { // Test default values Matrix44 a = new Matrix44(); Assert.That(a, Is.EqualTo(Matrix44.Zero)); } { Double a = -18759; Double b = 345; Double c = 774; Double d = -3431; Double e = -55; Double f = 47; Double g = 45; Double h = 3461; Double i = -4; Double j = 453; Double k = -3; Double l = -3441; Double m = -189; Double n = 5; Double o = -87; Double p = 341; Matrix44 expected = new Matrix44( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p); Assert.That(expected.R0C0, Is.EqualTo(a)); Assert.That(expected.R0C1, Is.EqualTo(b)); Assert.That(expected.R0C2, Is.EqualTo(c)); Assert.That(expected.R0C3, Is.EqualTo(d)); Assert.That(expected.R1C0, Is.EqualTo(e)); Assert.That(expected.R1C1, Is.EqualTo(f)); Assert.That(expected.R1C2, Is.EqualTo(g)); Assert.That(expected.R1C3, Is.EqualTo(h)); Assert.That(expected.R2C0, Is.EqualTo(i)); Assert.That(expected.R2C1, Is.EqualTo(j)); Assert.That(expected.R2C2, Is.EqualTo(k)); Assert.That(expected.R2C3, Is.EqualTo(l)); Assert.That(expected.R3C0, Is.EqualTo(m)); Assert.That(expected.R3C1, Is.EqualTo(n)); Assert.That(expected.R3C2, Is.EqualTo(o)); Assert.That(expected.R3C3, Is.EqualTo(p)); } }
public void TestOperator_Addition_iv () { for(Int32 i = 0; i < 100; ++i) { var a = GetNextRandomMatrix44(); var b = GetNextRandomMatrix44(); var expected = new Matrix44( a.R0C0 + b.R0C0, a.R0C1 + b.R0C1, a.R0C2 + b.R0C2, a.R0C3 + b.R0C3, a.R1C0 + b.R1C0, a.R1C1 + b.R1C1, a.R1C2 + b.R1C2, a.R1C3 + b.R1C3, a.R2C0 + b.R2C0, a.R2C1 + b.R2C1, a.R2C2 + b.R2C2, a.R2C3 + b.R2C3, a.R3C0 + b.R3C0, a.R3C1 + b.R3C1, a.R3C2 + b.R3C2, a.R3C3 + b.R3C3 ); this.TestAddition(a, b, expected); } }
public void TestMemberFn_ToString () { Matrix44 a = new Matrix44( 42, -17, 13, -44, 46, -23, -22, 90, 34, -21, 52, 33, 88, -12, -78, 50); String result = a.ToString(); String expected = "{ " + "{R0C0:42 R0C1:-17 R0C2:13 R0C3:-44} " + "{R1C0:46 R1C1:-23 R1C2:-22 R1C3:90} " + "{R2C0:34 R2C1:-21 R2C2:52 R2C3:33} " + "{R3C0:88 R3C1:-12 R3C2:-78 R3C3:50} " + "}"; Assert.That(result, Is.EqualTo(expected)); }
public void TestOperator_Subtraction_i () { var a = new Matrix44( 12, -4, 14, 18, 44, -6, -2, -11, 34, 54, 4, 5, 4, -6, 2, 2); var b = new Matrix44( 15, 11, 7, 27, 4, 1, -4, 11, 3, 21, -22, 19, 6, -5, 23, 11); var expected = new Matrix44( -3, -15, 7, -9, 40, -7, 2, -22, 31, 33, 26, -14, -2, -1, -21, -9); this.TestSubtraction(a, b, expected); var c = new Matrix44( -423, 342, 7, -800, 44, -54, -22, 11, 44, -54, -22, 11, 44, -54, -22, 11); this.TestSubtraction(c, Matrix44.Zero, c); }
public void TestConstant_Identity_i () { Matrix44 result = Matrix44.Identity; Matrix44 expected = new Matrix44 ( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); AssertEqualWithinReason(result, expected); } [Test]
// Test Operator: Negation //-----------------------------------------// /// <summary> /// Helper method for testing negation. /// </summary> void TestNegation (Matrix44 a, Matrix44 expected ) { // This test asserts the following: // -a == expected var result_1a = -a; Matrix44 result_1b; Matrix44.Negate(ref a, out result_1b); Assert.That(result_1a, Is.EqualTo(expected)); Assert.That(result_1b, Is.EqualTo(expected)); }
public void TestStaticFn_CreateFromQuaternion_i () { Double yaw; Maths.Pi(out yaw); yaw /= (Double) 4; Double pitch; Maths.Pi(out pitch); pitch /= (Double) (-8); Double roll; Maths.Pi(out roll); roll /= (Double) 2; Quaternion q; Quaternion.CreateFromYawPitchRoll(ref yaw, ref pitch, ref roll, out q); q.Normalise(); Matrix44 m; Matrix44.CreateFromQuaternion(ref q, out m); Matrix44 expected = new Matrix44 (); expected.R0C0 = (Double) (-0.270598); expected.R0C1 = (Double) 0.9238795; expected.R0C2 = (Double) (-0.270598); expected.R0C3 = 0; expected.R1C0 = (Double) (-0.7071067); expected.R1C1 = 0; expected.R1C2 = (Double) 0.7071067; expected.R1C3 = 0; expected.R2C0 = (Double) 0.6532815; expected.R2C1 = (Double) 0.3826834; expected.R2C2 = (Double) 0.6532815; expected.R2C3 = 0; expected.R3C0 = 0; expected.R3C1 = 0; expected.R3C2 = 0; expected.R3C3 = 1; AssertEqualWithinReason (m, expected); }
public void TestOperator_Negation_ii () { Double t = -3432; Double u = 6218; Double r = 3432; Double s = -6218; var c = new Matrix44( t, u, r, s, r, s, t, u, r, s, t, u, r, s, t, u); var d = new Matrix44( s, r, u, t, r, s, t, u, r, s, t, u, r, s, t, u); this.TestNegation(c, Matrix44.Zero - c); this.TestNegation(d, Matrix44.Zero - d); }
public void TestStaticFn_CreateFromQuaternion_ii () { Quaternion q = new Quaternion ( (Double) (-0.163863438188094), (Double) (0.7106071968472370), (Double) (0.6722283804612080), (Double) (-0.127652614217613)); Matrix44 m; Matrix44.CreateFromQuaternion(ref q, out m); Matrix44 expected = new Matrix44 (); expected.R0C0 = (Double) (-0.9137071674171720); expected.R0C1 = (Double) (-0.4045084971874740); expected.R0C2 = (Double) (-0.0388855746211755); expected.R0C3 = 0; expected.R1C0 = (Double) (-0.0612616567188929); expected.R1C1 = (Double) (0.0425155562553572); expected.R1C2 = (Double) (0.9972158426801860); expected.R1C3 = 0; expected.R2C0 = (Double) (-0.4017290400587740); expected.R2C1 = (Double) (0.9135454576426010); expected.R2C2 = (Double) (-0.0636276291718221); expected.R2C3 = 0; expected.R3C0 = 0; expected.R3C1 = 0; expected.R3C2 = 0; expected.R3C3 = 1; AssertEqualWithinReason (m, expected); }
public void TestOperator_Multiplication_i () { var a = new Matrix44(); a.R0C0 = -27; a.R0C1 = 36; a.R0C2 = 9; a.R0C3 = -54; a.R1C0 = 36; a.R1C1 = 3; a.R1C2 = 9; a.R1C3 = 9; a.R2C0 = 9; a.R2C1 = 9; a.R2C2 = -36; a.R2C3 = 6; a.R3C0 = -24; a.R3C1 = 9; a.R3C2 = 36; a.R3C3 = -12; var b = new Matrix44(); b.R0C0 = 3402; b.R0C1 = -1269; b.R0C2 = -2187; b.R0C3 = 2484; b.R1C0 = -999; b.R1C1 = 1467; b.R1C2 = 351; b.R1C3 = -1971; b.R2C0 = -387; b.R2C1 = 81; b.R2C2 = 1674; b.R2C3 = -693; b.R3C0 = 1584; b.R3C1 = -621; b.R3C2 = -1863; b.R3C3 = 1737; this.TestMultiplication(a, a, b); }
public void TestStaticFn_Transpose_i () { Matrix44 startMatrix = new Matrix44( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); Matrix44 testMatrix = startMatrix; Matrix44 testMatrixExpectedTranspose = new Matrix44( 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15); // RUN THE STATIC VERSION OF THE FUNCTION Matrix44 resultMatrix = Matrix44.Identity; Matrix44.Transpose(ref testMatrix, out resultMatrix); Assert.That(resultMatrix, Is.EqualTo(testMatrixExpectedTranspose)); }
void CalculateTransforms() { Matrix44 scale = Matrix44.CreateScale(Configuration.SpriteSpaceScale); Quaternion q = Configuration.SpriteSpaceOrientation; Matrix44 rotation; Matrix44.CreateFromQuaternion( ref q, out rotation); // defines how to move from world space to sprite space. spriteSpaceMatrix = rotation * scale; Matrix44.Invert(ref spriteSpaceMatrix, out inverseSpriteSpaceMatrix); }
// Test Operator: Equality //-----------------------------------------// /// <summary> /// Helper method for testing equality. /// </summary> void TestEquality (Matrix44 a, Matrix44 b, Boolean expected ) { // This test asserts the following: // (a == b) == expected // (b == a) == expected // (a != b) == !expected // (b != a) == !expected Boolean result_1a = (a == b); Boolean result_1b = (a.Equals(b)); Boolean result_1c = (a.Equals((Object)b)); Boolean result_2a = (b == a); Boolean result_2b = (b.Equals(a)); Boolean result_2c = (b.Equals((Object)a)); Boolean result_3a = (a != b); Boolean result_4a = (b != a); Assert.That(result_1a, Is.EqualTo(expected)); Assert.That(result_1b, Is.EqualTo(expected)); Assert.That(result_1c, Is.EqualTo(expected)); Assert.That(result_2a, Is.EqualTo(expected)); Assert.That(result_2b, Is.EqualTo(expected)); Assert.That(result_2c, Is.EqualTo(expected)); Assert.That(result_3a, Is.EqualTo(!expected)); Assert.That(result_4a, Is.EqualTo(!expected)); }
public void TestOperator_Equality_ii () { var a = new Matrix44(44, 54, 2, 11, 44, -54, -22, 11, 44, -54, -22, 11, 44, -54, -22, 11); var b = new Matrix44(44, -54, 2, -1, 44, -54, -22, 11, 44, -54, -22, 11, 44, -54, -22, 11); Boolean expected = false; this.TestEquality(a, b, expected); }
extern private static void ICall_CameraComponent_GetViewTransForm(CameraComponent self, out Matrix44 view);