# Oriented bounding box flattening

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

## Recommended Posts

I have a mesh that is oriented in some arbitrary way and I've computed the OBB for it. What I would like to do is orient the box such that it aligns itself the the axes in 3D space yet retain its tight fit around the object. Can anyone tell me of an algorithm that takes an OBB and aligns it so that the box (along with the mesh WITHOUT manipulating the mesh data) so that it lies flat in 3D space???? Thank you Jon

##### Share on other sites
Applying the inverse of the matrix formed by the normalized base of the OBB as a rotation matrix should give you axis alignment.

##### Share on other sites
I'm not quite sure I follow what you're saying. Can you or anyone explain in more detail about normalizing the base of the bounding box and then making a matrix out of it. The method I used to create the bounding box was found by finding the orientation of the mesh (by rotating it around) and then applying the orientation to the min and max of the box defined by the mesh. Is there a way I can backtrack and create a matrix for the bounding box??? Much thanks for your replies

##### Share on other sites
I'm not really thinking this out on paper, so be aware there might be some mistakes.

What Shadow was saying is that for your OBB your should have 3 axis X', Y', Z' which your box is alligned to. so first normalize them (make them unit length). Then create a change of bases matrix out of them
| X'x Y'x Z'x |
| X'y Y'y Z'y | = R
| X'z Y'z Z'z |

This matrix should change any coords in world space (allinged to X, Y, Z) into values of your OBB space (alligned to X', Y', Z'). What you need is the inverse, since this is a change of basis matrix the inverse is the transpose

| X'x X'y X'z | -1
| Y'x Y'y Y'z | = R
| Z'x Z'y Z'z |

multiplying any point by this matrix will change any point on your bounding box (or in that space actually), into a the a point in world space.

I'm pretty sure this is correct and should technically "rotate" your OBB around to make it allign with the world coordinate system.

The problem you may have though is maintaining that tight fit. If you simply turn the box with the model not moving, you will not be guarenteed that your box is a tight fit, or that it even bounds the entire object anymore.

My question would be 1) what exactly are you trying to do here? and 2) could it possibly be easier to calculate the AABB instead?

--Ninj4D4n

##### Share on other sites
Well the reason I'm using OBB is exactly because of the tight fit of the object and the interactions that the objects are doing require them to have a tight fit because of the kinds of collision detection. The reason I'm trying to get the box flat is because I'm trying to align my object with another reference object which is oriented "flat" such that when it is loaded it is aligned to the axes (thats the way the object has been modeled).

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!