glRotatef behaves strange

Started by
19 comments, last by EasyCoder 11 years, 8 months ago
Also, please post what you're using for your projection matrix (you suspect that it is related to perspective.)
Stop twiddling your bits and use them already!
Advertisement
Is your box centered around the origin?

gl.glScalef(0.25f, 0.25f, 0.0f); [/quote]
You realize this is collapsing the z-axis to 0. If you want any depth to your 2d Images, this should be 1 for the z-component, otherwise they will have have a z-value of zero.

You should post a video because nobody knows really what is going on.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


You realize this is collapsing the z-axis to 0. If you want any depth to your 2d Images, this should be 1 for the z-component, otherwise they will have have a z-value of zero.

It only collapses the Z-value of the model up to the point where the scaling takes place in the sequence of transformations. There are no problems collapsing the object onto a 2D plane and then translate it into its correct depth value so that depth testing of the 2D object can take place properly.
Yup I edited right after, It should be fine. Which is why I edited to say post a video because we need to see it happen.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

[attachment=10267:glRotatef-y.jpg]

So this is how it looks like, when I use the above code.

I am using GL_MODELVIEW in glMatrixMode and fovy (field of view angle in y direction) in gluPerspective is set to 45.0f.

Could it have anything to do with fovy, as it is also in y direction ? unsure.png
If those quads are rotated 45 degrees about the Y-axis, then the only reason I can see for that behaviour is normal perspective effects. Objects to the left will be viewed more from the right that centered objects and thus appear, due to perspective, slightly narrower. Think of a cube; the further to the right on the screen the cube is, the more of its left side you can see. They are not rotated, but perspective shifted.

If those quads are rotated 45 degrees about the Y-axis, then the only reason I can see for that behaviour is normal perspective effects. Objects to the left will be viewed more from the right that centered objects and thus appear, due to perspective, slightly narrower. Think of a cube; the further to the right on the screen the cube is, the more of its left side you can see. They are not rotated, but perspective shifted.


I see. Is there any way to change the perspective, so they all appear the same ?
Use glOrtho instead of gluPerspective.

If you hold your hand 45 degrees like the image and put it far left of your head and them move it towards the right, you will see the same thing. On the left your hand is facing you, on the right it is facing away from you and distorted because you are looking down the side of the hand and cant see the front anymore.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


Use glOrtho instead of gluPerspective.

If you hold your hand 45 degrees like the image and put it far left of your head and them move it towards the right, you will see the same thing. On the left your hand is facing you, on the right it is facing away from you and distorted because you are looking down the side of the hand and cant see the front anymore.


Yes, your explanation makes perfect sense to me.

And gluOrtho2D works like a charm ! smile.png

Now all 15 objects rotate exactly at the same angle. Thanks for your help & suggestion.

Only one more question: can you swap back and forth between gluOrtho2D and gluPerspective within the onDrawFrame ?

This is for a game which I am developing, and the engine is already finished and working fine in gluPerspective, so I am not very keen to change it to gluOrtho2D.

I just want to do that rotation effect in gluOrtho2D, then get rid of the objects and swap back to gluPerspective.

Is this possible ?
You can change any matrix at any time as many times you like.

This topic is closed to new replies.

Advertisement