Jump to content

  • Log In with Google      Sign In   
  • Create Account


AABB - AABB Collision response ( sliding )


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 xynapse   Members   -  Reputation: 151

Like
0Likes
Like

Posted 21 March 2012 - 11:21 AM

Posted Image




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

Here is what i have for AABB:
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();
}

Longer description:

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 ?

perfection.is.the.key

Sponsor:

#2 Net Gnome   Members   -  Reputation: 769

Like
0Likes
Like

Posted 21 March 2012 - 11:51 AM

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.

#3 xynapse   Members   -  Reputation: 151

Like
0Likes
Like

Posted 21 March 2012 - 12:05 PM

Net Gnome,

Any chance for any code snippet ?
perfection.is.the.key

#4 Net Gnome   Members   -  Reputation: 769

Like
0Likes
Like

Posted 21 March 2012 - 03:54 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS