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;
//我的全局变量
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;
//我在渲染函数中的glulookat函数
gluLookAt(x, 1.0, z, x+lx, 1.0+ly, z+lz, 0.0, 1.0, 0.0);
结果是相机旋转但只向一个方向前进