I like the way you have written this Owen, nice piece of code.
Looking at the code the check_diff, has x4 compares.
Check_collision calls check_diff, so that 24 compares in total.
Try these things out...
(1) put the 'check_diff' definition into a header file to help maximize the chance of it becoming inline.
(2) To optimise 'check_collision' use logical OR '||' not bitwise OR '|', now the second part is only evaluated when the first evaluates to false.
Worst case is still the same, but you can still try swapping the order as this may help if say the second part is true more often. In my example, since check_diff returns 'bool' I've use logical AND '&&' . (I undertand that with some CPU's you can get the compile to do nice things in some cases by avoiding logical compares)
(3) Check_diff same thing as step 2
(4) If your calling code uses structures, pass in pointer of guVector (guVector structure is defined in ogc\gu.h)
(5) If its possible add new box check routine that takes four edges, no need to add/sub the length, width & depth.
guVector Ship1 = {10,10,10};
guVector Ship2 = {15,15,11}; ...
bState CheckBoxCollision( &Ship1, &Ship2...
CheckBoxCollision(
bool CheckBoxCollision( guVector* PointA, guVector* PointB, guVector* SizeA, guVector* SizeB)
{
return (check_diff(PointA->x, PointB->x, SizeA->x) &&
check_diff(PointA->y, PointB->y, SizeA->y) &&
check_diff(PointA->z, PointB->z, SizeA->z)
||
check_diff(PointB->x, PointA->x, SizeB->x) &&
check_diff(PointB->y, PointA->y, SizeB->y) &&
check_diff(PointB->z, PointA->z, SizeB->z) ) ;
}
Extra note: The Sphere test has far less overhead - but its a case of swings and roundabouts.
If you get the chance try using a sphere test out on things like small projectiles.
(I find box checking not worth the effort, projectiles can still pass through the box edge depending and the type of math used to track motion)