# generating bounding boxes

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

## 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 on other sites
Quote:
 Original post by ehmdjiihello,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 on other sites
thanks, yeah, thats better! :)

##### 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 on other sites
You may find this table useful. You'll want an AABB-Ray intersection test.

##### Share on other sites
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.

##### 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.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631740
• Total Posts
3001959
×