# How do I approach this collision model?

This is the game level prototype I have already implemented. It has few objects per room to allow me to finally add some collision detection/response code into it.

VIDEO

As you can probably see, every object inside has it's own AABB, even the room itself has AABB. Also my player is inside the Room's AABB.

My player will be exactly inside the room, so he would have to collide correctly with those AABBs, so that when he hits any of those objects inside he get's a proper collision response from those AABB's.

Now I would like to hear from you what kind of collision approach should I choose in here?

How do I approach this kind of stuff:

• AABB to AABB collision detection then when this is positive go with AABB - Try to find proper plane normal and calculate response ?

• AABB to AABB then when positive go with AABB - AABB Side check to find proper plane normal and calculate response?

• Anything else?

How do you do this ?

Many thanks.

-

Ok, here is how i approached this model: PSEUDOCODE

``````CVector3 vResponse(0,0,0);

// Find out the sector we're in ( player is inside )
pCurrentSector = GetCurrentSector();

// Here is how we do it:
// 1. Test player AABB against Sector AABB
// 2. Test player against sector Triangles (if above true)
//
// --iterate through all objects inside current sector--
// 3. Test player AABB against ObjectX AABB
// 4. Test player against ObjectX Triangles (if above true)
// -----------------------------------------------------
//
// add -response vector from all Tri tests to our velocity

// Check if Play AABB collides Sector(room) AABB ( which is normally true )
// AABB - AABB test
if( pPlayer->AABB()->HasCollided(pCurrentSector->GetAABB()) )
{

// Test against this sector triangles, and return response vectra
// Sphere - TRI test
if(pPlayer->HasCollided(pCurrentSector->GetTrianglesList())==true)
{
vResponse += ...
}

// Now test against all objects inside this sector (room)
for(all_objects_inside_this_sector)
{

// Check against this object AABB
// AABB - AABB test
if(pPlayer->AABB()->HasCollided(pObjectX->AABB())==true)
{

// Check against this object triangles and add response
// Sphere - TRI test
if(pPlayer->HasCollided(pObjectX->GetTriangles())==true)
{
vResponse += ...
}

}

}

}

Player.SetVelocity(Player.GetVelocity()-vResponse);
``````
-

First, your room should not have an AABB like that. Give each wall an AABB (which will effectively be planes). Otherwise you have to deal with inverted logic, where some objects push out of each other and other objects must be contained. You don't want that duality.

Second, to fine proper plane normals with AABBs, you can use a simplified Separating Axis Theorem test to find the plane of least penetration, which will be your normal. The second you start dealing with any other shapes though (spheres, capsules, OBBs, arbitrary convex hulls, etc.) that will no longer give satisfactory results.

You can use a modified GJK (Gilbert–Johnson–Keerthi) algorithm or MPR (Minkowski Portal Refinement). The latter is a bit more direct for physics needs, but the former can be a bit simpler to understand. I would recommend getting a grasp on GJK first and then looking into MPR.

A nice link to explain the basics of GJK for collision detection (but not manifold generation) is here: http://www.codezealot.org/archives/88

A decent link I just found on MPR is here: http://motleycoder.com/?p=66

-

Are you asking the how you would do the math? It's simple really.

To test "collisions" (intersections) between two AABBs all you need is the minimum and the maximum coordinates of the boxes you're testing.

Say you have two AABBs called `A` and `B` which each have minimum and maximum values on each axis. You test if on each axis if they overlap. If they overlap all 3 axis, then they are colliding. If not, they are not colliding.

There is only one problem; your room is an AABB, so the aforementioned method will not work. So you could just have the floor as a AABB instead, or possibly look at convex collision.

-