Page 1 of 1

MD2 Animation bug

Posted: Sun Nov 14, 2004 8:58 pm
by MessiaH
This is rather strange.
When at then beginnig I write
node->setMD2AnimationType(scene::EMAT_STAND);
and then
node->setAnimationSpeed(0);
node->setCurrentFrame(197);
the animation is stopped(OK),but frame number is changed to 1,while it should be 197!
What is the problem?!

Posted: Sat Dec 04, 2004 9:43 am
by niko
Seems to be a bug. :)

MD2 Animation bug

Posted: Thu Dec 23, 2004 6:01 pm
by MessiaH
Another question.
:roll: Have You ever tried to use "->setFrameLoop(stFr,enFr);" with MD2's?!
I have tried->again not the thing i expected!!! :x :x :x

Posted: Fri Dec 24, 2004 1:56 am
by Murphy
HMMMM...

Code: Select all

//! sets the current frame. from now on the animation is played from this frame.
void CAnimatedMeshSceneNode::setCurrentFrame(s32 frame)
{
}
Maybe it's just me, but something looks suspicious. :wink:


It seems like the concept of setCurrentFrame() is sort of tricky here. Since these animations are time-dependent, what does it mean to set the current frame? Maybe this is why it's not currently implemented?

I can see two options for setCurrentFrame():

In one option, this would just override the time based animation, probably just forcing getFrameNr() to always return the set frame number.

The other option would have setCurrentFrame() essentially add an offset to getFrameNr() (in a new member variable). This would let you skip to other positions in the animation while maintaining the proper loop start position. If the animation is stopped, it'd have the effect of just switching to the desired frame. Without having tested it or even thinking about it that hard, I think something like this:

Code: Select all

void CAnimatedMeshSceneNode::setCurrentFrame(s32 frame)
{
	OffsetFrame = 0;
	OffsetFrame = frame - getFrameNr();
}

inline s32 CAnimatedMeshSceneNode::getFrameNr()
{
	s32 frame = 0;

	if (EndFrame - StartFrame)
		frame = StartFrame + (OffsetFrame + s32((os::Timer::getTime() - BeginFrameTime) * (FramesPerSecond/1000.0f))) % (EndFrame - StartFrame);
	else
		frame = StartFrame + OffsetFrame;
	return frame;
}
Hopefully, that'll at least get my point across even if the code isn't right. :wink: Of course, the desired frame has to be within StartFrame and EndFrame.