title: Rotating a quad around a coordinate in OpenGL
body: <p>I'm currently programming a primary flight display using Python and OpenGL.
  As I have zero experience with OpenGL <em>(and little experience with coding in general)</em> I do struggle with most simple feature implementation but until now I got this far:</p>
  
  <p><a href="https://i.stack.imgur.com/WdeB8.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WdeB8.gif" alt="Pi2Fly"></a></p>
  
  <p>What my problem now is to rotate the artificial horizon around the center point of the viewport <em>(400x240)</em> according to the roll data.
  My viewport is 800x480 with the quad representing the artificial horizon having the size of 1000x2880.</p>
  
  <p>Displaying the pitch data is easy because 1 degree equals 8 pixels on the viewport/horizon texture.</p>
  
  <p><code>Numbers.p_offset = -Data.pitch*8</code>, which I can just add to all four y-coordinates of the quad.</p>
  
  <pre><code>def horizon():
  
      glBindTexture(GL_TEXTURE_2D, horizontexture)
  
      glEnable(GL_BLEND)
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
      glEnable(GL_TEXTURE_2D)
      glColor4f(1, 1, 1, 1)
  
      glBegin(GL_QUADS)
      glTexCoord2f(0, 1); glVertex2f(-100, -1200+Numbers.p_offset)
      glTexCoord2f(1, 1); glVertex2f(900, -1200+Numbers.p_offset)
      glTexCoord2f(1, 0); glVertex2f(900, 1680+Numbers.p_offset)
      glTexCoord2f(0, 0); glVertex2f(-100, 1680+Numbers.p_offset)
      glEnd()
  
      glDisable(GL_TEXTURE_2D)
  </code></pre>
  
  <p>What isn't easy is to display the roll data <em>(-180° to 180°)</em>, as a change in roll would change the x- <em>and</em> y-coordinate of the quad. First, the pitch offset would need to be applied <em>(to keep the vertical center-line of the quad in the center of the viewport)</em> and then the rotation corresponding to the roll. I cannot figure out the math on how to calculate the offsets roll would cause, so I'm looking for a solution on how to do it with some OpenGL functionality I do not know of yet.</p>
  
  <p>All the tutorials and questions/answers I found were specifically asking on how to rotate the quad around its own center point and not another coordinate.</p>
  
  <hr>
  
  <p><strong>Question:</strong> How is it possible to rotate a quad around a specific coordinate in an orthographic projection in OpenGL and Python? </p>