# 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:
    00126             virtual ~Listener() {}
    00127
    00131             virtual bool getInterpolatedKeyFrame(const AnimationTrack* t, const TimeIndex& timeIndex, KeyFrame* kf) = 0;
    00132         };
    00133
    00135         AnimationTrack(Animation* parent, unsigned short handle);
    00136
    00137         virtual ~AnimationTrack();
    00138
    00140         unsigned short getHandle(void) const { return mHandle; }
    00141
    00143         virtual unsigned short getNumKeyFrames(void) const;
    00144
    00146         virtual KeyFrame* getKeyFrame(unsigned short index) const;
    00147
    00169         virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
    00170             unsigned short* firstKeyIndex = 0) const;
    00171
    00179         virtual KeyFrame* createKeyFrame(Real timePos);
    00180
    00182         virtual void removeKeyFrame(unsigned short index);
    00183
    00185         virtual void removeAllKeyFrames(void);
    00186
    00187
    00197         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
    00198
    00206         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
    00207
    00210         virtual void _keyFrameDataChanged(void) const {}
    00211
    00216         virtual bool hasNonZeroKeyFrames(void) const { return true; }
    00217
    00219         virtual void optimise(void) {}
    00220
    00222         virtual void _collectKeyFrameTimes(std::vector<Real>& keyFrameTimes);
    00223
    00226         virtual void _buildKeyFrameIndexMap(const std::vector<Real>& keyFrameTimes);
    00227
    00229         virtual void setListener(Listener* l) { mListener = l; }
    00230
    00232         Animation *getParent() const { return mParent; }
    00233     protected:
    00234         typedef std::vector<KeyFrame*> KeyFrameList;
    00235         KeyFrameList mKeyFrames;
    00236         Animation* mParent;
    00237         unsigned short mHandle;
    00238         Listener* mListener;
    00239
    00241         typedef std::vector<ushort> KeyFrameIndexMap;
    00242         KeyFrameIndexMap mKeyFrameIndexMap;
    00243
    00245         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
    00246
    00248         virtual void populateClone(AnimationTrack* clone) const;
    00249
    00250
    00251
    00252     };
    00253
    00256     class _OgreExport NumericAnimationTrack : public AnimationTrack
    00257     {
    00258     public:
    00260         NumericAnimationTrack(Animation* parent, unsigned short handle);
    00262         NumericAnimationTrack(Animation* parent, unsigned short handle,
    00263             AnimableValuePtr& target);
    00264
    00272         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
    00273
    00275         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
    00276
    00278         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
    00279
    00288         void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex,
    00289             Real weight = 1.0, Real scale = 1.0f);
    00290
    00292         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
    00293
    00296         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
    00297
    00299         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
    00300
    00302         NumericAnimationTrack* _clone(Animation* newParent) const;
    00303
    00304
    00305     protected:
    00307         AnimableValuePtr mTargetAnim;
    00308
    00310         KeyFrame* createKeyFrameImpl(Real time);
    00311
    00312
    00313     };
    00314
    00317     class _OgreExport NodeAnimationTrack : public AnimationTrack
    00318     {
    00319     public:
    00321         NodeAnimationTrack(Animation* parent, unsigned short handle);
    00323         NodeAnimationTrack(Animation* parent, unsigned short handle,
    00324             Node* targetNode);
    00326         virtual ~NodeAnimationTrack();
    00334         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
    00336         virtual Node* getAssociatedNode(void) const;
    00337
    00339         virtual void setAssociatedNode(Node* node);
    00340
    00342         virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0,
    00343             Real scale = 1.0f);
    00344
    00346         virtual void setUseShortestRotationPath(bool useShortestPath);
    00347
    00349         virtual bool getUseShortestRotationPath() const;
    00350
    00352         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
    00353
    00355         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
    00356
    00358         void _keyFrameDataChanged(void) const;
    00359
    00361         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
    00362
    00363
    00368         virtual bool hasNonZeroKeyFrames(void) const;
    00369
    00371         virtual void optimise(void);
    00372
    00374         NodeAnimationTrack* _clone(Animation* newParent) const;
    00375
    00376     protected:
    00378         KeyFrame* createKeyFrameImpl(Real time);
    00379         // Flag indicating we need to rebuild the splines next time
    00380         virtual void buildInterpolationSplines(void) const;
    00381
    00382         // Struct for store splines, allocate on demand for better memory footprint
    00383         struct Splines
    00384         {
    00385             SimpleSpline positionSpline;
    00386             SimpleSpline scaleSpline;
    00387             RotationalSpline rotationSpline;
    00388         };
    00389
    00390         Node* mTargetNode;
    00391         // Prebuilt splines, must be mutable since lazy-update in const method
    00392         mutable Splines* mSplines;
    00393         mutable bool mSplineBuildNeeded;
    00395         mutable bool mUseShortestRotationPath ;
    00396     };
    00397
    00456     enum VertexAnimationType
    00457     {
    00459         VAT_NONE = 0,
    00461         VAT_MORPH = 1,
    00463         VAT_POSE = 2
    00464     };
    00465
    00469     class _OgreExport VertexAnimationTrack : public AnimationTrack
    00470     {
    00471     public:
    00473         enum TargetMode
    00474         {
    00476             TM_SOFTWARE,
    00479             TM_HARDWARE
    00480         };
    00482         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
    00484         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType,
    00485             VertexData* targetData, TargetMode target = TM_SOFTWARE);
    00486
    00488         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
    00489
    00497         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
    00498
    00501         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
    00502
    00506         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const {}
    00507
    00509         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
    00510
    00513         virtual void applyToVertexData(VertexData* data,
    00514             const TimeIndex& timeIndex, Real weight = 1.0,
    00515             const PoseList* poseList = 0);
    00516
    00517
    00519         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
    00520
    00522         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
    00523
    00525         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
    00527         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
    00528
    00530         void setTargetMode(TargetMode m) { mTargetMode = m; }
    00532         TargetMode getTargetMode(void) const { return mTargetMode; }
    00533
    00538         virtual bool hasNonZeroKeyFrames(void) const;
    00539
    00541         virtual void optimise(void);
    00542
    00544         VertexAnimationTrack* _clone(Animation* newParent) const;
    00545
    00546     protected:
    00548         VertexAnimationType mAnimationType;
    00550         VertexData* mTargetVertexData;
    00552         TargetMode mTargetMode;
    00553
    00555         KeyFrame* createKeyFrameImpl(Real time);
    00556
    00558         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
    00559
    00560
    00561     };
    00562
    00563 }
    00564
    00565 #endif

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