// 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); } }
public CollisionShape FindClosestCollision(CollisionShape cap, Vector3 start, Vector3 end, ref Vector3 intersection) { collisionTimeStamp++; SphereTreeNode s = sphereTree.FindSmallestContainer(cap, null); CollisionParms parms = new CollisionParms(); parms.genNormals = false; List <CollisionShape> shapes = new List <CollisionShape>(); s.FindIntersectingShapes(cap, shapes, collisionTimeStamp, ref collisionTestCount, parms); intersection = Vector3.Zero; if (shapes.Count == 0) { return(null); } else { collisionTimeStamp++; return(FindClosestIntersectingShape(shapes, start, end, ref intersection)); } }