Sign in to follow this  
juxie

OBB-Line Intersection

Recommended Posts

Hi, I am trying to implement OBB-Line intersection but unable to implement it correctly Sorry if this has already been answered. I have structured my OBB as follows and assuming I have a variable::
struct OBB
{
   D3DXVECTOR3 pos, min, max;
   D3DXMATRIX rot;
};

D3DXMATRIX objTransform;

The objTransform will store the final transformation of the OBB. Then this is how I do my collision detection. I use the inverse transformation of OBB to transform the line origin and ray to OBB space. Also I did the same thing for min and max. Finally calling an Ray-AABB intersection function.
D3DXVECTOR3 bMin, bMax, p1, p2;
D3DXMATRIX invFinal;
D3DXMatrixInverse(&invFinal, NULL, &objTransform);

// Transform min and max first 
D3DXVec3TransformCoord(&bMin, &oBBox->min, &invFinal);
D3DXVec3TransformCoord(&bMax, &oBBox->max, &invFinal);

// Transform line to OBB space
D3DXVec3TransformCoord(&p1, &(lineOri - oBBox->pos), &invFinal);
D3DXVec3TransformCoord(&p2, &(lineEnd - oBBox->pos), &invFinal);

if( CollisionDetector::RayAABBIntersection(bMin, bMax, p1, p2, time) )
        // Do something
else
	// Do something

But this doesn't seem to work. What have I done wrong in my algorithm? Hope someone could help me out. If there is any article on this I could read up to understand it will be much better. Thanks.

Share this post


Link to post
Share on other sites
Alright, I know where I was wrong in the algorithm.
However, I am now looking for a way to actually calculate the collision normal.
Is there a way to determine the collision normal without having to check within the collision code which side is colliding?
Thanks.

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