Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

endo

sphere/plane collisions

This topic is 5923 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to write some functions to handle sphere/polygon 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 distance 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;
}    
[edited by - endo on May 1, 2002 7:07:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
problem solved, the normal wasnt a unit vector - thanks anyway

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!