Collision of bounding box and sphere

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Collision of bounding box and sphere

Post by Sylence »

Hi!

Currently I'm doing a little space game but I ran into a problem:
I have a cube scene node and a sphere scene node (the cube is textured with an image of a spaceship and the sphere is a planet) but how can I check if the cube collides with the sphere?

The bounding box of the sphere is too big for my needs (it can be intersected at the "edges" that are far away from the real sphere)

Thanks in advance for any help
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Collision of bounding box and sphere

Post by randomMesh »

Sylence wrote:...how can I check if the cube collides with the sphere?
Maybe this helps?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

IIRC there's box-ellipsoid intersection methods in the bounding box selector. Another option is a combination of aabbox3d::isPointInside and plane3d::getDistanceFrom.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
radubolovan
Posts: 60
Joined: Tue Nov 13, 2007 7:03 pm
Location: Bucharest - Romania
Contact:

Post by radubolovan »

1) calculate the direction:
vector3df dir = ( sphere->getPosition() + box->getPosition() ).Normalize();
2) calculate a point on this direction which is on sphere:
vector3df sphereVertex = sphereRadius * dir;
3) test if this point is in bounding box:
bool collision = box.isPointInside( sphereVertex );
If collision is true ... the two objects intersects!
Post Reply