Toggle navigation
ivorium
iv_components
Example project
GitHub
Main Page
Modules
Classes
Files
File List
File Members
ivorium_graphics
Animation
Connectors
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
42
struct
LinearTransform
43
{
44
Anim_float
operator()
(
Anim_float
x )
45
{
46
return
x;
47
}
48
};
49
54
struct
Smoothstep2Transform
55
{
56
public
:
57
Anim_float
operator()
(
Anim_float
x )
58
{
59
return
x*x*( 3.0 - 2.0*x ) ;
60
}
61
};
62
67
struct
Smoothstep3Transform
68
{
69
public
:
70
Anim_float
operator()
(
Anim_float
x )
71
{
72
return
x*x*x*( x*( x*6.0 - 15.0 ) + 10.0 );
73
}
74
};
75
79
struct
QuickstepTransform
80
{
81
public
:
82
Anim_float
operator()
(
Anim_float
x )
83
{
84
return
1.0 - ( 1.0-x )*( 1.0-x );
85
}
86
};
87
95
struct
ExponentialTransform
96
{
97
public
:
98
ExponentialTransform
(
Anim_float
degree ) : degree( degree ){}
99
100
Anim_float
operator()
(
Anim_float
x )
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
}