   [C++] Skinned Meshes and Animation Troubles.
  For the past few days I've been trying as hard as I can to figure this out, but so far nothing has come up, so hopefully somebody can help me with this.My problem can be best described as such:This is Mr. Ninja, say hi Mr. Ninja!  See, he's giving you all a nice little wave to show how happy he is to meet you!Mr. Ninja is so happy, that he's willing to show you one of his tricks: his knee of unnatural rotations of DOOM.  He raises his leg to show you...And cries out in pain as some ironic force rips his leg to shreds, forcing it into a position unnatural for even his unnatural trick!As shown by the third image, my problem is thus: some, not all, of the bones of my mesh aren't transformed properly, and the vertices associated with them are transformed around the parent of the bone they should be transformed around.Now, I don't have any idea what may cause this problem.  For loading the model, and assigning pointers to arrays to make manipulating the bones a tad bit easier (at least, as easy as I can find a way how to), I use the following:void PCActor::LoadActor(LPCWSTR Name){//Reset Standard World TransformationsPosition.x = 0.0f; Position.y = 0.0f; Position.z = 0.0f;Rotation.x = 0.0f; Rotation.y = 0.0f; Rotation.z = 0.0f;Scale.x = 1.0f; Scale.y = 1.0f; Scale.z = 1.0f;//Load the Mesh Hierarchy and Setup Bone Matrix Pointers and What NotD3DXLoadMeshHierarchyFromX( Name, D3DXMESH_MANAGED, DX_D3DDevice,&this->Alloc, NULL, &this->g_pFrameRoot, &this->g_pAnimController );this->SetupBoneMatrixPointers( this->g_pFrameRoot );//If there is an Animation, Reset it at 0.if(g_pAnimController != NULL){g_pAnimController->SetTrackPosition(0,0.00);}//Start parsing hierarchy and storing pointers to arrays for easy access.if(g_pAnimController != NULL){//Ready Variablesint CurrentMatrix = 1;int CurrentSibling = 0;ActorBoneTotal = 100; //Temporary ValueOriginalBoneMatrices = new D3DXMATRIXA16[ActorBoneTotal];BonePointers = new D3DXMATRIX*[ActorBoneTotal];BoneParents = new int[ActorBoneTotal];D3DXFRAME* *BoneSiblings = new D3DXFRAME*[ActorBoneTotal];int* BoneSiblingParents = new int[ActorBoneTotal];D3DXFRAME *Temp = this->g_pFrameRoot;OriginalBoneMatrices[0] = Temp->TransformationMatrix;BonePointers[0] = &Temp->TransformationMatrix;for(int x=0;x<ActorBoneTotal;x++){BoneSiblings[x] = NULL;}BoneParents[0] = NULL;//Load each Frame's Child, and Assign Siblings to another array to go through later.while(Temp->pFrameFirstChild != NULL){Temp = Temp->pFrameFirstChild;BoneParents[CurrentMatrix] = CurrentMatrix-1;OriginalBoneMatrices[CurrentMatrix] = Temp->TransformationMatrix;BonePointers[CurrentMatrix] = &Temp->TransformationMatrix;CurrentMatrix+=1;//If there are siblings, add to another array to go through later.if(Temp->pFrameSibling != NULL){if(CurrentSibling > 0){CurrentSibling+=1;}BoneSiblings[CurrentSibling] = Temp->pFrameSibling;BoneSiblingParents[CurrentSibling] = CurrentMatrix-1;while(BoneSiblings[CurrentSibling]->pFrameSibling != NULL){CurrentSibling+=1;BoneSiblings[CurrentSibling] = BoneSiblings[CurrentSibling-1]->pFrameSibling;BoneSiblingParents[CurrentSibling] = CurrentMatrix-1;}}}//Go through the Sibling Bones, and assign them to the main bone array,//assigning each of their own children it's own spot, and assigning further//siblings to the sibling array.while(BoneSiblings[0] != NULL && CurrentSibling >= 0){Temp = BoneSiblings[0];OriginalBoneMatrices[CurrentMatrix] = Temp->TransformationMatrix;BonePointers[CurrentMatrix] = &Temp->TransformationMatrix;BoneParents[CurrentMatrix] = BoneSiblingParents[0];CurrentMatrix+=1;while(Temp->pFrameFirstChild != NULL){Temp = Temp->pFrameFirstChild;BoneParents[CurrentMatrix] = CurrentMatrix-1;OriginalBoneMatrices[CurrentMatrix] = Temp->TransformationMatrix;BonePointers[CurrentMatrix] = &Temp->TransformationMatrix;CurrentMatrix+=1;if(Temp->pFrameSibling != NULL){if(CurrentSibling > 0){CurrentSibling+=1;}BoneSiblings[CurrentSibling] = Temp->pFrameSibling;BoneSiblingParents[CurrentSibling] = CurrentMatrix-1;while(BoneSiblings[CurrentSibling]->pFrameSibling != NULL){CurrentSibling+=1;BoneSiblings[CurrentSibling] = BoneSiblings[CurrentSibling-1]->pFrameSibling;BoneSiblingParents[CurrentSibling] = CurrentMatrix-1;}}}//Move siblings down the line to start going through children for next sibling bone.for(int x=0;x<ActorBoneTotal-1;x++){BoneSiblings[x] = BoneSiblings[x+1];BoneSiblingParents[x] = BoneSiblingParents[x+1];}//NULL top of the array and continue.BoneSiblings[ActorBoneTotal-1] = NULL;BoneSiblingParents[ActorBoneTotal-1] = NULL;CurrentSibling -= 1;}//We're done.  Set the new amount of bones for the actor and ready the array//which will store transformation data for the bone.ActorBoneTotal = CurrentMatrix;BoneData = new BoneVectors[ActorBoneTotal]; //Struct, stores position, rotation, and scale values.for(int x=0;x<ActorBoneTotal;x++){BoneData[x].x = 0.0f;BoneData[x].y = 0.0f;BoneData[x].z = 0.0f;BoneData[x].rx = 0.0f;BoneData[x].ry = 0.0f;BoneData[x].rz = 0.0f;BoneData[x].sx = 1.0f;BoneData[x].sy = 1.0f;BoneData[x].sz = 1.0f;}}//Hmm...well, if there wasn't any animation/bones, set the Bone Total to 0, no bones.else{ActorBoneTotal = 0;}}During the main loop, the BoneData array can be accessed to manipulate individual bones.  When you're ready to draw, you call the following (derived from the DXSDK Simple Animation example):void PCActor::DrawActor(){D3DXMATRIX Transform;D3DXMATRIXA16 World = SetUpWorldMatrix(Position.x,Position.y,Position.z,Rotation.x,Rotation.y,Rotation.z,Scale.x,Scale.y,Scale.z);for(int x=0;x<ActorBoneTotal;x++){*BonePointers[x] = OriginalBoneMatrices[x];Transform = SetUpWorldMatrix(BoneData[x].x,BoneData[x].x,BoneData[x].z, BoneData[x].rx,BoneData[x].ry,BoneData[x].rz, BoneData[x].sx,BoneData[x].sy,BoneData[x].sz);D3DXMatrixInverse(&Transform, NULL, &Transform);D3DXMatrixMultiply(BonePointers[x],BonePointers[x], &Transform);}UpdateFrameMatrices(this->g_pFrameRoot, &World);this->DrawFrame( DX_D3DDevice, this->g_pFrameRoot );}That function set's up the bone transformation matrices for each bone, and then follows the procedure explained in the DXSDK Simple Animation Example, using Software rendering.If anyone can help me understand just why some of the bones react the way they do (such as the Now-In-Much-Pain Ninja's Knee up there), and maybe provide a solution to my problem, it would be greatly appreciated.  Thank you.   
  It looks like there are two bones at the knee, and one of them is being more than just rotated.  Somehow a translation is being applied, and it is being carried down to that bones children.There ain't no way anyone else can debug this for you.  It is either a problem with the animation key data or the code that does the animation.;Quote:There ain't no way anyone else can debug this for you. It is either a problem with the animation key data or the code that does the animation.Actually, I figured out I was setting the transformation data to the wrong matrices.You see, the entire Actor class was derived from functions based on the DirectX SDK example Simple Animation, which, weren't explained in detail; I've pretty much been guessing, all of this time on how things work.  Hell, I found my solution by trial and error, and I can honestly say, too, that I jumped in way over my head trying this so early.  But, now that I have an idea on how to fix this, I might be able to turn this entire post from a flop to something useful for other people.I'm hoping to have my Class, and a thorough explanation of what I did wrong, done by tomorrow at latest, and hopefully it can provide a good example on how to animate a mesh's bones manually for others who may have had the same problems as I have.