Exemple #1
0
 public void SearchForCollisions()
 {
     /*
      * for (int i = narrowPhase.physicsEngines.Length - 1; i > 0; i--) {
      *      for (int j = 0; j < i; j++) {
      *              if (!(narrowPhase.physicsEngines [i].isStatic && narrowPhase.physicsEngines [j].isStatic)) {
      *                      narrowPhase.addParticleCollision (i, j);
      *                      //narrowPhase.physicsEngines [i].colRecord.Add (new CollisionObject (narrowPhase.physicsEngines [i], narrowPhase.physicsEngines [j]));
      *              }
      *      }
      * }
      */
     for (int i = 0; i < narrowPhase.physicsEngines.Length; i++)
     {
         for (int k = 0; k < narrowPhase.planeIndices.Length; k++)
         {
             narrowPhase.addPlaneCollision(i, k);
         }
     }
     for (int i = narrowPhase.physicsEngines.Length - 1; i >= 0; i--)
     {
         for (int j = 0; j < i; j++)
         {
             if (narrowPhase.physicsEngines [i] != narrowPhase.physicsEngines [j] && (!narrowPhase.physicsEngines[i].isStatic && !narrowPhase.physicsEngines[j].isStatic))
             {
                 narrowPhase.addParticleCollision(j, i);
             }
         }
     }
 }
 public void searchForCollisions()
 {
     CreateMask();
     for (int j = 0; j < narrowPhase.physicsEngines.Length; j++)
     {
         //top
         if ((bitmasks [j, 1] & boundsBitmasks[0]) > 0)
         {
             narrowPhase.addPlaneCollision(j, 0);
         }
         //bottom
         if ((bitmasks [j, 1] & boundsBitmasks[1]) > 0)
         {
             narrowPhase.addPlaneCollision(j, 1);
         }
         //front
         if ((bitmasks [j, 2] & boundsBitmasks [2]) > 0)
         {
             narrowPhase.addPlaneCollision(j, 2);
         }
         //back
         if ((bitmasks [j, 2] & boundsBitmasks [3]) > 0)
         {
             narrowPhase.addPlaneCollision(j, 3);
         }
         //left
         if ((bitmasks [j, 0] & boundsBitmasks [4]) > 0)
         {
             narrowPhase.addPlaneCollision(j, 4);
         }
         //right
         if ((bitmasks [j, 0] & boundsBitmasks [5]) > 0)
         {
             narrowPhase.addPlaneCollision(j, 5);
         }
     }
     for (int j = narrowPhase.physicsEngines.Length - 1; j >= 0; j--)
     {
         for (int i = 0; i < j; i++)
         {
             if (narrowPhase.physicsEngines [j] != narrowPhase.physicsEngines [i])
             {
                 if (!narrowPhase.physicsEngines[j].isStatic || !narrowPhase.physicsEngines[i].isStatic)
                 {
                     if ((bitmasks [j, 0] & bitmasks [i, 0]) > 0 &&
                         (bitmasks [j, 1] & bitmasks [i, 1]) > 0 &&
                         (bitmasks [j, 2] & bitmasks [i, 2]) > 0)
                     {
                         narrowPhase.addParticleCollision(j, i);
                     }
                 }
             }
         }
     }
 }
    //Get collisions for root node
    public void GetCollisions()
    {
        for (int i = 0; i < objects.Count; i++)
        {
            for (int k = 0; k < narrowPhase.planeIndices.Length; k++)
            {
                narrowPhase.addPlaneCollision(objects [i], k);
            }
        }
        for (int i = objects.Count - 1; i >= 0; i--)
        {
            for (int j = 0; j < i; j++)
            {
                if (objects [i] != objects [j] && !(objects [i].isStatic && objects [j].isStatic))
                {
                    narrowPhase.addParticleCollision(objects [i], objects [j]);
                }
            }
        }

        if (activeChildren < 1)
        {
            return;
        }

        /*
         * if (activeChildren == 0) {
         *      return;
         * }
         */

        for (int flags = activeChildren, index = 0; flags > 0; flags >>= 1, index++)
        {
            if ((flags & 1) == 1)
            {
                children[index].GetCollisions(objects);
            }
        }
    }