/// <summary> /// Registering the interation between 2 rbelement types /// </summary> public void RegisterRBElementInteraction(MyRBElementType type1, MyRBElementType type2, MyRBElementInteraction intr) { int t1 = (int)type1; int t2 = (int)type2; List <MyRBElementInteraction> intrList = null; if (t1 < t2) { intrList = m_IslandsPool[t1, t2]; m_IslandsPoolStatic[t1, t2] = intr.CreateNewInstance(); } else { intrList = m_IslandsPool[t2, t1]; m_IslandsPoolStatic[t2, t1] = intr.CreateNewInstance(); } intrList.Capacity = m_preAllocCount; intrList.Add(intr); for (int i = 1; i < m_preAllocCount; i++) { MyRBElementInteraction ins = intr.CreateNewInstance(); intrList.Add(ins); } }
/// <summary> /// find interaction method from pool /// </summary> public MyRBElementInteraction FindRBElementInteractionForStaticTesting(MyRBElementType type1, MyRBElementType type2) { int t1 = (int)type1; int t2 = (int)type2; MyRBElementInteraction intrList = null; if (t1 < t2) { intrList = m_IslandsPoolStatic[t1, t2]; } else { intrList = m_IslandsPoolStatic[t2, t1]; } return(intrList); }
/// <summary> /// find interaction method from pool /// </summary> public MyRBElementInteraction FindRBElementInteractionForStaticTesting(MyRBElementType type1, MyRBElementType type2) { int t1 = (int)type1; int t2 = (int)type2; MyRBElementInteraction intrList = null; if (t1 < t2) intrList = m_IslandsPoolStatic[t1, t2]; else intrList = m_IslandsPoolStatic[t2, t1]; return intrList; }
/// <summary> /// Registering the interation between 2 rbelement types /// </summary> public void RegisterRBElementInteraction(MyRBElementType type1, MyRBElementType type2, MyRBElementInteraction intr) { int t1 = (int)type1; int t2 = (int)type2; List<MyRBElementInteraction> intrList = null; if (t1 < t2) { intrList = m_IslandsPool[t1, t2]; m_IslandsPoolStatic[t1, t2] = intr.CreateNewInstance(); } else { intrList = m_IslandsPool[t2, t1]; m_IslandsPoolStatic[t2, t1] = intr.CreateNewInstance(); } intrList.Capacity = m_preAllocCount; intrList.Add(intr); for (int i = 1; i < m_preAllocCount; i++) { MyRBElementInteraction ins = intr.CreateNewInstance(); intrList.Add(ins); } }
/// <summary> /// Debug draw of this physics object. /// </summary> public void DebugDraw() { const float alpha = 0.3f; if (!Enabled) { return; } foreach (var primitive in this.rigidBody.GetRBElementList()) { MyRBElementType type = primitive.GetElementType(); switch (type) { case MyRBElementType.ET_BOX: { var box = (MyRBBoxElement)primitive; MyDebugDraw.DrawHiresBoxWireframe( Matrix.CreateScale(box.Size) * box.GetGlobalTransformation(), Color.Green.ToVector3(), alpha); } break; case MyRBElementType.ET_SPHERE: { var sphere = (MyRBSphereElement)primitive; MyDebugDraw.DrawSphereWireframe( Matrix.CreateScale(sphere.Radius) * sphere.GetGlobalTransformation(), Color.Green.ToVector3(), alpha); } break; case MyRBElementType.ET_TRIANGLEMESH: { var triMesh = (MyRBTriangleMeshElement)primitive; var model = triMesh.Model; Matrix transformMatrix = this.rigidBody.Matrix; MyDebugDrawCachedLines.Clear(); // This is just a reserve const int numberOfAddTrianglesInLoop = 3; int triangleIndex = 0; while (true) { //bool finished = triangleIndex >= mesh.GetNumTriangles(); bool finished = triangleIndex >= model.GetTrianglesCount(); if ((MyDebugDrawCachedLines.IsFull(-numberOfAddTrianglesInLoop)) || (finished)) { MyDebugDrawCachedLines.DrawLines(); MyDebugDrawCachedLines.Clear(); } if (finished) { break; } MyTriangleVertexIndices triangle = model.Triangles[triangleIndex]; // We now transform the triangleVertexes into world space (we could keep leave the mesh alone // but at this point 3 vector transforms is probably not a major slow down) Vector3 triVec0 = model.GetVertex(triangle.I0); Vector3 triVec1 = model.GetVertex(triangle.I2); Vector3 triVec2 = model.GetVertex(triangle.I1); // Move triangle into world space Vector3.Transform(ref triVec0, ref transformMatrix, out triVec0); Vector3.Transform(ref triVec1, ref transformMatrix, out triVec1); Vector3.Transform(ref triVec2, ref transformMatrix, out triVec2); MyDebugDrawCachedLines.AddLine(triVec0, triVec1, Color.Green, Color.Green); MyDebugDrawCachedLines.AddLine(triVec1, triVec2, Color.Green, Color.Green); MyDebugDrawCachedLines.AddLine(triVec2, triVec0, Color.Green, Color.Green); /* * MyTriangle_Vertexes tv = new MyTriangle_Vertexes(); * tv.Vertex0 = triVec0; * tv.Vertex1 = triVec1; * tv.Vertex2 = triVec2; * Vector3 calculatedTriangleNormal = MyUtils.GetNormalVectorFromTriangle(ref tv); * Vector3 center = (triVec0 + triVec1 + triVec2)/3.0f; * MyDebugDrawCachedLines.AddLine(center, center + calculatedTriangleNormal * 5, Color.Red, Color.Red); */ //MyDebugDraw.AddDrawTriangle(triVec0, triVec1, triVec2, new Color(0,0.8f, 0, 0.1f)); triangleIndex++; } } break; } } }