Sign in to follow this  
mike74

gluPerspective

Recommended Posts

Does gluPerspective make any weird changes to the OpenGL matrices besides adding perspective? Basically, I was just doing: glLoadIdentity(); Now, I'm doing: glLoadIdentity(); gluPerspective(90, yadda, yadda, yadda); When I did a glTranslatef(0, 0, -10) call initially and placed a point, it would be at (0, 0, -10). However, now with gluPerspective in place, the point is now at (0, 0, 10) after a glTranslatef(0, 0, -10). What's up with that? Mike C. http://www.coolgroups.com/zoomer/

Share this post


Link to post
Share on other sites
Quote:
Original post by matthughson
You may want to try posting this in the OpenGL board if you still aren't getting responses here.

Matt Hughson


Three and a half hours after posting, a bit hasty no?

Anyway, mike74, the perspective matrix affects how your points move. I can think of a couple things:
1) Maybe something is important in the "yadda"s.
2) You should call gluPerspective with the matrix mode set to projection, then switch back to modelview, like so:

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( ... );
glMatrixMode( GL_MODELVIEW );

If you try to apply the perspective without doing that, it will affect the model view matrix in weird ways and generally not do the right things.

Share this post


Link to post
Share on other sites
What I think the conflict is that the gluPerspective() function places a matrix onto the stack. Well, a matrix at its most basic changes between coordinate systems. For example, a glTranslatef(5.0f, 5.0f, 5.0f) will place the point {5.0f, 5.0f, 5.0f} at the origin.

The matrix created by gluPerspective not only adds perspective to the scene, it also changes the coordinate system. In this case, it switched around the z axis. The z values increase as they go forward from the origin (0, 0, 0), and decrease as they go backwards from the origin.

Z AXIS
<-----------|----------->
-4 -3 -2 -1 0 1 2 3 4

Hopefully that solves your problem.

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
Quote:
Original post by matthughson
You may want to try posting this in the OpenGL board if you still aren't getting responses here.

Matt Hughson


Three and a half hours after posting, a bit hasty no?


It's never too early to help someone out [wink].

Matt Hughson

Share this post


Link to post
Share on other sites

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