# 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-2005 The OGRE Team
    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 */
    00025
    00026 #ifndef __AnimationTrack_H__
    00027 #define __AnimationTrack_H__
    00028
    00029 #include "OgrePrerequisites.h"
    00030 #include "OgreSimpleSpline.h"
    00031 #include "OgreRotationalSpline.h"
    00032 #include "OgreKeyFrame.h"
    00033 #include "OgreAnimable.h"
    00034 #include "OgrePose.h"
    00035
    00036 namespace Ogre
    00037 {
    00057     class _OgreExport AnimationTrack
    00058     {
    00059     public:
    00061         AnimationTrack(Animation* parent, unsigned short handle);
    00062
    00063         virtual ~AnimationTrack();
    00064
    00066         unsigned short getHandle(void) const { return mHandle; }
    00067
    00069         virtual unsigned short getNumKeyFrames(void) const;
    00070
    00072         virtual KeyFrame* getKeyFrame(unsigned short index) const;
    00073
    00095         virtual Real getKeyFramesAtTime(Real timePos, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
    00096             unsigned short* firstKeyIndex = 0) const;
    00097
    00105         virtual KeyFrame* createKeyFrame(Real timePos);
    00106
    00108         virtual void removeKeyFrame(unsigned short index);
    00109
    00111         virtual void removeAllKeyFrames(void);
    00112
    00113
    00123         virtual void getInterpolatedKeyFrame(Real timeIndex, KeyFrame* kf) const = 0;
    00124
    00134         virtual void apply(Real timePos, Real weight = 1.0, bool accumulate = false,
    00135             Real scale = 1.0f) = 0;
    00136
    00139         virtual void _keyFrameDataChanged(void) const {}
    00140
    00145         virtual bool hasNonZeroKeyFrames(void) const { return true; }
    00146
    00148         virtual void optimise(void) {}
    00149
    00150     protected:
    00151         typedef std::vector<KeyFrame*> KeyFrameList;
    00152         KeyFrameList mKeyFrames;
    00153         Animation* mParent;
    00154         unsigned short mHandle;
    00155
    00157         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
    00158
    00160         virtual void populateClone(AnimationTrack* clone) const;
    00161
    00162
    00163
    00164     };
    00165
    00168     class _OgreExport NumericAnimationTrack : public AnimationTrack
    00169     {
    00170     public:
    00172         NumericAnimationTrack(Animation* parent, unsigned short handle);
    00174         NumericAnimationTrack(Animation* parent, unsigned short handle,
    00175             AnimableValuePtr& target);
    00176
    00184         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
    00185
    00187         void getInterpolatedKeyFrame(Real timeIndex, KeyFrame* kf) const;
    00188
    00190         void apply(Real timePos, Real weight = 1.0, bool accumulate = false,
    00191             Real scale = 1.0f);
    00192
    00201         void applyToAnimable(const AnimableValuePtr& anim, Real timePos,
    00202             Real weight = 1.0, Real scale = 1.0f);
    00203
    00205         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
    00206
    00209         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
    00210
    00212         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
    00213
    00215         NumericAnimationTrack* _clone(Animation* newParent) const;
    00216
    00217
    00218     protected:
    00220         AnimableValuePtr mTargetAnim;
    00221
    00223         KeyFrame* createKeyFrameImpl(Real time);
    00224
    00225
    00226     };
    00227
    00230     class _OgreExport NodeAnimationTrack : public AnimationTrack
    00231     {
    00232     public:
    00234         NodeAnimationTrack(Animation* parent, unsigned short handle);
    00236         NodeAnimationTrack(Animation* parent, unsigned short handle,
    00237             Node* targetNode);
    00245         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
    00247         virtual Node* getAssociatedNode(void) const;
    00248
    00250         virtual void setAssociatedNode(Node* node);
    00251
    00253         virtual void applyToNode(Node* node, Real timePos, Real weight = 1.0,
    00254             bool accumulate = false, Real scale = 1.0f);
    00255
    00257         virtual void setUseShortestRotationPath(bool useShortestPath);
    00258
    00260         virtual bool getUseShortestRotationPath() const;
    00261
    00263         void getInterpolatedKeyFrame(Real timeIndex, KeyFrame* kf) const;
    00264
    00266         void apply(Real timePos, Real weight = 1.0, bool accumulate = false,
    00267             Real scale = 1.0f);
    00268
    00270         void _keyFrameDataChanged(void) const;
    00271
    00273         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
    00274
    00275
    00280         virtual bool hasNonZeroKeyFrames(void) const;
    00281
    00283         virtual void optimise(void);
    00284
    00286         NodeAnimationTrack* _clone(Animation* newParent) const;
    00287
    00288     protected:
    00290         KeyFrame* createKeyFrameImpl(Real time);
    00291         // Flag indicating we need to rebuild the splines next time
    00292         virtual void buildInterpolationSplines(void) const;
    00293
    00294         Node* mTargetNode;
    00295         // Prebuilt splines, must be mutable since lazy-update in const method
    00296         mutable bool mSplineBuildNeeded;
    00297         mutable SimpleSpline mPositionSpline;
    00298         mutable SimpleSpline mScaleSpline;
    00299         mutable RotationalSpline mRotationSpline;
    00301         mutable bool mUseShortestRotationPath ;
    00302
    00303
    00304     };
    00305
    00364     enum VertexAnimationType
    00365     {
    00367         VAT_NONE = 0,
    00369         VAT_MORPH = 1,
    00371         VAT_POSE = 2
    00372     };
    00373
    00377     class _OgreExport VertexAnimationTrack : public AnimationTrack
    00378     {
    00379     public:
    00381         enum TargetMode
    00382         {
    00384             TM_SOFTWARE,
    00387             TM_HARDWARE
    00388         };
    00390         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
    00392         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType,
    00393             VertexData* targetData, TargetMode target = TM_SOFTWARE);
    00394
    00396         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
    00397
    00405         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
    00406
    00409         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
    00410
    00414         void getInterpolatedKeyFrame(Real timeIndex, KeyFrame* kf) const {}
    00415
    00417         void apply(Real timePos, Real weight = 1.0, bool accumulate = false,
    00418             Real scale = 1.0f);
    00419
    00422         virtual void applyToVertexData(VertexData* data,
    00423             Real timePos, Real weight = 1.0,
    00424             const PoseList* poseList = 0);
    00425
    00426
    00428         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
    00429
    00431         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
    00432
    00434         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
    00436         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
    00437
    00439         void setTargetMode(TargetMode m) { mTargetMode = m; }
    00441         TargetMode getTargetMode(void) const { return mTargetMode; }
    00442
    00447         virtual bool hasNonZeroKeyFrames(void) const;
    00448
    00450         virtual void optimise(void);
    00451
    00453         VertexAnimationTrack* _clone(Animation* newParent) const;
    00454
    00455     protected:
    00457         VertexAnimationType mAnimationType;
    00459         VertexData* mTargetVertexData;
    00461         TargetMode mTargetMode;
    00462
    00464         KeyFrame* createKeyFrameImpl(Real time);
    00465
    00467         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
    00468
    00469
    00470     };
    00471
    00472
    00473 }
    00474
    00475 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 17 15:39:07 2006