我知道相机位于0,0,0并且我需要围绕它旋转世界,但我对于翻译和旋转的顺序感到困惑。
如果有一个理论上的x,y,z坐标系,其中摄像机处于cx,cy,cz并且它面向cox,coy,coz和我有一个立方体,位于bx,by,bz面向盒子,那么男孩,那么什么系列的glTranslatef和glRotatef需要正确地旋转盒子并在远离相机的正确位置?
以下是基本操作,但我不知道将它们放入的顺序以及使其按预期显示所需的其他操作。
gl.glLoadIdentity();
// rotation and translation for cube
gl.glRotatef(box, 1,0,0);
gl.glRotatef(boy, 0,1,0);
gl.glRotatef(boz, 0,0,1);
gl.glTranslatef(bx,by,bz);
// rotation and translation for camera
gl.glRotatef(cox, 1,0,0);
gl.glRotatef(coy, 0,1,0);
gl.glRotatef(coz, 0,0,1);
gl.glTranslatef(cx,cy,cz);
// draw the cube
cube.draw(gl);
答案 0 :(得分:1)
反过来说:首先是相机变换,然后是你的对象:
gl.glLoadIdentity();
// rotation and translation for camera
gl.glRotatef(-cox, 1,0,0);
gl.glRotatef(-coy, 0,1,0);
gl.glRotatef(-coz, 0,0,1);
gl.glTranslatef(-cx,-cy,-cz);
// rotation and translation for cube
gl.glRotatef(box, 1,0,0);
gl.glRotatef(boy, 0,1,0);
gl.glRotatef(boz, 0,0,1);
gl.glTranslatef(bx,by,bz);
// draw the cube
cube.draw(gl);