I am trying to do skeletal animation with GLSL. For each bone, I have a translation(x,y,z) and a rotation(pitch, roll, yaw) (in degrees). I could construct a 4×4 matrix for each bone but that would take alot of register space in the shader, so I would like to only have to store the 6 values I have per bone, but I don’t know how to do this.
Share
Simple: don’t.
Yaw-pitch-roll is a terrible way to encode an orientation, especially for an animation system. Use a quaternion instead. It’s 4 values rather than 3, and the code for rotation is well-known.
Also, it doesn’t require heavy-weight operations like
sinandcos.If you want to compare and contrast the effort needed, consider the math.
Given a quaternion
q, a positionv, you need to do this to rotate it:That’s a fair bit of math. Now, consider what you have to do for your YPR case, given :
That’s not everything. But that’s enough. That’s three
cosand threesinoperations. These are not fast operations. That alone probably takes about as long as the entire quaternion/vector rotation computation. But after doing this, you now have to do several multiplies and adds to compute the 3×3 matrix. And then, after all that, you still have to do the actual matrix multiply to rotate the vector.