Jump to content
  • Advertisement
Sign in to follow this  
hossainiir

[MDX] Problem with AdvanceTime

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i created a simple animation viewer ,this app is very similar to multi animation in DirectX SDK, but i wrote this with C# and MDX.
the following steps show u what am i doing in this sample.
1-load a skin mesh from file(tiny_4anim.x).
2-set some keycallbacks to all animationSets.
3-render the mesh.

the problem is that when i call AdvanceTime(timeDelta, animCallback) for each animationSet ,AdvanceTime does not call animCallback . but when i change animation ,AdvanceTime call animCallback until previous track become false.

maybe following line help u more to understand my problem.
State of animation : ========playing current anim========+++++++++Blend current anim to new anim++++++++=========playing new anim=========
State of animCallback : =====animCallback does not call=====++++++++++animCallback calls here+++++++++++++======animCallback does not call=====

any one can help me.
excuse for bad english.

Share this post


Link to post
Share on other sites
Advertisement
i write some code may help u.
[source [color="#1C2837"]lang="c-sharp"]

public struct AnimationCallbackData
{
public int Sound;
public double CameraDistance;
}
public class SkinMesh
{
public HandleAnimationCallback AnimCallback;

public AnimationCallbackData d1, d2, d3,d4;
private AnimationRootFrame _rootFrame;

public SkinMesh(string meshFile,string path)
{
//Some Code for Creating Skin mesh
CreatSkinMesh(meshFile,path)
AnimCallback =new HandleAnimationCallback( SkinMesh_AnimCallback);
//KeyCallbaks set here

var keys1 = new KeyCallback[4];
d1 = new AnimationCallbackData { CameraDistance = 1, Sound = 1 };
d2 = new AnimationCallbackData { CameraDistance = 1, Sound = 2 };
d3 = new AnimationCallbackData { CameraDistance = 1, Sound = 3 };
d4 = new AnimationCallbackData { CameraDistance = 1, Sound = 4 };
fixed (AnimationCallbackData* p1 = &d1)
{
keys1[0] = new KeyCallback { Time = 0, CallBackData = new IntPtr(p1) };
}

fixed (AnimationCallbackData* p2 = &d2)
{
keys1[1] = new KeyCallback { Time = (float)(animationSet.Period / 8 * animationSet.SourceTicksPerSecond), CallBackData = new IntPtr(p2) };
}

fixed (AnimationCallbackData* p3 = &d3)
{
keys1[2] = new KeyCallback { Time = (float)(animationSet.Period / 4 * animationSet.SourceTicksPerSecond), CallBackData = new IntPtr(p3) };
}

fixed (AnimationCallbackData* p4 = &d4)
{
keys1[3] = new KeyCallback { Time = (float)(animationSet.Period / 1.5 * animationSet.SourceTicksPerSecond), CallBackData = new IntPtr(p4) };
}
SetCallbackToAnimation(animationSet1, 0.25f, keys1);//jog
SetCallbackToAnimation(animationSet2, 0.25f, keys1);//walk
SetCallbackToAnimation(animationSet3, 0.25f, keys1);//Loiter
}


public void SkinMesh_AnimCallback(int track, IntPtr callbackData)
{
unsafe
{
var data = (AnimationCallbackData*) callbackData;
}
}

public void SetCallbackToAnimation(KeyframedAnimationSet animSet, float compress, KeyCallback[] keyCallbacks)
{
var graphicsStream = animSet.Compress(CompressionFlags.Default, compress, null);

var animationSet = new CompressedAnimationSet(animSet.Name, animSet.SourceTicksPerSecond, animSet.PlaybackType, graphicsStream, keyCallbacks);
_rootFrame.AnimationController.UnregisterAnimationSet(animSet);
_rootFrame.AnimationController.RegisterAnimationSet(animationSet);
}


public void SetAnimationKey(int newAnimationTrack)
{
var newTrack = _currentTrack == 0 ? 1 : 0;
var animationSet = _rootFrame.AnimationController.GetAnimationSet(newAnimationTrack);
_rootFrame.AnimationController.SetTrackAnimationSet(newTrack, animationSet);

_rootFrame.AnimationController.UnkeyAllTrackEvents(_currentTrack);
_rootFrame.AnimationController.UnkeyAllTrackEvents(newTrack);

_rootFrame.AnimationController.KeyTrackEnable(_currentTrack, false, _currentTime + MoveTransitionTime);
_rootFrame.AnimationController.KeyTrackSpeed(_currentTrack, 0.0f, _currentTime, MoveTransitionTime,TransitionType.Linear);
_rootFrame.AnimationController.KeyTrackWeight(_currentTrack, 0.0f, _currentTime, MoveTransitionTime,TransitionType.Linear);

_rootFrame.AnimationController.SetTrackEnable(newTrack,true);
_rootFrame.AnimationController.KeyTrackSpeed(newTrack, 1f, _currentTime, MoveTransitionTime,TransitionType.Linear);
_rootFrame.AnimationController.KeyTrackWeight(newTrack, 1f, _currentTime, MoveTransitionTime,TransitionType.Linear);
_currentTrack = newTrack;
}



public void AdvanceTime(float timeDelta)
{
_currentTime += (timeDelta);
_rootFrame.AnimationController.AdvanceTime(timeDelta, AnimCallback);
UpdateFrameMatrices(_rootFrame.FrameHierarchy as AnimationFrame, _world*_mat);
}
}
[/source]
i can not understand why callback did not triggered when animation are playing, and triggered when current animation blend to new animation!!!!
the main question is when keyCallback triggered in playing interval or in blending interval?

Share this post


Link to post
Share on other sites
blink.gif
In practice i understood that if i wrote the following codes the keyCallback has been triggered :
[source lang="c-sharp"] AnimationController.AdvanceTime(timeDelta/2, AnimCallback);
AnimationController.AdvanceTime(timeDelta/2, AnimCallback);
[/source]
but callbackData become corrupt.

Any idea ??

Share this post


Link to post
Share on other sites
dry.gif
finally i solve the problem by my self , i'm wonder why no one answered me!!
i write the solution, maybe some one have same problem.
i used the following codes
[source='c-sharp'] AnimationController.AdvanceTime(elapsedTime, AnimCallback);AnimationController.AdvanceTime(0, AnimCallback);[/source]
this codes cause that callbacks trigger in right times but a big problem still remains.because of some unknown reason [color="#1C2837"]CallbackData become corrupt. i think that i have right times, current playing animation and current playing track , with having this informations i don't need CallBackData any more so i set them to null.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!