Brunot
Loading...
Searching...
No Matches
imgui_bezier.hpp
Go to the documentation of this file.
1#pragma once
2
3#define IMGUI_DEFINE_MATH_OPERATORS
4#include <imgui.h>
5#include <imgui_internal.h>
6#include <time.h>
7
8namespace ImGui
9{
10template <int steps>
11auto bezier_table(ImVec2 P[], ImVec2 results[]) -> void
12{
13 static float C[(steps + 1) * 4], *K = nullptr;
14 if (!K)
15 {
16 K = C;
17 for (unsigned step = 0; step <= steps; ++step)
18 {
19 auto t = static_cast<float>(step) / static_cast<float>(steps);
20 C[step * 4 + 0] = (1 - t) * (1 - t) * (1 - t); // * P0
21 C[step * 4 + 1] = 3 * (1 - t) * (1 - t) * t; // * P1
22 C[step * 4 + 2] = 3 * (1 - t) * t * t; // * P2
23 C[step * 4 + 3] = t * t * t; // * P3
24 }
25 }
26 for (unsigned step = 0; step <= steps; ++step)
27 {
28 ImVec2 point = {
29 K[step * 4 + 0] * P[0].x + K[step * 4 + 1] * P[1].x + K[step * 4 + 2] * P[2].x + K[step * 4 + 3] * P[3].
30 x,
31 K[step * 4 + 0] * P[0].y + K[step * 4 + 1] * P[1].y + K[step * 4 + 2] * P[2].y + K[step * 4 + 3] * P[3].
32 y};
33 results[step] = point;
34 }
35}
36
37auto BezierValue(float dt01, float P[4]) -> float;
38
39auto Bezier(const char* label, float P[5]) -> int;
40
41// void ShowBezierDemo() {
42// { static float v[5] = { 0.950f, 0.050f, 0.795f, 0.035f };
43// Bezier("easeInExpo", v); }
44//}
45} // namespace ImGui
@ C
Definition Card.h:26
Definition imgui_bezier.cpp:4
auto Bezier(const char *label, float P[]) -> int
Definition imgui_bezier.cpp:15
auto bezier_table(ImVec2 P[], ImVec2 results[]) -> void
Definition imgui_bezier.hpp:11
auto BezierValue(float dt01, float P[]) -> float
Definition imgui_bezier.cpp:6