在 2D 中仅旋转一个四边形
在 OpenGL 中,对于 2D 中的以下情况,如何旋转这一个四边形 - 并且仅旋转这一个四边形(场景中的其他所有内容都应保持在原来的位置)?
// Draw in immediate mode
glBegin(GL_QUADS); // begin drawing quads
glVertex2f(box.x,box.y); // top-left corner
glVertex2f(box.x+box.w,box.y); // top-right corner
glVertex2f(box.x+box.w,box.y+box.h); // bottom-right corner
glVertex2f(box.x,box.y+box.h); // bottom-left corner
glEnd(); // end drawing quads
glRotatef(angle, x,y,z)
似乎旋转了我的整个场景。
In OpenGL, for the following situation in 2D, how can I rotate this one quad - and only this one quad (everything else in the scene should stay where it is)?
// Draw in immediate mode
glBegin(GL_QUADS); // begin drawing quads
glVertex2f(box.x,box.y); // top-left corner
glVertex2f(box.x+box.w,box.y); // top-right corner
glVertex2f(box.x+box.w,box.y+box.h); // bottom-right corner
glVertex2f(box.x,box.y+box.h); // bottom-left corner
glEnd(); // end drawing quads
glRotatef(angle, x,y,z)
seems to rotate my whole scene.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其包含在 glPushMatrix 和 popMatrix 中
基本上,在上面的示例中,您将 modevliew 矩阵推入堆栈中的一个位置,本质上将其保存。然后旋转模型视图并绘制四边形。
然后,您在模型视图中弹回一个位置,恢复到旋转和绘图之前的状态。
Enclose it in glPushMatrix and popMatrix
Basically in the above example you are pushing the modevliew matrix one position up into the stack, saving it in an essence. Then you rotate the modelview and draw your quad.
Afterwards you pop back one position in the modelview taking back to how it was before the rotation and the drawing.