Sign in to follow this  

Problem with frustum culling

This topic is 4688 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
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
Yes and no in that order :)

Winter ends roughly at the start of march but unfortunately where I'm living in Scotland atm it's actually getting colder if anything :(

Share this post


Link to post
Share on other sites
Finally got things working.
Don't have to perform any tweak I mentioned. Just follow what markmoley laid out in ExtractFrustum.

What went wrong? I found this little bug in the matrixmultiplication function.
So the clip matrix(modelview*projection) was wrong in the first place. Silly me. I hate bugs, bugs, bugs....erggggg. You know when codes get to many/long, its hard to follow.

Thanks. Have a great year ahead!!

Share this post


Link to post
Share on other sites
Just so you know, I'm the one that saved Mark Morley's tutorial out of the google cache. I had it hosted on my webpage at college, but I graduated last year so I had to move it. I got a SourceForge project for the project I am working on, so you can still find it here. I left it up on my college server as long as I dared, but finally felt like I should take it down. Sorry about that.

Share this post


Link to post
Share on other sites

This topic is 4688 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this