OgreAnimationTrack.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 __AnimationTrack_H__
00031 #define __AnimationTrack_H__
00032 
00033 #include "OgrePrerequisites.h"
00034 #include "OgreSimpleSpline.h"
00035 #include "OgreRotationalSpline.h"
00036 #include "OgreKeyFrame.h"
00037 #include "OgreAnimable.h"
00038 #include "OgrePose.h"
00039 
00040 namespace Ogre 
00041 {
00044     class _OgreExport TimeIndex
00045     {
00046     protected:
00049         Real mTimePos;
00055         uint mKeyIndex;
00056 
00059         static const uint INVALID_KEY_INDEX = (uint)-1;
00060 
00061     public:
00064         TimeIndex(Real timePos)
00065             : mTimePos(timePos)
00066             , mKeyIndex(INVALID_KEY_INDEX)
00067         {
00068         }
00069 
00075         TimeIndex(Real timePos, uint keyIndex)
00076             : mTimePos(timePos)
00077             , mKeyIndex(keyIndex)
00078         {
00079         }
00080 
00081         bool hasKeyIndex(void) const
00082         {
00083             return mKeyIndex != INVALID_KEY_INDEX;
00084         }
00085 
00086         Real getTimePos(void) const
00087         {
00088             return mTimePos;
00089         }
00090 
00091         uint getKeyIndex(void) const
00092         {
00093             return mKeyIndex;
00094         }
00095     };
00096 
00116     class _OgreExport AnimationTrack : public AnimationAlloc
00117     {
00118     public:
00119 
00123         class _OgreExport Listener
00124         {
00125         public:
00129             virtual bool getInterpolatedKeyFrame(const AnimationTrack* t, const TimeIndex& timeIndex, KeyFrame* kf) = 0;
00130         };
00131 
00133         AnimationTrack(Animation* parent, unsigned short handle);
00134 
00135         virtual ~AnimationTrack();
00136 
00138         unsigned short getHandle(void) const { return mHandle; }
00139 
00141         virtual unsigned short getNumKeyFrames(void) const;
00142 
00144         virtual KeyFrame* getKeyFrame(unsigned short index) const;
00145 
00167         virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
00168             unsigned short* firstKeyIndex = 0) const;
00169 
00177         virtual KeyFrame* createKeyFrame(Real timePos);
00178 
00180         virtual void removeKeyFrame(unsigned short index);
00181 
00183         virtual void removeAllKeyFrames(void);
00184 
00185 
00195         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
00196 
00204         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
00205 
00208         virtual void _keyFrameDataChanged(void) const {}
00209 
00214         virtual bool hasNonZeroKeyFrames(void) const { return true; }
00215 
00217         virtual void optimise(void) {}
00218 
00220         virtual void _collectKeyFrameTimes(std::vector<Real>& keyFrameTimes);
00221 
00224         virtual void _buildKeyFrameIndexMap(const std::vector<Real>& keyFrameTimes);
00225 
00227         virtual void setListener(Listener* l) { mListener = l; }
00228 
00230         Animation *getParent() const { return mParent; }
00231     protected:
00232         typedef std::vector<KeyFrame*> KeyFrameList;
00233         KeyFrameList mKeyFrames;
00234         Animation* mParent;
00235         unsigned short mHandle;
00236         Listener* mListener;
00237 
00239         typedef std::vector<ushort> KeyFrameIndexMap;
00240         KeyFrameIndexMap mKeyFrameIndexMap;
00241 
00243         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
00244 
00246         virtual void populateClone(AnimationTrack* clone) const;
00247         
00248 
00249 
00250     };
00251 
00254     class _OgreExport NumericAnimationTrack : public AnimationTrack
00255     {
00256     public:
00258         NumericAnimationTrack(Animation* parent, unsigned short handle);
00260         NumericAnimationTrack(Animation* parent, unsigned short handle, 
00261             AnimableValuePtr& target);
00262 
00270         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
00271 
00273         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00274 
00276         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00277 
00286         void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex, 
00287             Real weight = 1.0, Real scale = 1.0f);
00288 
00290         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
00291 
00294         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
00295 
00297         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
00298 
00300         NumericAnimationTrack* _clone(Animation* newParent) const;
00301 
00302 
00303     protected:
00305         AnimableValuePtr mTargetAnim;
00306 
00308         KeyFrame* createKeyFrameImpl(Real time);
00309 
00310 
00311     };
00312 
00315     class _OgreExport NodeAnimationTrack : public AnimationTrack
00316     {
00317     public:
00319         NodeAnimationTrack(Animation* parent, unsigned short handle);
00321         NodeAnimationTrack(Animation* parent, unsigned short handle, 
00322             Node* targetNode);
00324         virtual ~NodeAnimationTrack();
00332         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
00334         virtual Node* getAssociatedNode(void) const;
00335 
00337         virtual void setAssociatedNode(Node* node);
00338 
00340         virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0, 
00341             Real scale = 1.0f);
00342 
00344         virtual void setUseShortestRotationPath(bool useShortestPath);
00345 
00347         virtual bool getUseShortestRotationPath() const;
00348 
00350         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00351 
00353         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00354 
00356         void _keyFrameDataChanged(void) const;
00357 
00359         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
00360 
00361 
00366         virtual bool hasNonZeroKeyFrames(void) const;
00367 
00369         virtual void optimise(void);
00370 
00372         NodeAnimationTrack* _clone(Animation* newParent) const;
00373         
00374     protected:
00376         KeyFrame* createKeyFrameImpl(Real time);
00377         // Flag indicating we need to rebuild the splines next time
00378         virtual void buildInterpolationSplines(void) const;
00379 
00380         // Struct for store splines, allocate on demand for better memory footprint
00381         struct Splines
00382         {
00383             SimpleSpline positionSpline;
00384             SimpleSpline scaleSpline;
00385             RotationalSpline rotationSpline;
00386         };
00387 
00388         Node* mTargetNode;
00389         // Prebuilt splines, must be mutable since lazy-update in const method
00390         mutable Splines* mSplines;
00391         mutable bool mSplineBuildNeeded;
00393         mutable bool mUseShortestRotationPath ;
00394     };
00395 
00454     enum VertexAnimationType
00455     {
00457         VAT_NONE = 0,
00459         VAT_MORPH = 1,
00461         VAT_POSE = 2
00462     };
00463 
00467     class _OgreExport VertexAnimationTrack : public AnimationTrack
00468     {
00469     public:
00471         enum TargetMode
00472         {
00474             TM_SOFTWARE, 
00477             TM_HARDWARE
00478         };
00480         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
00482         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType, 
00483             VertexData* targetData, TargetMode target = TM_SOFTWARE);
00484 
00486         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
00487 
00495         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
00496 
00499         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
00500 
00504         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const {}
00505 
00507         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00508 
00511         virtual void applyToVertexData(VertexData* data, 
00512             const TimeIndex& timeIndex, Real weight = 1.0, 
00513             const PoseList* poseList = 0);
00514 
00515 
00517         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
00518 
00520         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
00521 
00523         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
00525         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
00526 
00528         void setTargetMode(TargetMode m) { mTargetMode = m; }
00530         TargetMode getTargetMode(void) const { return mTargetMode; }
00531 
00536         virtual bool hasNonZeroKeyFrames(void) const;
00537 
00539         virtual void optimise(void);
00540 
00542         VertexAnimationTrack* _clone(Animation* newParent) const;
00543 
00544     protected:
00546         VertexAnimationType mAnimationType;
00548         VertexData* mTargetVertexData;
00550         TargetMode mTargetMode;
00551 
00553         KeyFrame* createKeyFrameImpl(Real time);
00554 
00556         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
00557 
00558 
00559     };
00560 
00561 }
00562 
00563 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Aug 28 20:53:45 2008