2011-12-12 67 views
1

我想要做的是为我正在制作的fps游戏绘制一把枪,但它似乎总是关闭。我知道我应该在深度测试禁用的情况下最后绘制它。但我似乎无法让它跟随相机的视图。假设我们现在正在画一个三角形来表示枪支,其基础是玩家端。我可以访问玩家位置和他正在寻找的点(用于gluLookAt),并且我还可以访问俯仰和偏航。和想法做什么?如何使用OpenGL绘制第一人称对象

+0

代码在哪里? –

+0

你想看什么部分? – Mirza

+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

祝你好运! :)

+0

为什么你推/拉矩阵两次? –

+0

我不知道,但由于某种原因(至少在我非常类似的代码),它不工作,如果你只做一次...如果有人能解释,会很好! (这是我在这里问的问题:http://stackoverflow.com/questions/8469034/efficiency-of-display-lists-in-opengl-with-python) – SudoNhim