Sign in to follow this  
Darkbouncer4689

OBB Intersection Tests

Recommended Posts

Hey all,

I'm implementing a few different OBB intersection tests (mainly ray/OBB and OBB/OBB for now). I have implemented two versions of ray/OBB intersection tests.

One is from Real Time Rendering which uses a Slabs Method.
The other is from David Eberly's book which uses a 6 separating axes test.

I have both algorithms working but I have a question I am hoping someone may be able to shed some light on. I am having trouble finding documentation that talks about how to handle OBB's that exist in a game engine (i.e. world space). The OBB may undergo translation, rotation, scaling, etc, which are all baked into the modelMatrix. These algorithms assume an OBB with unit vectors. Thus in order for these algorithms to work we must convert the axes of the OBB to unit vectors.

Here is my solution to this problem:

To convert an OBB center C to world coordinates, simply multiply it by the objects modelMatrix. Easy enough.

To convert the axes of the OBB to world space we take the 4x4 modelMatrix and convert it to an upper 3x3 modelMatrix (i.e. rotationMatrix), and multiply the axes by this matrix. Next we normalize the vectors. However, we must also change the values of the extents (or half lengths) since we have normalized the vectors. I do this by taking the inverse of the value used to normalize the vectors and multiply the extents by that.

Example:
len = Math.sqrt(axisU.x*axisU.x + axisU.y*axisU.y + axisU.z*axisU.z)
len = 1/len
axisU.x = axisU.x*len
axisU.y = axisU.y*len
axisU.z = axisU.z*len
extentU = extentU*(1/len);

and repeat for the other 2 axes/extents.

Then we can go on our marry way implementing the algorithms with unit vectors.

I am not a math ninja like Mr. Eberly and I'm not sure if this is the most effecient way of doing things. Obviously for intersection tests, having effecient algorithms is imporant. I was hoping someone may be able to offer some advice on my implementatation and how to handle OBB's combined with a modelMatrix.


Thanks in advance.

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