views:

130

answers:

1

I have a rigged (biped) and animated model in 3D Studio Max which I've exported as a .x file.

When I use it the animations run fine, however I've been trying to get the model itself to lean and turn from the hip but I'm having difficulty in finding where in the bone hierarchy I should apply the rotation matrices.

In 3D Studio Max there is a bipe object on the model called Bip01, when I select and rotate it the rotation cascades on all bones above the hip so I assumed that applyhing rotation matrices to the same D3DXFRAME (which has the same name, Bip01) would have the same effect but it does not. What happens is the effect ends up applying to everything in the bone hierarchy so applying transformations to Bip01 is like applying it to the route bone (which it might be as I'm not sure how to tell one bone from the other).

Here's the code where frame transformations are updating and I've added a bit of code attempting to apply the matrix transformation to Bip01, I'm not sure if there is any other relevant code I can show... (the rotation value is just a random value I threw in)

void CAnimInstance::UpdateFrames( MultiAnimFrame* pFrame, D3DXMATRIX* pmxBase )
{
    assert( pFrame != NULL );
    assert( pmxBase != NULL );

if(strcmp(pFrame->Name, "Bip01") == 0 ) { D3DXMATRIX rot;D3DXMatrixRotationY(&rot, 3.141); D3DXMatrixMultiply( &pFrame->TransformationMatrix, &pFrame->TransformationMatrix, &rot ); }

    D3DXMatrixMultiply( &pFrame->TransformationMatrix,
                        &pFrame->TransformationMatrix,
                        pmxBase );


    // transform siblings by the same matrix
    if( pFrame->pFrameSibling )
        UpdateFrames( ( MultiAnimFrame* )pFrame->pFrameSibling, pmxBase );

    // transform children by the transformed matrix - hierarchical transformation
    if( pFrame->pFrameFirstChild )
 {
  UpdateFrames( ( MultiAnimFrame* )pFrame->pFrameFirstChild,
    &pFrame->TransformationMatrix );
 }
}

*What I think I should be doing is finding all the children frames for Bip01 and apply the transform to them but how do I do that?

+1  A: 

Bip01 is the root node for the skeleton in Character Studio - which I assume is where you skeleton is set up.
So your code is correct i.e applying a rotation to bip01 and then cascading that down to all it's children will update all bones in the skeleton.

I'm guessing ( and it's a total guess ) that the reason why you aren't seeing this in 3D Studio Max is because it's set up with a bunch of constraints to help the animator.

What I'd suggest doing is finding the bone names - they usually follow a convention of bip01 - L Finger 1 etc then find the name of the hip bone ( it's probably called Bip01 - Hip ).
Alternatively on startup in your code, iterate from Bip01 down all the children and build up a dictionary of all bone names.

I'm sure there's a better answer but as my 3DS max is pretty rusty that's about the best I can do for now :)

zebrabox