Esempio n. 1
0
 public bool DetectCollisions(CollisionDetector.CollisionObject Obj1, CollisionDetector.CollisionObject Obj2)
 {
     if (CLCalc.CLAcceleration == CLCalc.CLAccelerationType.UsingCL)
     {
         CLCalc.Program.Variable variable1 = this.CLCalcVertexDisplacement(Obj1.Vertex, Obj1.Displacement);
         CLCalc.Program.Variable variable2 = this.CLCalcVertexDisplacement(Obj2.Vertex, Obj2.Displacement);
         int[] Values = new int[1];
         CLCalc.Program.Variable variable3 = new CLCalc.Program.Variable(Values);
         CLCalc.Program.Variable variable4 = new CLCalc.Program.Variable(Obj1.Triangle);
         CLCalc.Program.Variable variable5 = new CLCalc.Program.Variable(Obj2.Triangle);
         int[] GlobalWorkSize = new int[2]
         {
             Obj1.Triangle.Length / 3,
             Obj2.Triangle.Length / 3
         };
         this.kernelCalcExactCollision.Execute((CLCalc.Program.MemoryObject[]) new CLCalc.Program.Variable[5]
         {
             variable1,
             variable4,
             variable2,
             variable5,
             variable3
         }, GlobalWorkSize);
         variable3.ReadFromDeviceTo(Values);
         return(Values[0] > 0);
     }
     else
     {
         float[] Obj1Vertexes  = this.CalcVertexDisplacement(Obj1.Vertex, Obj1.Displacement);
         float[] Obj2Vertexes  = this.CalcVertexDisplacement(Obj2.Vertex, Obj2.Displacement);
         int[]   numCollisions = new int[1];
         this.CalcExactCollision(Obj1Vertexes, Obj1.Triangle, Obj2Vertexes, Obj2.Triangle, numCollisions);
         return(numCollisions[0] > 0);
     }
 }
Esempio n. 2
0
 public int[] PerVertexDetectCollisions(CollisionDetector.CollisionObject MovingObj, CollisionDetector.CollisionObject Obj, float CollisionDistance, out float[] MovingObjDistances)
 {
     if ((double)CollisionDistance < 0.0)
     {
         throw new Exception("Collision distance should be positive");
     }
     float[] numArray1 = new float[MovingObj.Vertex.Length];
     float[] numArray2 = new float[Obj.Vertex.Length];
     float[] numArray3 = new float[9];
     for (int index = 0; index < MovingObj.Vertex.Length; ++index)
     {
         numArray1[index] = MovingObj.Vertex[index];
     }
     for (int index = 0; index < Obj.Vertex.Length; ++index)
     {
         numArray2[index] = Obj.Vertex[index];
     }
     if ((double)MovingObj.Displacement[3] != 0.0 || (double)MovingObj.Displacement[4] != 0.0 || (double)MovingObj.Displacement[5] != 0.0)
     {
         this.CalcRotMatrix(numArray3, MovingObj.Displacement);
         this.CalcRotacoes(numArray3, MovingObj.Vertex, numArray1);
     }
     if ((double)Obj.Displacement[3] != 0.0 || (double)Obj.Displacement[4] != 0.0 || (double)Obj.Displacement[5] != 0.0)
     {
         this.CalcRotMatrix(numArray3, Obj.Displacement);
         this.CalcRotacoes(numArray3, Obj.Vertex, numArray2);
     }
     this.CalcTransl(MovingObj.Displacement, numArray1);
     this.CalcTransl(Obj.Displacement, numArray2);
     int[] MovingObjCollisions = new int[MovingObj.Vertex.Length / 3];
     MovingObjDistances = new float[MovingObj.Vertex.Length / 3];
     for (int index = 0; index < MovingObjCollisions.Length; ++index)
     {
         MovingObjCollisions[index] = -1;
         MovingObjDistances[index]  = CollisionDistance * 2f;
     }
     float[] CollisionDistance1 = new float[1]
     {
         CollisionDistance
     };
     float[] N = new float[Obj.Triangle.Length];
     this.CalcVectors(numArray2, Obj.Triangle, N);
     this.CalcCollision(CollisionDistance1, numArray1, numArray2, Obj.Triangle, N, MovingObjCollisions, MovingObjDistances);
     return(MovingObjCollisions);
 }