Jump to content
  • Advertisement
Sign in to follow this  
Gondolin

AABB Collision Method?

This topic is 4073 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 came up with a method for testing AABB collisions, I don't know if its any good.
bool AABox::intersect(const AABox& b) const
{
	return ((int(max.x - b.min.x) ^ int(min.x - b.max.x)) <= 0 && 
		(int(max.y - b.min.y) ^ int(min.y - b.max.y)) <= 0 &&
		(int(max.z - b.min.z) ^ int(min.z - b.max.z)) <= 0);
}
It appears to work for every type of intersection I've tested, including when neither min or max are inside the other or when both are. Do you think this method might be faster than the simple testing if mins are greater than maxes? It avoids branching at the cost of some subtraction, but I just want to know if its a valid method in respect to that one?
If it isn't clear in the code, this method essentially tests to see if subtracting the other min from the max is the same sign as the other max from the min.

Share this post


Link to post
Share on other sites
Advertisement
been a while since ive looked at generated code, but i think that still has branching ie
if ( X ) return

Share this post


Link to post
Share on other sites
Quote:
Original post by Gondolin
It avoids branching at the cost of some subtraction, but I just want to know if its a valid method in respect to that one?

Don't forget the cost of casting to an integer (if they weren't already), if you're using IEEE floats you might get away with comparing the integer representation of the floating point number. The only thing useful to say is benchmark. And see if the intersection test is really the bottleneck, and if it is there might be better solutions to minimise the number of tests.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!