Game Development Reference
In-Depth Information
return count + getPotentialContactsWith(
other->children[1], contacts+count, limit-count
);
} else {
return count;
}
}
}
This code can work with any kind of bounding volume hierarchy as long as each node
implements the overlaps method to check to see whether two volumes overlap. The
bounding sphere hierarchy is implemented as
Excerpt from include/cyclone/collide_coarse.h
/**
* Represents a bounding sphere that can be tested for overlap.
*/
struct BoundingSphere
{
Vector3 center;
real radius;
public:
/**
* Creates a new bounding sphere at the given center and radius.
*/
BoundingSphere(const Vector3 &center, real radius);
/**
* Creates a bounding sphere to enclose the two given bounding
* spheres.
*/
BoundingSphere(const BoundingSphere &one, const BoundingSphere &two);
/**
* Checks if the bounding sphere overlaps with the other given
* bounding sphere.
*/
bool overlaps(const BoundingSphere *other) const;
};
Excerpt from src/collide_coarse.cpp
bool BoundingSphere::overlaps(const BoundingSphere *other) const
{
Search Nedrilad ::




Custom Search