2013-05-09 77 views
0

我正试图通过引用角色来移动我的世界。它适用于度数为零(玩家前进)但在其他地方混乱。当它是90度时,玩家向后而不是向前。我觉得我正处在正确的轨道上,而我只是搞砸了一些小事。openGL向前移动,旋转角度为0度,向后角度为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() 

它可能是什么有什么想法?

回答

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))