Results 1 to 3 of 3

Thread: Problem with glulookat/gltranslatef

  1. #1
    Newbie Newbie
    Join Date
    Aug 2015
    Posts
    5

    Problem with glulookat/gltranslatef

    I have a wierd issue that Im sure has a simple solution.

    Quick history : I usually use lwjgl, but I am converting some stuff to C++.
    I have a class (p) that keeps proper track of my 3 control vectors (right,up,view/forward)

    Here is my issue:

    I basically have the following display code that looks like :
    <code>
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glLoadIdentity();
    p->getView(&ploc,&uVec,&vDir);
    gluLookAt(ploc.x,ploc.y,ploc.z,vDir.x+ploc.x,vDir. y+ploc.y,vDir.z+ploc.z,uVec.x,uVec.y,uVec.z);

    float x= 0;
    float y = 2;
    float z = 2;
    float n =1 ;
    glBegin(GL_QUADS);

    glVertex3f( x+n, y-n,z); // Top Right Of The Quad (Top)
    glVertex3f(x-n, y-n,z); // Top Left Of The Quad (Top)
    glVertex3f(x-n, y+n, z); // Bottom Left Of The Quad (Top)
    glVertex3f( x+n, y+n, z); // Bottom Right Of The Quad (Top)
    glEnd();
    glPopMatrix();

    </code>

    Now, when uVec == 0,1,0 everything works fine. That is to say, when ploc.y increases, my box "moves down". Beautiful.

    In addition, I can change my uVec within class p and the view of my box rotates beautifully. It also "rotates" up and down when my view direction changes.
    In this example VDir = 0,0,1 (looking straight ahead) and never changes.

    It all works.

    Here is the issue. When uVec == 1,0,0 (ie, I have rotated my camera 90 degrees), as ploc.y increases, my box does not "move down". It "moves to the right". In other words, the gltranslatef part of gluLookat is translating the y coordinate along the up Vector, rather than just translating to the world y location.

    This was wierd, so I quickly wrote my own gluLookAt function. I won't go into the detail, but I basically created the rotation matrix using https://www.opengl.org/sdk/docs/man2.../gluLookAt.xml.

    Again, it works flawlessly with all my rotation tests, but as soon as I do a gltranslatef(), it wants to use the rotational axis for the direction of the gltranslatef rather than the actual real location. In other words, uVec=1,0,0 and any changes to ploc.y makes the box move left and right, not up and down.

    The wierd thing is, I do this all the time using lwjgl and it is not an issue. GL11.gltranslatef does not use the rotational matrix to determine where to translate to with gluLookat, or when my make my own matrix.

    The only thing I can think of is in lwjgl, I am specficially using glut 1.1 (GL11 calls) where as in C++ on linux, I am using freeglut3 libraries. Is there a setting I need to set to use real coordinates? Otherwise it would be a nightmare to keep track of where your camera is in world space, and where you are viewing from.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,105
    Quote Originally Posted by gandolf23 View Post
    Here is the issue. When uVec == 1,0,0 (ie, I have rotated my camera 90 degrees), as ploc.y increases, my box does not "move down". It "moves to the right". In other words, the gltranslatef part of gluLookat is translating the y coordinate along the up Vector, rather than just translating to the world y location.
    No, it translates along the world's Y axis. Which is aligned with the screen's X axis because of uVec.

    Quote Originally Posted by gandolf23 View Post
    The wierd thing is, I do this all the time using lwjgl and it is not an issue. GL11.gltranslatef does not use the rotational matrix to determine where to translate to with gluLookat, or when my make my own matrix.
    LWJGL is just a Java binding for OpenGL. There is no difference between using LWJGL and using the C API directly.

    One thing which might make a difference in the case where construct the matrix yourself is that you might be using row-major order where column-major order is required. But that isn't an issue for gluLookAt().

    Quote Originally Posted by gandolf23 View Post
    The only thing I can think of is in lwjgl, I am specficially using glut 1.1 (GL11 calls) where as in C++ on linux, I am using freeglut3 libraries. Is there a setting I need to set to use real coordinates?
    No. You just need to convert your LWJGL code faithfully to C++ without accidentally changing something.

  3. #3
    Newbie Newbie
    Join Date
    Aug 2015
    Posts
    5

    ugh...

    Bah!! Never mind. This is what I get for testing without a horizon line. You are obviously correct and I had a brain shut down. Never mind, my bad . It is acting as it completely should. Thanks for just telling me the obvious .

Similar Threads

  1. problem moving objects using glTranslatef()
    By cassandra in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 03-11-2010, 05:06 AM
  2. Problem with gluLookAt
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-13-2006, 04:55 PM
  3. gltranslatef problem
    By doodlemunch in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-12-2005, 07:55 PM
  4. problem with glTranslatef
    By lud2k in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-04-2003, 05:07 AM
  5. gluLookAt PROBLEM!
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-04-2000, 09:05 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