Results 1 to 9 of 9

Thread: glTranslatef....PLEASE HELP!

  1. #1
    Member Newbie
    Join Date
    Jun 2000
    Posts
    32

    glTranslatef....PLEASE HELP!

    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.
    Thanks

  2. #2
    Junior Member Newbie
    Join Date
    Jun 2000
    Location
    Russia
    Posts
    4

    Re: glTranslatef....PLEASE HELP!

    Hi blide,
    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.

  3. #3
    Member Newbie
    Join Date
    Jun 2000
    Posts
    32

    Re: glTranslatef....PLEASE HELP!

    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?

  4. #4

    Re: glTranslatef....PLEASE HELP!

    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....

  5. #5
    Member Newbie
    Join Date
    Jun 2000
    Posts
    32

    Re: glTranslatef....PLEASE HELP!

    Here is my drawing code:

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();

    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


    glBegin(GL_TRIANGLES);
    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);
    glEnd();

    SwapBuffers(hdc);

  6. #6
    Member Newbie
    Join Date
    May 2000
    Location
    LONDON
    Posts
    46

    Re: glTranslatef....PLEASE HELP!

    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.

    Dan.
    Being crazy is not a requirement but it helps.

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2000
    Location
    Russia
    Posts
    4

    Re: glTranslatef....PLEASE HELP!

    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).]

  8. #8
    Guest

    Re: glTranslatef....PLEASE HELP!

    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

  9. #9
    Member Newbie
    Join Date
    Jun 2000
    Posts
    32

    Re: glTranslatef....PLEASE HELP!

    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.

Similar Threads

  1. Cant glTranslatef
    By ethereal in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-23-2012, 08:04 AM
  2. glTranslatef
    By vikramsingh in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-22-2011, 06:53 AM
  3. glTranslatef
    By nick2price in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-11-2009, 11:56 PM
  4. glTranslatef bug
    By Richard145 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-03-2007, 11:31 AM
  5. glTranslatef
    By G in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 07-01-2003, 09:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean