source: OGRE/trunk/ogrenew/OgreMain/src/OgreAnimation.cpp @ 657

Revision 657, 7.6 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26#include "OgreAnimation.h"
27#include "OgreKeyFrame.h"
28#include "OgreAnimationTrack.h"
29#include "OgreException.h"
30#include "OgreSkeleton.h"
31#include "OgreBone.h"
32
33namespace Ogre {
34
35    Animation::InterpolationMode Animation::msDefaultInterpolationMode = Animation::IM_LINEAR;
36    Animation::RotationInterpolationMode
37        Animation::msDefaultRotationInterpolationMode = Animation::RIM_LINEAR;
38    //---------------------------------------------------------------------
39    Animation::Animation(const String& name, Real length) : mName(name), mLength(length)
40    {
41        mInterpolationMode = Animation::msDefaultInterpolationMode;
42        mRotationInterpolationMode = Animation::msDefaultRotationInterpolationMode;
43    }
44    //---------------------------------------------------------------------
45    Animation::~Animation()
46    {
47        destroyAllTracks();
48    }
49    //---------------------------------------------------------------------
50    Real Animation::getLength(void) const
51    {
52        return mLength;
53    }
54    //---------------------------------------------------------------------
55    AnimationTrack* Animation::createTrack(unsigned short handle)
56    {
57        AnimationTrack* ret;
58
59        ret = new AnimationTrack(this);
60
61        mTrackList[handle] = ret;
62        return ret;
63    }
64    //---------------------------------------------------------------------
65    AnimationTrack* Animation::createTrack(unsigned short handle, Node* node)
66    {
67        AnimationTrack* ret = createTrack(handle);
68
69        ret->setAssociatedNode(node);
70
71        return ret;
72    }
73    //---------------------------------------------------------------------
74    unsigned short Animation::getNumTracks(void) const
75    {
76        return (unsigned short)mTrackList.size();
77    }
78    //---------------------------------------------------------------------
79    AnimationTrack* Animation::getTrack(unsigned short handle) const
80    {
81        TrackList::const_iterator i = mTrackList.find(handle);
82
83        if (i == mTrackList.end())
84        {
85            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
86                "Cannot find track with the specified handle",
87                "Animation::getTrack");
88        }
89
90        return i->second;
91
92    }
93    //---------------------------------------------------------------------
94    void Animation::destroyTrack(unsigned short handle)
95    {
96        TrackList::iterator i = mTrackList.find(handle);
97
98                if (i != mTrackList.end())
99                {
100                        delete i->second;
101                        mTrackList.erase(i);
102                }
103    }
104    //---------------------------------------------------------------------
105    void Animation::destroyAllTracks(void)
106    {
107        TrackList::iterator i;
108        for (i = mTrackList.begin(); i != mTrackList.end(); ++i)
109        {
110            delete i->second;
111        }
112        mTrackList.clear();
113    }
114    //---------------------------------------------------------------------
115    const String& Animation::getName(void) const
116    {
117        return mName;
118    }
119    //---------------------------------------------------------------------
120        void Animation::apply(Real timePos, Real weight, bool accumulate, Real scale)
121    {
122        TrackList::iterator i;
123        for (i = mTrackList.begin(); i != mTrackList.end(); ++i)
124        {
125            i->second->apply(timePos, weight, accumulate, scale);
126        }
127
128
129    }
130    //---------------------------------------------------------------------
131    void Animation::apply(Skeleton* skel, Real timePos, Real weight,
132                bool accumulate, Real scale)
133    {
134        TrackList::iterator i;
135        for (i = mTrackList.begin(); i != mTrackList.end(); ++i)
136        {
137            // get bone to apply to
138            Bone* b = skel->getBone(i->first);
139            i->second->applyToNode(b, timePos, weight, accumulate, scale);
140        }
141
142
143    }
144    //---------------------------------------------------------------------
145    void Animation::setInterpolationMode(InterpolationMode im)
146    {
147        mInterpolationMode = im;
148    }
149    //---------------------------------------------------------------------
150    Animation::InterpolationMode Animation::getInterpolationMode(void) const
151    {
152        return mInterpolationMode;
153    }
154    //---------------------------------------------------------------------
155    void Animation::setDefaultInterpolationMode(InterpolationMode im)
156    {
157        msDefaultInterpolationMode = im;
158    }
159    //---------------------------------------------------------------------
160    Animation::InterpolationMode Animation::getDefaultInterpolationMode(void)
161    {
162        return msDefaultInterpolationMode;
163    }
164    //---------------------------------------------------------------------
165    const Animation::TrackList& Animation::_getTrackList(void) const
166    {
167        return mTrackList;
168
169    }
170    //---------------------------------------------------------------------
171    void Animation::setRotationInterpolationMode(RotationInterpolationMode im)
172    {
173        mRotationInterpolationMode = im;
174    }
175    //---------------------------------------------------------------------
176    Animation::RotationInterpolationMode Animation::getRotationInterpolationMode(void) const
177    {
178        return mRotationInterpolationMode;
179    }
180    //---------------------------------------------------------------------
181    void Animation::setDefaultRotationInterpolationMode(RotationInterpolationMode im)
182    {
183        msDefaultRotationInterpolationMode = im;
184    }
185    //---------------------------------------------------------------------
186    Animation::RotationInterpolationMode Animation::getDefaultRotationInterpolationMode(void)
187    {
188        return msDefaultRotationInterpolationMode;
189    }
190    //---------------------------------------------------------------------
191        void Animation::optimise(void)
192        {
193                // Iterate over the tracks and identify those with no useful keyframes
194                std::list<unsigned short> tracksToDestroy;
195        TrackList::iterator i;
196        for (i = mTrackList.begin(); i != mTrackList.end(); ++i)
197        {
198                        AnimationTrack* track = i->second;
199                        if (!track->hasNonZeroKeyFrames())
200                        {
201                                // mark the entire track for destruction
202                                tracksToDestroy.push_back(i->first);
203                        }
204                        else
205                        {
206                                track->optimise();
207                        }
208                       
209                }
210               
211                // Now destroy the tracks we marked for death
212                for(std::list<unsigned short>::iterator h = tracksToDestroy.begin();
213                        h != tracksToDestroy.end(); ++h)
214                {
215                        destroyTrack(*h);
216                }
217               
218        }
219
220}
221
222
Note: See TracBrowser for help on using the repository browser.