gpt4 book ai didi

python - 在 OpenGL 中围绕中心点旋转四边形

转载 作者:行者123 更新时间:2023-11-28 17:54:51 25 4
gpt4 key购买 nike

我正在制作 2D 游戏。我希望能够在围绕中心点旋转一定量后在屏幕上渲染纹理。基本上这是为了围绕玩家进行关卡轮换。玩家位置是旋转点,玩家的方向是角度。此代码不起作用:

def draw_texture(texture,offset,size,a,rounded,rotation,point):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity() #Loads model matrix
glColor4f(1,1,1,float(a)/255.0)
glTranslatef(point[0],point[1],0)
glRotatef(rotation,0,0,1)
glBindTexture(GL_TEXTURE_2D, texture)
if rounded == 0:
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0)
glVertex2i(*offset) #Top Left
glTexCoord2f(0.0, 1.0)
glVertex2i(offset[0],offset[1] + size[1]) #Bottom Left
glTexCoord2f(1.0, 1.0)
glVertex2i(offset[0] + size[0],offset[1] + size[1]) #Bottom, Right
glTexCoord2f(1.0, 0.0)
glVertex2i(offset[0] + size[0],offset[1]) #Top, Right
glEnd()
else:
#Nothing important here
glEnd()

有什么办法让它工作吗?谢谢。

最佳答案

尝试倒车

glTranslatef(point[0],point[1],0)

glRotatef(rotation,0,0,1)

你正在向玩家移动,然后绕着原点(而不是玩家)旋转

插图来自red book : rotate

关于python - 在 OpenGL 中围绕中心点旋转四边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2089849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com