OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-2014 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 "OgreHeaderPrefix.h"
34 #include "OgreSimpleSpline.h"
35 #include "OgreRotationalSpline.h"
36 #include "OgrePose.h"
37 
38 namespace Ogre
39 {
40  class VertexPoseKeyFrame;
41  class KeyFrame;
42 
52  {
53  protected:
63 
66  static const uint INVALID_KEY_INDEX = (uint)-1;
67 
68  public:
71  TimeIndex(Real timePos)
72  : mTimePos(timePos)
73  , mKeyIndex(INVALID_KEY_INDEX)
74  {
75  }
76 
82  TimeIndex(Real timePos, uint keyIndex)
83  : mTimePos(timePos)
84  , mKeyIndex(keyIndex)
85  {
86  }
87 
88  bool hasKeyIndex(void) const
89  {
90  return mKeyIndex != INVALID_KEY_INDEX;
91  }
92 
93  Real getTimePos(void) const
94  {
95  return mTimePos;
96  }
97 
98  uint getKeyIndex(void) const
99  {
100  return mKeyIndex;
101  }
102  };
103 
124  {
125  public:
126 
131  {
132  public:
133  virtual ~Listener() {}
134 
138  virtual bool getInterpolatedKeyFrame(const AnimationTrack* t, const TimeIndex& timeIndex, KeyFrame* kf) = 0;
139  };
140 
142  AnimationTrack(Animation* parent, unsigned short handle);
143 
144  virtual ~AnimationTrack();
145 
147  unsigned short getHandle(void) const { return mHandle; }
148 
150  virtual unsigned short getNumKeyFrames(void) const;
151 
153  virtual KeyFrame* getKeyFrame(unsigned short index) const;
154 
176  virtual Real getKeyFramesAtTime(const TimeIndex& timeIndex, KeyFrame** keyFrame1, KeyFrame** keyFrame2,
177  unsigned short* firstKeyIndex = 0) const;
178 
186  virtual KeyFrame* createKeyFrame(Real timePos);
187 
189  virtual void removeKeyFrame(unsigned short index);
190 
192  virtual void removeAllKeyFrames(void);
193 
194 
204  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const = 0;
205 
213  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f) = 0;
214 
217  virtual void _keyFrameDataChanged(void) const {}
218 
223  virtual bool hasNonZeroKeyFrames(void) const { return true; }
224 
226  virtual void optimise(void) {}
227 
229  virtual void _collectKeyFrameTimes(vector<Real>::type& keyFrameTimes);
230 
233  virtual void _buildKeyFrameIndexMap(const vector<Real>::type& keyFrameTimes);
234 
236  virtual void _applyBaseKeyFrame(const KeyFrame* base) {}
237 
239  virtual void setListener(Listener* l) { mListener = l; }
240 
242  Animation *getParent() const { return mParent; }
243  protected:
247  unsigned short mHandle;
249 
253 
255  virtual KeyFrame* createKeyFrameImpl(Real time) = 0;
256 
258  virtual void populateClone(AnimationTrack* clone) const;
259 
260 
261 
262  };
263 
267  {
268  public:
270  NumericAnimationTrack(Animation* parent, unsigned short handle);
272  NumericAnimationTrack(Animation* parent, unsigned short handle,
273  AnimableValuePtr& target);
274 
282  virtual NumericKeyFrame* createNumericKeyFrame(Real timePos);
283 
285  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
286 
288  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
289 
298  void applyToAnimable(const AnimableValuePtr& anim, const TimeIndex& timeIndex,
299  Real weight = 1.0, Real scale = 1.0f);
300 
302  virtual const AnimableValuePtr& getAssociatedAnimable(void) const;
303 
306  virtual void setAssociatedAnimable(const AnimableValuePtr& val);
307 
309  NumericKeyFrame* getNumericKeyFrame(unsigned short index) const;
310 
312  NumericAnimationTrack* _clone(Animation* newParent) const;
313 
314 
315  protected:
318 
320  KeyFrame* createKeyFrameImpl(Real time);
321 
322 
323  };
324 
328  {
329  public:
331  NodeAnimationTrack(Animation* parent, unsigned short handle);
333  NodeAnimationTrack(Animation* parent, unsigned short handle, Node* targetNode);
335  virtual ~NodeAnimationTrack();
343  virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
344 
354  void setInitialState(const Vector3& position, const Quaternion orientation, const Vector3& scale);
355 
360  void resetNodeToInitialState(void);
361 
363  Node* getAssociatedNode(void) const;
364 
366  void setAssociatedNode(Node* node);
367 
369  void applyToNode(Node* node, const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
370 
372  virtual void setUseShortestRotationPath(bool useShortestPath);
373 
375  virtual bool getUseShortestRotationPath() const;
376 
378  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
379 
381  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
382 
384  void _keyFrameDataChanged(void) const;
385 
387  virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
388 
389 
394  virtual bool hasNonZeroKeyFrames(void) const;
395 
397  virtual void optimise(void);
398 
400  NodeAnimationTrack* _clone(Animation* newParent) const;
401 
402  void _applyBaseKeyFrame(const KeyFrame* base);
403 
404  protected:
406  KeyFrame* createKeyFrameImpl(Real time);
407  // Flag indicating we need to rebuild the splines next time
408  virtual void buildInterpolationSplines(void) const;
409 
410  // Struct for store splines, allocate on demand for better memory footprint
411  struct Splines
412  {
416  };
417 
419 
429 
430  // Prebuilt splines, must be mutable since lazy-update in const method
431  mutable Splines* mSplines;
432  mutable bool mSplineBuildNeeded;
435  };
436 
440  {
441  public:
443  OldNodeAnimationTrack(Animation* parent, unsigned short handle);
445  OldNodeAnimationTrack(Animation* parent, unsigned short handle,
446  OldNode* targetNode);
448  virtual ~OldNodeAnimationTrack();
456  virtual TransformKeyFrame* createNodeKeyFrame(Real timePos);
458  OldNode* getAssociatedNode(void) const;
459 
461  void setAssociatedNode(OldNode* node);
462 
464  void applyToNode(OldNode* node, const TimeIndex& timeIndex, Real weight = 1.0,
465  Real scale = 1.0f);
466 
468  virtual void setUseShortestRotationPath(bool useShortestPath);
469 
471  virtual bool getUseShortestRotationPath() const;
472 
474  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
475 
477  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
478 
480  void _keyFrameDataChanged(void) const;
481 
483  virtual TransformKeyFrame* getNodeKeyFrame(unsigned short index) const;
484 
485 
490  virtual bool hasNonZeroKeyFrames(void) const;
491 
493  virtual void optimise(void);
494 
496  OldNodeAnimationTrack* _clone(Animation* newParent) const;
497 
498  void _applyBaseKeyFrame(const KeyFrame* base);
499 
500  protected:
502  KeyFrame* createKeyFrameImpl(Real time);
503  // Flag indicating we need to rebuild the splines next time
504  virtual void buildInterpolationSplines(void) const;
505 
506  // Struct for store splines, allocate on demand for better memory footprint
507  struct Splines
508  {
512  };
513 
515  // Prebuilt splines, must be mutable since lazy-update in const method
516  mutable Splines* mSplines;
517  mutable bool mSplineBuildNeeded;
520  };
521 
581  {
583  VAT_NONE = 0,
588  };
589 
594  {
595  public:
598  {
603  TM_HARDWARE
604  };
606  VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType);
608  VertexAnimationTrack(Animation* parent, unsigned short handle, VertexAnimationType animType,
609  VertexData* targetData, TargetMode target = TM_SOFTWARE);
610 
612  VertexAnimationType getAnimationType(void) const { return mAnimationType; }
613 
615  bool getVertexAnimationIncludesNormals() const;
616 
624  virtual VertexMorphKeyFrame* createVertexMorphKeyFrame(Real timePos);
625 
628  virtual VertexPoseKeyFrame* createVertexPoseKeyFrame(Real timePos);
629 
632  virtual void getInterpolatedKeyFrame(const TimeIndex& timeIndex, KeyFrame* kf) const;
633 
635  virtual void apply(const TimeIndex& timeIndex, Real weight = 1.0, Real scale = 1.0f);
636 
639  virtual void applyToVertexData(VertexData* data,
640  const TimeIndex& timeIndex, Real weight = 1.0,
641  const PoseList* poseList = 0);
642 
643 
645  VertexMorphKeyFrame* getVertexMorphKeyFrame(unsigned short index) const;
646 
648  VertexPoseKeyFrame* getVertexPoseKeyFrame(unsigned short index) const;
649 
651  void setAssociatedVertexData(VertexData* data) { mTargetVertexData = data; }
653  VertexData* getAssociatedVertexData(void) const { return mTargetVertexData; }
654 
656  void setTargetMode(TargetMode m) { mTargetMode = m; }
658  TargetMode getTargetMode(void) const { return mTargetMode; }
659 
664  virtual bool hasNonZeroKeyFrames(void) const;
665 
667  virtual void optimise(void);
668 
670  VertexAnimationTrack* _clone(Animation* newParent) const;
671 
672  void _applyBaseKeyFrame(const KeyFrame* base);
673 
674  protected:
681 
683  KeyFrame* createKeyFrameImpl(Real time);
684 
686  void applyPoseToVertexData(const Pose* pose, VertexData* data, Real influence);
687 
688 
689  };
692 }
693 
694 #include "OgreHeaderSuffix.h"
695 
696 #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:255
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.
bool mUseShortestRotationPath
Defines if rotation is done using shortest path.
Class representing a general-purpose OldNode an articulated scene graph.
Definition: OgreOldNode.h:63
Implementation of a Quaternion, i.e.
vector< Pose * >::type PoseList
Definition: OgrePose.h:134
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.
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. ...
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
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.
Vector3 mInitialPosition
OldNodeAnimationTrack delegated intial transform information to the OldNode.
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
Specialised AnimationTrack for dealing with node transforms.
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:90
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:58
VertexData * getAssociatedVertexData(void) const
Gets the associated VertexData which this track will update.
virtual void _applyBaseKeyFrame(const KeyFrame *base)
Internal method to re-base the keyframes relative to a given keyframe.
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 ...