Reputation: 489
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 4x4 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.
Upvotes: 2
Views: 19324
Reputation: 473302
What I don't know how to do is how to rotate a point using the rotation vec3 I have.
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 sin
and cos
.
If you want to compare and contrast the effort needed, consider the math.
Given a quaternion q
, a position v
, you need to do this to rotate it:
vec3 temp = cross(q.xyz, v) + q.w * v;
vec3 rotated = v + 2.0*cross(q.xyz, temp);
That's a fair bit of math. Now, consider what you have to do for your YPR case, given :
vec3 cosYPR = cos(ypr);
vec3 sinYPR = sin(ypr);
That's not everything. But that's enough. That's three cos
and three sin
operations. 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 3x3 matrix. And then, after all that, you still have to do the actual matrix multiply to rotate the vector.
Upvotes: 6