Brunot
Loading...
Searching...
No Matches
Bezier.h
Go to the documentation of this file.
1
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15
16
17#pragma once
18// undef some macros because they're conflicting and causing issues
19#undef max
20#undef min
21
24
25
26namespace th
27{
28
29struct Bezier
30{
31 Bezier() = default;
32
33 Bezier(Vector4D handle1, Vector4D handle2);
34
35
41 auto operator()(float t) -> float;
42
43
53 template <typename P>
54 auto operator()(float t, const P& begin, const P& end) -> P
55 {
56 return value(t, begin, end);
57 }
58
59
65 auto value(float t) -> float;
66
75 template <typename P>
76 auto value(float t, const P& start, const P& end) -> P
77 {
78 // starts at 0, ends at 1
79 auto fromEnd = value(t);
80 // starts at 1, ends at 0
81 auto fromBegin = 1 - fromEnd;
82
83 return fromBegin * start + fromEnd * end;
84 }
85
90 auto data() -> float*;
91
92
93 friend auto to_json(json& j, const Bezier& n) -> void;
94
95 friend auto from_json(const json& j, Bezier& n) -> void;
96
97private:
99 float handles[4] = {0.455f, 0.030f, 0.515f, 0.955f};
100
102 float selectedPreset = 0.f;
103
104};
105
106}
nlohmann::json json
Definition Json.cpp:19
Definition Factory.cpp:62
Definition Vector4D.h:23
Definition Bezier.h:30
auto operator()(float t, const P &begin, const P &end) -> P
interpolates between 2 values, using the bezier curve just calls value
Definition Bezier.h:54
auto operator()(float t) -> float
evaluates the bezier at a point along the curve.
Definition Bezier.cpp:26
friend auto from_json(const json &j, Bezier &n) -> void
Definition Bezier.cpp:50
auto data() -> float *
pointer to raw memory of bezier, for editors purposes
Definition Bezier.cpp:36
friend auto to_json(json &j, const Bezier &n) -> void
Definition Bezier.cpp:41
float handles[4]
the handles for the curve, in order, x1, y1, x2, y2. Defaults to InOut Quadradic Easing
Definition Bezier.h:99
auto value(float t, const P &start, const P &end) -> P
interpolates between 2 values, using the bezier curve
Definition Bezier.h:76
auto value(float t) -> float
evaluetates the bezier at a single point along it's curve
Definition Bezier.cpp:31
Bezier()=default
float selectedPreset
Extra float for use by imgui_bezier editor. If we refactor imgui_bezier, we might not need this.
Definition Bezier.h:102