Jump to content
  • Advertisement
Sign in to follow this  
juxie

OBB-Line Intersection

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!