Sign in to follow this  

frustum culling

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need some help with the subject. I have read countless articles on it on the web. It seems that everyone claims to work but not for me!! I am using the common method used by many as follows: calculateFrustumPlanes { projection = glGetFloatv(...) // Get current projection matrix modelview = glGetFloatv(...) // Get current modelview matrix clip = modelview * projection // Get clipping matrix ... // Calculate each of the 6 planes } The above pseudo-code does not work for me at all. After comparing with other online tutorials, I noticed some differences. My codes are using gluPerspective and gluLookAt as follow: glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(...); gluLookAt(...); Once I modify those working tutorial codes with gluPerspective and/or glLookAt, every thing does not work anymore. Now, I believe these 2 modification on the projection matrix does play an important role on what clip plane I get. So I tried a transpose on projection matrix as follow: calculateFrustumPlanes { projection = glGetFloatv(...); // Get current projection matrix modelview = glGetFloatv(...); // Get current modelview matrix projection.transpose(); clip = modelview * projection; // Get clipping matrix ... // Calculate each of the 6 planes with normalization } With the transpose, things gets better: I can see some objects pop-in/out as I rotate my camera. However, the frustum seems to be in the opposite direction and position compared to the actual camera. I would appreaciate if someone advise me on what additional tweak I have to do to rectify me problem. Do I have to perform a further inversion to offset the transformation done by gluLookAt()? I am rather frustrated as much time have been wasted on this irritating bug of mine.

Share this post


Link to post
Share on other sites
Not enough info, the problem could be in many places. For the clip matrix you should just be able to multiply the modelview and projection matricies, no other operations should be performed.

Where exactly did you add the gluPerspective/LookAt code in. I'm guessing its before you calculate the frustum but might want to check if you are accidentally calculating the frustum before and then doing the lookAt and perspective second.

Post the code that you use to calculate the planes, the function for plane calculation and post the code that you use to test against (point, sphere, bb, aabb, etc).

Share this post


Link to post
Share on other sites
Hi,

I render the entire scene as follow:

>> Scene Rendering <<
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)640/(GLfloat)480, 4.0f, 3000.0f);
gluLookAt(_CameraPos.nX, _CameraPos.nY, _CameraPos.nZ,
_CameraTarget.nX, _CameraTarget.nY, _CameraTarget.nZ,
_CameraUp.nX, _CameraUp.nY, _CameraUp.nZ);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
SceneCamera->UpdateFrustum();
Env->DisplaySkyBox(2000, 2000, 2000);
LandScape->DisplayLandScape(15, bWireFrame);



Each Frame I update the frustum as follow:

>> FRUSTUM CALCULATION FUNCTION <<
void UpdateFrustum () {
glGetFloatv(GL_MODELVIEW_MATRIX, mvm);
glGetFloatv(GL_PROJECTION_MATRIX, pvm);
Transpose(&Projection);
MatrixMultiplication(Model, Projection, &Final);

// Right plane of frustum
Frustum[0].a = Final.m14 - Final.m11;
Frustum[0].b = Final.m24 - Final.m21;
Frustum[0].c = Final.m34 - Final.m31;
Frustum[0].d = Final.m44 - Final.m41;
NormalizePlane(&Frustum[0].a, &Frustum[0].b, &Frustum[0].c, &Frustum[0].d);

// Left plane of frustum
Frustum[1].a = Final.m14 + Final.m11;
Frustum[1].b = Final.m24 + Final.m21;
Frustum[1].c = Final.m34 + Final.m31;
Frustum[1].d = Final.m44 + Final.m41;
NormalizePlane(&Frustum[1].a, &Frustum[1].b, &Frustum[1].c, &Frustum[1].d);

// Bottom plane of frustum
Frustum[2].a = Final.m14 + Final.m12;
Frustum[2].b = Final.m24 + Final.m22;
Frustum[2].c = Final.m34 + Final.m32;
Frustum[2].d = Final.m44 + Final.m42;
NormalizePlane(&Frustum[2].a, &Frustum[2].b, &Frustum[2].c, &Frustum[2].d);

// Top plane of frustum
Frustum[3].a = Final.m14 - Final.m12;
Frustum[3].b = Final.m24 - Final.m22;
Frustum[3].c = Final.m34 - Final.m32;
Frustum[3].d = Final.m44 - Final.m42;
NormalizePlane(&Frustum[3].a, &Frustum[3].b, &Frustum[3].c, &Frustum[3].d);

// Front plane of frustum
Frustum[4].a = Final.m14 + Final.m13;
Frustum[4].b = Final.m24 + Final.m23;
Frustum[4].c = Final.m34 + Final.m33;
Frustum[4].d = Final.m44 + Final.m43;
NormalizePlane(&Frustum[4].a, &Frustum[4].b, &Frustum[4].c, &Frustum[4].d);

// Back plane of frustum
Frustum[5].a = Final.m14 - Final.m13;
Frustum[5].b = Final.m24 - Final.m23;
Frustum[5].c = Final.m34 - Final.m33;
Frustum[5].d = Final.m44 - Final.m43;
NormalizePlane(&Frustum[5].a, &Frustum[5].b, &Frustum[5].c, &Frustum[5].d);
}

bool IsPtinFrustum(float x, float y, float z)
{
for (int i = 0; i < 6; i++) {
if(Frustum[i].a * x + Frustum[i].b * y + Frustum[i].c * z + Frustum[i].d <= 0.0)
{
return false;
}
}
return true;
}

Can you spot anything wrong?

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this