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-2012 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 _applyBaseKeyFrame(const KeyFrame* base) {}
00235 
00237         virtual void setListener(Listener* l) { mListener = l; }
00238 
00240         Animation *getParent() const { return mParent; }
00241     protected:
00242         typedef vector<KeyFrame*>::type KeyFrameList;
00243         KeyFrameList mKeyFrames;
00244         Animation* mParent;
00245         unsigned short mHandle;
00246         Listener* mListener;
00247 
00249         typedef vector<ushort>::type KeyFrameIndexMap;
00250         KeyFrameIndexMap mKeyFrameIndexMap;
00251 
00253         virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
00254 
00256         virtual void populateClone(AnimationTrack* clone) const;
00257         
00258 
00259 
00260     };
00261 
00264     class _OgreExport NumericAnimationTrack : public AnimationTrack
00265     {
00266     public:
00268         NumericAnimationTrack(Animation* parent, unsigned short handle);
00270         NumericAnimationTrack(Animation* parent, unsigned short handle, 
00271             AnimableValuePtr& target);
00272 
00280         virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
00281 
00283         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00284 
00286         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00287 
00296         void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex, 
00297             Real weight = 1.0, Real scale = 1.0f);
00298 
00300         virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
00301 
00304         virtual void setAssociatedAnimable(const AnimableValuePtr& val);
00305 
00307         NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
00308 
00310         NumericAnimationTrack* _clone(Animation* newParent) const;
00311 
00312 
00313     protected:
00315         AnimableValuePtr mTargetAnim;
00316 
00318         KeyFrame* createKeyFrameImpl(Real time);
00319 
00320 
00321     };
00322 
00325     class _OgreExport NodeAnimationTrack : public AnimationTrack
00326     {
00327     public:
00329         NodeAnimationTrack(Animation* parent, unsigned short handle);
00331         NodeAnimationTrack(Animation* parent, unsigned short handle, 
00332             Node* targetNode);
00334         virtual ~NodeAnimationTrack();
00342         virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
00344         virtual Node* getAssociatedNode(void) const;
00345 
00347         virtual void setAssociatedNode(Node* node);
00348 
00350         virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0, 
00351             Real scale = 1.0f);
00352 
00354         virtual void setUseShortestRotationPath(bool useShortestPath);
00355 
00357         virtual bool getUseShortestRotationPath() const;
00358 
00360         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00361 
00363         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00364 
00366         void _keyFrameDataChanged(void) const;
00367 
00369         virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
00370 
00371 
00376         virtual bool hasNonZeroKeyFrames(void) const;
00377 
00379         virtual void optimise(void);
00380 
00382         NodeAnimationTrack* _clone(Animation* newParent) const;
00383         
00384         void _applyBaseKeyFrame(const KeyFrame* base);
00385         
00386     protected:
00388         KeyFrame* createKeyFrameImpl(Real time);
00389         // Flag indicating we need to rebuild the splines next time
00390         virtual void buildInterpolationSplines(void) const;
00391 
00392         // Struct for store splines, allocate on demand for better memory footprint
00393         struct Splines
00394         {
00395             SimpleSpline positionSpline;
00396             SimpleSpline scaleSpline;
00397             RotationalSpline rotationSpline;
00398         };
00399 
00400         Node* mTargetNode;
00401         // Prebuilt splines, must be mutable since lazy-update in const method
00402         mutable Splines* mSplines;
00403         mutable bool mSplineBuildNeeded;
00405         mutable bool mUseShortestRotationPath ;
00406     };
00407 
00466     enum VertexAnimationType
00467     {
00469         VAT_NONE = 0,
00471         VAT_MORPH = 1,
00473         VAT_POSE = 2
00474     };
00475 
00479     class _OgreExport VertexAnimationTrack : public AnimationTrack
00480     {
00481     public:
00483         enum TargetMode
00484         {
00486             TM_SOFTWARE, 
00489             TM_HARDWARE
00490         };
00492         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
00494         VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType, 
00495             VertexData* targetData, TargetMode target = TM_SOFTWARE);
00496 
00498         VertexAnimationType getAnimationType(void) const { return mAnimationType; }
00499         
00501         bool getVertexAnimationIncludesNormals() const;
00502 
00510         virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
00511 
00514         virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
00515 
00518         virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
00519 
00521         virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
00522 
00525         virtual void applyToVertexData(VertexData* data, 
00526             const TimeIndex& timeIndex, Real weight = 1.0, 
00527             const PoseList* poseList = 0);
00528 
00529 
00531         VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
00532 
00534         VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
00535 
00537         void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
00539         VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
00540 
00542         void setTargetMode(TargetMode m) { mTargetMode = m; }
00544         TargetMode getTargetMode(void) const { return mTargetMode; }
00545 
00550         virtual bool hasNonZeroKeyFrames(void) const;
00551 
00553         virtual void optimise(void);
00554 
00556         VertexAnimationTrack* _clone(Animation* newParent) const;
00557         
00558         void _applyBaseKeyFrame(const KeyFrame* base);
00559 
00560     protected:
00562         VertexAnimationType mAnimationType;
00564         VertexData* mTargetVertexData;
00566         TargetMode mTargetMode;
00567 
00569         KeyFrame* createKeyFrameImpl(Real time);
00570 
00572         void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
00573 
00574 
00575     };
00578 }
00579 
00580 #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 Fri May 25 23:36:23 2012