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

Revision 10693, 2.4 kB (checked in by cedricpinson, 5 years ago)

From Cedric Pinson, The following commit include:
* Refactore of RigGeometry? to support hardware skinning
* Refactore of Timeline to split Action in differents files
* Add example how to use hardware skinning

RevLine 
[10344]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
[10693]17using namespace osgAnimation;
18
19Action::Action()
[10344]20{
21    _numberFrame = 25;
22    _fps = 25;
23    _speed = 1.0;
24    _loop = 1;
25}
[10693]26Action::Action(const Action&,const osg::CopyOp&) {}
27Action::Callback* Action::getFrameCallback(unsigned int frame)
[10344]28{
29    if (_framesCallback.find(frame) != _framesCallback.end())
30    {
[10351]31        return _framesCallback[frame].get();
[10344]32    }
33    return 0;
34}
35
[10693]36void Action::removeCallback(Callback* cb)
[10344]37{
[10693]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{
[10344]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    nbloop = frame / getNumFrames();
68    resultframe = frame;
69
70    if (frame > getNumFrames()-1)
71    {
72        if (!getLoop())
73            resultframe = frame % getNumFrames();
74        else
75        {
76            if (nbloop >= getLoop())
77                return false;
78            else
79                resultframe = frame % getNumFrames();
80        }
81    }
82    return true;
83}
Note: See TracBrowser for help on using the browser.