[1809] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | #ifndef __AnimationSet_H__
|
---|
| 27 | #define __AnimationSet_H__
|
---|
| 28 |
|
---|
| 29 | #include "OgrePrerequisites.h"
|
---|
| 30 |
|
---|
| 31 | #include "OgreString.h"
|
---|
| 32 | #include "OgreController.h"
|
---|
| 33 | #include "OgreIteratorWrappers.h"
|
---|
| 34 |
|
---|
| 35 | namespace Ogre {
|
---|
| 36 |
|
---|
| 37 | /** Represents the state of an animation and the weight of it's influence.
|
---|
| 38 | @remarks
|
---|
| 39 | Other classes can hold instances of this class to store the state of any animations
|
---|
| 40 | they are using.
|
---|
| 41 | */
|
---|
| 42 | class _OgreExport AnimationState
|
---|
| 43 | {
|
---|
| 44 | public:
|
---|
| 45 | /// Normal constructor with all params supplied
|
---|
| 46 | AnimationState(const String& animName, AnimationStateSet *parent,
|
---|
| 47 | Real timePos, Real length, Real weight = 1.0, bool enabled = false);
|
---|
| 48 | /// constructor to copy from an existing state with new parent
|
---|
| 49 | AnimationState(AnimationStateSet* parent, const AnimationState &rhs);
|
---|
| 50 | /** Destructor - is here because class has virtual functions and some compilers
|
---|
| 51 | would whine if it won't exist.
|
---|
| 52 | */
|
---|
| 53 | virtual ~AnimationState();
|
---|
| 54 |
|
---|
| 55 | /// Gets the name of the animation to which this state applies
|
---|
| 56 | const String& getAnimationName() const;
|
---|
| 57 | /// Gets the time position for this animation
|
---|
| 58 | Real getTimePosition(void) const;
|
---|
| 59 | /// Sets the time position for this animation
|
---|
| 60 | void setTimePosition(Real timePos);
|
---|
| 61 | /// Gets the total length of this animation (may be shorter than whole animation)
|
---|
| 62 | Real getLength() const;
|
---|
| 63 | /// Sets the total length of this animation (may be shorter than whole animation)
|
---|
| 64 | void setLength(Real len);
|
---|
| 65 | /// Gets the weight (influence) of this animation
|
---|
| 66 | Real getWeight(void) const;
|
---|
| 67 | /// Sets the weight (influence) of this animation
|
---|
| 68 | void setWeight(Real weight);
|
---|
| 69 | /** Modifies the time position, adjusting for animation length
|
---|
| 70 | @remarks
|
---|
| 71 | This method loops at the edges if animation looping is enabled.
|
---|
| 72 | */
|
---|
| 73 | void addTime(Real offset);
|
---|
| 74 |
|
---|
| 75 | /// Returns true if this animation is currently enabled
|
---|
| 76 | bool getEnabled(void) const;
|
---|
| 77 | /// Sets whether this animation is enabled
|
---|
| 78 | void setEnabled(bool enabled);
|
---|
| 79 |
|
---|
| 80 | /// Equality operator
|
---|
| 81 | bool operator==(const AnimationState& rhs) const;
|
---|
| 82 | // Inequality operator
|
---|
| 83 | bool operator!=(const AnimationState& rhs) const;
|
---|
| 84 |
|
---|
| 85 | /** Sets whether or not an animation loops at the start and end of
|
---|
| 86 | the animation if the time continues to be altered.
|
---|
| 87 | */
|
---|
| 88 | void setLoop(bool loop) { mLoop = loop; }
|
---|
| 89 | /// Gets whether or not this animation loops
|
---|
| 90 | bool getLoop(void) const { return mLoop; }
|
---|
| 91 |
|
---|
| 92 | /** Copies the states from another animation state, preserving the animation name
|
---|
| 93 | (unlike operator=) but copying everything else.
|
---|
| 94 | @param animState Reference to animation state which will use as source.
|
---|
| 95 | */
|
---|
| 96 | void copyStateFrom(const AnimationState& animState);
|
---|
| 97 |
|
---|
| 98 | /// Get the parent animation state set
|
---|
| 99 | AnimationStateSet* getParent(void) const { return mParent; }
|
---|
| 100 |
|
---|
| 101 | protected:
|
---|
| 102 | String mAnimationName;
|
---|
| 103 | AnimationStateSet* mParent;
|
---|
| 104 | Real mTimePos;
|
---|
| 105 | Real mLength;
|
---|
| 106 | Real mInvLength;
|
---|
| 107 | Real mWeight;
|
---|
| 108 | bool mEnabled;
|
---|
| 109 | bool mLoop;
|
---|
| 110 |
|
---|
| 111 | };
|
---|
| 112 |
|
---|
| 113 | // A map of animation states
|
---|
| 114 | typedef std::map<String, AnimationState*> AnimationStateMap;
|
---|
| 115 | typedef MapIterator<AnimationStateMap> AnimationStateIterator;
|
---|
| 116 | typedef ConstMapIterator<AnimationStateMap> ConstAnimationStateIterator;
|
---|
| 117 | // A list of enabled animation states
|
---|
| 118 | typedef std::list<AnimationState*> EnabledAnimationStateList;
|
---|
| 119 | typedef ConstVectorIterator<EnabledAnimationStateList> ConstEnabledAnimationStateIterator;
|
---|
| 120 |
|
---|
| 121 | /** Class encapsulating a set of AnimationState objects.
|
---|
| 122 | */
|
---|
| 123 | class _OgreExport AnimationStateSet
|
---|
| 124 | {
|
---|
| 125 | public:
|
---|
| 126 | /// Create a blank animation state set
|
---|
| 127 | AnimationStateSet();
|
---|
| 128 | /// Create an animation set by copying the contents of another
|
---|
| 129 | AnimationStateSet(const AnimationStateSet& rhs);
|
---|
| 130 |
|
---|
| 131 | ~AnimationStateSet();
|
---|
| 132 |
|
---|
| 133 | /** Create a new AnimationState instance.
|
---|
| 134 | @param animName The name of the animation
|
---|
| 135 | @param timePos Starting time position
|
---|
| 136 | @param length Length of the animation to play
|
---|
| 137 | @param weight Weight to apply the animation with
|
---|
| 138 | @param enabled Whether the animation is enabled
|
---|
| 139 | */
|
---|
| 140 | AnimationState* createAnimationState(const String& animName,
|
---|
| 141 | Real timePos, Real length, Real weight = 1.0, bool enabled = false);
|
---|
| 142 | /// Get an animation state by the name of the animation
|
---|
| 143 | AnimationState* getAnimationState(const String& name) const;
|
---|
| 144 | /// Tests if state for the named animation is present
|
---|
| 145 | bool hasAnimationState(const String& name) const;
|
---|
| 146 | /// Remove animation state with the given name
|
---|
| 147 | void removeAnimationState(const String& name);
|
---|
| 148 | /// Remove all animation states
|
---|
| 149 | void removeAllAnimationStates(void);
|
---|
| 150 |
|
---|
| 151 | /// Get an iterator over all the animation states in this set
|
---|
| 152 | AnimationStateIterator getAnimationStateIterator(void);
|
---|
| 153 | /// Get an iterator over all the animation states in this set
|
---|
| 154 | ConstAnimationStateIterator getAnimationStateIterator(void) const;
|
---|
| 155 | /// Copy the state of any matching animation states from this to another
|
---|
| 156 | void copyMatchingState(AnimationStateSet* target) const;
|
---|
| 157 | /// Set the dirty flag and dirty frame number on this state set
|
---|
| 158 | void _notifyDirty(void);
|
---|
| 159 | /// Get the latest animation state been altered frame number
|
---|
| 160 | unsigned long getDirtyFrameNumber(void) const { return mDirtyFrameNumber; }
|
---|
| 161 |
|
---|
| 162 | /// Internal method respond to enable/disable an animation state
|
---|
| 163 | void _notifyAnimationStateEnabled(AnimationState* target, bool enabled);
|
---|
| 164 | /// Tests if exists enabled animation state in this set
|
---|
| 165 | bool hasEnabledAnimationState(void) const { return !mEnabledAnimationStates.empty(); }
|
---|
| 166 | /// Get an iterator over all the enabled animation states in this set
|
---|
| 167 | ConstEnabledAnimationStateIterator getEnabledAnimationStateIterator(void) const;
|
---|
| 168 |
|
---|
| 169 | protected:
|
---|
| 170 | unsigned long mDirtyFrameNumber;
|
---|
| 171 | AnimationStateMap mAnimationStates;
|
---|
| 172 | EnabledAnimationStateList mEnabledAnimationStates;
|
---|
| 173 |
|
---|
| 174 | };
|
---|
| 175 |
|
---|
| 176 | /** ControllerValue wrapper class for AnimationState.
|
---|
| 177 | @remarks
|
---|
| 178 | In Azathoth and earlier, AnimationState was a ControllerValue but this
|
---|
| 179 | actually causes memory problems since Controllers delete their values
|
---|
| 180 | automatically when there are no further references to them, but AnimationState
|
---|
| 181 | is deleted explicitly elsewhere so this causes double-free problems.
|
---|
| 182 | This wrapper acts as a bridge and it is this which is destroyed automatically.
|
---|
| 183 | */
|
---|
| 184 | class _OgreExport AnimationStateControllerValue : public ControllerValue<Real>
|
---|
| 185 | {
|
---|
| 186 | protected:
|
---|
| 187 | AnimationState* mTargetAnimationState;
|
---|
| 188 | public:
|
---|
| 189 | /** Constructor, pass in the target animation state. */
|
---|
| 190 | AnimationStateControllerValue(AnimationState* targetAnimationState)
|
---|
| 191 | : mTargetAnimationState(targetAnimationState) {}
|
---|
| 192 | /// Destructor (parent already virtual)
|
---|
| 193 | ~AnimationStateControllerValue() {}
|
---|
| 194 | /** ControllerValue implementation. */
|
---|
| 195 | Real getValue(void) const;
|
---|
| 196 |
|
---|
| 197 | /** ControllerValue implementation. */
|
---|
| 198 | void setValue(Real value);
|
---|
| 199 |
|
---|
| 200 | };
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | #endif
|
---|
| 206 |
|
---|