【发布时间】:2021-01-23 02:49:31
【问题描述】:
我正在尝试制造一种可以沿 X 轴移动并围绕 Z 轴旋转的锤子武器。现在我的锤子有问题。锤子可以在一个固定的支点上绕 Z 轴旋转,但是当我将锤子移动到新位置然后旋转锤子时,锤子仍然围绕旧的支点旋转。
我尝试添加移动到旧枢轴点的距离,但它不起作用。我该如何解决这个问题?感谢您的帮助!
这是我的代码:
glPushMatrix();
//the rotation angle of Z-axis
glTranslatef(0.5f,1.0f,-1.0f); //Back to original point
glRotatef(zr, 0.0f, 0.0f, 1.0f); //Rotating
glTranslatef(-0.5f,-1.0f,1.0f); //The rotation piovt point
//build weapon base
//the moving distant on X-axis
glPushMatrix();
glColor3f(1, 0, 0);
glTranslatef(0.5f+xr, 1.0f, -1.0f);
glRotatef(-90.0, 1.0, 0.0, 0.0);
quadratic = gluNewQuadric();
gluCylinder(quadratic, 0.2f, 0.2f, 2.0f, 50, 50);
glPopMatrix();
//build hammer
glPushMatrix();
glTranslatef(0.0+xr, 3.0f, -1.0f);
glRotatef(90.0, 0.0, 1.0, 0.0);
glColor3f(0, 1, 0);
quadratic = gluNewQuadric();
gluCylinder(quadratic, 0.2f, 0.2f, 1.0f, 50, 50);
glPopMatrix();
glPopMatrix();
【问题讨论】:
标签: c++ opengl freeglut opengl-compat