• 13
• 18
• 19
• 27
• 10

# Problem with frustum culling

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

## 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 on other sites
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.

##### Share on other sites
Weird. It said I was logged in but posted anonymously anyway, *shrug* here's the link: clicky.

##### Share on other sites
Hi,

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?

##### Share on other sites
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.

##### Share on other sites
Hi,

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

matrixmode = projection
gluperspective
matrixmode = modelview
...

Try adding glulookat after gluperspective line. I think this will mess up your frustum.

##### Share on other sites
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);'.

##### Share on other sites
Is it before "glMatrixMode(GL_MODELVIEW);" or after?

##### Share on other sites
It's before as gluLookAt() alters the projection matrix.