簡體   English   中英

openGL向前旋轉時旋轉0度,向后旋轉90度

[英]openGL move forward with rotation works for 0 degrees, backwards for 90 degrees

我試圖通過角色來改變我的世界。 如果度數為零(玩家前進),則有效,但其他地方都混亂。 當角度為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()

有什么想法嗎?

公式不正確。 這是正確的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM