Skip to content Skip to sidebar Skip to footer

How Can I Rotate Multiple Quads Separately? (pygame, Pyopengl)

I'd like to rotate my quads roughly around they own axis. My first thought was to use glPushMatrix() and glPophMatrix(), but doesn't work. Regardless of that I believe this is the

Solution 1:

Note, that drawing by glBegin/glEnd sequences and the fixed function pipeline matrix stack, is deprecated since decades. Read about Fixed Function Pipeline and see Vertex Specification and Shader for a state of the art way of rendering.


Anyway, OpenGL has different matrix modes, which are GL_MODELVIEW, GL_PROJECTION, and GL_TEXTURE - see glMatrixMode. Ech matrix mode provides a current matrix and a matrix stack. glPushMatrix / glPopMatrix push the current matrix to the stack and pop the top mast matrix form the stack and store it to the current matrix

If you want to do an individual matrix transformation to an object, then you have to:

  • Push the current matrix to the stack by glPushMatrix
  • Do the transformations like glTranslate, glRotate, glScale or even glLoadMatrix which loads a completely new matrix. For the sak of completeness, there als exists glLoadIdentity and glMultMatrix.
  • Draw the object.
  • Pop the top most matrix glPopMatrix, to restore the current matrix and the matrix stack. Now the current matrix and the matrix stack seem to be so, as the above transformations never would have happened.

e.g.

glPushMatrix()
glTranslated(250, 100, 0)
glRotated(5, 0, 0, 1)
makeQuad()
glPopMatrix()

If you want to animate the quads separately, then i recommend to use the 2 control variables a1 and a2, which control the angle of rotation and are incremented ongoing in the main loop:

a1, a2 = 0, 0whileTrue:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

    glPushMatrix()
    glTranslated(250, 100, 0)
    glRotated(a1, 0, 0, 1)
    makeQuad()
    glPopMatrix()

    glPushMatrix()
    glTranslated(100, 250, 0)
    glRotated(a2, 0, 0, 1)
    makeQuad()
    glPopMatrix()

    a1 += 1
    a2 += 2

    pygame.display.flip()

Preview:

Post a Comment for "How Can I Rotate Multiple Quads Separately? (pygame, Pyopengl)"