1

我的应用程序中有一个简单的矩形形状,我正在旋转固定它的一侧,并围绕 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 旋转,但是当它们组合在一起时,它会组合成一些奇怪的旋转效果。

4

2 回答 2

1

听起来您只想要以下内容。如果你不告诉我,我会改变它。

glPushMatrix();
glTranslatef(position of the axis point which has to be fixed for rotation);
glRotatef(rotationAmount, 1,0,0); // <- keep this but also
glRotatef(rotationAmountAroundYAxis, 0,1,0); // <- add this
glTranslatef(-position of the axis point which has to be fixed for rotation);
Rectangle(xPosition, Position,200,100);
glPopMatrix();
于 2012-12-04T07:36:20.477 回答
0

你需要改变这个:

glRotatef(rotationAmount, 1,0,0);

进入这个:

glRotatef(rotationAmount, 1,1,0);
于 2012-12-04T07:38:32.410 回答