[osg-users] Speeding u/down animation smoothly

Julien Valentin julienvalentin51 at gmail.com
Wed Dec 5 15:16:20 PST 2018


Code:
float getAnimationTime{return ((_latestTime-_firstTime)-_timeOffset)*_timeMultiplier;}



so you'll have to do math!!
;)


dhhabyc wrote:
> Hello,
> 
> I'm trying to sppeding up/down an animation using AnimationPathCallback. The idea is to pause/speed/up/down the animation using key strokes, for this I have a GuiEventHandler derived class and a NodeVisitor derived class. So far I've playing round with the base clases AnimationPath and AnimationPathCallback methods get/setStartTime, get/setTimeOffset, get/setLastTime and get/settimeMultiplier with no success.
> 
>  I found http://forum.openscenegraph.org/viewtopic.php?t=10014 but my implementation still jumps around when speeding up/down:
> 
> 
> Code:
> void AnimationVisitor::apply(osg::Transform& transform)
> {
> 	osg::AnimationPathCallback* apc = dynamic_cast<osg::AnimationPathCallback*>(transform.getUpdateCallback());
> 	
> 	if (apc)
> 	{
> 		osg::AnimationPath * path = apc->getAnimationPath();
> 		int key = getKey();
> 		double lambda;
> 		switch (key)
> 		{
> 		case osgGA::GUIEventAdapter::KEY_Space:
> 		{
> 			bool is_paused = apc->getPause();
> 			apc->setPause(!is_paused);
> 			std::cout << "Animation time: " << apc->getAnimationTime() << std::endl;
> 			std::cout << "\tPause: " << !is_paused << std::endl;
> 			std::cout << "---------------------------" << std::endl;
> 			break;
> 		}
> 		case osgGA::GUIEventAdapter::KEY_Right:
> 		{
> 			double last = path->getLastTime();
> 			double first = path->getFirstTime();
> 			lambda = apc->getTimeMultiplier();
> 			double simTime = last - first;
> 			double currOffset = apc->getTimeOffset();
> 			double offset = simTime - (simTime - currOffset) / 1.1;
> 			apc->setTimeMultiplier(1.1*lambda);
> 			apc->setTimeOffset(offset);
> 			std::cout << "Animation time: " << apc->getAnimationTime() << std::endl;
> 			std::cout << "\tSpeed up: : " << lambda * 1.1 << std::endl;
> 			std::cout << "---------------------------" << std::endl;
> 			break;
> 		}
> 		case osgGA::GUIEventAdapter::KEY_Left:
> 		{
> 			double last = path->getLastTime();
> 			double first = path->getFirstTime();
> 			lambda = apc->getTimeMultiplier();
> 			double simTime = last - first;
> 			double currOffset = apc->getTimeOffset();
> 			double offset = simTime - (simTime - currOffset) * 0.9;
> 			apc->setTimeMultiplier(0.9*lambda);
> 			apc->setTimeOffset(offset);
> 			std::cout << "Animation time: " << apc->getAnimationTime() << std::endl;
> 			std::cout << "\tSpeed up: : " << lambda * 0.9 << std::endl;
> 			std::cout << "---------------------------" << std::endl;
> 			break;
> 		}
>                 default:
> 			break;
> 		}
> 		
> 	}
> 	traverse(transform);
> }
> 
> 
>    
> 
> Can anyone give some pointers about how to achieve a smooth speeding transition? I look up in the source code of both classes involved (AnimationPath and AnimationPathCallback) but I havent been able to figure out a solution. What can I do? or What am I missing?
> 
> Thank you!
> 
> Cheers


------------------------
Twirling twirling twirling toward freedom

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75288#75288







More information about the osg-users mailing list