# Skinning Matrices [Solved]

This topic is 2098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm attempting to animate a skinned mesh with joints. I have looked at many different materials, and something isn't right with my understanding. All of my nodes hold a local and global matrix. When I load in the joints, I calculate the inverse pose matrix like so:

[b]Pose Matrix[/b] = Mesh's Inverse Global * Joint Global
[b]Inverse Pose Matrix[/b] = Inverse of Pose Matrix

Then when my joints are updated, I calculate the joint in mesh space and multiply it with the inverse pose matrix.

[b]Joint wrt Mesh[/b] = Mesh's Inverse Global * Joint Global
[b]Deform Matrix[/b] = Joint wrt Mesh * Inverse Pose Matrix

I uploaded the following video files to demonstrate what is happening to my mesh. Is my algorithm correct in handling the matrices in mesh space and calculating the inverse pose matrix? If I knew that, it would be easier to further study the problem.

[url="http://tinypic.com/r/ncmnpj/5"]Source animation..[/url]

[url="http://tinypic.com/r/egviqf/5"]My Results..[/url]

These are my references -

##### Share on other sites
Hi, the solution in my game engine is the following:
[CODE]
struct Bone {
Matrix4 staticMat;
unsigned int jointIndex;
std::string name;
std::vector<Bone*> children;
};

struct Skeleton {
Bone* rootBone;
std::map<std::string, Bone*> bones;
};

struct BonePose {
Matrix4 poseMat, dynamicMat;
};

class SkeletonPose {
public:
std::map<std::string, BonePose*> bonePoses;
SkeletonPose(Skeleton* skeleton);
~SkeletonPose();
void calculateBonePose(Bone* bone, Bone* parentBone);
void calculateDisplayMatrix(Bone* bone, Bone* parentBone, Matrix4* mats);
};

void SkeletonPose::calculateBonePose(Bone* bone, Bone* parentBone) {
BonePose* bonePose = bonePoses[bone->name];
bonePose->dynamicMat.setIdentity();
if(parentBone) {
bonePose->dynamicMat = bonePose->poseMat;
bonePose->dynamicMat.translate(bone->staticMat.pos-parentBone->staticMat.pos);
bonePose->dynamicMat *= bonePoses[parentBone->name]->dynamicMat;
}else{ //Is root bone
bonePose->dynamicMat = bonePose->poseMat;
bonePose->dynamicMat.translate(bone->staticMat.pos);
}
for(unsigned int i = 0; i < bone->children.size(); i ++)
calculateBonePose(bone->children[i], bone);
}

void SkeletonPose::calculateDisplayMatrix(Bone* bone, Bone* parentBone, Matrix4* mats) {
Matrix4 mat;
mat.setIdentity();
mat.translate(bone->staticMat.pos*-1);
mats[bone->jointIndex] = mat * bonePoses[bone->name]->dynamicMat;
for(unsigned int i = 0; i < bone->children.size(); i ++)
calculateDisplayMatrix(bone->children[i], bone, mats);
}

//Draw Frame

//Calculate the hierarchical transformations of the skeleton
skeletonPose->calculateBonePose(humanModel->skeleton->rootBone, NULL);

//Calculate the matrices used in the shader
Matrix4* mats = new Matrix4[skeleton->bones.size()];
skeletonPose->calculateDisplayMatrix(skeleton->rootBone, NULL, mats);
delete [] mats;
for(unsigned int i = 0; i < meshes.size(); i ++)
meshes[i]->draw();
[/CODE]

I hope you can understand my code [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img].