Prevent negative scalar speed in CAnimatedMeshSceneNode

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Prevent negative scalar speed in CAnimatedMeshSceneNode

Post by teto »

Hi,

For those who hate the idea of having a scalar speed negative, I have modified CAnimatedMeshSceneNode so that setFrameLoop(startFrame,endFrame) really uses startFrame as a start and endFrame as an end because right now, if endFrame < startFrame they are switch and you need to set a negative speed to play the reverse animation. Not only is that illogical - at least for me - but also it prevents you from setting an animation speed without taking into consideration startFrame and endFrame which might be a pain from pragmatical consideration:
old code:

Code: Select all

 
 
    const int currentFrame = _animatedNode->getFrameNr();
 
    if(targetedFrame < currentFrame)
    {
        _animatedNode->setAnimationSpeed(-5);
    }
    else if(targetedFrame > currentFrame )
    {
        _animatedNode->setAnimationSpeed(5);
    }
    // if targetedFrame == curentFrame
    else
    {
        _LOG_WARNING << "Frames are equal";
        return false;
    }
 
    if( _animatedNode->setFrameLoop(currentFrame,targetedFrame) )
   
new code:

Code: Select all

 
 _animatedNode->setAnimationSpeed(5);
_animatedNode->setFrameLoop(currentFrame,targetedFrame) 
 
You might download patch from there for rev4065:
http://downloads.tuxfamily.org/bluecosm ... Loop.patch

As possible improvements, one might also add getAnimationProgress(); (would return a float between 0 and 1 as the percentage) and a isTransforming() functions. I could do it too though it's easy to implement.
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
Post Reply