我正在尝试做的是为我正在制作的fps游戏画一把枪,但似乎总是关闭。我知道我应该在禁用深度测试时最后绘制它。但我似乎无法让它跟随相机的视图。假设我们现在正在绘制一个三角形代表枪,底部位于玩家端。我可以访问玩家位置和他正在寻找的位置(用于gluLookAt),我也可以进入球场和偏航。关于该怎么做的想法?
答案 0 :(得分:1)
我不是专家,但我会尝试类似以下的东西来拔枪:
#If not already in modelview mode
glMatrixMode(GL_MODELVIEW)
#Push the current modelview matrix onto the stack, leaving us working with a copy
glPushMatrix()
#Translate forward to where we want to draw the gun
glTranslatef(0,0,dist)
#Draw the gun starting from this position, translation may need to account for offset so that it is centered correctly
gun.draw()
#Get rid of our modified modelview matrix and return to the original so that the camera is in the correct positon
glPopMatrix()
我发现用于理解OpenGL几何的最佳指南是http://www.songho.ca/opengl/gl_transform.html
祝你好运! :)