SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAnimTrack.h
Go to the documentation of this file.
1 /**
2  * \file SLAnimTrack.h
3  * \date Autumn 2014
4  * \remarks Please use clangformat to format the code. See more code style on
5  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
6  * \authors Marc Wacker, Marcus Hudritsch
7  * \copyright http://opensource.org/licenses/GPL-3.0
8 */
9 
10 #ifndef SLANIMTRACK_h
11 #define SLANIMTRACK_h
12 
13 #include <map>
14 
15 #include <SLEnums.h>
16 #include <SLAnimKeyframe.h>
17 
18 class SLNode;
19 class SLAnimation;
20 class SLCurve;
21 class SLSceneView;
22 
23 //-----------------------------------------------------------------------------
24 //! Abstract base class for SLAnimationTracks providing time and keyframe functions
25 /*!
26 An animation track is a specialized track that affects a single SLNode or an
27 SLJoint of an SLAnimSkeleton by interpolating its transform. It holds therefore a
28 list of SLKeyframe. For a smooth motion it can interpolate the transform at a
29 given time between two neighboring SLKeyframe.
30 */
32 {
33 public:
34  SLAnimTrack(SLAnimation* parent);
35  virtual ~SLAnimTrack();
36 
37  SLAnimKeyframe* createKeyframe(SLfloat time); // create and add a new keyframe
39  SLAnimKeyframe** k1,
40  SLAnimKeyframe** k2) const;
41  virtual void calcInterpolatedKeyframe(SLfloat time,
42  SLAnimKeyframe* keyframe) const = 0; // we need a way to get an output value for a time we put in
43  virtual void apply(SLfloat time,
44  SLfloat weight = 1.0f,
45  SLfloat scale = 1.0f) = 0;
46  virtual void drawVisuals(SLSceneView* sv) = 0;
47  SLint numKeyframes() const { return (SLint)_keyframes.size(); }
49 
50 protected:
51  /// Keyframe creator function for derived implementations
53 
54  SLAnimation* _animation; //!< parent animation that created this track
55  SLVKeyframe _keyframes; //!< keyframe list for this track
56 };
57 
58 //-----------------------------------------------------------------------------
59 //! Specialized animation track for node animations
60 /*!
61  Allows for translation, scale and rotation parameters to be animated.
62  Also allows for either linear or Bezier interpolation of the position
63  parameter in the track.
64 */
66 {
67 public:
69  virtual ~SLNodeAnimTrack();
70 
72 
73  void animatedNode(SLNode* target) { _animatedNode = target; }
75 
76  virtual void calcInterpolatedKeyframe(SLfloat time, SLAnimKeyframe* keyframe) const;
77  virtual void apply(SLfloat time, SLfloat weight = 1.0f, SLfloat scale = 1.0f);
78  virtual void applyToNode(SLNode* node, SLfloat time, SLfloat weight = 1.0f, SLfloat scale = 1.0f);
79  virtual void drawVisuals(SLSceneView* sv);
80 
81  void interpolationCurve(SLCurve* curve);
83 
84 protected:
85  void buildInterpolationCurve() const;
87 
88  SLNode* _animatedNode; //!< the target node for this track_nodeID
89  mutable SLCurve* _interpolationCurve; //!< the translation interpolation curve
90  SLAnimInterpolation _translationInterpolation; //!< interpolation mode for translations (Bezier or linear)
91  SLbool _rebuildInterpolationCurve; //!< dirty flag of the Bezier curve
92 };
93 //-----------------------------------------------------------------------------
94 typedef std::map<SLuint, SLNodeAnimTrack*> SLMNodeAnimTrack;
95 //-----------------------------------------------------------------------------
96 #endif
float SLfloat
Definition: SL.h:173
bool SLbool
Definition: SL.h:175
int SLint
Definition: SL.h:170
vector< SLAnimKeyframe * > SLVKeyframe
std::map< SLuint, SLNodeAnimTrack * > SLMNodeAnimTrack
Definition: SLAnimTrack.h:94
SLAnimInterpolation
Enumeration for animation modes.
Definition: SLEnums.h:160
Base class for all animation keyframes.
Abstract base class for SLAnimationTracks providing time and keyframe functions.
Definition: SLAnimTrack.h:32
SLAnimTrack(SLAnimation *parent)
Definition: SLAnimTrack.cpp:18
virtual SLAnimKeyframe * createKeyframeImpl(SLfloat time)=0
Keyframe creator function for derived implementations.
SLAnimKeyframe * keyframe(SLint index)
Definition: SLAnimTrack.cpp:48
SLAnimKeyframe * createKeyframe(SLfloat time)
Definition: SLAnimTrack.cpp:38
virtual void calcInterpolatedKeyframe(SLfloat time, SLAnimKeyframe *keyframe) const =0
virtual void drawVisuals(SLSceneView *sv)=0
SLAnimation * _animation
parent animation that created this track
Definition: SLAnimTrack.h:54
SLfloat getKeyframesAtTime(SLfloat time, SLAnimKeyframe **k1, SLAnimKeyframe **k2) const
Definition: SLAnimTrack.cpp:62
virtual void apply(SLfloat time, SLfloat weight=1.0f, SLfloat scale=1.0f)=0
SLint numKeyframes() const
Definition: SLAnimTrack.h:47
virtual ~SLAnimTrack()
Definition: SLAnimTrack.cpp:26
SLVKeyframe _keyframes
keyframe list for this track
Definition: SLAnimTrack.h:55
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33
Base class for curves defined by multiple 3D points.
Definition: SLCurve.h:24
Specialized animation track for node animations.
Definition: SLAnimTrack.h:66
SLNode * animatedNode()
Definition: SLAnimTrack.h:74
SLbool _rebuildInterpolationCurve
dirty flag of the Bezier curve
Definition: SLAnimTrack.h:91
virtual void drawVisuals(SLSceneView *sv)
Draws all visualizations of node animations.
void animatedNode(SLNode *target)
Definition: SLAnimTrack.h:73
void interpolationCurve(SLCurve *curve)
virtual ~SLNodeAnimTrack()
SLCurve * _interpolationCurve
the translation interpolation curve
Definition: SLAnimTrack.h:89
SLAnimInterpolation _translationInterpolation
interpolation mode for translations (Bezier or linear)
Definition: SLAnimTrack.h:90
SLTransformKeyframe * createNodeKeyframe(SLfloat time)
SLNode * _animatedNode
the target node for this track_nodeID
Definition: SLAnimTrack.h:88
void buildInterpolationCurve() const
virtual void applyToNode(SLNode *node, SLfloat time, SLfloat weight=1.0f, SLfloat scale=1.0f)
void translationInterpolation(SLAnimInterpolation interp)
Definition: SLAnimTrack.h:82
SLNodeAnimTrack(SLAnimation *parent)
virtual void calcInterpolatedKeyframe(SLfloat time, SLAnimKeyframe *keyframe) const
virtual void apply(SLfloat time, SLfloat weight=1.0f, SLfloat scale=1.0f)
virtual SLAnimKeyframe * createKeyframeImpl(SLfloat time)
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
SLTransformKeyframe is a specialized SLKeyframe for node transformations.