openGL向前移动,旋转工作0度,向后旋转90度

时间:2013-05-09 03:07:10

标签: python opengl 3d rotation trigonometry

我试图移动我的世界参考一个角色。如果学位为零(玩家向前),它会起作用,但在其他地方会混乱。当它是90度时,玩家向后而不是向前。我觉得自己走在了正确的轨道上,而我只是搞砸了一些小事。

这是goForward()函数的等式

   rad = angle * (pi/180)
   world_loc = (world_loc[0] + speed * sin(rad), world_loc[1], world_loc[2] + speed* cos(rad))

然后这是我展示我的世界的方式

glPushMatrix()
   glRotate(angle, 0,1,0)
   glTranslatef(world_loc[0],world_loc[1],world_loc[2])
   for x in range(len(world)):
      for y in range(len(world[0])):
         for z in range(len(world[0][0])):
            if(world[x][y][z] != None):              
               glPushMatrix()
               glTranslatef(x*2,y*2,z*2)
               glCallList(world[x][y][z])
               glPopMatrix()
   glPopMatrix()

对它可能是什么的任何想法?

1 个答案:

答案 0 :(得分:0)

公式不正确。这是正确的:

def moveForward():
   global angle, angle_speed, world_loc, maxSize
   rad = (angle+90) * (pi/180)
   world_loc = (world_loc[0] - speed * cos(rad), world_loc[1], world_loc[2] - speed *    sin(rad))