root/OpenSceneGraph/trunk/src/osgAnimation/ActionStripAnimation.cpp @ 13041

Revision 13041, 3.6 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
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
16#include <osgAnimation/ActionStripAnimation>
17
18using namespace osgAnimation;
19
20ActionAnimation* ActionStripAnimation::getAnimation() { return _animation.get(); }
21ActionBlendIn* ActionStripAnimation::getBlendIn() { return _blendIn.get(); }
22ActionBlendOut* ActionStripAnimation::getBlendOut() { return _blendOut.second.get(); }
23const ActionAnimation* ActionStripAnimation::getAnimation() const { return _animation.get(); }
24const ActionBlendIn* ActionStripAnimation::getBlendIn() const { return _blendIn.get(); }
25const ActionBlendOut* ActionStripAnimation::getBlendOut() const { return _blendOut.second.get(); }
26unsigned int ActionStripAnimation::getBlendOutStartFrame() const { return _blendOut.first; }
27
28unsigned int ActionStripAnimation::getLoop() const { return _animation->getLoop(); }
29
30
31ActionStripAnimation::ActionStripAnimation(const ActionStripAnimation& a, const osg::CopyOp& c) : Action(a,c)
32{
33    _animation = a._animation;
34    _blendIn = a._blendIn;
35    _blendOut = a._blendOut;
36}
37
38ActionStripAnimation::ActionStripAnimation(Animation* animation, double blendInDuration, double blendOutDuration, double blendInWeightTarget)
39{
40    _blendIn = new ActionBlendIn(animation, blendInDuration, blendInWeightTarget);
41    _animation = new ActionAnimation(animation);
42    unsigned int start = static_cast<unsigned int>(floor((_animation->getDuration() - blendOutDuration) * _fps));
43    _blendOut = FrameBlendOut(start, new ActionBlendOut(animation, blendOutDuration));
44    setName(animation->getName() + "_Strip");
45    _blendIn->setName(_animation->getName() + "_" + _blendIn->getName());
46    _blendOut.second->setName(_animation->getName() + "_" + _blendOut.second->getName());
47    setDuration(animation->getDuration());
48}
49
50
51void ActionStripAnimation::setLoop(unsigned int loop)
52{
53    _animation->setLoop(loop);
54    if (!loop)
55        setDuration(-1);
56    else
57        setDuration(loop * _animation->getDuration());
58
59    // duration changed re evaluate the blendout duration
60    unsigned int start = static_cast<unsigned int>(floor((getDuration() - _blendOut.second->getDuration()) * _fps));
61    _blendOut = FrameBlendOut(start, _blendOut.second);
62}
63
64void ActionStripAnimation::traverse(ActionVisitor& visitor)
65{
66    if (_blendIn.valid())
67    {
68        unsigned int f = visitor.getStackedFrameAction().back().first;
69        visitor.pushFrameActionOnStack(FrameAction(f,_blendIn.get()));
70        _blendIn->accept(visitor);
71        visitor.popFrameAction();
72    }
73    if (_blendOut.second.valid())
74    {
75        unsigned int f = visitor.getStackedFrameAction().back().first;
76        visitor.pushFrameActionOnStack(FrameAction(f + _blendOut.first,_blendOut.second.get()));
77        _blendOut.second.get()->accept(visitor);
78        visitor.popFrameAction();
79    }
80
81    if (_animation.valid())
82    {
83        unsigned int f = visitor.getStackedFrameAction().back().first;
84        visitor.pushFrameActionOnStack(FrameAction(f,_animation.get()));
85        _animation->accept(visitor);
86        visitor.popFrameAction();
87    }
88}
Note: See TracBrowser for help on using the browser.