Why am I retarded?
Ok...I have 4 objects each at the +/- 10 coords of the z and x plane. However, when I move my camera in the -x direction...I move AWAY from the red triangle....why?
So when i''m facing the red triangle (camera at 0,0,0)...and move x coor is like -4...camera moves away from it
glLoadIdentity();
glRotatef(oPlayerCamera->rotx,1.0f, 0, 0);
glRotatef(oPlayerCamera->roty,0, 1.0f, 0);
glTranslatef(oPlayerCamera->x,oPlayerCamera->y,oPlayerCamera->z);
...
glPushMatrix();
glTranslatef(10.0,0.0,0.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,1.0f,1.0f);
...
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(-10.0,0.0,0.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
...
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,0.0,10.0);
glBegin(GL_QUADS);
glColor3f(1.0f,1.0f,1.0f);
...
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,0.0,-10.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
...
glEnd();
glPopMatrix();
The last TRIANGLES should be QUADS...
so there are 2 white objects (box and triangle) and 2 red (box and triangle)
so there are 2 white objects (box and triangle) and 2 red (box and triangle)
I haven''t used OpenGL for a while, but it looks like you have two problems. First, you need to transform the world by the inverse of the camera coordinates. Second, glTranslate/Rotate calls work differently from regular translation and rotation functions, so you need to swap them. So, as far as I know, the code for the camera should look like so:
glLoadIdentity();glTranslatef(-oPlayerCamera->x,-oPlayerCamera->y,-oPlayerCamera->z);glRotatef(-oPlayerCamera->roty,0, 1.0f, 0);glRotatef(-oPlayerCamera->rotx,1.0f, 0, 0);
Hmm, no, I do beleave that you have to rotate before translating, inversing everything is a must though.
But if you translate before you rotate, the translation won''t be made in the correct direction. And you will find yourself only able to walk along 2 static axes.
return 1;
But if you translate before you rotate, the translation won''t be made in the correct direction. And you will find yourself only able to walk along 2 static axes.
return 1;
Yes, normally in math you rotate before translating, but for some reason the makers of opengl decided to do it differently for some inexplicable reason (at least if I''m remembering correctly).
"...if you rotate the ojbect first and then translate it, the rotated object appears on the x-axis. If you translate it down the xaxis first, however, and then rotate about the origin, the object is on the line y = x..."
- pg 107 in OpenGL programming Guide 3rd Ed
Just depends on the effect you want...
but generally you want to rotate first...
- pg 107 in OpenGL programming Guide 3rd Ed
Just depends on the effect you want...
but generally you want to rotate first...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement