[英]openGL move forward with rotation works for 0 degrees, backwards for 90 degrees
I am trying to move my world in reference to a character. 我试图通过角色来改变我的世界。 It works if the degree is zero (the player goes forward) but messes up everywhere else.
如果度数为零(玩家前进),则有效,但其他地方都混乱。 When it is 90 degrees, the player goes backwards instead of forwards.
当角度为90度时,播放器将向后而不是向前。 I feel like I am on the right track and I just messed up something small.
我觉得自己处在正确的轨道上,只是弄乱了一些小东西。
Here is my equation for the goForward() function 这是我对goForward()函数的方程式
rad = angle * (pi/180)
world_loc = (world_loc[0] + speed * sin(rad), world_loc[1], world_loc[2] + speed* cos(rad))
Then this is how I display my world 那就是我展现我的世界的方式
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()
Any thoughts on what it could be? 有什么想法吗?
The formula is incorrect. 公式不正确。 Here is the correct one:
这是正确的:
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.