View Full Version : glTranslatef....PLEASE HELP!
06-27-2000, 07:19 PM
I posted earlier on this, but it was never fully answered. When I use glTranslatef on the negative z-axis(ie. glTranslatef(0,0,-6); it SHOULD move me 6 units into the scene, but instead it seems to move me 6 units away from the scene toward the viewer...why is this??!!
My assumption on what it SHOULD do is based on the fact that at Nehe's tutorials it says that positive z-axis is toward the viewer and that negative z-axis is away from the viewer.
I guess you apply glTranslate(0, 0, -6) to the projection matrix stack so, look sharp - you see along +Z-axis of the viewer's coordinate system (that you said "positive z-axis is toward the viewer and that negative z-axis is away from the viewer" is about world coordinate system but it doesn't matter if you set viewer's position and look direction at world CS once and modify current projection matrix only). Let the initial projection matrix is identity matrix so after glTranslate() call you've got the translation of all points to z'=z-6, i.e. toward the viewer.
06-27-2000, 08:58 PM
Being opengl impaired, and the idiot that I am, I don't exactly understand what you are saying...from what I thought of glTranslatef, it moved the position of the view from your current position to that many units away: as in if i were at 0,0,0 and i did glTranslatef(0,0,-6) that my view would now be from 0,0,-6. But from u said...there are 2 different coordinate systems..the world coordinates where negative z is into the scene....and the viewer coordinates where the z-axis is just flipped....is that what you were saying or is it a bit more complicated?
06-27-2000, 09:31 PM
Well if you paste a snippet of your code...it may help a bit.....mainly the glTranslate, but very importantly your glVertex* code as well....because some logical errors can occur when placing the vertices....
06-27-2000, 09:38 PM
Here is my drawing code:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0, 0, -4); //this way moves me 4 away from scene, as in toward viewer
//glTranslatef(0, 0, 4) this way it moves me 4 into screen
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, -3.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, -3.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -3.0f);
What does your set-up looks like ?? Did you call gluLookAt or position the camera in some calls to glRotate or glTranslate beforehand ??
Otherwise, if you did not do any set-up, if you are looking towards the positive z-axis, translating by -4 will bring objects closer to you. Just to the maths.
Blide, are you familiar with linear math and analytic geometry? That's you need is a good book. Unfortunately I can't suggest any but you should begin from vertex processing pipeline picture to track the whole way of vertices and then how glTranslate(), glRotate(), glScale() and others change current matrix. The thing is more complicated: those functions dont't move primitives, they modify the pipeline. They generate M matrix which multiplys current C and result replaces C: C = C*M. So glTranslate() and then glScale() or glScale() and then glTranslate() generate different transform matricies and result will be different.
[This message has been edited by Yaro (edited 06-28-2000).]
remember the viewport is set at 0,0,0 in opengl so when you translate 0,0,-4 you are translating the geometry not the camera if you will so... nehe is right -z is into the screen, but you are moving the geometry not yourself in that fashion....
so the geometry is further away
06-28-2000, 01:51 PM
Thanks for all the help, although I do not understand a thing about matricies or the graphics pipeline, I finally understand what is going on... I am not being translated, everything else is!!!
Thanks once again all.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.