Skip to content

Commit 1b7a9fc

Browse files
committed
TO mode added, color example updated
1 parent 2e0c7ff commit 1b7a9fc

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

cframe.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <tuple>
33
#include <type_traits>
44
#include <vector>
5+
#include <iostream>
56

67
namespace {
78
// https://gist.github.com/utilForever/1a058050b8af3ef46b58bcfa01d5375d
@@ -95,7 +96,6 @@ enum class EasingFunction {
9596
BOUNCE_IN_OUT
9697
};
9798

98-
//TODO define the header at top of file, then put implementations under #ifdef etc..
9999
template <typename T>
100100
struct Animation {
101101

@@ -134,11 +134,10 @@ struct Animation {
134134

135135
} //CF
136136

137-
// #define CFRAME_IMPLEMENTATION
137+
#define CFRAME_IMPLEMENTATION
138138
#ifdef CFRAME_IMPLEMENTATION
139139

140140
namespace {
141-
//TODO put these in anonymous namespace
142141
// ====================== Easing Functions ======================
143142
// The following easing functions ripped from AHeasing (https://github.com/warrenm/AHEasing)
144143

@@ -539,14 +538,16 @@ T CF::Animation<T>::get() {
539538
__Step(max_index);
540539
}
541540

541+
auto output_tuple = _initial_tuple; //resets output to initial at each step
542+
542543
for (auto i = 0; i < _index_checkpoints.size(); i++) {
543544
if ((_index_checkpoints[i] < index) && (i%2 != 1)) {
544545
// auto transform_tuple = __ToTuple(_keyframes[(i/2)]._transformation);
545546
float easing_index = __CalculateEasing(_easing_func, __Compare(index, _index_checkpoints[i], _index_checkpoints[i+1]));
546-
__ApplyTransform(_initial_tuple, _keyframes[(i/2)].transform, easing_index, _keyframes[(i/2)].type);
547+
__ApplyTransform(output_tuple, _keyframes[(i/2)].transform, easing_index, _keyframes[(i/2)].type);
547548
}
548549
}
549-
return std::make_from_tuple<T>(std::move(_initial_tuple));
550+
return std::make_from_tuple<T>(std::move(output_tuple));
550551
}
551552

552553
template <typename T>
@@ -646,6 +647,9 @@ void CF::Animation<T>::__ApplyTransform(TupleT&& transformed_tuple, std::vector<
646647
((out += (easing*transformer[idx++])), ...);
647648
else if (transform == TransformType::SCALE)
648649
((out *= (1+(easing*(transformer[idx++]-1)))), ...);
650+
else if (transform == TransformType::TO) {
651+
((out += ( easing * (transformer[idx++]-out) )), ...);
652+
}
649653

650654
}, std::forward<TupleT>(transformed_tuple));
651655
}

examples/colors.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,42 @@ int main() {
1515
.type = CF::TransformType::OFFSET,
1616
.transform = {200, 0, 0, 0},
1717
.easing_frames = 60,
18-
.held_frames = 10
18+
.held_frames = 0
1919
},
2020
{
2121
.type = CF::TransformType::OFFSET,
2222
.transform = {-100, -200, 0, 0},
2323
.easing_frames = 60,
24-
.held_frames = 10
24+
.held_frames = 0
2525
},
2626
{
2727
.type = CF::TransformType::OFFSET,
2828
.transform = {-100, 200, 0, 0},
2929
.easing_frames = 60,
30-
.held_frames = 10
30+
.held_frames = 0
3131
}
3232
};
3333

3434
std::vector<CF::Keyframe<Color>> color_keyframes = {
3535
{
36-
.type = CF::TransformType::OFFSET,
37-
.transform = {-255, 255, 0, 0},
36+
.type = CF::TransformType::TO,
37+
.transform = {0, 255, 0, 255},
38+
.easing_frames = 60,
39+
.held_frames = 0
3840

3941
},
4042
{
41-
.type = CF::TransformType::OFFSET,
42-
.transform = {0, -255, 255, 0},
43+
.type = CF::TransformType::TO,
44+
.transform = {0, 0, 255, 255},
45+
.easing_frames = 60,
46+
.held_frames = 0
4347

4448
},
4549
{
46-
.type = CF::TransformType::OFFSET,
47-
.transform = {255, 0, -255, 0},
50+
.type = CF::TransformType::TO,
51+
.transform = {255, 0, 0, 255},
52+
.easing_frames = 60,
53+
.held_frames = 0
4854

4955
}
5056
};
@@ -53,15 +59,22 @@ int main() {
5359
{
5460
.type = CF::TransformType::OFFSET,
5561
.transform = {1.0f},
56-
.easing_frames = 120
62+
.easing_frames = 60,
63+
.held_frames = 0
64+
},
65+
{
66+
.type = CF::TransformType::OFFSET,
67+
.transform = {-1.0},
68+
.easing_frames = 60,
69+
.held_frames = 0
5770
}
5871
};
5972

60-
CF::Animation<float> roundness = {0.0f, roundness_keyframes, CF::PlayMode::BOOMERANG_LOOP, CF::EasingFunction::QUADRATIC_IN_OUT};
73+
CF::Animation<float> roundness = {0.0f, roundness_keyframes, CF::PlayMode::LOOP, CF::EasingFunction::CUBIC_OUT};
6174

62-
CF::Animation<Rectangle> rectangle = {{200, 250, 60, 60}, rectangle_keyframes, CF::PlayMode::LOOP, CF::EasingFunction::QUADRATIC_IN_OUT};
75+
CF::Animation<Rectangle> rectangle = {{200, 250, 60, 60}, rectangle_keyframes, CF::PlayMode::LOOP, CF::EasingFunction::CUBIC_OUT};
6376

64-
CF::Animation<Color> color = {{255, 0, 0, 255}, color_keyframes, CF::PlayMode::BOOMERANG_LOOP, CF::EasingFunction::CUBIC_IN_OUT};
77+
CF::Animation<Color> color = {{255, 0, 0, 255}, color_keyframes, CF::PlayMode::LOOP, CF::EasingFunction::CUBIC_OUT};
6578

6679
while(!WindowShouldClose()) {
6780

0 commit comments

Comments
 (0)