- 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
- 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 twice as much
- 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.
Within the shader I've defined structs for holding a quaternion, as well as methods for rotating a vector by a quaternion, which work on their own when I rotate an object by itself.
gl_Position = mvpMatrix * (vec4(parentPosition,1) + rotVertexByQuaternion(parentOrientation, vec4(objectPosition,1) + rotVertexByQuaternion(objectOrientation,vertex) ) );
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.