private void CalcVectors(float[] ObjVertexes, int[] ObjTriangles, float[] N) { int num = ObjTriangles.Length / 3; for (int index1 = 0; index1 < num; ++index1) { int index2 = 3 * index1; floatVector floatVector1 = new floatVector(ObjVertexes[3 * ObjTriangles[index2]], ObjVertexes[3 * ObjTriangles[index2] + 1], ObjVertexes[3 * ObjTriangles[index2] + 2]); floatVector floatVector2 = new floatVector(ObjVertexes[3 * ObjTriangles[index2 + 1]], ObjVertexes[3 * ObjTriangles[index2 + 1] + 1], ObjVertexes[3 * ObjTriangles[index2 + 1] + 2]); floatVector floatVector3d = new floatVector(ObjVertexes[3 * ObjTriangles[index2 + 2]], ObjVertexes[3 * ObjTriangles[index2 + 2] + 1], ObjVertexes[3 * ObjTriangles[index2 + 2] + 2]); floatVector v1 = floatVector2 - floatVector1; floatVector v2 = floatVector3d - floatVector1; floatVector floatVector4 = floatVector.CrossProduct(v1, v2); floatVector4.normalize(); v1.normalize(); v2.normalize(); N[index2] = floatVector4.x; N[index2 + 1] = floatVector4.y; N[index2 + 2] = floatVector4.z; } }
private bool RetaCruzaTriangulo(floatVector A, floatVector B, floatVector C, floatVector D, floatVector E) { floatVector floatVector1 = B - A; floatVector floatVector2 = D - C; floatVector floatVector3 = E - C; float num1 = (float)((double)floatVector2.x * (double)floatVector3.y * (double)floatVector1.z - (double)floatVector2.x * (double)floatVector1.y * (double)floatVector3.z - (double)floatVector2.y * (double)floatVector3.x * (double)floatVector1.z + (double)floatVector2.y * (double)floatVector1.x * (double)floatVector3.z + (double)floatVector2.z * (double)floatVector3.x * (double)floatVector1.y - (double)floatVector2.z * (double)floatVector1.x * (double)floatVector3.y); if ((double)num1 == 0.0) { return(false); } float num2 = -1f / num1; float[,] numArray = new float[3, 3] { { (float)(-(double)floatVector3.y * (double)floatVector1.z + (double)floatVector3.z * (double)floatVector1.y), (float)(-(double)floatVector3.z * (double)floatVector1.x + (double)floatVector1.z * (double)floatVector3.x), (float)((double)floatVector3.y * (double)floatVector1.x - (double)floatVector3.x * (double)floatVector1.y) }, { (float)((double)floatVector2.y * (double)floatVector1.z - (double)floatVector2.z * (double)floatVector1.y), (float)((double)floatVector2.z * (double)floatVector1.x - (double)floatVector1.z * (double)floatVector2.x), (float)(-(double)floatVector2.y * (double)floatVector1.x + (double)floatVector2.x * (double)floatVector1.y) }, { (float)((double)floatVector2.y * (double)floatVector3.z - (double)floatVector2.z * (double)floatVector3.y), (float)((double)floatVector2.z * (double)floatVector3.x - (double)floatVector3.z * (double)floatVector2.x), (float)(-(double)floatVector2.y * (double)floatVector3.x + (double)floatVector2.x * (double)floatVector3.y) } }; float num3 = (float)((double)numArray[0, 0] * ((double)A.x - (double)C.x) + (double)numArray[0, 1] * ((double)A.y - (double)C.y) + (double)numArray[0, 2] * ((double)A.z - (double)C.z)); float num4 = (float)((double)numArray[1, 0] * ((double)A.x - (double)C.x) + (double)numArray[1, 1] * ((double)A.y - (double)C.y) + (double)numArray[1, 2] * ((double)A.z - (double)C.z)); float num5 = (float)((double)numArray[2, 0] * ((double)A.x - (double)C.x) + (double)numArray[2, 1] * ((double)A.y - (double)C.y) + (double)numArray[2, 2] * ((double)A.z - (double)C.z)); float num6 = num3 * num2; float num7 = num4 * num2; float num8 = num5 * num2; return(0.0 <= (double)num8 && (double)num8 <= 1.0 && ((double)num6 >= 0.0 && (double)num7 >= 0.0) && (double)num6 + (double)num7 <= 1.0); }
private void CalcExactCollision(float[] Obj1Vertexes, int[] Obj1Triangles, float[] Obj2Vertexes, int[] Obj2Triangles, int[] numCollisions) { int num1 = Obj1Triangles.Length / 3; int num2 = Obj2Triangles.Length / 3; for (int index1 = 0; index1 < num1; ++index1) { for (int index2 = 0; index2 < num2; ++index2) { int index3 = 3 * index1; int index4 = 3 * index2; floatVector floatVector1 = new floatVector(Obj1Vertexes[3 * Obj1Triangles[index3]], Obj1Vertexes[3 * Obj1Triangles[index3] + 1], Obj1Vertexes[3 * Obj1Triangles[index3] + 2]); floatVector floatVector2 = new floatVector(Obj1Vertexes[3 * Obj1Triangles[index3 + 1]], Obj1Vertexes[3 * Obj1Triangles[index3 + 1] + 1], Obj1Vertexes[3 * Obj1Triangles[index3 + 1] + 2]); floatVector floatVector3 = new floatVector(Obj1Vertexes[3 * Obj1Triangles[index3 + 2]], Obj1Vertexes[3 * Obj1Triangles[index3 + 2] + 1], Obj1Vertexes[3 * Obj1Triangles[index3 + 2] + 2]); floatVector floatVector4 = new floatVector(Obj2Vertexes[3 * Obj2Triangles[index4]], Obj2Vertexes[3 * Obj2Triangles[index4] + 1], Obj2Vertexes[3 * Obj2Triangles[index4] + 2]); floatVector floatVector5 = new floatVector(Obj2Vertexes[3 * Obj2Triangles[index4 + 1]], Obj2Vertexes[3 * Obj2Triangles[index4 + 1] + 1], Obj2Vertexes[3 * Obj2Triangles[index4 + 1] + 2]); floatVector floatVector6 = new floatVector(Obj2Vertexes[3 * Obj2Triangles[index4 + 2]], Obj2Vertexes[3 * Obj2Triangles[index4 + 2] + 1], Obj2Vertexes[3 * Obj2Triangles[index4 + 2] + 2]); if (numCollisions[0] <= 0 && this.RetaCruzaTriangulo(floatVector1, floatVector2, floatVector4, floatVector5, floatVector6)) { ++numCollisions[0]; } if (numCollisions[0] <= 0 && this.RetaCruzaTriangulo(floatVector1, floatVector3, floatVector4, floatVector5, floatVector6)) { ++numCollisions[0]; } if (numCollisions[0] <= 0 && this.RetaCruzaTriangulo(floatVector2, floatVector3, floatVector4, floatVector5, floatVector6)) { ++numCollisions[0]; } if (numCollisions[0] <= 0 && this.RetaCruzaTriangulo(floatVector4, floatVector5, floatVector1, floatVector2, floatVector3)) { ++numCollisions[0]; } if (numCollisions[0] <= 0 && this.RetaCruzaTriangulo(floatVector4, floatVector6, floatVector1, floatVector2, floatVector3)) { ++numCollisions[0]; } } } }
private void CalcCollision(float[] CollisionDistance, float[] MovingObjVertexes, float[] ObjVertexes, int[] ObjTriangles, float[] N, int[] MovingObjCollisions, float[] MovingObjDistances) { int num1 = MovingObjVertexes.Length / 3; int num2 = ObjTriangles.Length / 3; for (int index1 = 0; index1 < num1; ++index1) { for (int index2 = 0; index2 < num2; ++index2) { floatVector floatVector1 = new floatVector(MovingObjVertexes[3 * index1], MovingObjVertexes[3 * index1 + 1], MovingObjVertexes[3 * index1 + 2]); int index3 = 3 * index2; floatVector floatVector2 = new floatVector(ObjVertexes[3 * ObjTriangles[index3]], ObjVertexes[3 * ObjTriangles[index3] + 1], ObjVertexes[3 * ObjTriangles[index3] + 2]); floatVector v1 = floatVector1 - floatVector2; floatVector v2 = new floatVector(N[index3], N[index3 + 1], N[index3 + 2]); if ((double)v2.x != 0.0 || (double)v2.y != 0.0 || (double)v2.y != 0.0) { float num3 = floatVector.DotProduct(v1, v2); if ((double)Math.Abs(num3) <= (double)CollisionDistance[0] && MovingObjCollisions[index1] < 0) { floatVector floatVector3d = new floatVector(ObjVertexes[3 * ObjTriangles[index3 + 1]], ObjVertexes[3 * ObjTriangles[index3 + 1] + 1], ObjVertexes[3 * ObjTriangles[index3 + 1] + 2]); floatVector floatVector4 = new floatVector(ObjVertexes[3 * ObjTriangles[index3 + 2]], ObjVertexes[3 * ObjTriangles[index3 + 2] + 1], ObjVertexes[3 * ObjTriangles[index3 + 2] + 2]); floatVector floatVector5 = floatVector3d - floatVector2; floatVector floatVector6 = floatVector4 - floatVector2; floatVector floatVector7 = v1 - -num3 * v2; float num4; float num5; float num6; float num7; float num8; float num9; if ((double)Math.Abs(v2.x) >= (double)Math.Abs(v2.y) && (double)Math.Abs(v2.x) >= (double)Math.Abs(v2.z)) { num4 = floatVector7.z; num5 = floatVector7.y; num6 = floatVector5.z; num7 = floatVector5.y; num8 = floatVector6.z; num9 = floatVector6.y; } else if ((double)Math.Abs(v2.y) >= (double)Math.Abs(v2.x) && (double)Math.Abs(v2.y) >= (double)Math.Abs(v2.z)) { num4 = floatVector7.x; num5 = floatVector7.z; num6 = floatVector5.x; num7 = floatVector5.z; num8 = floatVector6.x; num9 = floatVector6.z; } else { num4 = floatVector7.x; num5 = floatVector7.y; num6 = floatVector5.x; num7 = floatVector5.y; num8 = floatVector6.x; num9 = floatVector6.y; } float num10 = (float)(1.0 / ((double)num6 * (double)num9 - (double)num7 * (double)num8)); float num11 = (float)((double)num9 * (double)num4 - (double)num8 * (double)num5); float num12 = (float)(-(double)num7 * (double)num4 + (double)num6 * (double)num5); float num13 = num11 * num10; float num14 = num12 * num10; if ((double)num13 + (double)num14 <= 1.0 && (double)num13 >= 0.0 && (double)num14 >= 0.0) { MovingObjCollisions[index1] = index2; MovingObjDistances[index1] = num3; } } } if (MovingObjCollisions[index1] >= 0) { index2 = num2; } } } }