I have this SphereInFrustrum function here:
0.49% int FrustumG::sphereInFrustum(Vec3 &p, float radius) {
int result = INSIDE;
float distance;
2.40% for(int i=0; i < 6; i++) {
7.94% distance = pl[i].distance(p);
12.21% if (distance < -radius)
0.67% return OUTSIDE;
3.67% else if (distance < radius)
result = INTERSECT;
}
return(result);
}
The numbers are from my code profiler. The issue is that, this check is taking longer than actually rendering. The whole point of implementing geometry culling was so that I could have really big levels. I really just need a very quick and dirty way to see if an AABB is in or out. Right now I provide it with the radius of the cube and the center. Given that my boxes are AABB, is there a faster way to do this? I favor speed over accuracy.
Thanks
If I provided the cube's min and max would that make it faster? I'm sure there must be a way to do this without the distance formula with an expensif square root;
float Plane::distance(Vec3 &p) {
return (d + normal.innerProduct(p));
}
float Vec3::innerProduct(Vec3 &v) {
return (x * v.x + y * v.y + z * v.z);
}