43 minutes ago, Doug Patterson said:Why not have nested conditionals so that if the collision check along the x-axis fails you can abandon the checks on y and z and return a false.
The compiler should be able to figure this option out. But probably the fastest way would be to use simd instructions to do all 3 dimensions at once. (Which the compiler might do for us under the hood as well - aligning data helps here i guess.)
8 minutes ago, bmarci said:if ((abs(a.pos.x - b.pos.x) < a.size.x + b.size.x) && abs(a.pos.y - b.pos.y) < a.size.y + b.size.y) && abs(a.pos.z - b.pos.z) < a.size.z + b.size.z)) { ... you have collision ... }
Notice this code assumes pos at the center not at the corner, so it differs from the OP convention.
Usually the fastest representation of boxes is having min and max coords, which has the same memory but does not need additional multiplications or additions when checking overlaps (or also for ray hit):
return (a.max >= b.min && a.min <= b.max);