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.x < min.x)
min.x = points.x;
else if (points.x > max.x )
max.x = points.x;
if (points.y < min.y)
min.y = points.y;
else if (points.y > max.y )
max.y = points.y;
if (points.z < min.z)
min.z = points.z;
else if (points.z > max.z )
max.z = points.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 );
if (dist > maxDistance)
maxDistance = dist;
}
mRadius = ::IvSqrt( maxDistance );
}
Just need a basic idea on how to do this. Thank you