TimeTransform.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Animation/AnimConnector.hpp"
4 #include <functional>
5 
6 namespace iv
7 {
8 
11 class TimeTransform : public std::function< Anim_float( Anim_float ) >
12 {
13 public:
14  using std::function< Anim_float( Anim_float ) >::function;
15 
16  Anim_float Transform( Anim_float src_time, Anim_float total_time ) const
17  {
18  // do we even use a transformation?
19  if( !(*this) )
20  return src_time;
21 
22  // use linear transform if src_time is out of bounds
23  if( src_time > total_time || src_time < Anim_float( 0.0 ) )
24  return src_time;
25 
26  // get source factor
27  Anim_float src_factor = src_time / total_time;
28 
29  // user transform
30  Anim_float tgt_factor = (*this)( src_factor );
31  tgt_factor = iv::clamp( tgt_factor, Anim_float( 0.0 ), Anim_float( 1.0 ) );
32 
33  // target time
34  Anim_float tgt_time = tgt_factor * total_time;
35  return tgt_time;
36  }
37 };
38 
43 {
45  {
46  return x;
47  }
48 };
49 
55 {
56 public:
58  {
59  return x*x*( 3.0 - 2.0*x ) ;
60  }
61 };
62 
68 {
69 public:
71  {
72  return x*x*x*( x*( x*6.0 - 15.0 ) + 10.0 );
73  }
74 };
75 
80 {
81 public:
83  {
84  return 1.0 - ( 1.0-x )*( 1.0-x );
85  }
86 };
87 
96 {
97 public:
98  ExponentialTransform( Anim_float degree ) : degree( degree ){}
99 
101  {
102  if( degree == Anim_float( 1.0 ) )
103  return x;
104  else
105  return ( pow( this->degree, x ) - Anim_float( 1.0 ) ) / ( this->degree - Anim_float( 1.0 ) );
106  }
107 
108 private:
109  Anim_float degree;
110 };
111 
112 }