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 
00166         virtual KeyFrame* createKeyFrame(Real timePos);
00167 
00169         virtual void removeKeyFrame(unsigned short index);
00170 
00172         virtual void removeAllKeyFrames(void);
00173 
00174 
00184         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
00185 
00193         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
00194 
00197         virtual void _keyFrameDataChanged(void) const {}
00198 
00203         virtual bool hasNonZeroKeyFrames(void) const { return true; }
00204 
00206         virtual void optimise(void) {}
00207 
00209         virtual void _collectKeyFrameTimes(std::vector<Real>& keyFrameTimes);
00210 
00213         virtual void _buildKeyFrameIndexMap(const std::vector<Real>& keyFrameTimes);
00214 
00215     protected:
00216         typedef std::vector<KeyFrame*> KeyFrameList;
00217         KeyFrameList mKeyFrames;
00218         Animation* mParent;
00219         unsigned short mHandle;
00220 
00222         typedef std::vector<ushort> KeyFrameIndexMap;
00223         KeyFrameIndexMap mKeyFrameIndexMap;
00224 
00226         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
00227 
00229         virtual void populateClone(AnimationTrack* clone) const;
00230         
00231 
00232 
00233     };
00234 
00237     class _OgreExport NumericAnimationTrack : public AnimationTrack
00238     {
00239     public:
00241         NumericAnimationTrack(Animation* parent, unsigned short handle);
00243         NumericAnimationTrack(Animation* parent, unsigned short handle, 
00244             AnimableValuePtr& target);
00245 
00253         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
00254 
00256         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00257 
00259         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00260 
00269         void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex, 
00270             Real weight = 1.0, Real scale = 1.0f);
00271 
00273         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
00274 
00277         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
00278 
00280         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
00281 
00283         NumericAnimationTrack* _clone(Animation* newParent) const;
00284 
00285 
00286     protected:
00288         AnimableValuePtr mTargetAnim;
00289 
00291         KeyFrame* createKeyFrameImpl(Real time);
00292 
00293 
00294     };
00295 
00298     class _OgreExport NodeAnimationTrack : public AnimationTrack
00299     {
00300     public:
00302         NodeAnimationTrack(Animation* parent, unsigned short handle);
00304         NodeAnimationTrack(Animation* parent, unsigned short handle, 
00305             Node* targetNode);
00307         virtual ~NodeAnimationTrack();
00315         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
00317         virtual Node* getAssociatedNode(void) const;
00318 
00320         virtual void setAssociatedNode(Node* node);
00321 
00323         virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0, 
00324             Real scale = 1.0f);
00325 
00327         virtual void setUseShortestRotationPath(bool useShortestPath);
00328 
00330         virtual bool getUseShortestRotationPath() const;
00331 
00333         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00334 
00336         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00337 
00339         void _keyFrameDataChanged(void) const;
00340 
00342         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
00343 
00344 
00349         virtual bool hasNonZeroKeyFrames(void) const;
00350 
00352         virtual void optimise(void);
00353 
00355         NodeAnimationTrack* _clone(Animation* newParent) const;
00356         
00357     protected:
00359         KeyFrame* createKeyFrameImpl(Real time);
00360         // Flag indicating we need to rebuild the splines next time
00361         virtual void buildInterpolationSplines(void) const;
00362 
00363         // Struct for store splines, allocate on demand for better memory footprint
00364         struct Splines
00365         {
00366             SimpleSpline positionSpline;
00367             SimpleSpline scaleSpline;
00368             RotationalSpline rotationSpline;
00369         };
00370 
00371         Node* mTargetNode;
00372         // Prebuilt splines, must be mutable since lazy-update in const method
00373         mutable Splines* mSplines;
00374         mutable bool mSplineBuildNeeded;
00376         mutable bool mUseShortestRotationPath ;
00377 
00378 
00379     };
00380 
00439     enum VertexAnimationType
00440     {
00442         VAT_NONE = 0,
00444         VAT_MORPH = 1,
00446         VAT_POSE = 2
00447     };
00448 
00452     class _OgreExport VertexAnimationTrack : public AnimationTrack
00453     {
00454     public:
00456         enum TargetMode
00457         {
00459             TM_SOFTWARE, 
00462             TM_HARDWARE
00463         };
00465         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
00467         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType, 
00468             VertexData* targetData, TargetMode target = TM_SOFTWARE);
00469 
00471         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
00472 
00480         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
00481 
00484         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
00485 
00489         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const {}
00490 
00492         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00493 
00496         virtual void applyToVertexData(VertexData* data, 
00497             const TimeIndex& timeIndex, Real weight = 1.0, 
00498             const PoseList* poseList = 0);
00499 
00500 
00502         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
00503 
00505         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
00506 
00508         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
00510         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
00511 
00513         void setTargetMode(TargetMode m) { mTargetMode = m; }
00515         TargetMode getTargetMode(void) const { return mTargetMode; }
00516 
00521         virtual bool hasNonZeroKeyFrames(void) const;
00522 
00524         virtual void optimise(void);
00525 
00527         VertexAnimationTrack* _clone(Animation* newParent) const;
00528 
00529     protected:
00531         VertexAnimationType mAnimationType;
00533         VertexData* mTargetVertexData;
00535         TargetMode mTargetMode;
00536 
00538         KeyFrame* createKeyFrameImpl(Real time);
00539 
00541         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
00542 
00543 
00544     };
00545 
00546 
00547 }
00548 
00549 #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 Sat May 10 16:24:56 2008