我的应用程序中有一个简单的矩形形状,我正在旋转固定它的一侧,并围绕 X 轴旋转。旋转看起来像下图(灰色表示我用这个图得到的当前旋转)
我正在使用以下代码来获取此轮换
glPushMatrix();
glTranslatef(position of the axis point which has to be fixed for rotation);
glRotatef(rotationAmount, 1,0,0);
glTranslatef(-position of the axis point which has to be fixed for rotation);
Rectangle(xPosition, Position,200,100);
glPopMatrix();
但是,我必须围绕其一侧(图中的绿色箭头方向)围绕 y 轴进行额外的旋转来旋转同一个图形。如何旋转这个矩形,使其同时围绕 x 轴和 y 轴旋转?
编辑:我确实尝试添加另一个glRotatef(rotateAroundYaxis amount,0,1,0)
,但输出实际上并不像我期望的那样。该图形在两个象限中旋转,而不是像简单的翻页那样围绕 y 轴旋转。
如果我在程序中仅使用其中一个(而不是一起)独立尝试这两个旋转,即
glRotatef(rotateAmount,1,0,0);
glRotatef(rotateYamount,0,-1,0);
我确实独立获得了所需的 X 和 Y 旋转,但是当它们组合在一起时,它会组合成一些奇怪的旋转效果。