Frustum Culling Box Issues

I am having problems with correct truncation culling work. I have a great suggestion from someone about accurate AABB testing, and it works great, but I got to the point that the maximum and minimum testing do not always work, because often they will not be in a truncated state, but the plane is from one of parties will be. Therefore, I need to go on to fully detect the bounding box. I already have a code that checks the bounding box on the plane of the truncated cone, you just need to adjust the bounding box.

Does anyone have some sample code or an idea on how to do this. My two points with which I can create my bounding box are minimum xy and z and maximum xy and z.

Thank!:)

+3
source share
1 answer

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; // inside
        if(d+e.radius<-Epsilon) return -1; // outside
        return 0; // crossing the plane
    }

    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; // both in the same side
        return 0; // we have the object crossing the plane
    }
+1
source

All Articles