How to manually control frames/bones in directx animation

Started by
6 comments, last by chillypacman 14 years, 2 months ago
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
"REAL programmers use a magnetised needle and a steady hand"xkcd.com/378
Advertisement
Can you be more explicit or description about what you mean by "controlling" frames/bones?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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
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 :)
"REAL programmers use a magnetised needle and a steady hand"xkcd.com/378
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]

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

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..
"REAL programmers use a magnetised needle and a steady hand"xkcd.com/378
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..
"REAL programmers use a magnetised needle and a steady hand"xkcd.com/378
When you update animations it sets bone transforms which will override whatever you have set yourself.

This topic is closed to new replies.

Advertisement