Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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
00117     {
00118     public:
00120         AnimationTrack(Animation* parent, unsigned short handle);
00121 
00122         virtual ~AnimationTrack();
00123 
00125         unsigned short getHandle(void) const { return mHandle; }
00126 
00128         virtual unsigned short getNumKeyFrames(void) const;
00129 
00131         virtual KeyFrame* getKeyFrame(unsigned short index) const;
00132 
00154         virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
00155             unsigned short* firstKeyIndex = 0) const;
00156 
00164         virtual KeyFrame* createKeyFrame(Real timePos);
00165 
00167         virtual void removeKeyFrame(unsigned short index);
00168 
00170         virtual void removeAllKeyFrames(void);
00171 
00172 
00182         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
00183 
00191         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
00192 
00195         virtual void _keyFrameDataChanged(void) const {}
00196 
00201         virtual bool hasNonZeroKeyFrames(void) const { return true; }
00202 
00204         virtual void optimise(void) {}
00205 
00207         virtual void _collectKeyFrameTimes(std::vector<Real>& keyFrameTimes);
00208 
00211         virtual void _buildKeyFrameIndexMap(const std::vector<Real>& keyFrameTimes);
00212 
00213     protected:
00214         typedef std::vector<KeyFrame*> KeyFrameList;
00215         KeyFrameList mKeyFrames;
00216         Animation* mParent;
00217         unsigned short mHandle;
00218 
00220         typedef std::vector<ushort> KeyFrameIndexMap;
00221         KeyFrameIndexMap mKeyFrameIndexMap;
00222 
00224         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
00225 
00227         virtual void populateClone(AnimationTrack* clone) const;
00228         
00229 
00230 
00231     };
00232 
00235     class _OgreExport NumericAnimationTrack : public AnimationTrack
00236     {
00237     public:
00239         NumericAnimationTrack(Animation* parent, unsigned short handle);
00241         NumericAnimationTrack(Animation* parent, unsigned short handle, 
00242             AnimableValuePtr& target);
00243 
00251         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
00252 
00254         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00255 
00257         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00258 
00267         void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex, 
00268             Real weight = 1.0, Real scale = 1.0f);
00269 
00271         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
00272 
00275         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
00276 
00278         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
00279 
00281         NumericAnimationTrack* _clone(Animation* newParent) const;
00282 
00283 
00284     protected:
00286         AnimableValuePtr mTargetAnim;
00287 
00289         KeyFrame* createKeyFrameImpl(Real time);
00290 
00291 
00292     };
00293 
00296     class _OgreExport NodeAnimationTrack : public AnimationTrack
00297     {
00298     public:
00300         NodeAnimationTrack(Animation* parent, unsigned short handle);
00302         NodeAnimationTrack(Animation* parent, unsigned short handle, 
00303             Node* targetNode);
00305         virtual ~NodeAnimationTrack();
00313         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
00315         virtual Node* getAssociatedNode(void) const;
00316 
00318         virtual void setAssociatedNode(Node* node);
00319 
00321         virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0, 
00322             Real scale = 1.0f);
00323 
00325         virtual void setUseShortestRotationPath(bool useShortestPath);
00326 
00328         virtual bool getUseShortestRotationPath() const;
00329 
00331         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00332 
00334         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00335 
00337         void _keyFrameDataChanged(void) const;
00338 
00340         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
00341 
00342 
00347         virtual bool hasNonZeroKeyFrames(void) const;
00348 
00350         virtual void optimise(void);
00351 
00353         NodeAnimationTrack* _clone(Animation* newParent) const;
00354         
00355     protected:
00357         KeyFrame* createKeyFrameImpl(Real time);
00358         // Flag indicating we need to rebuild the splines next time
00359         virtual void buildInterpolationSplines(void) const;
00360 
00361         // Struct for store splines, allocate on demand for better memory footprint
00362         struct Splines
00363         {
00364             SimpleSpline positionSpline;
00365             SimpleSpline scaleSpline;
00366             RotationalSpline rotationSpline;
00367         };
00368 
00369         Node* mTargetNode;
00370         // Prebuilt splines, must be mutable since lazy-update in const method
00371         mutable Splines* mSplines;
00372         mutable bool mSplineBuildNeeded;
00374         mutable bool mUseShortestRotationPath ;
00375 
00376 
00377     };
00378 
00437     enum VertexAnimationType
00438     {
00440         VAT_NONE = 0,
00442         VAT_MORPH = 1,
00444         VAT_POSE = 2
00445     };
00446 
00450     class _OgreExport VertexAnimationTrack : public AnimationTrack
00451     {
00452     public:
00454         enum TargetMode
00455         {
00457             TM_SOFTWARE, 
00460             TM_HARDWARE
00461         };
00463         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
00465         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType, 
00466             VertexData* targetData, TargetMode target = TM_SOFTWARE);
00467 
00469         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
00470 
00478         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
00479 
00482         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
00483 
00487         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const {}
00488 
00490         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00491 
00494         virtual void applyToVertexData(VertexData* data, 
00495             const TimeIndex& timeIndex, Real weight = 1.0, 
00496             const PoseList* poseList = 0);
00497 
00498 
00500         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
00501 
00503         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
00504 
00506         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
00508         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
00509 
00511         void setTargetMode(TargetMode m) { mTargetMode = m; }
00513         TargetMode getTargetMode(void) const { return mTargetMode; }
00514 
00519         virtual bool hasNonZeroKeyFrames(void) const;
00520 
00522         virtual void optimise(void);
00523 
00525         VertexAnimationTrack* _clone(Animation* newParent) const;
00526 
00527     protected:
00529         VertexAnimationType mAnimationType;
00531         VertexData* mTargetVertexData;
00533         TargetMode mTargetMode;
00534 
00536         KeyFrame* createKeyFrameImpl(Real time);
00537 
00539         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
00540 
00541 
00542     };
00543 
00544 
00545 }
00546 
00547 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun May 6 10:54:20 2007