Opengl es 一系列OpenGL ES平移和旋转的正确顺序是什么?

Opengl es 一系列OpenGL ES平移和旋转的正确顺序是什么?,opengl-es,Opengl Es,我知道相机的位置是0,0,0,我需要绕着它旋转世界,但我不知道平移和旋转的顺序 如果有一个理论上的x,y,z坐标系,相机位于cx,cy,cz,它朝向cox,coy,coz,我有一个立方体,它位于bx,by,bz,朝向box,boy,boz,那么需要哪一系列的glTranslatef和glRotatef来正确地旋转盒子,并且在远离相机的正确位置 以下是基本操作,但我不知道将它们放在什么顺序中,以及需要什么其他操作才能使其按预期显示 gl.glLoadIdentity(); // rotation

我知道相机的位置是0,0,0,我需要绕着它旋转世界,但我不知道平移和旋转的顺序

如果有一个理论上的x,y,z坐标系,相机位于cx,cy,cz,它朝向cox,coy,coz,我有一个立方体,它位于bx,by,bz,朝向box,boy,boz,那么需要哪一系列的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);

以另一种方式进行:首先进行摄影机变换,然后进行对象变换:


以另一种方式进行:首先进行摄影机变换,然后进行对象变换:

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