Example #1
0
 // Test for collision with any object in this sphere
 public void FindIntersectingShapes(CollisionShape part,
                                    List <CollisionShape> shapes,
                                    ulong timeStamp,
                                    ref int collisionTestCount,
                                    CollisionParms parms)
 {
     if (containedShape != null)
     {
         collisionTestCount++;
         parms.swapped = false;
         if (Primitives.TestCollisionFunctions[(int)part.ShapeType(),
                                               (int)containedShape.ShapeType()]
                 (part, containedShape, parms))
         {
             shapes.Add(containedShape);
         }
         else
         {
             containedShape.timeStamp = timeStamp;
         }
     }
     // Iterate over the shapes in this sphere and not wholly
     // contained in a subsphere
     foreach (CollisionShape obstacle in intersectingShapes)
     {
         if (obstacle.timeStamp == timeStamp)
         {
             continue;
         }
         collisionTestCount++;
         parms.swapped = false;
         if (Primitives.TestCollisionFunctions[(int)part.ShapeType(), (int)obstacle.ShapeType()]
                 (part, obstacle, parms))
         {
             shapes.Add(obstacle);
         }
         else
         {
             obstacle.timeStamp = timeStamp;
         }
     }
     // Now iterate over subspheres
     for (int i = 0; i < SphereTreeNode.childCount; i++)
     {
         SphereTreeNode cs = children[i];
         if (cs == null)
         {
             continue;
         }
         // Skip any sphere that doesn't overlap the part in question
         if (!cs.SphereOverlap(part))
         {
             continue;
         }
         cs.FindIntersectingShapes(part, shapes, timeStamp, ref collisionTestCount, parms);
     }
 }
Example #2
0
 private void AddToChildIntersectingShapes(CollisionShape shape)
 {
     if (shape == containedShape)
     {
         return;
     }
     for (int i = 0; i < childCount; i++)
     {
         SphereTreeNode child = children[i];
         if (child != null && child.SphereOverlap(shape))
         {
             child.AddIntersectingShape(shape);
             child.AddToChildIntersectingShapes(shape);
         }
     }
 }