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

Revision 13041, 2.6 kB (checked in by robert, 2 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#include <osgAnimation/Action>
16
17using namespace osgAnimation;
18
19Action::Action()
20{
21    _numberFrame = 25;
22    _fps = 25;
23    _speed = 1.0;
24    _loop = 1;
25}
26Action::Action(const Action&,const osg::CopyOp&) {}
27Action::Callback* Action::getFrameCallback(unsigned int frame)
28{
29    if (_framesCallback.find(frame) != _framesCallback.end())
30    {
31        return _framesCallback[frame].get();
32    }
33    return 0;
34}
35
36void Action::removeCallback(Callback* cb)
37{
38    std::vector<unsigned int> keyToRemove;
39    for (FrameCallback::iterator it = _framesCallback.begin(); it != _framesCallback.end(); ++it)
40    {
41        if (it->second.get())
42        {
43            if (it->second.get() == cb)
44            {
45                it->second = it->second->getNestedCallback();
46                if (!it->second.valid())
47                    keyToRemove.push_back(it->first);
48            }
49            else
50            {
51                it->second->removeCallback(cb);
52            }
53        }
54    }
55    for (std::vector<unsigned int>::iterator it = keyToRemove.begin(); it != keyToRemove.end(); ++it)
56        _framesCallback.erase(*it);
57}
58
59Action::Callback* Action::getFrameCallback(double time)
60{
61    unsigned int frame = static_cast<unsigned int>(floor(time * _fps));
62    return getFrameCallback(frame);
63}
64
65bool osgAnimation::Action::evaluateFrame(unsigned int frame, unsigned int& resultframe, unsigned int& nbloop )
66{
67    unsigned int nbFrames = getNumFrames();
68    if (!nbFrames) {
69        nbFrames = 1;
70        osg::notify(osg::WARN) << "osgAnimation::Action::evaluateFrame your action " << getName() << " has 0 frames, it seems like an error in the data" << std::endl;
71    }
72
73    nbloop = frame / nbFrames;
74    resultframe = frame;
75
76    if (frame > nbFrames-1)
77    {
78        if (!getLoop())
79            resultframe = frame % nbFrames;
80        else
81        {
82            if (nbloop >= getLoop())
83                return false;
84            else
85                resultframe = frame % nbFrames;
86        }
87    }
88    return true;
89}
Note: See TracBrowser for help on using the browser.