Here's my code for applying a quaternion to a matrix that I multiply with a translation and scale matrix:
Code: Select all
if(NumAnimations > 0) {
ScePspFMatrix4 mat;
for(int i=0;i<Animations[0].NumFrames;i++) {
Animations[0].Frames[i].Keys = new ScePspFMatrix4[Animations[0].Frames[i].NumKeys];
for(int e=0;e<Animations[0].Frames[i].NumKeys;e++) {
gumLoadIdentity(&mat);
gumLoadIdentity(&Animations[0].Frames[i].Keys[e]);
// manually plug the quaternion into the matrix
mat.x.x =
(Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].w) +
(Animations[0].Frames[i].quaternion[e].x * Animations[0].Frames[i].quaternion[e].x) -
(Animations[0].Frames[i].quaternion[e].y * Animations[0].Frames[i].quaternion[e].y) -
(Animations[0].Frames[i].quaternion[e].z * Animations[0].Frames[i].quaternion[e].z);
mat.x.y =
(2.0f * Animations[0].Frames[i].quaternion[e].x * Animations[0].Frames[i].quaternion[e].y) -
(2.0f * Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].z);
mat.x.z =
(2.0f * Animations[0].Frames[i].quaternion[e].x * Animations[0].Frames[i].quaternion[e].z) +
(2.0f * Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].y);
mat.y.x =
(2.0f * Animations[0].Frames[i].quaternion[e].x * Animations[0].Frames[i].quaternion[e].y) +
(2.0f * Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].z);
mat.y.y =
(Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].w) +
(Animations[0].Frames[i].quaternion[e].x * Animations[0].Frames[i].quaternion[e].x) -
(Animations[0].Frames[i].quaternion[e].y * Animations[0].Frames[i].quaternion[e].y) -
(Animations[0].Frames[i].quaternion[e].z * Animations[0].Frames[i].quaternion[e].z);
mat.y.z =
(2.0f * Animations[0].Frames[i].quaternion[e].y * Animations[0].Frames[i].quaternion[e].z) -
(2.0f * Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].x);
mat.z.x =
(2.0f * Animations[0].Frames[i].quaternion[e].x * Animations[0].Frames[i].quaternion[e].z) -
(2.0f * Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].y);
mat.z.y =
(2.0f * Animations[0].Frames[i].quaternion[e].y * Animations[0].Frames[i].quaternion[e].z) +
(2.0f * Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].x);
mat.z.z =
(Animations[0].Frames[i].quaternion[e].w * Animations[0].Frames[i].quaternion[e].w) +
(Animations[0].Frames[i].quaternion[e].x * Animations[0].Frames[i].quaternion[e].x) -
(Animations[0].Frames[i].quaternion[e].y * Animations[0].Frames[i].quaternion[e].y) -
(Animations[0].Frames[i].quaternion[e].z * Animations[0].Frames[i].quaternion[e].z);
gumMultMatrix(&Animations[0].Frames[i].Keys[e], &mat, &Animations[0].Frames[i].Keys[e]);
gumTranslate(&Animations[0].Frames[i].Keys[e], Animations[0].Frames[i].translate);
//gumScale(&Animations[0].Frames[i].Keys[e], Animations[0].Frames[i].scale);
}
}
}
Anyway, the motion appears to be correct from what it looks like. For some reason, all the boxes attached to my biped model are squashed, but they do appear to move, and from what it looks like, rotate the right way. If anyone has any suggestions, I'm more than happy to hear them! =)
EDIT: Never mind about what I said earlier about the motion. It is wrong!