Hey everyone,
Currently working on a project with a 3d interactive scene of a low poly spaceship model. I have the perspective camera rotating on mouse movement.
My question is this: I am using the ASDW keys to control walking around the scene. However, when the camera is rotated, its still moving around in global coordinates and not in the correct vectors in relation to the camera. For example, if i rotate the camera 90 deg. to the left, and press the W key to travel forward, it still strafes to the positive X direction (to the right of the camera)
Here are bits of my code:
For the rotation on mouse movement:
Code:
void myMouseMove(int xw, int yw){
int xpos,ypos; // mouse position in coords with origin at lower left.
xpos = xw;
ypos = getDisplayHeight() - yw;
yrot += 0.3*(xpos-xclik); // change rot. angle by drag distance
xrot -= 0.3*(ypos-yclik); // (drag in X direction rotates on Y axis)
xclik = xpos; // (drag in Y direction rotates on X axis)
yclik = ypos; // update current mouse position.
}
Display function piece for drawing the scene:
Code:
glMatrixMode (GL_MODELVIEW); glLoadIdentity ();
glClear(GL_DEPTH_BUFFER_BIT );
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glRotatef(zrot, 0.0f, 0.0f, 1.0f);
gluLookAt (0.0, 2.0, -10.0,
0.0, 2.0, 0.0,
0.0, 1.0, 0.0);
glPushMatrix();
glTranslated(-movex,movey,-movez);
drawScene();
glPopMatrix();
I've tried several different strategies for correcting the movement but havent gotten anywhere :/
I'd appreciate any help i can get. Thanks!
And... theres my first post on this forum! bam!