gpt4 book ai didi

c++ - 对同一图形应用多个同时旋转

转载 作者:太空宇宙 更新时间:2023-11-04 12:02:09 24 4
gpt4 key购买 nike

我的应用程序中有一个简单的矩形形状,我正在旋转固定它的一侧,并绕 X 轴旋转。旋转看起来像下图(灰色表示我从这张图中得到的当前旋转)

enter image description here

我正在使用以下代码来获取此旋转

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 旋转,但当它们结合在一起时,它会组合成一些奇怪的旋转效果。

最佳答案

听起来您只需要以下内容。如果您不这样做,请告诉我,我会更改它。

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();

关于c++ - 对同一图形应用多个同时旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13697890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com