# AABB Collision Method?

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

## 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 on other sites
been a while since ive looked at generated code, but i think that still has branching ie
if ( X ) return

##### 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.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 9
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633331
• Total Posts
3011394
• ### Who's Online (See full list)

There are no registered users currently online

×