1) add the following lines to CAnimatedMeshSceneNode.h
Code: Select all
private:
//I added the following for no-loop option
bool loop; //stores whether the current animation should be looped
void (*onAnimEnd) (IAnimatedMeshSceneNode*); /*pointer to user created function for notification of animation ending*/
public:
//added for no-loop option
virtual void setLoopState(bool _loop);
//also added for no-loop option
virtual void setLoopCallback(void(*_onAnimEnd)(IAnimatedMeshSceneNode*));
2) replace getFrameNr in CAnimatedMeshSceneNode.cpp with
Code: Select all
inline s32 CAnimatedMeshSceneNode::getFrameNr()
{
s32 frame = 0;
frame = StartFrame + ((s32)((os::Timer::getTime() - BeginFrameTime)* (FramesPerSecond/1000.0f)));
if (frame > EndFrame) /*if our set frame loop has passed the last frame */
{
if (loop==false)//if set to not loop animation
{
setFrameLoop(EndFrame,EndFrame); //stop animation
if(onAnimEnd)
{
(*onAnimEnd) ((IAnimatedMeshSceneNode*)this); /*notify user that animation ended. Pass pointer to this scenenode*/
}
frame=EndFrame;
}
else //if loop set (default)
{
frame=StartFrame;//go to beginning
BeginFrameTime=os::Timer::getTime(); //set this as begining
}
}
return frame;
}
Code: Select all
void CAnimatedMeshSceneNode::setLoopState(bool _loop)
{
loop=_loop; //set wether or not to loop animation
}
void CAnimatedMeshSceneNode::setLoopCallback(void(*_onAnimEnd)(IAnimatedMeshSceneNode*))
{
onAnimEnd=_onAnimEnd; //set the callback to call when not looping and have reached end of animation
}
Code: Select all
virtual void setLoopCallback (void(*_onAnimEnd)(IAnimatedMeshSceneNode*))=0;
virtual void setLoopState(bool _loop)=0;
It's all really quite simple, though it took me a while because I messed up my include paths and was including a different set of irrlicht headers than I was compiling (took me hours to figure that one out )
I just finished it yesterday and haven't really tested it, so there may be bugs. I think it might crash if younever set a callback function, though that's easy to fix.