# How to manually control frames/bones in directx animation

This topic is 2897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
Can you be more explicit or description about what you mean by "controlling" frames/bones?

##### Share on other sites
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 on other sites
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 on other sites
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 translationD3DXVECTOR3 trans = D3DXVECTOR3(frameTransform._41, frameTransform._42, frameTransforms._43);D3DXMATRIX rotx;D3DXMatrixRotationX(&rotx,...); // rotation about the bone's local axisrotx._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 on other sites
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 on other sites
Okay i got all of the names of the bones and everything works now.
Thanks for the help, i dont know why it wasnt working before..

##### Share on other sites
When you update animations it sets bone transforms which will override whatever you have set yourself.