Game Development Reference
In-Depth Information
selected an insertion algorithm for the flexibility of being usable during the game.
Given the sphere hierarchy we created previously, we can implement the insertion
algorithm in this way:
Excerpt from include/cyclone/collide_coarse.h
* A base class for nodes in a bounding volume hierarchy.
* This class uses a binary tree to store the bounding volumes.
template<class BoundingVolumeClass>
class BVHNode
// ... other BVHNode code as before ...
* Inserts the given rigid body, with the given bounding volume,
* into the hierarchy. This may involve the creation of
* further bounding volume nodes.
void insert(RigidBody* body, const BoundingVolumeClass &volume);
template<class BoundingVolumeClass>
void BVHNode<BoundingVolumeClass>::insert(
RigidBody* newBody, const BoundingVolumeClass &newVolume
// If we are a leaf, then the only option is to spawn two
// new children and place the new body in one.
if (isLeaf())
// Child one is a copy of us.
children[0] = new BVHNode<BoundingVolumeClass>(
this, volume, body
// Child two holds the new body
children[1] = new BVHNode<BoundingVolumeClass>(
this, newVolume, newBody
// And we now loosen the body (we're no longer a leaf).
this->body = NULL;
Search Nedrilad ::

Custom Search