• Advertisement
Sign in to follow this  

Axis Aligned Bounding Boxes logic error?

This topic is 3483 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

Hello All, I have a quick question regarding Collision Detection. In the book that I'm currently reading, it describes Axis Aligned Bounding Boxes (AABB) and gives the logic: float Dx = Math.Abs(r2.x - r1.x); float Dy = Math.Abs(r2.y - r1.y); if (Dx > (r1.extentX + r2.extentX) && (Dy > (r1.extentY + r2.extentY)) // the boxes do not overlap else // the boxes overlap My question is what is extentX and extentY? Is it the Height and Width? Using x and y as the top left value of a rectangle and ExtentX, ExtentY as the height and width, I can't seem to get it to work as expected.

Share this post


Link to post
Share on other sites
Advertisement
'x' and 'y' represent the center of the box, the x extent is half the width, and the y extent is half the height.

Also, I think it should probably be 'or', not 'and':
if (Dx > (r1.extentX + r2.extentX) || (Dy > (r1.extentY + r2.extentY)) {}

Share this post


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

  • Advertisement