You need the frum planes to look inside (their normals should point to the center). Throwing away the rendering can then be done by checking if the object is completely outside one of the six planes of frust. You can do this using a sphere or using AABB or any other container where you can calculate the distance (and side) to the plane.
From my own code on the plane (so if any plane returns -1, discards the rendering), I added some comments to make it easier to understand:
int Side(const Sphere &e) const {
float d=Distance(e.center);
if(d-e.radius>Epsilon) return 1;
if(d+e.radius<-Epsilon) return -1;
return 0;
}
int Side(const Vector3f &v) const {
float d=Distance(v);
if(d>Epsilon) return 1;
if(d<-Epsilon) return -1;
return 0;
}
int Side(const Box3f &c) const {
Vector3f a,b;
if(Normal.x>=0.0) { a.x=c.min.x; b.x=c.max.x; }
else { b.x=c.min.x; a.x=c.max.x; }
if(Normal.y>=0.0) { a.y=c.min.y; b.y=c.max.y; }
else { b.y=c.min.y; a.y=c.max.y; }
if(Normal.z>=0.0) { a.z=c.min.z; b.z=c.max.z; }
else { b.z=c.min.z; a.z=c.max.z; }
int l1 = Side(a), l2= Side(b);
if(l1==l2) return l1;
return 0;
}
source
share