如何旋转相机并向前移动(glulookat)

时间:2016-11-24 16:50:34

标签: c++ opengl glulookat

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);

结果是相机旋转但只向一个方向前进

0 个答案:

没有答案