I want to know the steps so I can create a bounding sphere on a object so when I get close, it will collide and will not intersect the object. I think my main question is..Will I get the distance of the radius and the center of my object to detect this? Second, do I run this function below on all the vertices of the object? I just need the steps.
The code snippet I got is:
void
IvBoundingSphere::Set( const IvVector3* points, unsigned int numPoints )
{
ASSERT( points );
// compute minimal and maximal bounds
IvVector3 min(points[0]), max(points[0]);
unsigned int i;
for ( i = 1; i < numPoints; ++i )
{
if (points[i].x < min.x)
min.x = points[i].x;
else if (points[i].x > max.x )
max.x = points[i].x;
if (points[i].y < min.y)
min.y = points[i].y;
else if (points[i].y > max.y )
max.y = points[i].y;
if (points[i].z < min.z)
min.z = points[i].z;
else if (points[i].z > max.z )
max.z = points[i].z;
}
// compute center and radius
mCenter = 0.5f*(min + max);
float maxDistance = ::DistanceSquared( mCenter, points[0] );
for ( i = 1; i < numPoints; ++i )
{
float dist = ::DistanceSquared( mCenter, points[i] );
if (dist > maxDistance)
maxDistance = dist;
}
mRadius = ::IvSqrt( maxDistance );
}
Just need a basic idea on how to do this. Thank you
↧