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-2013 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 #include "OgreHeaderPrefix.h"
00039 
00040 namespace Ogre 
00041 {
00050     class _OgreExport TimeIndex
00051     {
00052     protected:
00055         Real mTimePos;
00061         uint mKeyIndex;
00062 
00065         static const uint INVALID_KEY_INDEX = (uint)-1;
00066 
00067     public:
00070         TimeIndex(Real timePos)
00071             : mTimePos(timePos)
00072             , mKeyIndex(INVALID_KEY_INDEX)
00073         {
00074         }
00075 
00081         TimeIndex(Real timePos, uint keyIndex)
00082             : mTimePos(timePos)
00083             , mKeyIndex(keyIndex)
00084         {
00085         }
00086 
00087         bool hasKeyIndex(void) const
00088         {
00089             return mKeyIndex != INVALID_KEY_INDEX;
00090         }
00091 
00092         Real getTimePos(void) const
00093         {
00094             return mTimePos;
00095         }
00096 
00097         uint getKeyIndex(void) const
00098         {
00099             return mKeyIndex;
00100         }
00101     };
00102 
00122     class _OgreExport AnimationTrack : public AnimationAlloc
00123     {
00124     public:
00125 
00129         class _OgreExport Listener
00130         {
00131         public:
00132             virtual ~Listener() {}
00133 
00137             virtual bool getInterpolatedKeyFrame(const AnimationTrack* t, const TimeIndex& timeIndex, KeyFrame* kf) = 0;
00138         };
00139 
00141         AnimationTrack(Animation* parent, unsigned short handle);
00142 
00143         virtual ~AnimationTrack();
00144 
00146         unsigned short getHandle(void) const { return mHandle; }
00147 
00149         virtual unsigned short getNumKeyFrames(void) const;
00150 
00152         virtual KeyFrame* getKeyFrame(unsigned short index) const;
00153 
00175         virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
00176             unsigned short* firstKeyIndex = 0) const;
00177 
00185         virtual KeyFrame* createKeyFrame(Real timePos);
00186 
00188         virtual void removeKeyFrame(unsigned short index);
00189 
00191         virtual void removeAllKeyFrames(void);
00192 
00193 
00203         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
00204 
00212         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
00213 
00216         virtual void _keyFrameDataChanged(void) const {}
00217 
00222         virtual bool hasNonZeroKeyFrames(void) const { return true; }
00223 
00225         virtual void optimise(void) {}
00226 
00228         virtual void _collectKeyFrameTimes(vector<Real>::type& keyFrameTimes);
00229 
00232         virtual void _buildKeyFrameIndexMap(const vector<Real>::type& keyFrameTimes);
00233         
00235         virtual void _applyBaseKeyFrame(const KeyFrame* base) {}
00236 
00238         virtual void setListener(Listener* l) { mListener = l; }
00239 
00241         Animation *getParent() const { return mParent; }
00242     protected:
00243         typedef vector<KeyFrame*>::type KeyFrameList;
00244         KeyFrameList mKeyFrames;
00245         Animation* mParent;
00246         unsigned short mHandle;
00247         Listener* mListener;
00248 
00250         typedef vector<ushort>::type KeyFrameIndexMap;
00251         KeyFrameIndexMap mKeyFrameIndexMap;
00252 
00254         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
00255 
00257         virtual void populateClone(AnimationTrack* clone) const;
00258         
00259 
00260 
00261     };
00262 
00265     class _OgreExport NumericAnimationTrack : public AnimationTrack
00266     {
00267     public:
00269         NumericAnimationTrack(Animation* parent, unsigned short handle);
00271         NumericAnimationTrack(Animation* parent, unsigned short handle, 
00272             AnimableValuePtr& target);
00273 
00281         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
00282 
00284         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00285 
00287         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00288 
00297         void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex, 
00298             Real weight = 1.0, Real scale = 1.0f);
00299 
00301         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
00302 
00305         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
00306 
00308         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
00309 
00311         NumericAnimationTrack* _clone(Animation* newParent) const;
00312 
00313 
00314     protected:
00316         AnimableValuePtr mTargetAnim;
00317 
00319         KeyFrame* createKeyFrameImpl(Real time);
00320 
00321 
00322     };
00323 
00326     class _OgreExport NodeAnimationTrack : public AnimationTrack
00327     {
00328     public:
00330         NodeAnimationTrack(Animation* parent, unsigned short handle);
00332         NodeAnimationTrack(Animation* parent, unsigned short handle, 
00333             Node* targetNode);
00335         virtual ~NodeAnimationTrack();
00343         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
00345         virtual Node* getAssociatedNode(void) const;
00346 
00348         virtual void setAssociatedNode(Node* node);
00349 
00351         virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0, 
00352             Real scale = 1.0f);
00353 
00355         virtual void setUseShortestRotationPath(bool useShortestPath);
00356 
00358         virtual bool getUseShortestRotationPath() const;
00359 
00361         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00362 
00364         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00365 
00367         void _keyFrameDataChanged(void) const;
00368 
00370         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
00371 
00372 
00377         virtual bool hasNonZeroKeyFrames(void) const;
00378 
00380         virtual void optimise(void);
00381 
00383         NodeAnimationTrack* _clone(Animation* newParent) const;
00384         
00385         void _applyBaseKeyFrame(const KeyFrame* base);
00386         
00387     protected:
00389         KeyFrame* createKeyFrameImpl(Real time);
00390         // Flag indicating we need to rebuild the splines next time
00391         virtual void buildInterpolationSplines(void) const;
00392 
00393         // Struct for store splines, allocate on demand for better memory footprint
00394         struct Splines
00395         {
00396             SimpleSpline positionSpline;
00397             SimpleSpline scaleSpline;
00398             RotationalSpline rotationSpline;
00399         };
00400 
00401         Node* mTargetNode;
00402         // Prebuilt splines, must be mutable since lazy-update in const method
00403         mutable Splines* mSplines;
00404         mutable bool mSplineBuildNeeded;
00406         mutable bool mUseShortestRotationPath ;
00407     };
00408 
00467     enum VertexAnimationType
00468     {
00470         VAT_NONE = 0,
00472         VAT_MORPH = 1,
00474         VAT_POSE = 2
00475     };
00476 
00480     class _OgreExport VertexAnimationTrack : public AnimationTrack
00481     {
00482     public:
00484         enum TargetMode
00485         {
00487             TM_SOFTWARE, 
00490             TM_HARDWARE
00491         };
00493         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
00495         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType, 
00496             VertexData* targetData, TargetMode target = TM_SOFTWARE);
00497 
00499         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
00500         
00502         bool getVertexAnimationIncludesNormals() const;
00503 
00511         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
00512 
00515         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
00516 
00519         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00520 
00522         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00523 
00526         virtual void applyToVertexData(VertexData* data, 
00527             const TimeIndex& timeIndex, Real weight = 1.0, 
00528             const PoseList* poseList = 0);
00529 
00530 
00532         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
00533 
00535         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
00536 
00538         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
00540         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
00541 
00543         void setTargetMode(TargetMode m) { mTargetMode = m; }
00545         TargetMode getTargetMode(void) const { return mTargetMode; }
00546 
00551         virtual bool hasNonZeroKeyFrames(void) const;
00552 
00554         virtual void optimise(void);
00555 
00557         VertexAnimationTrack* _clone(Animation* newParent) const;
00558         
00559         void _applyBaseKeyFrame(const KeyFrame* base);
00560 
00561     protected:
00563         VertexAnimationType mAnimationType;
00565         VertexData* mTargetVertexData;
00567         TargetMode mTargetMode;
00568 
00570         KeyFrame* createKeyFrameImpl(Real time);
00571 
00573         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
00574 
00575 
00576     };
00579 }
00580 
00581 #include "OgreHeaderSuffix.h"
00582 
00583 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:40