Sign in to follow this  
Nazdreg

How to manually control frames/bones in directx animation

Recommended Posts

Nazdreg    100
Hi, i have just learnt how to use animated meshes in direct3d9 for c++ I have tried manually controlling a frame except i have gotten nowhere. this is the code i am using to render the animation // if the mesh is animated... if(AnimationController) { static DWORD Time = GetTickCount(); // move the animation forward by the elapsed time AnimationController->AdvanceTime((GetTickCount() - Time) * 0.001f, NULL); // reset Time for the next time through Time = GetTickCount(); } // update each combined matrix update_frames((CUSTOM_FRAME*)TopFrame, NULL); //2nd param is the parents combined matrix // update the mesh containers update_mesh_containers((CUSTOM_FRAME*)TopFrame); // render each mesh container draw_mesh((CUSTOM_FRAME*)TopFrame); If someone could please explain how to manually change the frames it would be most appreciated

Share this post


Link to post
Share on other sites
namar777    488
Don't know what your code does, but the general idea of bones is:

Bones are like normal objects (transformed by matrices). Child bones' transformations come after parent's transformations are applied.

Arm Transformation -> Hand Transformation.

Each transformation applied, takes you to object's space, where child exists.

Good Luck

Share this post


Link to post
Share on other sites
Nazdreg    100
Thanks namar,
what i mean about controlling bones is setting the pose of the bones from values within the code, not defined from an animation, for things like ragdolls or modifying an animation so that parts of the character are in specific locations.
I have tried setting the transformation matrix of various bones using matrices i made using D3DXMatrixRotationX() etc, but there did not appear to be any change.
Currently the program updates all of the bones with the animation using AdvanceTime() then it calculates the combined matrix for each bone, which is an extra member of the bone in my CUSTOM_FRAME struct.
It then updates all of the mesh containers with the combined matrices and finally draws the meshes in the mesh containers.
I tried replacing the transoframtion matrix in one of the bones for a set rotation martix after i updated them using AdvanceTime() and before i calculated the combination mtrices, except that when i ran it it just displayed the normal animation. I would like to know if there is anything else i have to do, or how to do it if i am completely wrong :)

Share this post


Link to post
Share on other sites
Buckeye    10747
Quote:
I tried replacing the transoframtion matrix in one of the bones for a set rotation martix after i updated them using AdvanceTime() and before i calculated the combination mtrices

Things to remember:

1. If you want to change the animation that way, the frame transformation needs to be "replaced" every frame. Did you do that? The animation controller updates (overwrites) the frame transform every AdvanceTime() from the time key data in the animation data. You may have been successful, but only for a single frame.

2. If you don't get the results you expect, remember that a bone's frame transformation is a local transformation. If you set a rotation about the X axis, that will the bone's local X axis, which may or may not correspond to the global X axis. Also, if the animated frame transform has a translation as well as a rotation, you won't get the result you expect.

You can try something like:

// grab the animated translation
D3DXVECTOR3 trans = D3DXVECTOR3(frameTransform._41, frameTransform._42, frameTransforms._43);
D3DXMATRIX rotx;
D3DXMatrixRotationX(&rotx,...); // rotation about the bone's local axis
rotx._41 = trans.x; rotx._42 = trans.y; rotx._43 = trans.z;
frameTransform = rotx;
// calc the combined transforms

3. Did any of the bones you tried (or their children) influence any vertices? If a bone has no influences, and it's child have none, no vertices will be affected.

[Edited by - Buckeye on February 14, 2010 9:31:53 PM]

Share this post


Link to post
Share on other sites
Nazdreg    100
Yes, i did replace the matrix each frame, and thanks for the local/global tip.
I have just tried removing the animation update completely and setting each matrix with some rotation and that is now affecting the frames, so i dont know what was happening before..
Do you happen to know what the names of the frames in the tiny.x animation are called? if not i can make code to find out..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this