XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

How do I find the penetration depth between an intersecting OBB and AABB?

Last post 11/2/2009 5:11 PM by Matt Sams. 3 replies.
  • 11/2/2009 3:29 PM

    How do I find the penetration depth between an intersecting OBB and AABB?

    This one has me stuck.  I have a working intersection test using separating axis theorem for an AABB and an OBB, but the problem is that I can't work out my collision resolution with knowing what the penetration depth is.

    How do I find this penetration depth when the two bounding volumes intersect?

    Thank you.

    P.S. I can attach the code for the intersection test if necessary but I've omitted it for now as it is rather long.
  • 11/2/2009 3:37 PM In reply to

    Re: How do I find the penetration depth between an intersecting OBB and AABB?

    It's been a little bit, but I believe you can get the minimum translation distance by comparing the overlap of the extents of the boxes on each projected axis vector.  Find the shortest amount of overlap, multiply this by your collision normal and you should have a seperation vector.
  • 11/2/2009 4:34 PM In reply to

    Re: How do I find the penetration depth between an intersecting OBB and AABB?

    Excellent, thank you!

    How do I find the collision normal in this case, can I treat the OBB as an AABB then transform the normal by a rotation matrix?
  • 11/2/2009 5:11 PM In reply to

    Re: How do I find the penetration depth between an intersecting OBB and AABB?

    Well if you've found the MTD, the scalar representing the penetration, then the current axis you are projecting onto is going to be the axis you push the collision out on.  The only thing you need to know is in which direction.  This is done by testing the intervals of the boxes on that axis.  Basically:

    float minA, maxA, minB, maxB;  
     
    // This just gets the minimum and maximum interval of the given OBB by testing its vertices.  You're finding lower/upper bounds here.  
    GetIntervals(OBB obbA, ref minA, ref maxA);  
    GetIntervals(OBB obbB, ref minB, ref maxB);  
     
    float d0 = (maxA - minB);  
    float d1 = (minA - maxB);  
    float d = d0 > d1 ? -1 : 1;  
     
    Vector2 pushVector = axis * mtdScalar * d; 

    Note that this is all done within the local space of obbA, turning it into an AABB.  This will tend to preserve one of the components of the original velocity, so your objects will slide along each other.
Page 1 of 1 (4 items) Previous Next