Sign in to follow this  
ehmdjii

generating bounding boxes

Recommended Posts

hello, i have a number of simple meshes to render. now i want to calculate a bounding box for each one. idea: i thought of taking all the vertices of a mesh, then calculate the average to get the position for the box and then calculate the max distance between to vertices to get the scale. good idea or bad? :-) or does anyone know of an algorithm that does something similar already? i dont want to reinvent the wheel. thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by ehmdjii
hello,

i have a number of simple meshes to render. now i want to calculate a bounding box for each one.

idea:
i thought of taking all the vertices of a mesh, then calculate the average to get the position for the box and then calculate the max distance between to vertices to get the scale.

good idea or bad? :-)

or does anyone know of an algorithm that does something similar already?
i dont want to reinvent the wheel.

thanks!


That wouuld in essence get you a bounding sphere (center point + radius) - the easiest way is to loop through the vertices, keeping track of the minimum and maximum x/y/z values, and using those for your 8 corners of a bounding box.

Share this post


Link to post
Share on other sites
ok, now my bounding boxes are calculated nicely.

next thing i would like to do is to test an intersection on them.

for starting, i would like to shoot a ray from the mousecursor and get boundingboxes under the cursor.
how would i do that theoretically?

thanks!

Share this post


Link to post
Share on other sites
Quote:
what if i rotate my scene? then the boxes are no more aligned to the viewing plane(=mousecursorplane).
Collision detection is typically carried out in world space rather than camera space, so it shouldn't make any difference what camera transform you apply to your scene.

If you transform your *objects* within world space, that's a different story. If you calculate an AABB for an object, rotating that object may take parts of it outside of the bounds of the AABB. Solutions include OBBs, as you mentioned, or simply making the AABB large enough to fully contain the object at any orientation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this