Advertisement

Problem with frustum culling

Started by February 12, 2005 11:38 PM
15 comments, last by eSCHEn 19 years, 7 months ago
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.
You may not have seen this tutorial by Mark Morely: clicky, I include it here in it's original form as saved from Google's gache by somebody else (who appears to be down as well). I couldn't figure out frustum culling a while back and this tutorial helped me loads.

Hope that helped.
Advertisement
Weird. It said I was logged in but posted anonymously anyway, *shrug* here's the link: clicky.
--
Cheers,
Darren Clark
Hi,

Thanks for your reply.
I have read similar codes countless times. My codes are identical to those posted. It does not work. The article did not address issues like how to offset the effect of glLookAt()? Or does it? Am I missing something there?
In addition, the links at the bottom are broken. Would appreciate if you can send the files if you still have them?
Sorry, I never downloaded the files and so can't give you them :(

I do have my implementation of the article as a C++ class, you can grab that here.

As for your questions about gluLookAt(), I'm sorry but I just don't know; I'm sure someone who knows better will be able to answer your queries.
--
Cheers,
Darren Clark
Hi,

Thanks. Got the file. I saw the part of the main.cpp file where you do:

matrixmode = projection
loadidentity
gluperspective
matrixmode = modelview
...

Try adding glulookat after gluperspective line. I think this will mess up your frustum.
Advertisement
Nope, unless I'm misunderstanding what you mean by 'messed up' it works exactly the same. The line I added (in case you want to test) was:
gluLookAt(1.0f, 1.0f, 1.0f,          4.0f, 0.0f, 0.0f,          0.0f, 1.0f, 0.0f);

At line 88, straight after 'gluPerspective(45.0, 800/600, 1.0, 1000.0);'.
--
Cheers,
Darren Clark
Is it before "glMatrixMode(GL_MODELVIEW);" or after?
It's before as gluLookAt() alters the projection matrix.
--
Cheers,
Darren Clark
Well, I tried your codes. Seems to work fine.
I notice your scene is one that rotates the entire world while camera stays fixed.

For mine, its a mixture. Does that matter?

This topic is closed to new replies.

Advertisement