OGRE: OgreAnimationTrack.h Source File - OGRE Documentation

# 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-2009 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 __AnimationTrack_H__
    00030 #define __AnimationTrack_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreSimpleSpline.h"
    00034 #include "OgreRotationalSpline.h"
    00035 #include "OgreKeyFrame.h"
    00036 #include "OgreAnimable.h"
    00037 #include "OgrePose.h"
    00038
    00039 namespace Ogre
    00040 {
    00049     class _OgreExport TimeIndex
    00050     {
    00051     protected:
    00054         Real mTimePos;
    00060         uint mKeyIndex;
    00061
    00064         static const uint INVALID_KEY_INDEX = (uint)-1;
    00065
    00066     public:
    00069         TimeIndex(Real timePos)
    00070             : mTimePos(timePos)
    00071             , mKeyIndex(INVALID_KEY_INDEX)
    00072         {
    00073         }
    00074
    00080         TimeIndex(Real timePos, uint keyIndex)
    00081             : mTimePos(timePos)
    00082             , mKeyIndex(keyIndex)
    00083         {
    00084         }
    00085
    00086         bool hasKeyIndex(void) const
    00087         {
    00088             return mKeyIndex != INVALID_KEY_INDEX;
    00089         }
    00090
    00091         Real getTimePos(void) const
    00092         {
    00093             return mTimePos;
    00094         }
    00095
    00096         uint getKeyIndex(void) const
    00097         {
    00098             return mKeyIndex;
    00099         }
    00100     };
    00101
    00121     class _OgreExport AnimationTrack : public AnimationAlloc
    00122     {
    00123     public:
    00124
    00128         class _OgreExport Listener
    00129         {
    00130         public:
    00131             virtual ~Listener() {}
    00132
    00136             virtual bool getInterpolatedKeyFrame(const AnimationTrack* t, const TimeIndex& timeIndex, KeyFrame* kf) = 0;
    00137         };
    00138
    00140         AnimationTrack(Animation* parent, unsigned short handle);
    00141
    00142         virtual ~AnimationTrack();
    00143
    00145         unsigned short getHandle(void) const { return mHandle; }
    00146
    00148         virtual unsigned short getNumKeyFrames(void) const;
    00149
    00151         virtual KeyFrame* getKeyFrame(unsigned short index) const;
    00152
    00174         virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
    00175             unsigned short* firstKeyIndex = 0) const;
    00176
    00184         virtual KeyFrame* createKeyFrame(Real timePos);
    00185
    00187         virtual void removeKeyFrame(unsigned short index);
    00188
    00190         virtual void removeAllKeyFrames(void);
    00191
    00192
    00202         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
    00203
    00211         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
    00212
    00215         virtual void _keyFrameDataChanged(void) const {}
    00216
    00221         virtual bool hasNonZeroKeyFrames(void) const { return true; }
    00222
    00224         virtual void optimise(void) {}
    00225
    00227         virtual void _collectKeyFrameTimes(vector<Real>::type& keyFrameTimes);
    00228
    00231         virtual void _buildKeyFrameIndexMap(const vector<Real>::type& keyFrameTimes);
    00232
    00234         virtual void setListener(Listener* l) { mListener = l; }
    00235
    00237         Animation *getParent() const { return mParent; }
    00238     protected:
    00239         typedef vector<KeyFrame*>::type KeyFrameList;
    00240         KeyFrameList mKeyFrames;
    00241         Animation* mParent;
    00242         unsigned short mHandle;
    00243         Listener* mListener;
    00244
    00246         typedef vector<ushort>::type KeyFrameIndexMap;
    00247         KeyFrameIndexMap mKeyFrameIndexMap;
    00248
    00250         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
    00251
    00253         virtual void populateClone(AnimationTrack* clone) const;
    00254
    00255
    00256
    00257     };
    00258
    00261     class _OgreExport NumericAnimationTrack : public AnimationTrack
    00262     {
    00263     public:
    00265         NumericAnimationTrack(Animation* parent, unsigned short handle);
    00267         NumericAnimationTrack(Animation* parent, unsigned short handle,
    00268             AnimableValuePtr& target);
    00269
    00277         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
    00278
    00280         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
    00281
    00283         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
    00284
    00293         void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex,
    00294             Real weight = 1.0, Real scale = 1.0f);
    00295
    00297         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
    00298
    00301         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
    00302
    00304         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
    00305
    00307         NumericAnimationTrack* _clone(Animation* newParent) const;
    00308
    00309
    00310     protected:
    00312         AnimableValuePtr mTargetAnim;
    00313
    00315         KeyFrame* createKeyFrameImpl(Real time);
    00316
    00317
    00318     };
    00319
    00322     class _OgreExport NodeAnimationTrack : public AnimationTrack
    00323     {
    00324     public:
    00326         NodeAnimationTrack(Animation* parent, unsigned short handle);
    00328         NodeAnimationTrack(Animation* parent, unsigned short handle,
    00329             Node* targetNode);
    00331         virtual ~NodeAnimationTrack();
    00339         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
    00341         virtual Node* getAssociatedNode(void) const;
    00342
    00344         virtual void setAssociatedNode(Node* node);
    00345
    00347         virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0,
    00348             Real scale = 1.0f);
    00349
    00351         virtual void setUseShortestRotationPath(bool useShortestPath);
    00352
    00354         virtual bool getUseShortestRotationPath() const;
    00355
    00357         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
    00358
    00360         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
    00361
    00363         void _keyFrameDataChanged(void) const;
    00364
    00366         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
    00367
    00368
    00373         virtual bool hasNonZeroKeyFrames(void) const;
    00374
    00376         virtual void optimise(void);
    00377
    00379         NodeAnimationTrack* _clone(Animation* newParent) const;
    00380
    00381     protected:
    00383         KeyFrame* createKeyFrameImpl(Real time);
    00384         // Flag indicating we need to rebuild the splines next time
    00385         virtual void buildInterpolationSplines(void) const;
    00386
    00387         // Struct for store splines, allocate on demand for better memory footprint
    00388         struct Splines
    00389         {
    00390             SimpleSpline positionSpline;
    00391             SimpleSpline scaleSpline;
    00392             RotationalSpline rotationSpline;
    00393         };
    00394
    00395         Node* mTargetNode;
    00396         // Prebuilt splines, must be mutable since lazy-update in const method
    00397         mutable Splines* mSplines;
    00398         mutable bool mSplineBuildNeeded;
    00400         mutable bool mUseShortestRotationPath ;
    00401     };
    00402
    00461     enum VertexAnimationType
    00462     {
    00464         VAT_NONE = 0,
    00466         VAT_MORPH = 1,
    00468         VAT_POSE = 2
    00469     };
    00470
    00474     class _OgreExport VertexAnimationTrack : public AnimationTrack
    00475     {
    00476     public:
    00478         enum TargetMode
    00479         {
    00481             TM_SOFTWARE,
    00484             TM_HARDWARE
    00485         };
    00487         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
    00489         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType,
    00490             VertexData* targetData, TargetMode target = TM_SOFTWARE);
    00491
    00493         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
    00494
    00502         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
    00503
    00506         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
    00507
    00511         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const
    00512         { (void)timeIndex; (void)kf; }
    00513
    00515         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
    00516
    00519         virtual void applyToVertexData(VertexData* data,
    00520             const TimeIndex& timeIndex, Real weight = 1.0,
    00521             const PoseList* poseList = 0);
    00522
    00523
    00525         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
    00526
    00528         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
    00529
    00531         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
    00533         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
    00534
    00536         void setTargetMode(TargetMode m) { mTargetMode = m; }
    00538         TargetMode getTargetMode(void) const { return mTargetMode; }
    00539
    00544         virtual bool hasNonZeroKeyFrames(void) const;
    00545
    00547         virtual void optimise(void);
    00548
    00550         VertexAnimationTrack* _clone(Animation* newParent) const;
    00551
    00552     protected:
    00554         VertexAnimationType mAnimationType;
    00556         VertexData* mTargetVertexData;
    00558         TargetMode mTargetMode;
    00559
    00561         KeyFrame* createKeyFrameImpl(Real time);
    00562
    00564         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
    00565
    00566
    00567     };
    00570 }
    00571
    00572 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51