OgreAnimationTrack.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __AnimationTrack_H__
#define __AnimationTrack_H__
#include "OgrePrerequisites.h"
#include "OgreSimpleSpline.h"
#include "OgreRotationalSpline.h"
#include "OgreKeyFrame.h"
#include "OgreAnimable.h"
#include "OgrePose.h"
#include "OgreHeaderPrefix.h"
namespace Ogre
{
class _OgreExport TimeIndex
{
protected:
Real mTimePos;
uint mKeyIndex;
static const uint INVALID_KEY_INDEX = (uint)-1;
public:
TimeIndex(Real timePos)
: mTimePos(timePos)
, mKeyIndex(INVALID_KEY_INDEX)
{
}
TimeIndex(Real timePos, uint keyIndex)
: mTimePos(timePos)
, mKeyIndex(keyIndex)
{
}
bool hasKeyIndex(void) const
{
return mKeyIndex != INVALID_KEY_INDEX;
}
Real getTimePos(void) const
{
return mTimePos;
}
uint getKeyIndex(void) const
{
return mKeyIndex;
}
};
class _OgreExport AnimationTrack : public AnimationAlloc
{
public:
class _OgreExport Listener
{
public:
virtual ~Listener() {}
virtual bool getInterpolatedKeyFrame(const AnimationTrack* t, const TimeIndex& timeIndex, KeyFrame* kf) = 0;
};
AnimationTrack(Animation* parent, unsigned short handle);
virtual ~AnimationTrack();
unsigned short getHandle(void) const { return mHandle; }
virtual unsigned short getNumKeyFrames(void) const;
virtual KeyFrame* getKeyFrame(unsigned short index) const;
virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
unsigned short* firstKeyIndex = 0) const;
virtual KeyFrame* createKeyFrame(Real timePos);
virtual void removeKeyFrame(unsigned short index);
virtual void removeAllKeyFrames(void);
virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
virtual void _keyFrameDataChanged(void) const {}
virtual bool hasNonZeroKeyFrames(void) const { return true; }
virtual void optimise(void) {}
virtual void _collectKeyFrameTimes(vector<Real>::type& keyFrameTimes);
virtual void _buildKeyFrameIndexMap(const vector<Real>::type& keyFrameTimes);
virtual void _applyBaseKeyFrame(const KeyFrame* base) {}
virtual void setListener(Listener* l) { mListener = l; }
Animation *getParent() const { return mParent; }
protected:
typedef vector<KeyFrame*>::type KeyFrameList;
KeyFrameList mKeyFrames;
Animation* mParent;
unsigned short mHandle;
Listener* mListener;
typedef vector<ushort>::type KeyFrameIndexMap;
KeyFrameIndexMap mKeyFrameIndexMap;
virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
virtual void populateClone(AnimationTrack* clone) const;
};
class _OgreExport NumericAnimationTrack : public AnimationTrack
{
public:
NumericAnimationTrack(Animation* parent, unsigned short handle);
NumericAnimationTrack(Animation* parent, unsigned short handle,
AnimableValuePtr& target);
virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex,
Real weight = 1.0, Real scale = 1.0f);
virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
virtual void setAssociatedAnimable(const AnimableValuePtr& val);
NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
NumericAnimationTrack* _clone(Animation* newParent) const;
protected:
AnimableValuePtr mTargetAnim;
KeyFrame* createKeyFrameImpl(Real time);
};
class _OgreExport NodeAnimationTrack : public AnimationTrack
{
public:
NodeAnimationTrack(Animation* parent, unsigned short handle);
NodeAnimationTrack(Animation* parent, unsigned short handle,
Node* targetNode);
virtual ~NodeAnimationTrack();
virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
virtual Node* getAssociatedNode(void) const;
virtual void setAssociatedNode(Node* node);
virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0,
Real scale = 1.0f);
virtual void setUseShortestRotationPath(bool useShortestPath);
virtual bool getUseShortestRotationPath() const;
virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
void _keyFrameDataChanged(void) const;
virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
virtual bool hasNonZeroKeyFrames(void) const;
virtual void optimise(void);
NodeAnimationTrack* _clone(Animation* newParent) const;
void _applyBaseKeyFrame(const KeyFrame* base);
protected:
KeyFrame* createKeyFrameImpl(Real time);
// Flag indicating we need to rebuild the splines next time
virtual void buildInterpolationSplines(void) const;
// Struct for store splines, allocate on demand for better memory footprint
struct Splines
{
SimpleSpline positionSpline;
SimpleSpline scaleSpline;
RotationalSpline rotationSpline;
};
Node* mTargetNode;
// Prebuilt splines, must be mutable since lazy-update in const method
mutable Splines* mSplines;
mutable bool mSplineBuildNeeded;
mutable bool mUseShortestRotationPath ;
};
enum VertexAnimationType
{
VAT_NONE = 0,
VAT_MORPH = 1,
VAT_POSE = 2
};
class _OgreExport VertexAnimationTrack : public AnimationTrack
{
public:
enum TargetMode
{
TM_SOFTWARE,
TM_HARDWARE
};
VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType,
VertexData* targetData, TargetMode target = TM_SOFTWARE);
VertexAnimationType getAnimationType(void) const { return mAnimationType; }
bool getVertexAnimationIncludesNormals() const;
virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
virtual void applyToVertexData(VertexData* data,
const TimeIndex& timeIndex, Real weight = 1.0,
const PoseList* poseList = 0);
VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
void setTargetMode(TargetMode m) { mTargetMode = m; }
TargetMode getTargetMode(void) const { return mTargetMode; }
virtual bool hasNonZeroKeyFrames(void) const;
virtual void optimise(void);
VertexAnimationTrack* _clone(Animation* newParent) const;
void _applyBaseKeyFrame(const KeyFrame* base);
protected:
VertexAnimationType mAnimationType;
VertexData* mTargetVertexData;
TargetMode mTargetMode;
KeyFrame* createKeyFrameImpl(Real time);
void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
};
}
#include "OgreHeaderSuffix.h"
#endif
Ogre::AnimationTrack::mHandle
unsigned short mHandle
Definition: OgreAnimationTrack.h:246
Ogre::AnimationTrack
A &#39;track&#39; in an animation sequence, i.e.
Definition: OgreAnimationTrack.h:122
Ogre::AnimationTrack::mKeyFrameIndexMap
KeyFrameIndexMap mKeyFrameIndexMap
Definition: OgreAnimationTrack.h:251
Ogre::TimeIndex::mKeyIndex
uint mKeyIndex
The global keyframe index (in relation to the whole animation sequence) that used to convert to local...
Definition: OgreAnimationTrack.h:61
Ogre::TimeIndex::getKeyIndex
uint getKeyIndex(void) const
Definition: OgreAnimationTrack.h:97
Ogre::TimeIndex
Time index object used to search keyframe at the given position.
Definition: OgreAnimationTrack.h:50
Ogre::VertexAnimationTrack::getAnimationType
VertexAnimationType getAnimationType(void) const
Get the type of vertex animation we&#39;re performing.
Definition: OgreAnimationTrack.h:499
Ogre::VertexAnimationTrack::setTargetMode
void setTargetMode(TargetMode m)
Set the target mode.
Definition: OgreAnimationTrack.h:543
Ogre::AnimationTrack::Listener
Listener allowing you to override certain behaviour of a track, for example to drive animation proced...
Definition: OgreAnimationTrack.h:129
OgreAnimable.h
Ogre::TimeIndex::hasKeyIndex
bool hasKeyIndex(void) const
Definition: OgreAnimationTrack.h:87
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
Ogre::PoseList
vector< Pose * >::type PoseList
Definition: OgrePose.h:135
OgreRotationalSpline.h
Ogre::AnimationTrack::mParent
Animation * mParent
Definition: OgreAnimationTrack.h:245
Ogre::NodeAnimationTrack::Splines::positionSpline
SimpleSpline positionSpline
Definition: OgreAnimationTrack.h:396
Ogre::SimpleSpline
A very simple spline class which implements the Catmull-Rom class of splines.
Definition: OgreSimpleSpline.h:57
Ogre::VertexData
Summary class collecting together vertex source information.
Definition: OgreVertexIndexData.h:49
Ogre::AnimationTrack::_applyBaseKeyFrame
virtual void _applyBaseKeyFrame(const KeyFrame *base)
Internal method to re-base the keyframes relative to a given keyframe.
Definition: OgreAnimationTrack.h:235
Ogre::VAT_MORPH
Morph animation is made up of many interpolated snapshot keyframes.
Definition: OgreAnimationTrack.h:472
Ogre::VertexAnimationTrack::TargetMode
TargetMode
The target animation mode.
Definition: OgreAnimationTrack.h:484
Ogre::TimeIndex::TimeIndex
TimeIndex(Real timePos, uint keyIndex)
Construct time index object by the given time position and global keyframe index. ...
Definition: OgreAnimationTrack.h:81
Ogre::AnimationTrack::mKeyFrames
KeyFrameList mKeyFrames
Definition: OgreAnimationTrack.h:244
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::VertexAnimationTrack::TM_SOFTWARE
Interpolate vertex positions in software.
Definition: OgreAnimationTrack.h:487
Ogre::VertexAnimationTrack::mTargetVertexData
VertexData * mTargetVertexData
Target to animate.
Definition: OgreAnimationTrack.h:565
Ogre::AnimationTrack::optimise
virtual void optimise(void)
Optimise the current track by removing any duplicate keyframes.
Definition: OgreAnimationTrack.h:225
Ogre::VertexAnimationTrack::mAnimationType
VertexAnimationType mAnimationType
Animation type.
Definition: OgreAnimationTrack.h:563
Ogre::TransformKeyFrame
Specialised KeyFrame which stores a full transform.
Definition: OgreKeyFrame.h:103
Ogre::NodeAnimationTrack::Splines
Definition: OgreAnimationTrack.h:394
Ogre::AnimationTrack::mListener
Listener * mListener
Definition: OgreAnimationTrack.h:247
Ogre::AnimationTrack::KeyFrameList
vector< KeyFrame * >::type KeyFrameList
Definition: OgreAnimationTrack.h:243
OgreSimpleSpline.h
Ogre::NumericAnimationTrack
Specialised AnimationTrack for dealing with generic animable values.
Definition: OgreAnimationTrack.h:265
Ogre::AnimationTrack::KeyFrameIndexMap
vector< ushort >::type KeyFrameIndexMap
Map used to translate global keyframe time lower bound index to local lower bound index...
Definition: OgreAnimationTrack.h:250
Ogre::VAT_NONE
No animation.
Definition: OgreAnimationTrack.h:470
Ogre::VertexAnimationTrack::getTargetMode
TargetMode getTargetMode(void) const
Get the target mode.
Definition: OgreAnimationTrack.h:545
Ogre::VertexAnimationTrack::mTargetMode
TargetMode mTargetMode
Mode to apply.
Definition: OgreAnimationTrack.h:567
Ogre::RotationalSpline
This class interpolates orientations (rotations) along a spline using derivatives of quaternions...
Definition: OgreRotationalSpline.h:58
Ogre::NodeAnimationTrack::mTargetNode
Node * mTargetNode
Definition: OgreAnimationTrack.h:401
Ogre::TimeIndex::getTimePos
Real getTimePos(void) const
Definition: OgreAnimationTrack.h:92
Ogre::NodeAnimationTrack::Splines::scaleSpline
SimpleSpline scaleSpline
Definition: OgreAnimationTrack.h:397
Ogre::VertexAnimationType
VertexAnimationType
Type of vertex animation.
Definition: OgreAnimationTrack.h:467
OgrePrerequisites.h
Ogre::AnimationTrack::setListener
virtual void setListener(Listener *l)
Set a listener for this track.
Definition: OgreAnimationTrack.h:238
Ogre::Node
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:64
Ogre::TimeIndex::mTimePos
Real mTimePos
The time position (in relation to the whole animation sequence)
Definition: OgreAnimationTrack.h:55
Ogre::Animation
An animation sequence.
Definition: OgreAnimation.h:92
Ogre::KeyFrame
A key frame in an animation sequence defined by an AnimationTrack.
Definition: OgreKeyFrame.h:56
Ogre::AnimationTrack::hasNonZeroKeyFrames
virtual bool hasNonZeroKeyFrames(void) const
Method to determine if this track has any KeyFrames which are doing anything useful - can be used to ...
Definition: OgreAnimationTrack.h:222
Ogre::AnimationTrack::getParent
Animation * getParent() const
Returns the parent Animation object for this track.
Definition: OgreAnimationTrack.h:241
Ogre::NodeAnimationTrack::mSplineBuildNeeded
bool mSplineBuildNeeded
Definition: OgreAnimationTrack.h:404
Ogre::VertexMorphKeyFrame
Specialised KeyFrame which stores absolute vertex positions for a complete buffer, designed to be interpolated with other keys in the same track.
Definition: OgreKeyFrame.h:154
Ogre::NodeAnimationTrack::mSplines
Splines * mSplines
Definition: OgreAnimationTrack.h:403
OgreHeaderSuffix.h
Ogre::TimeIndex::TimeIndex
TimeIndex(Real timePos)
Construct time index object by the given time position.
Definition: OgreAnimationTrack.h:70
Ogre::NodeAnimationTrack::Splines::rotationSpline
RotationalSpline rotationSpline
Definition: OgreAnimationTrack.h:398
Ogre::NumericAnimationTrack::mTargetAnim
AnimableValuePtr mTargetAnim
Target to animate.
Definition: OgreAnimationTrack.h:316
Ogre::AnimationTrack::Listener::~Listener
virtual ~Listener()
Definition: OgreAnimationTrack.h:132
Ogre::VertexAnimationTrack::getAssociatedVertexData
VertexData * getAssociatedVertexData(void) const
Gets the associated VertexData which this track will update.
Definition: OgreAnimationTrack.h:540
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::AnimationTrack::_keyFrameDataChanged
virtual void _keyFrameDataChanged(void) const
Internal method used to tell the track that keyframe data has been changed, which may cause it to reb...
Definition: OgreAnimationTrack.h:216
OgrePose.h
Ogre::SharedPtr< AnimableValue >
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::AnimationTrack::getHandle
unsigned short getHandle(void) const
Get the handle associated with this track.
Definition: OgreAnimationTrack.h:146
OgreHeaderPrefix.h
Ogre::VertexPoseKeyFrame
Specialised KeyFrame which references a Mesh::Pose at a certain influence level, which stores offsets...
Definition: OgreKeyFrame.h:184
Ogre::NodeAnimationTrack::mUseShortestRotationPath
bool mUseShortestRotationPath
Defines if rotation is done using shortest path.
Definition: OgreAnimationTrack.h:406
OgreKeyFrame.h
Ogre::VAT_POSE
Pose animation is made up of a single delta pose keyframe.
Definition: OgreAnimationTrack.h:474
Ogre::VertexAnimationTrack
Specialised AnimationTrack for dealing with changing vertex position information. ...
Definition: OgreAnimationTrack.h:480
Ogre::VertexAnimationTrack::setAssociatedVertexData
void setAssociatedVertexData(VertexData *data)
Sets the associated VertexData which this track will update.
Definition: OgreAnimationTrack.h:538
Ogre::NodeAnimationTrack
Specialised AnimationTrack for dealing with node transforms.
Definition: OgreAnimationTrack.h:326
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::NumericKeyFrame
Specialised KeyFrame which stores any numeric value.
Definition: OgreKeyFrame.h:80
Ogre::Pose
A pose is a linked set of vertex offsets applying to one set of vertex data.
Definition: OgrePose.h:55

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.