# world transform bone matrix?

## Recommended Posts

I've been toying with a mesh hierarchy c++ sample (from here: http://www.toymaker.info/Games/html/load_x_hierarchy.html). I tried adding a D3DXMatrix to the final world translation but it gave me a very garbled result:
void CXFileEntity::DrawMeshContainer(LPDIRECT3DDEVICE9 device,
LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase) const
{
assert(device);

// Cast to our extended frame type
D3DXFRAME_EXTENDED *frame = (D3DXFRAME_EXTENDED*)frameBase;

// Cast to our extended mesh container
D3DXMESHCONTAINER_EXTENDED *meshContainer = (D3DXMESHCONTAINER_EXTENDED*)meshContainerBase;

// Set the world transform
frame->exCombinedTransformationMatrix += pos; //<--- right here, pos is a D3DXMatrix declared earlier
device->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix);

// Loop through all the materials in the mesh rendering each subset
for (UINT iMaterial = 0; iMaterial < meshContainer->NumMaterials; iMaterial++)
{
// use the material in our extended data rather than the one in meshContainer->pMaterials[iMaterial].MatD3D
device->SetMaterial( &meshContainer->exMaterials[iMaterial] );
device->SetTexture( 0, meshContainer->exTextures[iMaterial] );

// Select the mesh to draw, if there is skin then use the skinned mesh else the normal one
LPD3DXMESH pDrawMesh = (meshContainer->pSkinInfo) ? meshContainer->exSkinMesh: meshContainer->MeshData.pMesh;

// Finally Call the mesh draw function
pDrawMesh->DrawSubset(iMaterial);
}
}


How can I transform the entire animation set in world space? Basically whats happening is the position is actually changing to where pos is however all the bits and pieces of the .x are pushed into itself. One of the models I'm trying toanimate is a skeleton and when I try to transform it in world space as above the skull is put right where the torso is and the legs are all garbled up. The animations actually still work as I cycle through them, but every part of the hierarchy is in a screwball position (like the skull is where the torso should be).

##### Share on other sites
You have to do a matrix multiply instead of adding it ... unless I'm mistaken

// world is ... the world matrix
// local is the objects local matrix
// trans is just my translation matrix
D3DXMatrixMultiply(&m_World, &m_local, &trans);

// so try this
REPLACE-> // Set the world transform
frame->exCombinedTransformationMatrix += pos; //<--- right here, pos is a D3DXMatrix declared earlier

with this

D3DXMATRIX world
D3DXMatrixMultiply(&world, &frame->exCombinedTransformationMatrix, &pos );

##### Share on other sites
I tried that, it doesn't seem to be doing anything at all..

Maybe I'm doing it wrong?

void CXFileEntity::DrawMeshContainer(LPDIRECT3DDEVICE9 device,									 LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase) const{	assert(device);	// Cast to our extended frame type	D3DXFRAME_EXTENDED *frame = (D3DXFRAME_EXTENDED*)frameBase;			// Cast to our extended mesh container	D3DXMESHCONTAINER_EXTENDED *meshContainer = (D3DXMESHCONTAINER_EXTENDED*)meshContainerBase;		// Set the world transform	D3DXMATRIX pos;	D3DXMatrixTranslation(&pos, 0, -10, 10);	D3DXMATRIX world;	D3DXMatrixMultiply( &world, &frame->exCombinedTransformationMatrix, &pos );    device->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix);	// Loop through all the materials in the mesh rendering each subset    for (UINT iMaterial = 0; iMaterial < meshContainer->NumMaterials; iMaterial++)    {		// use the material in our extended data rather than the one in meshContainer->pMaterials[iMaterial].MatD3D		device->SetMaterial( &meshContainer->exMaterials[iMaterial] );		device->SetTexture( 0, meshContainer->exTextures[iMaterial] );		// Select the mesh to draw, if there is skin then use the skinned mesh else the normal one		LPD3DXMESH pDrawMesh = (meshContainer->pSkinInfo) ? meshContainer->exSkinMesh: meshContainer->MeshData.pMesh;		// Finally Call the mesh draw function        pDrawMesh->DrawSubset(iMaterial);    }}

##### Share on other sites
wait, I figured it out.

D3DXMATRIX world is the output matrix so I used that with the transform and it works fine now.

Thanks :)