1
研究的另一个3D游戏GL的代码,我决定尝试创建一个非常简单的,走动之类的话。OpenGL的:相机theta和缩放
一切似乎工作确定,但只在一个轴上。当一个方向向前和向后走时,一切都很好。虽然,如果你转过90度,并开始向前/向后走,后退将作为向前和向后的功能。
这里是地面绘图代码:
def drawground(self):
glPushMatrix()
glTranslate(-1, -1, -3)
glRotate(90, True, False, False)
glBegin(GL_QUADS)
glColor(0.6, 0.6, 0.6)
glVertex(0, 0)
glVertex(0, self.winmain.world.xlen)
glVertex(self.winmain.world.ylen, self.winmain.world.xlen)
glVertex(self.winmain.world.ylen, 0)
glEnd()
glPopMatrix()
移动代码:
if pygame.key.get_pressed()[K_w]:
self.campos[0] -= 0.005*math.sin(self.camtheta * 3.14159/180)
self.campos[1] -= 0.005*math.cos(self.camtheta * 3.14159/180)
if pygame.key.get_pressed()[K_s]:
self.campos[0] += 0.005*math.sin(self.camtheta * 3.14159/180)
self.campos[1] += 0.005*math.cos(self.camtheta * 3.14159/180)
而且,相机THETA旋转:
if event.type == MOUSEMOTION:
self.camtheta -= 2 * event.rel[0] #Subtracting 2 * the relative moved pixels from the last position.
什么会导致这样的问题呢?
谢谢你的提示,但我不认为这涉及到它面对的方向移动相机。 – 2012-07-13 16:35:53
是的,它的确如此。如果你可以看到我的老C++代码,[这里是你如何使用gluLookAt(https://bitbucket.org/thrustmaster/firstpersonshooter/src/393e18698c3e/Player.cpp)在3D空间走动。是的,我明白这不是一个直接的答复,你将不得不挖掘一点。如果你不能,请告诉我,我会在答复中更新我的答案。 – SuperSaiyan 2012-07-13 16:43:36