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);
}
I wanted to just leave a comment to ask a question but i only seem to be able to leave an answer, this is just an observation:
Does this code really do what you want to do?
how this function reads to me is, assume the sphere is inside, for each point on your frustrum i, take the distance between i and the center of sphere p, if this distance is less than negative radius… and here my paradigm is destroyed.
So this returns early if you have a negative distance that is less than your negative radius? Is that really what you want right there?