# OgreAnimationState.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029
    00030 #ifndef __AnimationSet_H__
    00031 #define __AnimationSet_H__
    00032
    00033 #include "OgrePrerequisites.h"
    00034
    00035 #include "OgreString.h"
    00036 #include "OgreController.h"
    00037 #include "OgreIteratorWrappers.h"
    00038
    00039 namespace Ogre {
    00040
    00046     class _OgreExport AnimationState : public AnimationAlloc
    00047     {
    00048     public:
    00049
    00051       typedef std::vector<float> BoneBlendMask;
    00052
    00054         AnimationState(const String& animName, AnimationStateSet *parent,
    00055             Real timePos, Real length, Real weight = 1.0, bool enabled = false);
    00057         AnimationState(AnimationStateSet* parent, const AnimationState &rhs);
    00061         virtual ~AnimationState();
    00062
    00064         const String& getAnimationName() const;
    00066         Real getTimePosition(void) const;
    00068         void setTimePosition(Real timePos);
    00070         Real getLength() const;
    00072         void setLength(Real len);
    00074         Real getWeight(void) const;
    00076         void setWeight(Real weight);
    00081         void addTime(Real offset);
    00082
    00084         bool hasEnded(void) const;
    00085
    00087         bool getEnabled(void) const;
    00089         void setEnabled(bool enabled);
    00090
    00092         bool operator==(const AnimationState& rhs) const;
    00093         // Inequality operator
    00094         bool operator!=(const AnimationState& rhs) const;
    00095
    00099         void setLoop(bool loop) { mLoop = loop; }
    00101         bool getLoop(void) const { return mLoop; }
    00102
    00107         void copyStateFrom(const AnimationState& animState);
    00108
    00110         AnimationStateSet* getParent(void) const { return mParent; }
    00111
    00122       void createBlendMask(size_t blendMaskSizeHint, float initialWeight = 1.0f);
    00124       void destroyBlendMask();
    00132       void _setBlendMaskData(const float* blendMaskData);
    00140       void _setBlendMask(const BoneBlendMask* blendMask);
    00142       const BoneBlendMask* getBlendMask() const {return mBlendMask;}
    00144       bool hasBlendMask() const {return mBlendMask != 0;}
    00146       void setBlendMaskEntry(size_t boneHandle, float weight);
    00148       inline float getBlendMaskEntry(size_t boneHandle) const
    00149       {
    00150         assert(mBlendMask && mBlendMask->size() > boneHandle);
    00151         return (*mBlendMask)[boneHandle];
    00152       }
    00153     protected:
    00155       BoneBlendMask* mBlendMask;
    00156
    00157         String mAnimationName;
    00158         AnimationStateSet* mParent;
    00159         Real mTimePos;
    00160         Real mLength;
    00161         Real mWeight;
    00162         bool mEnabled;
    00163         bool mLoop;
    00164
    00165     };
    00166
    00167     // A map of animation states
    00168     typedef std::map<String, AnimationState*> AnimationStateMap;
    00169     typedef MapIterator<AnimationStateMap> AnimationStateIterator;
    00170     typedef ConstMapIterator<AnimationStateMap> ConstAnimationStateIterator;
    00171     // A list of enabled animation states
    00172     typedef std::list<AnimationState*> EnabledAnimationStateList;
    00173     typedef ConstVectorIterator<EnabledAnimationStateList> ConstEnabledAnimationStateIterator;
    00174
    00177     class _OgreExport AnimationStateSet : public AnimationAlloc
    00178     {
    00179     public:
    00181         OGRE_AUTO_MUTEX
    00183         AnimationStateSet();
    00185         AnimationStateSet(const AnimationStateSet& rhs);
    00186
    00187         ~AnimationStateSet();
    00188
    00196         AnimationState* createAnimationState(const String& animName,
    00197             Real timePos, Real length, Real weight = 1.0, bool enabled = false);
    00199         AnimationState* getAnimationState(const String& name) const;
    00201         bool hasAnimationState(const String& name) const;
    00203         void removeAnimationState(const String& name);
    00205         void removeAllAnimationStates(void);
    00206
    00213         AnimationStateIterator getAnimationStateIterator(void);
    00220         ConstAnimationStateIterator getAnimationStateIterator(void) const;
    00222         void copyMatchingState(AnimationStateSet* target) const;
    00224         void _notifyDirty(void);
    00226         unsigned long getDirtyFrameNumber(void) const { return mDirtyFrameNumber; }
    00227
    00229         void _notifyAnimationStateEnabled(AnimationState* target, bool enabled);
    00231         bool hasEnabledAnimationState(void) const { return !mEnabledAnimationStates.empty(); }
    00238         ConstEnabledAnimationStateIterator getEnabledAnimationStateIterator(void) const;
    00239
    00240     protected:
    00241         unsigned long mDirtyFrameNumber;
    00242         AnimationStateMap mAnimationStates;
    00243         EnabledAnimationStateList mEnabledAnimationStates;
    00244
    00245     };
    00246
    00255     class _OgreExport AnimationStateControllerValue : public ControllerValue<Real>
    00256     {
    00257     protected:
    00258         AnimationState* mTargetAnimationState;
    00259     public:
    00261         AnimationStateControllerValue(AnimationState* targetAnimationState)
    00262             : mTargetAnimationState(targetAnimationState) {}
    00264         ~AnimationStateControllerValue() {}
    00266         Real getValue(void) const;
    00267
    00269         void setValue(Real value);
    00270
    00271     };
    00272
    00273
    00274 }
    00275
    00276 #endif
    00277

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Dec 27 17:31:04 2009