我的 OpenGL 游戏中有一个墙图案 DrawWall
和一架飞机 DrawAirplane
。如何插入和弹出当前矩阵并仅平移场景中的墙?
我希望飞机能修好。
private: void DrawWall(){
glPushMatrix();
glBegin(GL_POLYGON);
LeftWallPattern();
glEnd();
glBegin(GL_POLYGON);
RightWallPattern();
glEnd();
glPopMatrix();
}
private: void DrawAirplane(){
glPushMatrix();
glBegin(GL_LINE_LOOP);
//...
glEnd();
glPopMatrix();
}
public: void Display(){
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(0, -0.02, 0);
DrawWall();
DrawAirplane();
glFlush();
}
最佳答案
使用glPushMatrix()
插入当前矩阵,执行glTranslate
并绘制墙壁,然后使用glPopMatrix()
绘制平面。这应该只平移墙。问题是您似乎是在显示中进行翻译,而不是在应该在 DrawWall
中进行翻译。
关于c++ - 如何在 OpenGL 中只平移场景中的一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17179665/