title: OpenGL/GLUT: glTranslatef and glRotatef before drawing cube, or after?
body: <p>I'm currently working with OpenGL and GLUT frameworks to play with particles.</p>
  
  <p>However, I can seem to get my logic working correctly for the rotations/translations.</p>
  
  <p>Pseudo code of my current situation:</p>
  
  <pre><code>void display() {
       drawEnvironment();
  
       for each particle 'part' in the array {
            glPushMatrix(); // pushes the matrix for the current transformations? i.e. this particle?
  
            glRotatef(part.angles); // rotate this matrix based of it's own angles (constantly changing)
  
            drawParticle(part); // draws at origin
  
            glTranslatef(part.positon); // translate to the position
  
            glPopMatrix();
       }
  }
  </code></pre>
  
  <p>What I think I'm doing here is as follows:</p>
  
  <ol>
  <li>Pushing the transformation matrix I need from the stack (for the current particle)</li>
  <li>Rotating said matrix (glRotatef rotates around the origin (0,0,0) )</li>
  <li>Drawing the particle at origin so it rotates on spot</li>
  <li>Translate the particle to it's position now that it's been rotated</li>
  <li>Pop the transformation matrix back onto the stack</li>
  </ol>
  
  <p>I've also tried translating -> rotating -> drawing, and a few other mixes.</p>
  
  <p>Hard to explain what's going wrong without a quick video:
  <a href="https://www.youtube.com/watch?v=G0ouhCKKcIM" rel="nofollow">https://www.youtube.com/watch?v=G0ouhCKKcIM</a></p>
  
  <p>Looks like it's rotating <em>after</em> it's being translated, so since it rotates around the origin it follows that larger circle, rather than spinning on it's own axis.</p>