# AABB Tests in D3D

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

## Recommended Posts

Hello,
There are 4 functions available in D3D for testing intersections
1) D3DXBoxBoundProbe
2) D3DXIntersect
3) D3DXIntersectSubset
4) D3DXIntersectTri
All of them require a ray during the test.
I wonder how do I test intersections between 2 AABBs using these functions?
Tests between AABBs shouldn't involve a ray.
And also there are 6 planes in an AABB, I just want to know which one of them intersects with other objects. How do I know which plane has intersected while others haven't? I understand that there may be 1/2/3 planes involved in an intersection at a time. How can I tell?
Thanks
Jack

##### Share on other sites
An AABB has two points that describe it, the max point (+x, +y, +z) and the min point (-x, -y, -z). you just have to test whether one of the points of a box is inside the limits of the other box (if it's between the min and max point on each axis). Here's a function i use in one of my lessons. it uses the xna math library, but the idea is the exact same, so you can easily change the xna XMVECTOR to D3DXVECTOR3 or whatever, and instead of XMVectorGetY(firstObjBoundingBoxMaxVertex) for example, you would just do firstObjBoundingBoxMaxVertex.y

bool BoundingBoxCollision(XMVECTOR& firstObjBoundingBoxMinVertex, XMVECTOR& firstObjBoundingBoxMaxVertex, XMVECTOR& secondObjBoundingBoxMinVertex, XMVECTOR& secondObjBoundingBoxMaxVertex) { //Is obj1's max X greater than obj2's min X? If not, obj1 is to the LEFT of obj2 if (XMVectorGetX(firstObjBoundingBoxMaxVertex) > XMVectorGetX(secondObjBoundingBoxMinVertex)) //Is obj1's min X less than obj2's max X? If not, obj1 is to the RIGHT of obj2 if (XMVectorGetX(firstObjBoundingBoxMinVertex) < XMVectorGetX(secondObjBoundingBoxMaxVertex)) //Is obj1's max Y greater than obj2's min Y? If not, obj1 is UNDER obj2 if (XMVectorGetY(firstObjBoundingBoxMaxVertex) > XMVectorGetY(secondObjBoundingBoxMinVertex)) //Is obj1's min Y less than obj2's max Y? If not, obj1 is ABOVE obj2 if (XMVectorGetY(firstObjBoundingBoxMinVertex) < XMVectorGetY(secondObjBoundingBoxMaxVertex)) //Is obj1's max Z greater than obj2's min Z? If not, obj1 is IN FRONT OF obj2 if (XMVectorGetZ(firstObjBoundingBoxMaxVertex) > XMVectorGetZ(secondObjBoundingBoxMinVertex)) //Is obj1's min Z less than obj2's max Z? If not, obj1 is BEHIND obj2 if (XMVectorGetZ(firstObjBoundingBoxMinVertex) < XMVectorGetZ(secondObjBoundingBoxMaxVertex)) //If we've made it this far, then the two bounding boxes are colliding return true; //If the two bounding boxes are not colliding, then return false return false; }

##### Share on other sites
Thanks iedoc, i was thinking too much about rays. Your solution seems to be better and simpler.
Thanks
Jack

##### Share on other sites
I am not sure why you are talking about planes in the AABB, since the bounding box is described by max and min point and if you have some rotations involved, between the objects you want to test for collisions, you will also need additional things. I will suggest you to check out http://www.toymaker.info/Games/html/collisions.html .

##### Share on other sites
yeah, if you want to be rotating your box, you'll have to look into OBB's. they fit the model tighter too (resulting in more accurate collision detections). also, AABB's have to be recalculated whenever you transform the object, but don't mistake that, you cannot rotate the AABB. but, if your just looking for simple collision detection, then i think you have what you need ;)

##### Share on other sites
One concern comes up to mind after reading a few articles, is that if 2 objects are moving so fast so that the collision may go unnoticed. How do I go about solving this situation?
Thanks
Jack

##### Share on other sites

I am not sure why you are talking about planes in the AABB, since the bounding box is described by max and min point and if you have some rotations involved, between the objects you want to test for collisions, you will also need additional things. I will suggest you to check out http://www.toymaker....collisions.html .

I don't want a collision event to be raised when it is a side-on collision. Just want to have head-to-head collision to be detected.
 ^ ^ A B 
In this illustration, A and B are moving in the same direction, but they are next to each other. If I use a bounding box check, it will report a collision and they will pause moving waiting for their ways to to cleared. I don't want this to happen...

Thanks
Jack

##### Share on other sites
i don't understand, the bounding box is a big box that can contain the entire model. the AABB is more like an estimate of a collision. if you want ACCURATE collision, you can look into triangle to triangle collision detection. Although I don't have a lesson for direct3d 11 for triangle to triangle collision detection, i do have one for direct3d 10, and triangle to triangle detection is the same for both (I use XNA math for d3d11 and the d3dx library for d3d 10, but the technique should be the exact same).

I guess i really don't understand what your problem is. if A and B are going in the same direction, there should only be a collision when their bounding boxes collide ( assuming your using the method above for the AABB)

##### Share on other sites
I ran into a situation that when 2 objects collide, they are tied up and locked in. On the next frame, the objects are still tied up. Their destinations have been pre-calculated and they can't be changed after the decisions are made, they must enter those positions. What strategies should I use in order to break the ties? They can't go reversing and they can't just simply replan because the outcome from the pathfinder would be the same.....
Thanks
Jack

##### Share on other sites
You need to take into account the side the collision occurred on. If it didn't occur in the direction the object is moving, then it's not an issue. So in your example, object B would continue moving, and object A would stop. On the next frame, A can move again because it's no longer colliding with object B.

• ### 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!

• 9
• 11
• 15
• 21
• 26