void Ovgl::Actor::UpdateAnimation( int bone, Ovgl::Matrix44* matrix, float time )
{
// Initialize animation rotation matrix.
Ovgl::Matrix44 animRot;
animRot = Ovgl::MatrixIdentity();
// Get original pose of this bone and remove translation. Later this is used to convert animation to local space.
Ovgl::Matrix44 Rot;
Rot = mesh->bones[bone]->matrix;
Rot._41 = 0.0f;
Rot._42 = 0.0f;
Rot._43 = 0.0f;
// Search for a key for this bone.
for( unsigned int i = 0; i < mesh->keyframes[(unsigned int)time]->keys.size(); i++ )
{
if(mesh->keyframes[(unsigned int)time]->keys.index == bone)
{
// Create animation rotation matrix.
Ovgl::Vector3 Euler;
Euler.x = Ovgl::DegToRad(mesh->keyframes[(unsigned int)time]->keys.rotation.x);
Euler.y = Ovgl::DegToRad(mesh->keyframes[(unsigned int)time]->keys.rotation.y);
Euler.z = Ovgl::DegToRad(mesh->keyframes[(unsigned int)time]->keys.rotation.z);
animRot = Ovgl::MatrixRotationEuler(Euler.x, Euler.y, Euler.z);
// Convert animation to local space.
animRot = Ovgl::MatrixInverse( &Ovgl::Vector4(), &animRot) * Rot;
}
}
// Offset the center of rotation to the location of the bone.
animRot = Ovgl::MatrixInverse( &Ovgl::Vector4(), &mesh->bones[bone]->matrix) * animRot * mesh->bones[bone]->matrix;
// Get difference from original pose to the animated pose.
matrices[bone] = animRot * ((*matrix) * Ovgl::MatrixInverse( &Ovgl::Vector4(), &mesh->bones[bone]->matrix));
// Loop through all child bones and update their animations.
for( unsigned int i = 0; i < mesh->bones[bone]->childen.size(); i++)
{
Ovgl::Matrix44 accumulate;
accumulate = animRot * (*matrix) * Ovgl::MatrixInverse( &Ovgl::Vector4(), &mesh->bones[bone]->matrix ) * mesh->bones[mesh->bones[bone]->childen]->matrix;
Ovgl::Actor::UpdateAnimation( mesh->bones[bone]->childen, &accumulate, time );
}
}
Here is an image representation of my problem and how I need to solve it:
[attachment=5413:example.png]