title: Rotating an object and its 'children'
body: <p>Right now I'm rotating an object, lets call it 'mainBody' but attached to the mainBody are several attachments and when I rotate my mainBody they are supposed to rotate along as well, but right now they don't. I'm not using a parent/child system. The main body has an array of it's attachments and draws them in the mainBody draw function.</p>
  
  <p>The glPopMatrix() from the main body is done after the equipment items are drawn.</p>
  
  <p>I know I managed to do this in the past with pushMatrix(); and popMatrix(); But now it doesn't seem to work.</p>
  
  <p>I'm using c++, opengl, and glm.</p>
  
  <p>Here is some code that shows you what I have right now:</p>
  
  <pre><code>{
  
      setupStartModelMatrix(); //&lt;---- Has glPushMatrix();
      setupModelviewMatrix();  //&lt;--- has all the gml stuff
      drawMainBody();
  
      }
  
      if(mNumberOfEquipementOwned != 0)
  
      {
          for(int i = 0; i &lt; mNumberOfEquipementOwned; i++)
          {
              //obj is retrieved with a function 
              obj-&gt;render();
          }
      }
  
      setupEndModelMatrix();  // &lt;--- Has glPopMatrix(); 
  }
  </code></pre>
  
  <p>And the glm code</p>
  
  <pre><code>void GameObject::setupModelviewMatrix()
  {
      glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
  
      glm::mat4 Model = glm::scale( glm::mat4(1.0f), glm::vec3(1.0f)); 
      glm::mat4 ViewTranslate = glm::translate( glm::mat4(1.0f), glm::vec3(mPosition.x, mPosition.y, mPosition.z)); 
      glm::mat4 ViewRotateX = glm::rotate( ViewTranslate, mRotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
      glm::mat4 ViewRotateY = glm::rotate( ViewRotateX, mRotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
      glm::mat4 View = glm::rotate( ViewRotateY, mRotation.z, glm::vec3(0.0f, 0.0f, 1.0f)); 
  
      glm::mat4 MVP = View * Model;
  
      glUniformMatrix4fv( 0, 1, GL_FALSE, glm::value_ptr(MVP)); 
  
      glLoadMatrixf(glm::value_ptr(MVP));
  }
  </code></pre>
  
  <p>And the draw equipement code </p>
  
  <pre><code>void Gun::render()
  {
      glPushMatrix();
      setupModelviewMatrix();
      mMesh-&gt;render();
      glPopMatrix();
  }
  </code></pre>