我创建了一个包含它的主体和较小部件的“约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();
我似乎无法环绕需要什么,以便发生为对象的小部分与对象的身体正常转动我的头(一个固定的点?)。