Rotate the quad around the center point of OpenGL

I am making a 2D game. I want to be able to display a texture on the screen after rotating its specific value around a center point. This is mainly for rotating the level around the player. The player’s position is the pivot point and the player’s direction as an angle. This code will not work:

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

Any way to make it work? Thank.

+3
source share
2 answers

try reverse

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

and

glRotatef(rotation,0,0,1)

you transfer to the player and then revolve around the source (not the player)

Illustration from the red book :rotate

+2
source

, . , - gluLookAt. , -, " ", .

0

Source: https://habr.com/ru/post/1728992/


All Articles