source: GTP/trunk/App/Demos/Geom/include/OgreAnimation.h @ 1030

Revision 1030, 10.3 KB checked in by gumbau, 18 years ago (diff)

Ogre Stuff initial import

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
26#ifndef __Animation_H__
27#define __Animation_H__
28
29#include "OgrePrerequisites.h"
30#include "OgreString.h"
31#include "OgreIteratorWrappers.h"
32
33namespace Ogre {
34
35    /** An animation sequence.
36    @remarks
37        This class defines the interface for a sequence of animation, whether that
38        be animation of a mesh, a path along a spline, or possibly more than one
39        type of animation in one. An animation is made up of many 'tracks', which are
40        the more specific types of animation.
41    @par
42        You should not create these animations directly. They will be created via a parent
43        object which owns the animation, e.g. Skeleton.
44    */
45    class _OgreExport Animation
46    {
47
48    public:
49        /** The types of animation interpolation available. */
50        enum InterpolationMode
51        {
52            /** Values are interpolated along straight lines. */
53            IM_LINEAR,
54            /** Values are interpolated along a spline, resulting in smoother changes in direction. */
55            IM_SPLINE
56        };
57
58        /** The types of rotational interpolation available. */
59        enum RotationInterpolationMode
60        {
61            /** Values are interpolated linearly. This is faster but does not
62                necessarily give a completely accurate result.
63            */
64            RIM_LINEAR,
65            /** Values are interpolated spherically. This is more accurate but
66                has a higher cost.
67            */
68            RIM_SPHERICAL
69        };
70        /** You should not use this constructor directly, use the parent object such as Skeleton instead.
71        @param name The name of the animation, should be unique within it's parent (e.g. Skeleton)
72        @param length The length of the animation in seconds.
73        */
74        Animation(const String& name, Real length);
75        virtual ~Animation();
76
77        /** Gets the name of this animation. */
78        const String& getName(void) const;
79
80        /** Gets the total length of the animation. */
81        Real getLength(void) const;
82
83        /** Creates an AnimationTrack.
84        @param handle Numeric handle to give the track, used for accessing the track later.
85            Must be unique within this Animation.
86        */
87        AnimationTrack* createTrack(unsigned short handle);
88
89        /** Creates a new AnimationTrack automatically associated with a Node.
90        @remarks
91            This method creates a standard AnimationTrack, but also associates it with a
92            target Node which will receive all keyframe effects.
93        @param handle Numeric handle to give the track, used for accessing the track later.
94            Must be unique within this Animation.
95        @param node A pointer to the Node object which will be affected by this track
96        */
97        AnimationTrack* createTrack(unsigned short handle, Node* node);
98
99        /** Gets the number of AnimationTrack objects which make up this animation. */
100        unsigned short getNumTracks(void) const;
101
102        /** Gets a track by it's handle. */
103        AnimationTrack* getTrack(unsigned short handle) const;
104
105
106        /** Destroys the track with the given handle. */
107        void destroyTrack(unsigned short handle);
108
109        /** Removes and destroys all tracks making up this animation. */
110        void destroyAllTracks(void);
111
112        /** Applies an animation given a specific time point and weight.
113        @remarks
114            Where you have associated animation tracks with Node objects, you can eaily apply
115            an animation to those nodes by calling this method.
116        @param timePos The time position in the animation to apply.
117        @param weight The influence to give to this track, 1.0 for full influence, less to blend with
118          other animations.
119            @param scale The scale to apply to translations and scalings, useful for
120                        adapting an animation to a different size target.
121        */
122        void apply(Real timePos, Real weight = 1.0, bool accumulate = false,
123                        Real scale = 1.0f);
124
125        /** Applies an animation given a specific time point and weight to a given skeleton.
126        @remarks
127        Where you have associated animation tracks with Node objects, you can eaily apply
128        an animation to those nodes by calling this method.
129        @param timePos The time position in the animation to apply.
130        @param weight The influence to give to this track, 1.0 for full influence, less to blend with
131        other animations.
132            @param scale The scale to apply to translations and scalings, useful for
133                        adapting an animation to a different size target.
134        */
135        void apply(Skeleton* skeleton, Real timePos, Real weight = 1.0,
136                        bool accumulate = false, Real scale = 1.0f);
137
138        /** Tells the animation how to interpolate between keyframes.
139        @remarks
140            By default, animations normally interpolate linearly between keyframes. This is
141            fast, but when animations include quick changes in direction it can look a little
142            unnatural because directions change instantly at keyframes. An alternative is to
143            tell the animation to interpolate along a spline, which is more expensive in terms
144            of calculation time, but looks smoother because major changes in direction are
145            distributed around the keyframes rather than just at the keyframe.
146        @par
147            You can also change the default animation behaviour by calling
148            Animation::setDefaultInterpolationMode.
149        */
150        void setInterpolationMode(InterpolationMode im);
151
152        /** Gets the current interpolation mode of this animation.
153        @remarks
154            See setInterpolationMode for more info.
155        */
156        InterpolationMode getInterpolationMode(void) const;
157        /** Tells the animation how to interpolate rotations.
158        @remarks
159            By default, animations interpolate lieanrly between rotations. This
160            is fast but not necessarily completely accurate. If you want more
161            accurate interpolation, use spherical interpolation, but be aware
162            that it will incur a higher cost.
163        @par
164            You can also change the default rotation behaviour by calling
165            Animation::setDefaultRotationInterpolationMode.
166        */
167        void setRotationInterpolationMode(RotationInterpolationMode im);
168
169        /** Gets the current rotation interpolation mode of this animation.
170        @remarks
171            See setRotationInterpolationMode for more info.
172        */
173        RotationInterpolationMode getRotationInterpolationMode(void) const;
174
175        // Methods for setting the defaults
176        /** Sets the default animation interpolation mode.
177        @remarks
178            Every animation created after this option is set will have the new interpolation
179            mode specified. You can also change the mode per animation by calling the
180            setInterpolationMode method on the instance in question.
181        */
182        static void setDefaultInterpolationMode(InterpolationMode im);
183
184        /** Gets the default interpolation mode for all animations. */
185        static InterpolationMode getDefaultInterpolationMode(void);
186
187        /** Sets the default rotation interpolation mode.
188        @remarks
189            Every animation created after this option is set will have the new interpolation
190            mode specified. You can also change the mode per animation by calling the
191            setInterpolationMode method on the instance in question.
192        */
193        static void setDefaultRotationInterpolationMode(RotationInterpolationMode im);
194
195        /** Gets the default rotation interpolation mode for all animations. */
196        static RotationInterpolationMode getDefaultRotationInterpolationMode(void);
197
198        typedef std::map<unsigned short, AnimationTrack*> TrackList;
199        typedef ConstMapIterator<TrackList> TrackIterator;
200
201        /// Fast access to NON-UPDATEABLE track list
202        const TrackList& _getTrackList(void) const;
203
204        /// Get non-updateable iterator over tracks
205        TrackIterator getTrackIterator(void) const
206        { return TrackIterator(mTrackList.begin(), mTrackList.end()); }
207       
208                /** Optimise an animation by removing unnecessary tracks and keyframes.
209                @remarks
210                        When you export an animation, it is possible that certain tracks
211                        have been keyfamed but actually don't include anything useful - the
212                        keyframes include no transformation. These tracks can be completely
213                        eliminated from the animation and thus speed up the animation.
214                        In addition, if several keyframes in a row have the same value,
215                        then they are just adding overhead and can be removed.
216                */
217                void optimise(void);
218               
219
220
221    protected:
222        /// Tracks, indexed by handle
223        TrackList mTrackList;
224        String mName;
225
226        Real mLength;
227
228        InterpolationMode mInterpolationMode;
229        RotationInterpolationMode mRotationInterpolationMode;
230
231        static InterpolationMode msDefaultInterpolationMode;
232        static RotationInterpolationMode msDefaultRotationInterpolationMode;
233
234       
235    };
236
237
238
239}
240
241
242#endif
243
Note: See TracBrowser for help on using the repository browser.