OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreAnimationTrack.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __AnimationTrack_H__
30 #define __AnimationTrack_H__
31 
32 #include "OgrePrerequisites.h"
33 #include "OgreSimpleSpline.h"
34 #include "OgreRotationalSpline.h"
35 #include "OgreKeyFrame.h"
36 #include "OgreAnimable.h"
37 #include "OgrePose.h"
38 
39 namespace Ogre
40 {
50  {
51  protected:
61 
64  static const uint INVALID_KEY_INDEX = (uint)-1;
65 
66  public:
69  TimeIndex(Real timePos)
70  : mTimePos(timePos)
71  , mKeyIndex(INVALID_KEY_INDEX)
72  {
73  }
74 
80  TimeIndex(Real timePos, uint keyIndex)
81  : mTimePos(timePos)
82  , mKeyIndex(keyIndex)
83  {
84  }
85 
86  bool hasKeyIndex(void) const
87  {
88  return mKeyIndex != INVALID_KEY_INDEX;
89  }
90 
91  Real getTimePos(void) const
92  {
93  return mTimePos;
94  }
95 
96  uint getKeyIndex(void) const
97  {
98  return mKeyIndex;
99  }
100  };
101 
122  {
123  public:
124 
129  {
130  public:
131  virtual ~Listener() {}
132 
136  virtual bool getInterpolatedKeyFrame(const AnimationTrack* t, const TimeIndex& timeIndex, KeyFrame* kf) = 0;
137  };
138 
140  AnimationTrack(Animation* parent, unsigned short handle);
141 
142  virtual ~AnimationTrack();
143 
145  unsigned short getHandle(void) const { return mHandle; }
146 
148  virtual unsigned short getNumKeyFrames(void) const;
149 
151  virtual KeyFrame* getKeyFrame(unsigned short index) const;
152 
174  virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
175  unsigned short* firstKeyIndex = 0) const;
176 
184  virtual KeyFrame* createKeyFrame(Real timePos);
185 
187  virtual void removeKeyFrame(unsigned short index);
188 
190  virtual void removeAllKeyFrames(void);
191 
192 
202  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
203 
211  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
212 
215  virtual void _keyFrameDataChanged(void) const {}
216 
221  virtual bool hasNonZeroKeyFrames(void) const { return true; }
222 
224  virtual void optimise(void) {}
225 
227  virtual void _collectKeyFrameTimes(vector<Real>::type& keyFrameTimes);
228 
231  virtual void _buildKeyFrameIndexMap(const vector<Real>::type& keyFrameTimes);
232 
234  virtual void setListener(Listener* l) { mListener = l; }
235 
237  Animation *getParent() const { return mParent; }
238  protected:
242  unsigned short mHandle;
244 
248 
250  virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
251 
253  virtual void populateClone(AnimationTrack* clone) const;
254 
255 
256 
257  };
258 
262  {
263  public:
265  NumericAnimationTrack(Animation* parent, unsigned short handle);
267  NumericAnimationTrack(Animation* parent, unsigned short handle,
268  AnimableValuePtr& target);
269 
277  virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
278 
280  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
281 
283  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
284 
293  void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex,
294  Real weight = 1.0, Real scale = 1.0f);
295 
297  virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
298 
301  virtual void setAssociatedAnimable(const AnimableValuePtr& val);
302 
304  NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
305 
307  NumericAnimationTrack* _clone(Animation* newParent) const;
308 
309 
310  protected:
313 
315  KeyFrame* createKeyFrameImpl(Real time);
316 
317 
318  };
319 
323  {
324  public:
326  NodeAnimationTrack(Animation* parent, unsigned short handle);
328  NodeAnimationTrack(Animation* parent, unsigned short handle,
329  Node* targetNode);
331  virtual ~NodeAnimationTrack();
339  virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
341  virtual Node* getAssociatedNode(void) const;
342 
344  virtual void setAssociatedNode(Node* node);
345 
347  virtual void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0,
348  Real scale = 1.0f);
349 
351  virtual void setUseShortestRotationPath(bool useShortestPath);
352 
354  virtual bool getUseShortestRotationPath() const;
355 
357  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
358 
360  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
361 
363  void _keyFrameDataChanged(void) const;
364 
366  virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
367 
368 
373  virtual bool hasNonZeroKeyFrames(void) const;
374 
376  virtual void optimise(void);
377 
379  NodeAnimationTrack* _clone(Animation* newParent) const;
380 
381  protected:
383  KeyFrame* createKeyFrameImpl(Real time);
384  // Flag indicating we need to rebuild the splines next time
385  virtual void buildInterpolationSplines(void) const;
386 
387  // Struct for store splines, allocate on demand for better memory footprint
388  struct Splines
389  {
393  };
394 
396  // Prebuilt splines, must be mutable since lazy-update in const method
397  mutable Splines* mSplines;
398  mutable bool mSplineBuildNeeded;
401  };
402 
462  {
464  VAT_NONE = 0,
469  };
470 
475  {
476  public:
479  {
484  TM_HARDWARE
485  };
487  VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
489  VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType,
490  VertexData* targetData, TargetMode target = TM_SOFTWARE);
491 
493  VertexAnimationType getAnimationType(void) const { return mAnimationType; }
494 
502  virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
503 
506  virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
507 
511  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const
512  { (void)timeIndex; (void)kf; }
513 
515  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
516 
519  virtual void applyToVertexData(VertexData* data,
520  const TimeIndex& timeIndex, Real weight = 1.0,
521  const PoseList* poseList = 0);
522 
523 
525  VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
526 
528  VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
529 
531  void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
533  VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
534 
536  void setTargetMode(TargetMode m) { mTargetMode = m; }
538  TargetMode getTargetMode(void) const { return mTargetMode; }
539 
544  virtual bool hasNonZeroKeyFrames(void) const;
545 
547  virtual void optimise(void);
548 
550  VertexAnimationTrack* _clone(Animation* newParent) const;
551 
552  protected:
559 
561  KeyFrame* createKeyFrameImpl(Real time);
562 
564  void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
565 
566 
567  };
570 }
571 
572 #endif
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:153
This class interpolates orientations (rotations) along a spline using derivatives of quaternions...
float Real
Software floating point type.
Specialised KeyFrame which stores a full transform.
Definition: OgreKeyFrame.h:102
#define _OgreExport
Definition: OgrePlatform.h:203
A key frame in an animation sequence defined by an AnimationTrack.
Definition: OgreKeyFrame.h:55
unsigned short getHandle(void) const
Get the handle associated with this track.
vector< KeyFrame * >::type KeyFrameList
virtual void setListener(Listener *l)
Set a listener for this track.
Morph animation is made up of many interpolated snapshot keyframes.
virtual void _keyFrameDataChanged(void) const
Internal method used to tell the track that keyframe data has been changed, which may cause it to reb...
Specialised AnimationTrack for dealing with generic animable values.
No animation.
Specialised AnimationTrack for dealing with node transforms.
A pose is a linked set of vertex offsets applying to one set of vertex data.
Definition: OgrePose.h:54
TargetMode mTargetMode
Mode to apply.
void setAssociatedVertexData(VertexData *data)
Sets the associated VertexData which this track will update.
Animation * getParent() const
Returns the parent Animation object for this track.
bool mUseShortestRotationPath
Defines if rotation is done using shortest path.
vector< Pose * >::type PoseList
Definition: OgrePose.h:111
TargetMode getTargetMode(void) const
Get the target mode.
bool hasKeyIndex(void) const
Listener allowing you to override certain behaviour of a track, for example to drive animation proced...
Pose animation is made up of a single delta pose keyframe.
VertexAnimationType getAnimationType(void) const
Get the type of vertex animation we're performing.
Time index object used to search keyframe at the given position.
virtual void getInterpolatedKeyFrame(const TimeIndex &timeIndex, KeyFrame *kf) const
This method in fact does nothing, since interpolation is not performed inside the keyframes for this ...
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Real mTimePos
The time position (in relation to the whole animation sequence)
A 'track' in an animation sequence, i.e.
virtual void optimise(void)
Optimise the current track by removing any duplicate keyframes.
VertexAnimationType mAnimationType
Animation type.
Specialised AnimationTrack for dealing with changing vertex position information. ...
uint mKeyIndex
The global keyframe index (in relation to the whole animation sequence) that used to convert to local...
Summary class collecting together vertex source information.
Real getTimePos(void) const
vector< ushort >::type KeyFrameIndexMap
Map used to translate global keyframe time lower bound index to local lower bound index...
TimeIndex(Real timePos, uint keyIndex)
Construct time index object by the given time position and global keyframe index. ...
KeyFrameIndexMap mKeyFrameIndexMap
A very simple spline class which implements the Catmull-Rom class of splines.
Specialised KeyFrame which references a Mesh::Pose at a certain influence level, which stores offsets...
Definition: OgreKeyFrame.h:183
TimeIndex(Real timePos)
Construct time index object by the given time position.
Interpolate vertex positions in software.
AnimableValuePtr mTargetAnim
Target to animate.
VertexData * mTargetVertexData
Target to animate.
Specialised KeyFrame which stores any numeric value.
Definition: OgreKeyFrame.h:79
void setTargetMode(TargetMode m)
Set the target mode.
VertexAnimationType
Type of vertex animation.
TargetMode
The target animation mode.
An animation sequence.
Definition: OgreAnimation.h:58
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:62
VertexData * getAssociatedVertexData(void) const
Gets the associated VertexData which this track will update.
uint getKeyIndex(void) const
unsigned int uint
virtual bool hasNonZeroKeyFrames(void) const
Method to determine if this track has any KeyFrames which are doing anything useful - can be used to ...