1 /*  -*-c++-*-
2  *  Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
3  *
4  * This library is open source and may be redistributed and/or modified under
5  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6  * (at your option) any later version.  The full license is in LICENSE file
7  * included with this distribution, and on the openscenegraph.org website.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * OpenSceneGraph Public License for more details.
13 */
14 
15 #include <osgAnimation/ActionBlendOut>
16 
17 using namespace osgAnimation;
18 
ActionBlendOut()19 ActionBlendOut::ActionBlendOut() : _weight(0) {}
ActionBlendOut(const ActionBlendOut & a,const osg::CopyOp & c)20 ActionBlendOut::ActionBlendOut(const ActionBlendOut& a, const osg::CopyOp& c) : Action(a,c)
21 {
22     _weight = a._weight;
23     _animation = a._animation;
24 }
25 
ActionBlendOut(Animation * animation,double duration)26 ActionBlendOut::ActionBlendOut(Animation* animation, double duration)
27 {
28     _animation = animation;
29     float d = duration * _fps;
30     setNumFrames(static_cast<unsigned int>(floor(d) + 1));
31     _weight = 1.0;
32     setName("BlendOut");
33 }
34 
computeWeight(unsigned int frame)35 void ActionBlendOut::computeWeight(unsigned int frame)
36 {
37     double ratio = ( (frame+1) * 1.0 / (getNumFrames()) );
38     double w = _weight * (1.0-ratio);
39     OSG_DEBUG << getName() << " BlendOut frame " << frame  << " weight " << w << std::endl;
40     _animation->setWeight(w);
41 }
42