YourGameLib
Loading...
Searching...
No Matches
include
toolbox
yourgame
util
motion.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2019-2024 Alexander Scholz
3
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
7
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
11
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
19
*/
20
#ifndef YOURGAME_MOTION_H
21
#define YOURGAME_MOTION_H
22
23
#include <functional>
24
#include <vector>
25
26
namespace
yourgame
27
{
28
namespace
util
29
{
30
class
Motion
31
{
32
public
:
33
enum class
FlowType
34
{
35
ONCE
,
36
REPEAT
,
37
PINGPONG
38
};
39
40
enum class
SegmentEase
41
{
42
NONE
,
43
SQUARE
,
44
SQUAREDOWN
,
45
CUBE
,
46
CUBEDOWN
,
47
SINE
,
48
SINEDOWN
,
49
SMOOTH
,
50
SMOOTH2
51
};
52
53
Motion
(
FlowType
flowType);
54
Motion
&
addIdle
(
float
dt,
float
val
);
55
Motion
&
addRamp
(
float
dt,
float
val0,
float
val1,
SegmentEase
ease);
56
57
void
tick
(
double
dt);
58
float
val
();
59
60
void
pause
(
bool
pause
);
61
void
restart
();
62
void
setDirection
(
bool
forward);
63
64
bool
isFinished
();
65
bool
isPaused
();
66
bool
getDirection
();
67
68
private
:
69
struct
Segment
70
{
71
Segment(
float
dt,
72
std::function<
float
(
float
,
const
Segment &)> calcFn,
73
std::function<
float
(
float
,
float
)> easeFn,
74
float
val0,
75
float
val1,
76
float
val2) : dt(dt), calcFn(calcFn), easeFn(easeFn), val0(val0), val1(val1), val2(val2) {}
77
78
float
dt;
79
std::function<float(
float
,
const
Segment &)> calcFn;
80
std::function<float(
float
,
float
)> easeFn;
81
float
val0;
82
float
val1;
83
float
val2;
84
};
85
86
std::vector<Segment> m_segments;
87
FlowType
m_flowType;
88
double
m_t;
89
double
m_direction;
90
double
m_duration;
91
float
m_currentValue;
92
bool
m_finished;
93
bool
m_paused;
94
95
static
float
calcIdle(
float
t,
const
Segment &segment);
96
static
float
calcRamp(
float
t,
const
Segment &segment);
97
static
std::function<float(
float
,
float
)> getEaseFn(
SegmentEase
ease);
98
static
float
calcEaseNone(
float
t,
float
dt);
99
static
float
calcEaseSquare(
float
t,
float
dt);
100
static
float
calcEaseSquareDown(
float
t,
float
dt);
101
static
float
calcEaseCube(
float
t,
float
dt);
102
static
float
calcEaseCubeDown(
float
t,
float
dt);
103
static
float
calcEaseSine(
float
t,
float
dt);
104
static
float
calcEaseSineDown(
float
t,
float
dt);
105
static
float
calcEaseSmooth(
float
t,
float
dt);
106
static
float
calcEaseSmooth2(
float
t,
float
dt);
107
};
108
}
// namespace util
109
}
// namespace yourgame
110
111
#endif
yourgame::util::Motion
Definition
motion.h:31
yourgame::util::Motion::FlowType
FlowType
Definition
motion.h:34
yourgame::util::Motion::FlowType::REPEAT
@ REPEAT
yourgame::util::Motion::FlowType::PINGPONG
@ PINGPONG
yourgame::util::Motion::FlowType::ONCE
@ ONCE
yourgame::util::Motion::pause
void pause(bool pause)
Definition
motion.cpp:120
yourgame::util::Motion::addIdle
Motion & addIdle(float dt, float val)
Definition
motion.cpp:35
yourgame::util::Motion::getDirection
bool getDirection()
Definition
motion.cpp:148
yourgame::util::Motion::SegmentEase
SegmentEase
Definition
motion.h:41
yourgame::util::Motion::SegmentEase::SQUAREDOWN
@ SQUAREDOWN
yourgame::util::Motion::SegmentEase::SQUARE
@ SQUARE
yourgame::util::Motion::SegmentEase::SINEDOWN
@ SINEDOWN
yourgame::util::Motion::SegmentEase::SMOOTH
@ SMOOTH
yourgame::util::Motion::SegmentEase::SMOOTH2
@ SMOOTH2
yourgame::util::Motion::SegmentEase::NONE
@ NONE
yourgame::util::Motion::SegmentEase::CUBEDOWN
@ CUBEDOWN
yourgame::util::Motion::SegmentEase::SINE
@ SINE
yourgame::util::Motion::SegmentEase::CUBE
@ CUBE
yourgame::util::Motion::isFinished
bool isFinished()
Definition
motion.cpp:138
yourgame::util::Motion::addRamp
Motion & addRamp(float dt, float val0, float val1, SegmentEase ease)
Definition
motion.cpp:42
yourgame::util::Motion::isPaused
bool isPaused()
Definition
motion.cpp:143
yourgame::util::Motion::val
float val()
Definition
motion.cpp:115
yourgame::util::Motion::restart
void restart()
Definition
motion.cpp:125
yourgame::util::Motion::tick
void tick(double dt)
Definition
motion.cpp:49
yourgame::util::Motion::setDirection
void setDirection(bool forward)
Definition
motion.cpp:133
yourgame
Definition
audio.h:27
Generated by
1.9.8