简体   繁体   中英

OpenGL - Unwanted z axis camera rotation

When I rotate my camera on the X axis while the Y rotation is > or < than 0, it also rotates the Z axis.
Why does it do this?

if(Keyboard.isKeyDown(Keyboard.KEY_UP)){
    xRot-=speed_rotation;
    glRotatef(-speed_rotation, 1, 0, 0);
}
if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)){
    xRot+=speed_rotation;
    glRotatef(speed_rotation, 1, 0, 0);
}
if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)){
    yRot-=speed_rotation;
    glRotatef(-speed_rotation, 0, 1, 0);
}

if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)){
    yRot+=speed_rotation;
    glRotatef(speed_rotation, 0, 1, 0);
}

I think I know what is causing it, but I'm not so sure...

不要glRotate()在键盘的处理程序,只需更新X / Y旋转值就像你正在做的,并发出组的glRotate()s在绘制之前。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM