|
Guest
|
I am calculating bounding volume both sphere and box using the
following function. supportig functions and
classes are also shown. Is this calculation is correct. also i want to
display my bounding sphere.
I don't want to use glutWireFrameSphere.
Thanks in Advance
void calculateOBV(3DModel *pModel, BoundingVolume *bv)
{
Vector3 rvec;
CalculateMinMax(pModel->VertexArray, pModel->numofVertices,
&bv->minExtent, &bv->maxExtent);
bv.radius = (bv.maxP - ((maxP + minP)/2)).magnitude()/2;
}
void CalculateMinMax(vector3 *points,int n,vector3& minP, vector3&
maxP)
{
bv->minP = points[0];
bv->maxP = points[0];
for(int i=0; i < n ;i++)
{
if(points[i].x > maxP.x) maxP.x = points[i].x;
if(points[i].y > maxP.y) maxP.y = points[i].y;
if(points[i].z > maxP.z) maxP.z = points[i].z;
if(points[i].x < minP.x) minP.x = points[i].x;
if(points[i].y < minP.y) minP.y = points[i].y;
if(points[i].z < minP.z) minP.z = points[i].z;
}
}
struct BoundingVolume
{
vector3 minExtent, maxExtent;
vector3 center;
float radius;
}
class Vector3
{
public:
float x, y, z;
Vector3();
Vector3(float a, float b, float c);
Vector3 operator-(Vector3& v);
Vector3 operator+(Vector3 &v);
Vector3 operator/(int m);
Vector3 operator*(int m);
float magnitude();
}; |
|
|