• Advertisement
Sign in to follow this  

AABB Collision Problems

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am doing an AABB collision and I can't seem to get it to work correctly. Here is how I set and test collision. I am only testing things on the X Axis right now.
void CBasicBoxCollision::SetInformation(float fX, float fY, float fZ, float fWidth, float fHeight, float fDepth)
{
	m_vMin = Vector3D(fX, fY, fZ);
	m_vMax = Vector3D(fX + fWidth, fY + fHeight, fZ + fDepth);
}

bool CBasicBoxCollision::CheckBasicBoxCollision(CBasicBoxCollision &bcIncBox)
{
	bool bReturn = false;

	if( m_vMax.GetX() < bcIncBox.m_vMin.GetX())
		bReturn = true;

	if( m_vMin.GetX() > bcIncBox.m_vMax.GetX())
		bReturn = true;

	return bReturn;
}
Here is what it looks like originally: | | | :--------: | | :--------: | | | Here is what it will look like for that to turn true:(When I am passing in the right wall). | --------| | --------| I am passing the wall in to the rectangle. So it would be Rect.TestCollision(Wall). Basically so *this in the function is the rectangle. The left wall always says it is colliding. Does anyone see what I am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Your function returns true when there's no collision, is that what you've intended?

Also it may just be that I've been at work too long and I'm starting to lose it, but I'm having a hard time understanding what you're demonstrating in that ASCII picture. You can post pictures here if you want, just upload the picture to an image hosting site like imageshack and post the html it gives you here.

Share this post


Link to post
Share on other sites
I would like for the collision to return false when there is no collision.

I would take a picture but for some reason I can't when direct ix open. Basically it is set up like this

(Wall1) (space) (Box) (space) (Wall2)

When I test the collision with the right wall, it will always say true on the first if check (saying there is collision). However, this is obviously wrong. When I test it with the wall on the left, there is collision, however, the box will need to on the other side of Wall1 for there to be collision, rather then the left side of the wall touching (it is the right side). It will look like this:
(box)(Wall1) (space) (space) (Wall2)

Share this post


Link to post
Share on other sites
If you want it to return true if there is a collision or false otherwise, your function should be like this:


bool CBasicBoxCollision::CheckBasicBoxCollision(CBasicBoxCollision &bcIncBox)
{
if( m_vMax.GetX() < bcIncBox.m_vMin.GetX())
return false;

if( m_vMin.GetX() > bcIncBox.m_vMax.GetX())
return false;

return true;
}

Share this post


Link to post
Share on other sites
That does work, however, it only works when I test it on wall 2 (the right wall). It does not work if I test it on left wall (wall 1).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement