我創建了一個包含它的主體和較小部件的「約7+部件」,它在不同的位置「附加」到它。我的目標是旋轉整個對象。我試圖在構造整個對象之前簡單地調用glRotatef(angle, 0, 1, 0)
,但我意識到這似乎是圍繞原點旋轉「一切」,無論翻譯是什麼。下面的代碼是試圖旋轉身體本身並旋轉附件。旋轉一個多部件對象
// glRotatef(angle, 0, 1, 0); //old way of rotating the object
// body
glPushMatrix();
// movement
glTranslatef(subx, suby + y, subz);
//rotating the body itself
glRotatef(angle, 0, 1, 0);
// starting position of the body
glScalef(9.0, 1.75, 1.75);
glTranslatef(-subx, -suby, -subz);
glTranslatef(subx, suby, subz);
glutSolidSphere(1.0, 50, 50);
glPopMatrix();
// attached part
glPushMatrix();
// movement
glTranslatef(rot1x, rot1y + y, rot1z);
// attempting to rotate the part while 'attached to' the body
glRotatef(angle, 0, 1, 0);
//placing the part on the object in starting position
glRotatef(rot1angle, rot1xrot, rot1yrot, rot1zrot);
glTranslatef(-rot1x, -rot1y, -rot1z);
glTranslatef(rot1x, rot1y, rot1z);
gluPartialDisk(gluNewQuadric(), 0, 1, 50, 1, 0, 100.0);
glPopMatrix();
我似乎無法環繞需要什麼,以便發生爲對象的小部分與對象的身體正常轉動我的頭(一個固定的點?)。