Jump to content
  • Advertisement
Sign in to follow this  
peterchong

Problem with frustum culling

This topic is 4904 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
Advertisement
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
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?

Share this post


Link to post
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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!