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-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 
00029 #ifndef __AnimationSet_H__
00030 #define __AnimationSet_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 
00034 #include "OgreString.h"
00035 #include "OgreController.h"
00036 #include "OgreIteratorWrappers.h"
00037 #include "Threading/OgreThreadHeaders.h"
00038 #include "OgreHeaderPrefix.h"
00039 
00040 namespace Ogre {
00041 
00054     class _OgreExport AnimationState : public AnimationAlloc
00055     {
00056     public:
00057 
00059         typedef vector<float>::type BoneBlendMask;
00060 
00075         AnimationState(const String& animName, AnimationStateSet *parent, 
00076             Real timePos, Real length, Real weight = 1.0, bool enabled = false);
00078         AnimationState(AnimationStateSet* parent, const AnimationState &rhs);
00079         virtual ~AnimationState();
00080         
00082         const String& getAnimationName() const;
00084         Real getTimePosition(void) const;
00086         void setTimePosition(Real timePos);
00088         Real getLength() const;
00090         void setLength(Real len);
00092         Real getWeight(void) const;
00094         void setWeight(Real weight);
00100         void addTime(Real offset);
00101 
00103         bool hasEnded(void) const;
00104 
00106         bool getEnabled(void) const;
00108         void setEnabled(bool enabled);
00109 
00111         bool operator==(const AnimationState& rhs) const;
00113         bool operator!=(const AnimationState& rhs) const;
00114 
00118         void setLoop(bool loop) { mLoop = loop; }
00120         bool getLoop(void) const { return mLoop; }
00121      
00126         void copyStateFrom(const AnimationState& animState);
00127 
00129         AnimationStateSet* getParent(void) const { return mParent; }
00130 
00141       void createBlendMask(size_t blendMaskSizeHint, float initialWeight = 1.0f);
00143       void destroyBlendMask();
00151       void _setBlendMaskData(const float* blendMaskData);
00159       void _setBlendMask(const BoneBlendMask* blendMask);
00161       const BoneBlendMask* getBlendMask() const {return mBlendMask;}
00163       bool hasBlendMask() const {return mBlendMask != 0;}
00165       void setBlendMaskEntry(size_t boneHandle, float weight);
00167       inline float getBlendMaskEntry(size_t boneHandle) const
00168       {
00169           assert(mBlendMask && mBlendMask->size() > boneHandle);
00170           return (*mBlendMask)[boneHandle];
00171       }
00172     protected:
00174         BoneBlendMask* mBlendMask;
00175 
00176         String mAnimationName;
00177         AnimationStateSet* mParent;
00178         Real mTimePos;
00179         Real mLength;
00180         Real mWeight;
00181         bool mEnabled;
00182         bool mLoop;
00183 
00184     };
00185 
00186     // A map of animation states
00187     typedef map<String, AnimationState*>::type AnimationStateMap;
00188     typedef MapIterator<AnimationStateMap> AnimationStateIterator;
00189     typedef ConstMapIterator<AnimationStateMap> ConstAnimationStateIterator;
00190     // A list of enabled animation states
00191     typedef list<AnimationState*>::type EnabledAnimationStateList;
00192     typedef ConstVectorIterator<EnabledAnimationStateList> ConstEnabledAnimationStateIterator;
00193 
00196     class _OgreExport AnimationStateSet : public AnimationAlloc
00197     {
00198     public:
00200             OGRE_AUTO_MUTEX;
00202         AnimationStateSet();
00204         AnimationStateSet(const AnimationStateSet& rhs);
00205 
00206         ~AnimationStateSet();
00207 
00215         AnimationState* createAnimationState(const String& animName,  
00216             Real timePos, Real length, Real weight = 1.0, bool enabled = false);
00218         AnimationState* getAnimationState(const String& name) const;
00220         bool hasAnimationState(const String& name) const;
00222         void removeAnimationState(const String& name);
00224         void removeAllAnimationStates(void);
00225 
00232         AnimationStateIterator getAnimationStateIterator(void);
00239         ConstAnimationStateIterator getAnimationStateIterator(void) const;
00241         void copyMatchingState(AnimationStateSet* target) const;
00243         void _notifyDirty(void);
00245         unsigned long getDirtyFrameNumber(void) const { return mDirtyFrameNumber; }
00246 
00248         void _notifyAnimationStateEnabled(AnimationState* target, bool enabled);
00250         bool hasEnabledAnimationState(void) const { return !mEnabledAnimationStates.empty(); }
00257         ConstEnabledAnimationStateIterator getEnabledAnimationStateIterator(void) const;
00258 
00259     protected:
00260         unsigned long mDirtyFrameNumber;
00261         AnimationStateMap mAnimationStates;
00262         EnabledAnimationStateList mEnabledAnimationStates;
00263 
00264     };
00265 
00274     class _OgreExport AnimationStateControllerValue : public ControllerValue<Real>
00275     {
00276     protected:
00277         AnimationState* mTargetAnimationState;
00278     public:
00280         AnimationStateControllerValue(AnimationState* targetAnimationState)
00281             : mTargetAnimationState(targetAnimationState) {}
00283         ~AnimationStateControllerValue() {}
00285         Real getValue(void) const;
00286 
00288         void setValue(Real value);
00289 
00290     };
00291 
00294 }
00295 
00296 #include "OgreHeaderSuffix.h"
00297 
00298 #endif
00299 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:40