title: Transformation Hierarchy - applying a parent's orientation to its children
body: <p><strong>My goal:</strong></p>
  
  <ul>
  <li>When being rendered, a child object needs to render relative to its parent; thus its own position and orientation need to be relative to its parent</li>
  </ul>
  
  <p><strong>My problem:</strong></p>
  
  <ul>
  <li>Translations work, but the parent's rotation/orientation isn't correctly being added to a child's transformation calculation; the child rotates on its own orientation fine, but when the parent's orientation is added the calculated vertex for the child is rotated <strong>twice as much</strong></li>
  </ul>
  
  <p><strong>My approach:</strong></p>
  
  <ul>
  <li>When calculating gl_Position in my vertex shader, I pass the shader my mvpMatrix, object vertex, object position, object orientation, parent position, and parent orientation.</li>
  <li><p>Within the shader I've defined structs for holding a quaternion, as well as methods for rotating a vector by a quaternion, <strong>which work on their own</strong> when I rotate an object by itself.</p>
  
  <pre><code>gl_Position = mvpMatrix * (vec4(parentPosition,1) + rotVertexByQuaternion(parentOrientation, vec4(objectPosition,1) + rotVertexByQuaternion(objectOrientation,vertex) ) );
  </code></pre></li>
  </ul>
  
  <p>Here's a picture depicting what I aim, and what I get. I omit adding the parents position in this example, because it is 0,0,0, but it would be done last anyways.
  I've labeled 1 vertex green for the child object and traced it all throughout, so that the rotations can be traced. Also, the current step in my calculation is displayed beneath each panel.
  <img src="https://i.stack.imgur.com/T9XpQ.png" alt="Example of the issue"></p>