Sign in to follow this  
xynapse

AABB - AABB Collision response ( sliding )

Recommended Posts

xynapse    151
[img]http://i.stack.imgur.com/2l7u4.jpg[/img]




[size=4][b]Here is the situation[/b]:[/size][list]
[*]I have a room with objects inside
[*]Each object has it's own AABB
[/list]
[size=4][b]Here is what i do[/b]:[/size][list]
[*]I check for collision between objects by checking AABB-AABB intersections
[/list]
[size=4][b]Here is what i need[/b]:[/size][list]
[*]How do i calculate the 'sliding' / response between those AABBs?
[/list]

[b]Here is what i have for AABB:[/b]
[CODE]
CBoundingBox::~CBoundingBox()
{
}
int CBoundingBox::classify(const CBoundingBox& rOther)
{
if( rOther.min.x >= min.x && rOther.max.x <= max.x &&
rOther.min.y >= min.y && rOther.max.y <= max.y &&
rOther.min.z >= min.z && rOther.max.z <= max.z )
{
return INSIDE;
}

if( max.x < rOther.min.x || min.x > rOther.max.x )
return OUTSIDE;
if( max.y < rOther.min.y || min.y > rOther.max.y )
return OUTSIDE;
if( max.z < rOther.min.z || min.z > rOther.max.z )
return OUTSIDE;

return INTERSECTS;

}
CVector3 CBoundingBox::closestPointOn(const CVector3& vPoint)
{
CVector3 xClosestPoint;
xClosestPoint.x = (vPoint.x < min.x)? min.x : (vPoint.x > max.x)? max.x : vPoint.x;
xClosestPoint.y = (vPoint.y < min.y)? min.y : (vPoint.y > max.y)? max.y : vPoint.y;
xClosestPoint.z = (vPoint.z < min.z)? min.z : (vPoint.z > max.z)? max.z : vPoint.z;
return xClosestPoint;
}
bool CBoundingBox::hasCollided(const CBoundingBox& rOther) const
{
if( min.x > rOther.max.x ) return false;
if( max.x < rOther.min.x ) return false;
if( min.y > rOther.max.y ) return false;
if( max.y < rOther.min.y ) return false;
if( min.z > rOther.max.z ) return false;
if( max.z < rOther.min.z ) return false;
return true;
}
bool CBoundingBox::hasCollided(const CVector3& vPosition) const
{
return vPosition.x <= max.x && vPosition.x >= min.x &&
vPosition.y <= max.y && vPosition.y >= min.y &&
vPosition.z <= max.z && vPosition.z >= min.z ;
}
CVector3 CBoundingBox::getCenter() const
{
return (min + max) * 0.5f;
}
float CBoundingBox::getRadius() const
{
return getSize() * 0.5f;
}
float CBoundingBox::getSize() const
{
return (max - min).magnitude();
}
[/CODE]

[size=4][b]Longer description:[/b][/size]

[size=4]I am absolutely sure you guys know what is the requirement here, i want "Player" to slide on other object's AABB's when in collision.
Can somebody please shed a bit of light on the calculations required ?[/size]

Share this post


Link to post
Share on other sites
NetGnome    773
you need to figure out which face's axis-normal they collided the least, then move them that amount apart along that axis-normal. This will cancel movement causing the collision, but continue the other axial movements, allowing you to slide against the AABB.

Share this post


Link to post
Share on other sites
NetGnome    773
my journal Conquering SAT for TileMaps has a code reference in there, for Separating Axis Theorem for tilemaps (2D), but here are some excellent resources that should supply you with a lot of food for thought:

http://www.codezealot.org/archives/55
http://www.realtimerendering.com/intersections.html
http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_games.php

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