Nehe's opengl tutorial and glTranslatef

I have been going through Nehe’s opengl tutorials lately and have fully completed the first one…making my own header to simplify my commands and everything. I even used a timer to get a specific frame rate. I moved on to tutorial 2…everything seemed fine except for glTranslatef. If I don’t use the translate to move some amount negativly on the z-axis I cannot see the triangle or quad. I don’t understand how the glTranslatef function works. glLoadIdentity is suppose to bring you back to viewing the center of the screen… so if I drew in the triangle and quad I should be able to see them, however I can’t without using glTranslatef. It works with the values Nehe used for translate, and it also works with a translation on z-axis that is negative.
SORRY FOR THE LONG POST, I just wanted to make sure you understood what I was saying. Could someone please tell me what the glTranslatef function is suppose to do, and why I cannot see the figures without using it first. Thanks a lot!

[This message has been edited by blide (edited 06-27-2000).]


glTranslate is used to move your “camera” ala viewpoint to anywhere you want. if you call glLoadIdentity() then the identity matrix is loaded and the camera is at the center of everything (0,0,0) looking at the positive z-axis (into the screen). When calling glTranslatef(0, 0, -10); the camera moves back, zooms out if you will, and all objects drawn at (x, y, -5) for example become visible.


Thanks for the help, but I still am a little confused…
First off…according to Nehe, if you move negativly on the z-axis, your moving into the screen, not toward the viewer(positive would be “zooming out” toward the viewer)
Second, say you were right about negative moving toward the viewer, that would mean that if I left myself at 0,0,0(no translation), that I should be able to see something drawn on the positive z-axis, however I still cannot see it.
Third…if Nehe is right that positive is moving toward the viewer, that means that at 0,0,0 I should be able to see something on the negative z-axis, which I cannot!
Thanks again.

[This message has been edited by blide (edited 06-27-2000).]
Wait, now I can see things on the negative z-axis from 0,0,0…which means Nehe was right.
Thanks for the help!

[This message has been edited by blide (edited 06-27-2000).]

Ok, now I am even more confused!!!
When I get rid of the glTranslatef and leave myself at 0,0,0 I am able to see things on the negative z-axis which is how it should be, since negative z is away from the viewer, but when I translate negativly on the z-axis(ie glTranslatef(0,0,-10)) I start backing up, as in moving toward the viewer like positivly on the z-axis!!! That does not make any sense to me considering that negative on the z-axis means moving into the scene and not backing up!!

okay, z axis INTO the screen is (-), and out towards you is (+).

so if you draw an object at (0,0,-10)
and at (0,0,10), but you are at the center and LOOKING FORWARD!!! (make sure you have this right). You should see the object at (0,0,-10)… by the way, are you looking forward??? gluLookat()

I got that negative z-axis is into the scene and positive z is outwards toward the viewer, however when I use glTranslatef, and move on the NEGATIVE z-axis(ie glTranslatef(0,0,-10) it doesnt move me into the scene like it should, instead it moves me outward toward the viewer!!! can someone tell me why that is!!!..
UNLESS…when you translate negativly on the z-axis it automatically turns you around which would explain why it seems like I back away and zoom out…is this the case?
Thanks again!

I don’t know what the bug is but we all got the theory right. Translate negative on the z axis should move into the scene, and visa-versa. For sure a bug here in your code. Sorry not more help than that. What I do in cas like this is start over. Actually what I did was build a “test bed” that I can re-use to try out different scenarios. Might work for you.

I’m also thinking that maybe you rotated or translated without using PushMatrix/PopMatrix. glTranslates are cumulative; that is they work on the current translation/rotation. Check that out.


Hmm. I never thought about it, but it actually seems weird. In my programs, i allways zoom out by using glTranslatef(0.0, 0.0, -10); or some value like that. So I’m not really bothered by it. IMHO: get used to it


Hehehe, looks like I confused you guys also oh well…actually from what I believe I now know why it does that…glTranslatef doesn’t move you, it translates everything around you, so glTranslatef(0, 0, -10) would take every plotted vertex on screen after the command and subtract 10 from the z-value, thereby moving it farther away from me!
Thanks for all the help anywasy hehe

true dat blide

Here is my explination of glTranslatef.

When you paint a object into the 3d world of OpenGL. You input X Y and Z around a point. When you use glLoadIdentity() you set that point to the camra viewpoint. Now, if you don’t want use large numbers to draw things. You can use the glTranslatef function.

The Quad,
glVertex3f(-1.0f, -1.0f, -6.0f);
glVertex3f( 1.0f, -1.0f, -6.0f);
glVertex3f( 1.0f, 1.0f, -6.0f);
glVertex3f(-1.0f, 1.0f, -6.0f);

is the same as

glTranslatef(0.0f, 0.0f, -6.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);

Why? Because the first example one draws objects useing the camra point as 0,0,0. The second, through the use of glTranslatef uses 0,0,-6 as a 0,0,0.

This help ya out or you need more?

Actually, I thought glTranslatef is another matrix type operation which operates on the scene and hence moves the scene, or object, back so you can see it. This way, using minus z values moves the scene backward/away. The moving of the eyepoint, however, seems interesting.