SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAnimPlayback.h
Go to the documentation of this file.
1 /**
2  * \file SLAnimPlayback.h
3  * \date Autumn 2014
4  * \authors Marc Wacker, Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLANIMPLAYBACK_h
11 #define SLANIMPLAYBACK_h
12 
13 #include <map>
14 #include <SL.h>
15 #include <SLEnums.h>
16 
17 class SLAnimation;
18 
19 //-----------------------------------------------------------------------------
20 //! Manages the playback of an SLAnimation
21 /*!
22 This class manages the playback state and the local time of an SLAnimation.
23 It manages the way the time advances and how the animation loops. It has all
24 functionality to play, pause, stop, enable, speedup and slowdown a playback.
25 A list of all SLAnimPlayback is hold by the SLAnimManager.
26 
27 It is possible to have multiple playbacks per animation. If we keep track
28 of which nodes are affected by which SLAnimPlayback we can only manipulate
29 these nodes for the time kept in the SLAnimPlayback.
30 A practical example for this behaviour would be special skeleton instances
31 that only keep track of SLAnimPlayback for their parent SLAnimSkeleton.
32 The skeleton instance can then change its skeletal data based on the
33 states and the actual SLAnimation has to only exist once in memory.
34 */
36 {
37 public:
39  SLfloat weight = 1.0f);
40 
41  // control functions
42  void playForward();
43  void playBackward();
44  void pause();
45  void skipToNextKeyframe();
46  void skipToPrevKeyframe();
47  void skipToStart();
48  void skipToEnd();
49 
50  // getters
51  SLfloat localTime() const { return _localTime; }
53  SLfloat playbackRate() const { return _playbackRate; }
54  SLfloat weight() const { return _weight; }
55  SLAnimLooping loop() const { return _loopingBehaviour; }
56  SLbool enabled() const { return _enabled; }
57  SLEasingCurve easing() const { return _easing; }
58  SLbool changed() const { return _gotChanged; }
59  SLbool isPlayingForward() const { return _enabled && _playbackDir == 1; }
60  SLbool isPlayingBackward() const { return _enabled && _playbackDir == -1; }
61  SLbool isPaused() const { return _enabled && _playbackDir == 0; }
62  SLbool isStopped() const { return !_enabled; }
63 
64  // setters
65  void localTime(SLfloat time);
66  void playbackRate(SLfloat pr) { _playbackRate = pr; }
69  void enabled(SLbool val) { _enabled = val; }
70  void easing(SLEasingCurve ec) { _easing = ec; }
72 
73  // advance time by the input real time delta
74  void advanceTime(SLfloat delta);
75  SLfloat calcEasingTime(SLfloat time) const;
76  SLfloat calcEasingTimeInv(SLfloat time) const;
77 
78 protected:
79  SLAnimation* _animation; //!< the animation this plays is referencing
80  SLfloat _localTime; //!< the current local timestamp (eased time)
81  SLfloat _weight; //!< the current weight
82  SLfloat _playbackRate; //!< the current playback speed
83  SLshort _playbackDir; //!< the current playback direction
84  SLbool _enabled; //!< is this animation running
85  SLEasingCurve _easing; //!< easing modifier curve (to customize start and end point easing)
86  SLfloat _linearLocalTime; //!< linear local time used for _easing propert
87  SLAnimLooping _loopingBehaviour; //!< We support different looping behaviours
88  SLbool _gotChanged; //!< Did this playback change in the last frame
89 };
90 //-----------------------------------------------------------------------------
91 typedef vector<SLAnimPlayback*> SLVAnimPlayback;
92 typedef std::map<SLstring, SLAnimPlayback*> SLMAnimPlayback;
93 //-----------------------------------------------------------------------------
94 #endif
float SLfloat
Definition: SL.h:173
bool SLbool
Definition: SL.h:175
short SLshort
Definition: SL.h:168
vector< SLAnimPlayback * > SLVAnimPlayback
std::map< SLstring, SLAnimPlayback * > SLMAnimPlayback
SLEasingCurve
Enumeration for animation easing curves.
Definition: SLEnums.h:180
SLAnimLooping
Enumeration for animation modes.
Definition: SLEnums.h:167
Manages the playback of an SLAnimation.
void playbackRate(SLfloat pr)
SLbool isPaused() const
SLbool changed() const
SLfloat _weight
the current weight
SLfloat _localTime
the current local timestamp (eased time)
void weight(SLfloat weight)
SLbool enabled() const
SLEasingCurve _easing
easing modifier curve (to customize start and end point easing)
SLshort _playbackDir
the current playback direction
SLfloat localTime() const
SLbool isPlayingBackward() const
SLfloat _playbackRate
the current playback speed
SLbool isPlayingForward() const
SLbool _gotChanged
Did this playback change in the last frame.
SLbool _enabled
is this animation running
SLfloat _linearLocalTime
linear local time used for _easing propert
void changed(SLbool changed)
SLAnimLooping _loopingBehaviour
We support different looping behaviours.
SLAnimLooping loop() const
SLbool isStopped() const
SLEasingCurve easing() const
SLfloat calcEasingTimeInv(SLfloat time) const
void easing(SLEasingCurve ec)
void advanceTime(SLfloat delta)
SLAnimation * _animation
the animation this plays is referencing
SLAnimPlayback(SLAnimation *parent, SLfloat weight=1.0f)
SLfloat weight() const
void loop(SLAnimLooping lb)
SLfloat playbackRate() const
void enabled(SLbool val)
SLfloat calcEasingTime(SLfloat time) const
Applies the easing time curve to the input time.
SLAnimation * parentAnimation()
SLAnimation is the base container for all animation data.
Definition: SLAnimation.h:33