generating bounding boxes

Started by
5 comments, last by Zakwayda 19 years ago
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!
Advertisement
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.

thanks, yeah, thats better! :)
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!
You may find this table useful. You'll want an AABB-Ray intersection test.
thanks a lot!

but why AABB?

what if i rotate my scene? then the boxes are no more aligned to the viewing plane(=mousecursorplane).

so i guess i'd need OBB.
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.

This topic is closed to new replies.

Advertisement