   Animation Controller doesn't work
  hi i'm trying to implement animations with .X files i allready read and follow like 5 diferents tutorials and i think i manage to understand everything i got the model draw with textures, and materials and everything is ok except that the TranformationMatrix of the frame never change so the model is always static.i'm using a single animationset model that i tested with the directXviewer and the animations work fine i also tested with a tutorial program and again the model works fine but in my code the TransformationMatrix never change.i hope you guys can help me i think that i miss a really silly thing but i dont manage to figure it out.btw my model doesn't have skinnininfo is just matrixtranformations.this is my allocator classtypedef struct CustomFrame : public D3DXFRAME{D3DXMATRIX matCombined;}CD3DXFRAME, *LPCD3DXFRAME;typedef struct CustomMeshContainer: public D3DXMESHCONTAINER{  LPDIRECT3DTEXTURE9* ppTextures; // Textures of the mesh  D3DMATERIAL9*  pMaterials9;// Use the DirectX 9 Material type    //Skinned mesh variables  LPD3DXMESH    pSkinMesh;   // The original mesh  D3DXMATRIX*   pBoneOffsets;// The bone matrix Offsets  D3DXMATRIX**   pFrameMatrices;   // The Frame Matrix}MESHCONTAINER, *LPMESHCONTAINER;HRESULT cMeshH::CreateFrame(LPCSTR Name, LPD3DXFRAME *retNewFrame){*retNewFrame = 0;LPCD3DXFRAME nFrame = new CD3DXFRAME();ZeroMemory(nFrame,sizeof(CD3DXFRAME));D3DXMatrixIdentity(&nFrame-&gt;TransformationMatrix);D3DXMatrixIdentity(&nFrame-&gt;matCombined);nFrame-&gt;Name = new char[strlen(Name)+1];printf("Loaded Frame: %s\n",Name);memcpy(nFrame-&gt;Name,Name,strlen(Name)*sizeof(char));*retNewFrame = nFrame;return S_OK;}HRESULT cMeshH::CreateMeshContainer(    LPCSTR Name,    CONST D3DXMESHDATA *meshData,    CONST D3DXMATERIAL *materials,    CONST D3DXEFFECTINSTANCE *effectInstances,    DWORD numMaterials,    CONST DWORD *adjacency,    LPD3DXSKININFO pSkinInfo,    LPD3DXMESHCONTAINER* retNewMeshContainer){   *retNewMeshContainer = 0;//Setting Mesh containerLPMESHCONTAINER nMeshContainer = new MESHCONTAINER();ZeroMemory(nMeshContainer,sizeof(MESHCONTAINER));nMeshContainer-&gt;Name = new char[strlen(Name)+1];printf("Loaded Mesh %s\n",Name);memcpy(nMeshContainer-&gt;Name,Name,strlen(Name)*sizeof(char));nMeshContainer-&gt;Name[strlen(Name)] = '\0';if(meshData-&gt;Type != D3DXMESHTYPE_MESH)return E_FAIL;//Mesh type & DirectX devicenMeshContainer-&gt;MeshData.Type = meshData-&gt;Type;LPDIRECT3DDEVICE9 dxDevice = 0;meshData-&gt;pMesh-&gt;GetDevice(&dxDevice);//Setting Adjency (Faces ID's)DWORD cFaces = meshData-&gt;pMesh-&gt;GetNumFaces();nMeshContainer-&gt;pAdjacency = new DWORD[cFaces*3];memcpy(nMeshContainer-&gt;pAdjacency,adjacency,sizeof(DWORD)*cFaces*3);//Copy mesh datanMeshContainer-&gt;MeshData.pMesh = meshData-&gt;pMesh;nMeshContainer-&gt;MeshData.pMesh-&gt;AddRef();//Setting Materials & Textures arrays. (Easy)nMeshContainer-&gt;NumMaterials = numMaterials;nMeshContainer-&gt;pMaterials = new D3DXMATERIAL[numMaterials];nMeshContainer-&gt;ppTextures = new LPDIRECT3DTEXTURE9[numMaterials];nMeshContainer-&gt;pMaterials9 = new D3DMATERIAL9[numMaterials];for(int i=0;i&lt;numMaterials;i++){nMeshContainer-&gt;pMaterials.MatD3D = materials.MatD3D;nMeshContainer-&gt;pMaterials9 = nMeshContainer-&gt;pMaterials.MatD3D;DWORD size = strlen(materials.pTextureFilename);nMeshContainer-&gt;pMaterials.pTextureFilename = new char[size+1];memcpy(nMeshContainer-&gt;pMaterials.pTextureFilename,materials.pTextureFilename,sizeof(char)*size);nMeshContainer-&gt;pMaterials.pTextureFilename[size] = '\0';nMeshContainer-&gt;ppTextures = NULL;}//Setting SkinInfoif(pSkinInfo){printf("skin info loaded..\n");nMeshContainer-&gt;pSkinInfo = pSkinInfo;pSkinInfo-&gt;AddRef();UINT numBones = pSkinInfo-&gt;GetNumBones();nMeshContainer-&gt;pBoneOffsets = new D3DXMATRIX[numBones];nMeshContainer-&gt;pFrameMatrices = new D3DXMATRIX*[numBones];for (UINT i = 0; i &lt; numBones; i++)   nMeshContainer-&gt;pBoneOffsets = *(nMeshContainer-&gt;pSkinInfo-&gt;GetBoneOffsetMatrix(i));}else{nMeshContainer-&gt;pSkinInfo = 0;nMeshContainer-&gt;pBoneOffsets = 0;nMeshContainer-&gt;pFrameMatrices = 0;nMeshContainer-&gt;pSkinMesh = 0;}*retNewMeshContainer = nMeshContainer;return S_OK;}and this is my implementation.//mainLPD3DXFRAME  dxframeRoot;LPD3DXANIMATIONCONTROLLER   dxaController;cMeshH *mAlloc=new cMeshH();HRESULT hr = D3DXLoadMeshHierarchyFromX("Models/TortugoTortugo.x",D3DXMESH_MANAGED,g_pd3dDevice,mAlloc, NULL, &dxframeRoot, &dxaController);//updatevoid UpdateMatrix(const D3DXFRAME *frameBase, const D3DXMATRIX *parentMatrix){ LPCD3DXFRAME currentFrame = (LPCD3DXFRAME)frameBase;// If parent matrix exists multiply our frame matrix by it    if (parentMatrix != NULL)   D3DXMatrixMultiply(&currentFrame-&gt;matCombined, &currentFrame-&gt;TransformationMatrix, parentMatrix);    else   currentFrame-&gt;matCombined = currentFrame-&gt;TransformationMatrix;// If we have a sibling recurseif (currentFrame-&gt;pFrameSibling != NULL)   UpdateMatrix(currentFrame-&gt;pFrameSibling, parentMatrix);// If we have a child recurseif (currentFrame-&gt;pFrameFirstChild != NULL)   UpdateMatrix(currentFrame-&gt;pFrameFirstChild, &currentFrame-&gt;matCombined);}//loopD3DXMATRIXA16 matPos;D3DXMatrixTranslation(&matPos,0.0f,-1.2f,0.0f);if(dxaController)  dxaController-&gt;AdvanceTime(elapsedTime, NULL);UpdateMatrix(dxframeRoot,matPos);the render method work fine so i dont post it.thnxs[Edited by - FallenV2 on May 15, 2010 8:38:28 PM]
  A couple comments:I would suggest using [ source] formatting for your code. It would likely make your post more readable.You say your model "doesn't have skininfo." Do you mean pSkinInfo is NULL for every call to CreateMeshContainer?Also Quote:the render method work fine so i dont post it.If the model isn't animated, perhaps your render method is not working and that may be the problem.Quote:dxaController->AdvanceTime(elapsedTime, NULL);Are you advancing the time?;  hi, thanks for the quick response,yup the pSkinInfo is NULL in every call and sorry about the bad formating post i didn't knew about the [ source] tag.here i put the full codeLPD3DXFRAME  dxframeRoot;LPD3DXANIMATIONCONTROLLER   dxaController;float   elapsedTime=0.02f;void UpdateMatrix(const D3DXFRAME *frameBase, const D3DXMATRIX *parentMatrix){ LPCD3DXFRAME currentFrame = (LPCD3DXFRAME)frameBase;// If parent matrix exists multiply our frame matrix by it    if (parentMatrix != NULL)   D3DXMatrixMultiply(&currentFrame->matCombined, &currentFrame->TransformationMatrix, parentMatrix);    else   currentFrame->matCombined = currentFrame->TransformationMatrix;// If we have a sibling recurseif (currentFrame->pFrameSibling != NULL)   UpdateMatrix(currentFrame->pFrameSibling, parentMatrix);// If we have a child recurseif (currentFrame->pFrameFirstChild != NULL)   UpdateMatrix(currentFrame->pFrameFirstChild, &currentFrame->matCombined);}void FrameTextures(LPD3DXFRAME Frame,LPCSTR path){LPMESHCONTAINER MeshC = (LPMESHCONTAINER)Frame->pMeshContainer;while(MeshC){int nMaterials = MeshC->NumMaterials;for(int i=0;i<nMaterials;i++){if(MeshC->pMaterials.pTextureFilename){char file[255];sprintf(file,"%s%s",path,MeshC->pMaterials.pTextureFilename);D3DXCreateTextureFromFile(g_pd3dDevice,file,&MeshC->ppTextures);}}MeshC = (LPMESHCONTAINER)MeshC->pNextMeshContainer;}if(Frame->pFrameSibling)FrameTextures(Frame->pFrameSibling,path);if(Frame->pFrameFirstChild)FrameTextures(Frame->pFrameFirstChild,path);}void loop(){D3DXMATRIXA16 matPos;D3DXMatrixTranslation(&matPos,0.0f,-1.2f,0.0f);if(dxaController)dxaController->AdvanceTime(elapsedTime, NULL);UpdateMatrix(Frame,matWorld);}void init(HWND hwnd){   //DirectX stuff camara device, etc.   cMeshH *mAlloc=new cMeshH();HRESULT hr = D3DXLoadMeshHierarchyFromX("Models/Tortugo/Tortugo.x",D3DXMESH_MANAGED, g_pd3dDevice, mAlloc, NULL, &dxframeRoot, &dxaController);FrameTextures(dxframeRoot,"Models/Tortugo/");}void DrawMeshContainer(LPD3DXMESHCONTAINER MeshC,LPD3DXFRAME  Frame){LPMESHCONTAINER Mesh = (LPMESHCONTAINER)MeshC;LPCD3DXFRAME frame = (LPCD3DXFRAME)Frame;g_pd3dDevice->SetTransform(D3DTS_WORLD,&frame->matCombined);for(int i=0;i<Mesh->NumMaterials;i++){g_pd3dDevice->SetMaterial( &Mesh->pMaterials9 );g_pd3dDevice->SetTexture( 0, Mesh->ppTextures );Mesh->MeshData.pMesh->DrawSubset(i);}}void DrawFrame(LPD3DXFRAME  Frame){LPD3DXMESHCONTAINER MeshC = Frame->pMeshContainer;while(MeshC){DrawMeshContainer(MeshC,Frame);MeshC = MeshC->pNextMeshContainer;}if(Frame->pFrameSibling)DrawFrame(Frame->pFrameSibling);if(Frame->pFrameFirstChild)DrawFrame(Frame->pFrameFirstChild);}VOID Render(){    if( NULL == g_pd3dDevice )   return;    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )    {DrawFrame(dxframeRoot);   g_pd3dDevice->EndScene();    }    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );}int main (HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil){    HWND hwnd;    MSG mensaje;  WNDCLASSEX wincl = { sizeof(WNDCLASSEX), CS_DBLCLKS, Mensajes, 0L, 0L,   GetModuleHandle(NULL), LoadIcon (NULL, IDI_APPLICATION),   LoadCursor (NULL, IDC_ARROW), (HBRUSH)COLOR_BACKGROUND, NULL,  "Vertex", LoadIcon (NULL, IDI_APPLICATION)};    if(!RegisterClassEx(&wincl)) return 0;    hwnd = CreateWindowEx(0,"Vertex","->DirectX Ejemplo Texturas<-",WS_OVERLAPPEDWINDOW,  CW_USEDEFAULT,CW_USEDEFAULT,600,600,HWND_DESKTOP,NULL,wincl.hInstance,NULL);ShowWindow(hwnd, SW_SHOWDEFAULT);UpdateWindow( hwnd );ZeroMemory( &mensaje, sizeof(mensaje) );   init(hwnd);while(mensaje.message!=WM_QUIT){loop();Render();if(PeekMessage(&mensaje, NULL, 0, 0,PM_REMOVE)){TranslateMessage(&mensaje);DispatchMessage(&mensaje);}}UnregisterClass( "Vertex", wincl.hInstance );return mensaje.wParam;};  No problem about the formatting. Good job [smile]You definitely need the skinning info to animate the mesh, as you need to set up an indexed mesh from the loaded mesh according to which vertices are influenced by which bones, etc. I'm not sure why pSkinInfo is not being created.Also, your instancing of the allocator is a bit unorthodox. I wouldn't think it would affect the animation but you're definitely setting up for a memory leak. You "new" the allocator but never delete it.Rather than new'ing the allocator, you might try:void init(HWND hwnd){   //DirectX stuff camara device, etc.   cMeshH mAlloc;HRESULT hr = D3DXLoadMeshHierarchyFromX("Models/Tortugo/Tortugo.x",D3DXMESH_MANAGED, g_pd3dDevice, &mAlloc, NULL, &dxframeRoot, &dxaController);FrameTextures(dxframeRoot,"Models/Tortugo/");}In the above code, note that mAlloc is an instance of the allocator, not a pointer. Also, in the D3DXLoadMesh call, "&mAlloc" is used instead of just "mAlloc"   ;  i solve my problem, btw i feel really dumb right now u.uthe problem was in my allocator class in the CreateFrame method when copying the name string into the nFrame->Name the string was unfinished because i forgot to copy the '\0' at the finish of the string size+1 at the memcpy solve everything thxs for the help i knew that i miss something really really dumb u.u   