# Frustum Problem

This topic is 3105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,
I am having problem with my frustum culling test (video describes):

Video

Here is the source:

//Frustum Calculation from ModelViewProjection Matrixvoid Frustum::Calculate(const Matrix &modelviewprojection) {	const real * m = modelviewprojection.row;	plane.normal.x = m[3] - m[0];	plane.normal.y = m[7] - m[4];	plane.normal.z = m[11] - m[8];	plane.d = m[15] - m[12];	plane.Normalize();	plane.normal.x = m[3] + m[0];	plane.normal.y = m[7] + m[4];	plane.normal.z = m[11] + m[8];	plane.d = m[15] + m[12];	plane.Normalize();	plane[TOP].normal.x = m[3] - m[1];	plane[TOP].normal.y = m[7] - m[5];	plane[TOP].normal.z = m[11] - m[9];	plane[TOP].d = m[15] - m[13];	plane[TOP].Normalize();	plane[BOTTOM].normal.x = m[3] + m[1];	plane[BOTTOM].normal.y = m[7] + m[5];	plane[BOTTOM].normal.z = m[11] + m[9];	plane[BOTTOM].d = m[15] + m[13];	plane[BOTTOM].Normalize();	plane[FAR].normal.x = m[3] - m[2];	plane[FAR].normal.y = m[7] - m[6];	plane[FAR].normal.z = m[11] - m[10];	plane[FAR].d = m[15] - m[14];	plane[FAR].Normalize();	plane[NEAR].normal.x = m[3] + m[2];	plane[NEAR].normal.y = m[7] + m[6];	plane[NEAR].normal.z = m[11] + m[10];	plane[NEAR].d = m[15] + m[14];	plane[NEAR].Normalize();}

//Test AABBVector3 getPositiveVertex(Vector3 min, Vector3 max, Vector3 point) {    Vector3 p(min);    if(point.x >= 0) p.x = max.x;    if(point.y >= 0) p.y = max.y;    if(point.z >= 0) p.z = max.z;    return p;}Vector3 getNegativeVertex(Vector3 min, Vector3 max, Vector3 point) {    Vector3 p(max);    if(point.x >= 0) p.x = min.x;    if(point.y >= 0) p.y = min.y;    if(point.z >= 0) p.z = min.z;    return p;}bool FrustumInBox(dour::Frustum * frustum, Vector3 min, Vector3 max) {    for(uint i = 0; i < 6; ++i) {        Plane &p = frustum->getPlane(i);        if(Vector3::Dot(p.normal, getPositiveVertex(min, max, p.normal) + p.d) < 0)  return false;        //if(Vector3::Dot(p.normal, getVertexNegative(p.normal, min, max) + p.d)) -> don't need inside or intersection right now. if has contact draw    }    return true;}

//Octree Testvoid OctreeInFrustum(dour::OctreeNode * root, dour::Frustum * frustum) {    if(FrustumInBox(frustum, root->min_, root->max_)) {        if(root->submeshes.size() > 0) visibleNodes.push_back(root);        if(root->nodes[0])            for(int i = 0; i < 8; ++i)                OctreeInFrustum(root->nodes, frustum);    }}

//Draw    for(VisNodeList::iterator i = visibleNodes.begin(); i != visibleNodes.end(); ++i)        DrawEntity((*i));

Thanks,
Kasya

Bump. Anyone?

##### Share on other sites
You might check and make sure you're using the right version of the frustum plane extraction algorithm (specifically, that you've got the z clipping range right).

I'd also recommend testing the different parts of the code in isolation to make sure they're working correctly. Create a 'debug camera' that can observe the 'real camera', and then render the frustum attached to the 'real camera' to make sure it's correct. Then, test culling of a single AABB to make sure the AABB-frustum test is implemented correctly (remember that the standard AABB-frustum test is conservative and will return false positives in some cases). Then, if that all checks out, move on to debugging the octree culling code.

(I didn't spot any obvious problems with your code, but I only glanced over it - if there is an obvious error somewhere, maybe someone else will spot it.)

##### Share on other sites
Thanks,

Quote:
 I'd also recommend testing the different parts of the code in isolation to make sure they're working correctly.

I wanted to test different parts before posting but i don't know how to draw the frustum (something like that: http://www.lighthouse3d.com/opengl/viewfrustum/images/demo.gif) with normal and scalar. Googled it for hours, no luck. Could you please give me some information about drawing because i want to draw the frustum and check spheres to see if its the problem of frustum then move forward to check frustum-aabb test.

Thanks,
Kasya

##### Share on other sites
There are a couple of different ways to build the rendering geometry for a frustum, but the way I prefer to do it is to intersect the frustum planes in sets of three to yield the frustum corners. (Some people 'reverse transform' the corners of the view volume in local space instead, but since you need the frustum planes anyway, it makes more sense to me to derive the corners from them directly.)

##### Share on other sites
Thanks. I'm going to check it out

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015447
×