Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreAnimationState.h @ 5

Last change on this file since 5 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 8.9 KB
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-2006 Torus Knot Software Ltd
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
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29
30#ifndef __AnimationSet_H__
31#define __AnimationSet_H__
32
33#include "OgrePrerequisites.h"
34
35#include "OgreString.h"
36#include "OgreController.h"
37#include "OgreIteratorWrappers.h"
38
39namespace Ogre {
40
41    /** Represents the state of an animation and the weight of it's influence.
42    @remarks
43        Other classes can hold instances of this class to store the state of any animations
44        they are using.
45    */
46    class _OgreExport AnimationState
47    {
48    public:
49        /// Normal constructor with all params supplied
50        AnimationState(const String& animName, AnimationStateSet *parent, 
51                        Real timePos, Real length, Real weight = 1.0, bool enabled = false);
52                /// constructor to copy from an existing state with new parent
53                AnimationState(AnimationStateSet* parent, const AnimationState &rhs);
54                /** Destructor - is here because class has virtual functions and some compilers
55                        would whine if it won't exist.
56                */
57                virtual ~AnimationState();
58       
59        /// Gets the name of the animation to which this state applies
60        const String& getAnimationName() const;
61        /// Gets the time position for this animation
62        Real getTimePosition(void) const;
63        /// Sets the time position for this animation
64        void setTimePosition(Real timePos);
65        /// Gets the total length of this animation (may be shorter than whole animation)
66        Real getLength() const;
67        /// Sets the total length of this animation (may be shorter than whole animation)
68        void setLength(Real len);
69        /// Gets the weight (influence) of this animation
70        Real getWeight(void) const;
71        /// Sets the weight (influence) of this animation
72        void setWeight(Real weight);
73        /** Modifies the time position, adjusting for animation length
74        @remarks
75            This method loops at the edges if animation looping is enabled.
76        */
77        void addTime(Real offset);
78
79                /// Returns true if the animation has reached the end and is not looping
80                bool hasEnded(void) const;
81
82        /// Returns true if this animation is currently enabled
83        bool getEnabled(void) const;
84        /// Sets whether this animation is enabled
85        void setEnabled(bool enabled);
86
87        /// Equality operator
88        bool operator==(const AnimationState& rhs) const;
89        // Inequality operator
90        bool operator!=(const AnimationState& rhs) const;
91
92        /** Sets whether or not an animation loops at the start and end of
93            the animation if the time continues to be altered.
94        */
95        void setLoop(bool loop) { mLoop = loop; }
96        /// Gets whether or not this animation loops           
97        bool getLoop(void) const { return mLoop; }
98     
99        /** Copies the states from another animation state, preserving the animation name
100        (unlike operator=) but copying everything else.
101        @param animState Reference to animation state which will use as source.
102        */
103        void copyStateFrom(const AnimationState& animState);
104
105                /// Get the parent animation state set
106                AnimationStateSet* getParent(void) const { return mParent; }
107
108    protected:
109        String mAnimationName;
110                AnimationStateSet* mParent;
111        Real mTimePos;
112        Real mLength;
113        Real mWeight;
114        bool mEnabled;
115        bool mLoop;
116
117    };
118
119        // A map of animation states
120        typedef std::map<String, AnimationState*> AnimationStateMap;
121        typedef MapIterator<AnimationStateMap> AnimationStateIterator;
122        typedef ConstMapIterator<AnimationStateMap> ConstAnimationStateIterator;
123    // A list of enabled animation states
124    typedef std::list<AnimationState*> EnabledAnimationStateList;
125    typedef ConstVectorIterator<EnabledAnimationStateList> ConstEnabledAnimationStateIterator;
126
127        /** Class encapsulating a set of AnimationState objects.
128        */
129        class _OgreExport AnimationStateSet
130        {
131        public:
132                /// Mutex, public for external locking if needed
133                OGRE_AUTO_MUTEX
134                /// Create a blank animation state set
135                AnimationStateSet();
136                /// Create an animation set by copying the contents of another
137                AnimationStateSet(const AnimationStateSet& rhs);
138
139                ~AnimationStateSet();
140
141                /** Create a new AnimationState instance.
142                @param animName The name of the animation
143                @param timePos Starting time position
144                @param length Length of the animation to play
145                @param weight Weight to apply the animation with
146                @param enabled Whether the animation is enabled
147                */
148                AnimationState* createAnimationState(const String& animName, 
149                        Real timePos, Real length, Real weight = 1.0, bool enabled = false);
150                /// Get an animation state by the name of the animation
151                AnimationState* getAnimationState(const String& name) const;
152                /// Tests if state for the named animation is present
153                bool hasAnimationState(const String& name) const;
154                /// Remove animation state with the given name
155                void removeAnimationState(const String& name);
156                /// Remove all animation states
157                void removeAllAnimationStates(void);
158
159                /** Get an iterator over all the animation states in this set.
160                @note
161                        The iterator returned from this method is not threadsafe,
162                        you will need to manually lock the public mutex on this
163                        class to ensure thread safety if you need it.
164                */
165                AnimationStateIterator getAnimationStateIterator(void);
166                /** Get an iterator over all the animation states in this set.
167                @note
168                        The iterator returned from this method is not threadsafe,
169                        you will need to manually lock the public mutex on this
170                        class to ensure thread safety if you need it.
171                */
172                ConstAnimationStateIterator getAnimationStateIterator(void) const;
173                /// Copy the state of any matching animation states from this to another
174                void copyMatchingState(AnimationStateSet* target) const;
175                /// Set the dirty flag and dirty frame number on this state set
176                void _notifyDirty(void);
177                /// Get the latest animation state been altered frame number
178                unsigned long getDirtyFrameNumber(void) const { return mDirtyFrameNumber; }
179
180        /// Internal method respond to enable/disable an animation state
181        void _notifyAnimationStateEnabled(AnimationState* target, bool enabled);
182        /// Tests if exists enabled animation state in this set
183        bool hasEnabledAnimationState(void) const { return !mEnabledAnimationStates.empty(); }
184                /** Get an iterator over all the enabled animation states in this set
185                @note
186                        The iterator returned from this method is not threadsafe,
187                        you will need to manually lock the public mutex on this
188                        class to ensure thread safety if you need it.
189                */
190                ConstEnabledAnimationStateIterator getEnabledAnimationStateIterator(void) const;
191
192        protected:
193                unsigned long mDirtyFrameNumber;
194                AnimationStateMap mAnimationStates;
195        EnabledAnimationStateList mEnabledAnimationStates;
196
197        };
198
199        /** ControllerValue wrapper class for AnimationState.
200        @remarks
201                In Azathoth and earlier, AnimationState was a ControllerValue but this
202                actually causes memory problems since Controllers delete their values
203                automatically when there are no further references to them, but AnimationState
204                is deleted explicitly elsewhere so this causes double-free problems.
205                This wrapper acts as a bridge and it is this which is destroyed automatically.
206        */
207        class _OgreExport AnimationStateControllerValue : public ControllerValue<Real>
208        {
209        protected:
210                AnimationState* mTargetAnimationState;
211        public:
212                /** Constructor, pass in the target animation state. */
213                AnimationStateControllerValue(AnimationState* targetAnimationState)
214                        : mTargetAnimationState(targetAnimationState) {}
215                /// Destructor (parent already virtual)
216                ~AnimationStateControllerValue() {}
217                /** ControllerValue implementation. */
218                Real getValue(void) const;
219
220                /** ControllerValue implementation. */
221                void setValue(Real value);
222
223        };
224
225
226}
227
228#endif
229
Note: See TracBrowser for help on using the repository browser.