到目前爲止我的代碼OpenGL,如何相互獨立地旋轉對象?
void display (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
gluLookAt( camera[0][0], camera[0][1], camera[0][2],
camera[1][0], camera[1][1], camera[1][2],
camera[2][0], camera[2][1], camera[2][2] ); //Set the point looking at
glRotatef(cubeRot[0], 1.0f, 0.0f, 0.0f); //rotate on x axis
glRotatef(cubeRot[1], 0.0f, 1.0f, 0.0f); //rotate on y axis
glRotatef(cubeRot[2], 0.0f, 0.0f, 1.0f); //rotate on z axis
switch (Rendermode) { //different render mode
case 'f':
//Draw object I want to rotate
break;
case 'v':
//Draw object I want to rotate
break;
case 'e':
//Draw object I want to rotate
break;
glLoadIdentity();
}
//Draw object I DO NOT want to rotate
glutSwapBuffers (); // Swap The Buffers To Not Be Left With A Clear Screen
}
然而,此刻我的所有對象的同時旋轉,我怎麼能旋轉,我已經注意到要旋轉,同時使我注意到不是那些對象想旋轉還是?
我已經把glPush和glPop放在我想旋轉的對象的圖畫周圍,但另一個對象仍在旋轉着它們。你介意C&P我的代碼並把它們放在正確的地方嗎? – sam
現在,我看到在代碼中調用'glRotatef()'3次''cubeRot'作爲參數。如果你想在一個單獨的對象上執行它們中的每一個,不要一次執行這些調用,絕對不能在'switch/case'之前執行。圍繞它自己的push/pop操作調用每個調用以及繪製該特定對象的方法調用。 – karlphillip
順便說一句,在'switch'結尾處刪除'glLoadIdentity()'。沒有必要。 – karlphillip