endo

05-01-2002, 02:51 AM

I have been trying to write some functions to handle sphere/polyogon collision and am nearly finished but now I'm stuck again.

The classifySphere(...) function shown below should tell me whether the sphere is infront of the plane, behind the plane, or intersects the plane. This is where the problem lies however because it only intersects the plane if the centre of the sphere is exactly on the plane.

I have tested values for the ditance variable and they are in the region of 10000x too high/low. Why is that? I'm sure its a simple thing but I can't find it....

Anyway here is the code :

SPHERE_POSITION classifySphere( Vector3d& centre, Vector3d& planeNormal, Vector3d& pointOnPlane, float radius, float &distance )

{

//distance of polygon plane from origin

float distFromOrigin = float( planeDistance( planeNormal, pointOnPlane ) );

//distance of sphere centre to polgon plane

distance = dotProduct( planeNormal, centre ) + distFromOrigin;

// cout << "distance : " << distance << endl;

// cout << "radius : " << radius << endl;

if( absolute( distance ) < radius )

{

return INTERSECTS;

}

else if( distance >= radius )

{

return IN_FRONT;

}

return BEHIND;

}

Edit : Why does my code always get posted at varying font sizes?

[This message has been edited by endo (edited 05-01-2002).]

The classifySphere(...) function shown below should tell me whether the sphere is infront of the plane, behind the plane, or intersects the plane. This is where the problem lies however because it only intersects the plane if the centre of the sphere is exactly on the plane.

I have tested values for the ditance variable and they are in the region of 10000x too high/low. Why is that? I'm sure its a simple thing but I can't find it....

Anyway here is the code :

SPHERE_POSITION classifySphere( Vector3d& centre, Vector3d& planeNormal, Vector3d& pointOnPlane, float radius, float &distance )

{

//distance of polygon plane from origin

float distFromOrigin = float( planeDistance( planeNormal, pointOnPlane ) );

//distance of sphere centre to polgon plane

distance = dotProduct( planeNormal, centre ) + distFromOrigin;

// cout << "distance : " << distance << endl;

// cout << "radius : " << radius << endl;

if( absolute( distance ) < radius )

{

return INTERSECTS;

}

else if( distance >= radius )

{

return IN_FRONT;

}

return BEHIND;

}

Edit : Why does my code always get posted at varying font sizes?

[This message has been edited by endo (edited 05-01-2002).]