How to rotate camera and move forward to the direction (glulookat)

328 views Asked by At
switch(key) {
case 'w':   // W - Go forward
    x += lx * movement;
    z += lz * movement;
    break;
case 's':   // S - Go back
    x -= lx * movement;
    z -= lz * movement;
    break;
case 'd':   // D - Turn right
    angle += 0.05;
    lx = sin(angle);
    lz = -cos(angle);
    break;
case 'a':   // A - Turn left
    angle -= 0.05;
    lx = sin(angle);
    lz = -cos(angle);
    break;    

// my global variables

float movement = 1.0;

float angle=0.0;

float lx=0.0f,lz=-1.0f , ly = 0.0 ;

float x=0.0f,z=0.0f;

// my glulookat function in the render function

gluLookAt(x, 1.0, z, x+lx, 1.0+ly, z+lz, 0.0, 1.0, 0.0);

The result is that camera rotates but only goes forward in one direction

0

There are 0 answers