Tatooine
bezier_widget.h
Go to the documentation of this file.
1#ifndef TATOOINE_BEZIER_WIDGET
2#define TATOOINE_BEZIER_WIDGET
3#include <vector>
9#define IMGUI_DEFINE_MATH_OPERATORS
10#include <imgui.h>
11
12//==============================================================================
13namespace ImGui {
14//==============================================================================
15auto BezierValue(float dt01, std::vector<float> const& handles) -> float;
16//------------------------------------------------------------------------------
17auto Bezier(const char* label, std::vector<float>& handles) -> int;
18//------------------------------------------------------------------------------
19template <int steps>
20auto BezierTable(ImVec2 P[4], ImVec2 results[steps + 1]) -> void {
21 static float C[(steps + 1) * 4], *K = 0;
22 if (!K) {
23 K = C;
24 for (unsigned step = 0; step <= steps; ++step) {
25 float t = (float)step / (float)steps;
26 C[step * 4 + 0] = (1 - t) * (1 - t) * (1 - t); // * P0
27 C[step * 4 + 1] = 3 * (1 - t) * (1 - t) * t; // * P1
28 C[step * 4 + 2] = 3 * (1 - t) * t * t; // * P2
29 C[step * 4 + 3] = t * t * t; // * P3
30 }
31 }
32 for (unsigned step = 0; step <= steps; ++step) {
33 ImVec2 point = {K[step * 4 + 0] * P[0].x + K[step * 4 + 1] * P[1].x +
34 K[step * 4 + 2] * P[3].x + K[step * 4 + 3] * P[2].x,
35 K[step * 4 + 0] * P[0].y + K[step * 4 + 1] * P[1].y +
36 K[step * 4 + 2] * P[3].y + K[step * 4 + 3] * P[2].y};
37 results[step] = point;
38 }
39}
40//==============================================================================
41} // namespace ImGui
42//==============================================================================
43#endif
Definition: bezier_widget.h:13
auto Bezier(const char *label, std::vector< float > &handles) -> int
auto BezierValue(float dt01, std::vector< float > const &handles) -> float
auto BezierTable(ImVec2 P[4], ImVec2 results[steps+1]) -> void
Definition: bezier_widget.h:20