From 5b4a191d1cf310a3d7a99351e716a1a60004be69 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Wed, 11 Nov 2026 09:32:30 +0300 Subject: publish --- src/main.c | 593 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 593 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..7200ffe --- /dev/null +++ b/src/main.c @@ -0,0 +1,593 @@ +#include +#include +#include +#include +#include +#include + +#define RAYGUI_IMPLEMENTATION +#include + +#include "retiming.h" +#include "cma-es.h" + +#define RGBA(HEX) (Color) { \ + (HEX) >> 3*8 & 0xFF, \ + (HEX) >> 2*8 & 0xFF, \ + (HEX) >> 1*8 & 0xFF, \ + (HEX) >> 0*8 & 0xFF, \ + } + +// #define LABEL_WIDTH 140 +#define LABEL_WIDTH 300 +#define SLIDER_WIDTH 40 +#define ITEM_WIDTH (LABEL_WIDTH + SLIDER_WIDTH) +#define ITEM_HEIGHT 15 +#define ITEM_MARGIN 5 +#define PANEL_WIDTH (ITEM_WIDTH + 2*ITEM_MARGIN) +#define PANEL_HEIGHT(N) (RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + (N)*(ITEM_HEIGHT + ITEM_MARGIN) + ITEM_MARGIN) + +#ifdef DARK +#define BACKGROUND RGBA (0x000000FF) +#else +#define BACKGROUND RGBA (0xFFFFFFFF) +#endif + +#define ARROW_THICKNESS 2.5 +#define ARROW_LENGTH 15 +#define ARROW_ANGLE 10 + +#define CONTROL_POINT_RADIUS 5 +#define CONTROL_POINT_RADIUS_FOCUSED 10 + +enum menu { + MENU_VISUALIZATION, + MENU_INPUT, + MENU_CHROMOSOME, + MENU_METRICS, + MENU_WEIGHTS, + MENU_COUNT +} menu = MENU_VISUALIZATION; + +const char *menu_to_label[] = { + [MENU_VISUALIZATION] = "VISUALIZATION", + [MENU_INPUT] = "INPUT", + [MENU_CHROMOSOME] = "CHROMOSOME", + [MENU_METRICS] = "METRICS", + [MENU_WEIGHTS] = "WEIGHTS", +}; + +struct fitness_breakdown fb; +struct fitness_weights w = { + .time = 1.5, + .length = 1.5, + .max_abs_kappa = 30, + .max_abs_dkappa = 30, + .max_abs_a = 30, + .max_abs_j = 25, + .rms_kappa = 2, + .rms_dkappa = 4, + .rms_a = 3, + .rms_j = 0.35, + .violation_a = 3.5, + .violation_j = 0.2, + .terminal = 100, +}; + +void +draw_arrow (Vector2 beg, Vector2 end, float thick, Color c) +{ + Vector2 off = Vector2Scale (Vector2Normalize (Vector2Subtract (end, beg)), + ARROW_LENGTH); + Vector2 ahl = Vector2Add (end, Vector2Rotate (off, +ARROW_ANGLE)); + Vector2 ahr = Vector2Add (end, Vector2Rotate (off, -ARROW_ANGLE)); + + DrawLineEx (beg, end, thick, c); + DrawLineEx (end, ahl, thick, c); + DrawLineEx (end, ahr, thick, c); + + DrawCircleV (beg, thick/2., c); + DrawCircleV (end, thick/2., c); + DrawCircleV (ahl, thick/2., c); + DrawCircleV (ahr, thick/2., c); +} + +void +draw_bezier5 (bezier5 cp) +{ + char text[] = "P0"; + DrawLineStrip (cp, 6, BLUE); + for (int i = 0; i < 6; ++i) { + DrawCircleLinesV (cp[i], 4, BLUE); + text[1] = '0' + i; + DrawText (text, cp[i].x - 5, cp[i].y + 7, 14, BLACK); + } +} + +void +chromosome_to_control_points (bezier5 cp, struct input in, struct chromosome ch) +{ + Vector2 e_beg = Vector2Normalize (in.v_beg); + Vector2 e_end = Vector2Normalize (in.v_end); + Vector2 n_beg = { -e_beg.y, +e_beg.x }; + Vector2 n_end = { -e_end.y, +e_end.x }; + + cp[0] = in.r_beg; + cp[1] = Vector2Add (in.r_beg, Vector2Scale (e_beg, +ch.rho*ch.tau_1)); + cp[2] = Vector2Add (in.r_beg, Vector2Scale (Vector2Add (Vector2Scale (e_beg, ch.alp_2), Vector2Scale (n_beg, ch.bet_2)), +ch.rho)); + cp[3] = Vector2Add (in.r_end, Vector2Scale (Vector2Add (Vector2Scale (e_end, ch.alp_3), Vector2Scale (n_end, ch.bet_3)), -ch.rho)); + cp[4] = Vector2Add (in.r_end, Vector2Scale (e_end, -ch.rho*ch.tau_4)); + cp[5] = in.r_end; +} + +struct chromosome +rand_chromosome (void) +{ + return (struct chromosome) { + 10 + 50 * (rand () /(float) RAND_MAX), + .5 + 5 * (rand () /(float) RAND_MAX), + .5 + 5 * (rand () /(float) RAND_MAX), + .5 + 5 * (rand () /(float) RAND_MAX), + .5 + 5 * (rand () /(float) RAND_MAX), + .5 + 5 * (rand () /(float) RAND_MAX), + .5 + 5 * (rand () /(float) RAND_MAX), + }; +} + +float sample_offset = 10; +float sample_spacing = PATH_SAMPLE_COUNT/4; +bool sample_dr = true; +bool sample_ddr = true; + +Color +lerp_color (Color a, Color b, float t) +{ + Color c; + c.r = (unsigned char) (a.r + (b.r - a.r)*t); + c.g = (unsigned char) (a.g + (b.g - a.g)*t); + c.b = (unsigned char) (a.b + (b.b - a.b)*t); + c.a = (unsigned char) (a.a + (b.a - a.a)*t); + return c; +} + +float ease_out_cubic (float x) { return 1 - powf (1 - x, 3); } +float ease_out_quint (float x) { return 1 - powf (1 - x, 5); } +float ease_out_sin (float x) { return sinf (PI*x/2); } +float ease_inout_sin (float x) { return -(cosf (PI*x) - 1)/2; } + +void +compute_ribbon_join (const struct path_table *p, int i, float half, + Vector2 *l, Vector2 *r) +{ + Vector2 t; + + if (i == 0) { + t = Vector2Normalize (Vector2Subtract (p->r[1], p->r[0])); + } else if (i == PATH_SAMPLE_COUNT - 1) { + t = Vector2Normalize (Vector2Subtract (p->r[i], p->r[i - 1])); + } else { + t = Vector2Normalize (Vector2Subtract (p->r[i + 1], p->r[i - 1])); + } + + Vector2 n = { -t.y, t.x }; + + *l = Vector2Add (p->r[i], Vector2Scale (n, half)); + *r = Vector2Add (p->r[i], Vector2Scale (n, -half)); +} + +void +draw_path_gradient_ribbon (const struct path_table *p, + float thick, Color c0, Color c1) +{ + if (PATH_SAMPLE_COUNT < 2 || thick <= 0) return; + + float half = thick/2; + + Vector2 l0, r0, l1, r1; + compute_ribbon_join (p, 0, half, &l0, &r0); + + rlBegin (RL_TRIANGLES); + for (int i = 0; i < PATH_SAMPLE_COUNT - 1; ++i) { + compute_ribbon_join (p, i + 1, half, &l1, &r1); + + float u0 = ease_out_cubic (fabsf (p->kappa[i + 0])/p->max_abs_kappa); + float u1 = ease_out_cubic (fabsf (p->kappa[i + 1])/p->max_abs_kappa); + + Color col0 = lerp_color (c0, c1, u0); + Color col1 = lerp_color (c0, c1, u1); + + rlColor4ub (col0.r, col0.g, col0.b, col0.a); rlVertex2f (l0.x, l0.y); + rlColor4ub (col1.r, col1.g, col1.b, col1.a); rlVertex2f (l1.x, l1.y); + rlColor4ub (col0.r, col0.g, col0.b, col0.a); rlVertex2f (r0.x, r0.y); + + rlColor4ub (col0.r, col0.g, col0.b, col0.a); rlVertex2f (r0.x, r0.y); + rlColor4ub (col1.r, col1.g, col1.b, col1.a); rlVertex2f (l1.x, l1.y); + rlColor4ub (col1.r, col1.g, col1.b, col1.a); rlVertex2f (r1.x, r1.y); + + l0 = l1; + r0 = r1; + } rlEnd (); +} + +void +draw_path (const struct path_table *p, float thick) +{ + const int c = PATH_SAMPLE_COUNT; + // DrawCircleV (p->r[ 0], thick/2., BLUE); + // DrawCircleV (p->r[c - 1], thick/2., BLUE); + draw_path_gradient_ribbon (p, thick, BLUE, RED); + for (int i = sample_offset; i < c; i += sample_spacing) { + Vector2 r = p->r[i]; + if (sample_dr ) draw_arrow (r, Vector2Add (r, Vector2Scale (Vector2Normalize (p-> dr[i]), 30)), thick/2, MAGENTA); + if (sample_ddr) draw_arrow (r, Vector2Add (r, Vector2Scale (Vector2Normalize (p->ddr[i]), 30)), thick/2, PURPLE); + } +} + +void +plot_motion_profile (Rectangle bb, const struct motion_profile *mp, + float v_max, float a_max, float j_max) +{ + const int n = PATH_SAMPLE_COUNT; + static Vector2 line[PATH_SAMPLE_COUNT]; + + float t = mp->t[n - 1]; + for (int i = 0; i < n; ++i) + line[i].x = Lerp (bb.x, bb.x + bb.width, mp->t[i]/t); + + // axis + Vector2 origin = { bb.x, bb.y + bb.height /(float) 2 }; + DrawLineEx (origin, Vector2Add (origin, (Vector2) { bb.width, 0 }), 1, GRAY); + for (int i = 0; i < n; ++i) { + DrawLineEx ((Vector2) { line[i].x, origin.y + 5 }, + (Vector2) { line[i].x, origin.y - 5 }, 1, GRAY); + } + + // velocity + for (int i = 0; i < n; ++i) + line[i].y = Lerp (origin.y, bb.y + 2, mp->v[i]/fabsf (mp->v_max)); + DrawSplineBezierCubic (line, n, 1, BLUE); + + // acceleration + for (int i = 0; i < n; ++i) + line[i].y = Lerp (origin.y, bb.y + 2, mp->a[i]/fabsf (mp->a_max)); + DrawSplineBezierCubic (line, n, 1, ORANGE); + + // jerk + for (int i = 0; i < n; ++i) + line[i].y = Lerp (origin.y, bb.y + 2, mp->j[i]/fabsf (mp->j_max)); + DrawSplineBezierCubic (line, n, 1, RED); +} + +int +panel_slider (int x, int y, int c, const char *label, const char *fmt, float *var, float min, float max) +{ + GuiLabel ((Rectangle) { x + ITEM_MARGIN, y + c*(ITEM_HEIGHT + ITEM_MARGIN), LABEL_WIDTH, ITEM_HEIGHT }, TextFormat ("%s: %s", label, TextFormat (fmt, *var))); + return GuiSliderBar ((Rectangle) { x + ITEM_MARGIN + LABEL_WIDTH, y + c*(ITEM_HEIGHT + ITEM_MARGIN), SLIDER_WIDTH, ITEM_HEIGHT }, NULL, NULL, var, min, max); +} + +int +panel_var (int x, int y, int c, const char *label, const char *fmt, float *var) +{ + GuiLabel ((Rectangle) { x + ITEM_MARGIN, y + c*(ITEM_HEIGHT + ITEM_MARGIN), ITEM_WIDTH, ITEM_HEIGHT }, + TextFormat ("%s: %s", label, TextFormat (fmt, *var))); + return 0; +} + +int +panel_bool (int x, int y, int c, const char *label, bool *checked) +{ + return GuiCheckBox ((Rectangle) { + x + ITEM_MARGIN, y + c*(ITEM_HEIGHT + ITEM_MARGIN), + ITEM_HEIGHT, ITEM_HEIGHT + }, label, checked); +} + +int +main (int argc, char *argv[]) +{ + srand (time (NULL)); + + SetConfigFlags (FLAG_MSAA_4X_HINT); + SetConfigFlags (FLAG_WINDOW_RESIZABLE); + InitWindow (800, 450, "GA"); + SetTargetFPS (60); + + Camera2D camera = { + .zoom = 1.0f, + }; + + Vector2 screen = { + .x = GetScreenWidth (), + .y = GetScreenHeight (), + }; + + GuiSetStyle(DEFAULT, TEXT_SIZE, 20); + // GuiGetStyle (); + + struct input in = { + .r_beg = { 100, 100 }, + // .r_end = { 100, 100 }, + .r_end = { 300, 300 }, + .v_beg = { 100, 10 }, + .v_end = { 100, 10 }, + .v_max = 250, + .a_max = 500, + .j_max = 16, + }; + + bezier5 cp; + struct chromosome ch = rand_chromosome (); + struct path_table pt; + struct motion_profile mp; + + float arrow_thickness = ARROW_THICKNESS; + float spline_thickness = ARROW_THICKNESS; + bool move_r_beg = false; + bool move_r_end = false; + bool move_v_beg = false; + bool move_v_end = false; + bool recompute = true; + bool show_fps = true; + bool show_menu = true; + bool show_graph = true; + bool draw_cp = true; + bool animate_sample_offset = false; + float animation_speed = 20; + int panel_item = 0; + bool resizing_graph = false; + int graph_height = screen.y/3; + while (!WindowShouldClose ()) { + screen = (Vector2) { + .x = GetScreenWidth (), + .y = GetScreenHeight (), + }; + float t = GetTime (); + float dt = GetFrameTime (); + + if (IsMouseButtonDown (MOUSE_BUTTON_RIGHT)) { + Vector2 delta = GetMouseDelta (); + delta = Vector2Scale (delta, -1.0f/camera.zoom); + camera.target = Vector2Add (camera.target, delta); + } + + if (IsKeyPressed (KEY_LEFT )) menu = menu ? menu - 1 : MENU_COUNT - 1; + if (IsKeyPressed (KEY_RIGHT)) menu = menu < MENU_COUNT - 1 ? menu + 1 : 0; + + if (IsKeyPressed (KEY_R)) { + ch = rand_chromosome (); + recompute = true; + } + + if (IsKeyDown (KEY_O)) { + struct chromosome res; + float cost; + example_cmaes_usage (&in, &ch, &w, &res, &cost); + ch = res; + recompute = true; + } + + if (IsKeyPressed (KEY_M)) show_menu = !show_menu; + if (IsKeyPressed (KEY_G)) show_graph = !show_graph; + if (IsKeyPressed (KEY_F)) show_fps = !show_fps; + + if (recompute) { + chromosome_to_control_points (cp, in, ch); + build_path_table (&pt, cp); + build_motion_profile (&mp, &pt, + Vector2Length (in.v_beg), + Vector2Length (in.v_end), + in.v_max, in.a_max, in.j_max); + fb = evaluate_motion_fitness (&pt, &mp, + Vector2Length (in.v_beg), + Vector2Length (in.v_end), + in.v_max, in.a_max, in.j_max, &w); + + recompute = false; + } + + float wheel = GetMouseWheelMove(); + if (wheel != 0) { + Vector2 offset = GetMousePosition (); + camera.target = GetScreenToWorld2D (offset, camera); + camera.offset = offset; + camera.zoom = Clamp (expf (logf (camera.zoom) + .2*wheel), .125, 64); + } + + Vector2 mouse_hud = GetMousePosition (); + Vector2 mouse = GetScreenToWorld2D (mouse_hud, camera); + + if (IsMouseButtonDown (MOUSE_BUTTON_LEFT) + && mouse_hud.y > screen.y - graph_height + && mouse_hud.y < screen.y - graph_height + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT) { + resizing_graph = true; + } + + if (resizing_graph) { + graph_height = Clamp (RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + 2, screen.y - 4, + screen.y - mouse_hud.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT/2); + if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT)) + resizing_graph = false; + } + + BeginDrawing (); + ClearBackground (BACKGROUND); + BeginMode2D (camera); + + if (CheckCollisionPointCircle (mouse, in.r_beg, 10)) { + DrawCircleLinesV (in.r_beg, 10, BLUE); + if (!move_v_beg && IsMouseButtonDown (MOUSE_BUTTON_LEFT)) + move_r_beg = true; + } else if (CheckCollisionPointCircle (mouse, in.r_end, 10)) { + DrawCircleLinesV (in.r_end, 10, BLUE); + if (!move_v_end && IsMouseButtonDown (MOUSE_BUTTON_LEFT)) + move_r_end = true; + } else if (CheckCollisionPointCircle (mouse, Vector2Add (in.r_beg, in.v_beg), 10)) { + DrawCircleLinesV (Vector2Add (in.r_beg, in.v_beg), 10, BLUE); + if (!move_r_beg && IsMouseButtonDown (MOUSE_BUTTON_LEFT)) + move_v_beg = true; + } else if (CheckCollisionPointCircle (mouse, Vector2Add (in.r_end, in.v_end), 10)) { + DrawCircleLinesV (Vector2Add (in.r_end, in.v_end), 10, BLUE); + if (!move_r_end && IsMouseButtonDown (MOUSE_BUTTON_LEFT)) + move_v_end = true; + } + + if (move_r_beg) { + in.r_beg = mouse; + if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT)) + move_r_beg = false; + } + if (move_r_end) { + in.r_end = mouse; + if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT)) + move_r_end = false; + } + if (move_v_beg) { + in.v_beg = Vector2Subtract (mouse, in.r_beg); + if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT)) + move_v_beg = false; + } + if (move_v_end) { + in.v_end = Vector2Subtract (mouse, in.r_end); + if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT)) + move_v_end = false; + } + + if (animate_sample_offset) + sample_offset = (int) (animation_speed*t) % (int) sample_spacing; + + // rlPushMatrix (); + // rlTranslatef (0, 25*50, 0); + // rlRotatef (90, 1, 0, 0); + // DrawGrid (100, 50); + // rlPopMatrix (); + + draw_path (&pt, spline_thickness); + if (draw_cp) draw_bezier5 (cp); + draw_arrow (in.r_beg, Vector2Add (in.r_beg, in.v_beg), arrow_thickness, GREEN); + draw_arrow (in.r_end, Vector2Add (in.r_end, in.v_end), arrow_thickness, RED); + + EndMode2D (); + + if (move_r_beg || + move_r_end || + move_v_beg || + move_v_end) { + GuiLock (); + recompute = true; + } + + if (show_menu) { + int x = 2; + int y = 2; + + GuiPanel ((Rectangle) { x, y, PANEL_WIDTH, PANEL_HEIGHT (panel_item) }, menu_to_label[menu]); + y += RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT; + y += ITEM_MARGIN; + panel_item = 0; + switch (menu) { + case MENU_VISUALIZATION: + panel_slider (x, y, panel_item++, "Arrow", "%.2f", &arrow_thickness, 1, 10); + panel_slider (x, y, panel_item++, "Spline", "%.2f", &spline_thickness, 1, 10); + panel_slider (x, y, panel_item++, "Spacing", "%.0f", &sample_spacing, 2, PATH_SAMPLE_COUNT - 1); + panel_slider (x, y, panel_item++, "Offset", "%.0f", &sample_offset, 0, sample_spacing); + panel_slider (x, y, panel_item++, "Speed", "%.0f", &animation_speed, 0, 30); + panel_bool (x, y, panel_item++, "Animate offset", &animate_sample_offset); + panel_bool (x, y, panel_item++, "Draw dr", &sample_dr); + panel_bool (x, y, panel_item++, "Draw ddr", &sample_ddr); + panel_bool (x, y, panel_item++, "Draw cp", &draw_cp); + break; + + case MENU_INPUT: + recompute |= panel_slider (x, y, panel_item++, "v_lim", "%.2f", &in.v_max, fmaxf (Vector2Length (in.v_beg), Vector2Length (in.v_beg)), 500); + recompute |= panel_slider (x, y, panel_item++, "a_lim", "%.2f", &in.a_max, 1, 500); + recompute |= panel_slider (x, y, panel_item++, "j_lim", "%.2f", &in.j_max, 1, 100); + panel_var (x, y, panel_item++, "r_beg.x", "%.2f", &in.r_beg.x); + panel_var (x, y, panel_item++, "r_beg.y", "%.2f", &in.r_beg.y); + panel_var (x, y, panel_item++, "r_end.x", "%.2f", &in.r_end.x); + panel_var (x, y, panel_item++, "r_end.y", "%.2f", &in.r_end.y); + panel_var (x, y, panel_item++, "v_beg.x", "%.2f", &in.v_beg.x); + panel_var (x, y, panel_item++, "v_beg.y", "%.2f", &in.v_beg.y); + panel_var (x, y, panel_item++, "v_end.x", "%.2f", &in.v_end.x); + panel_var (x, y, panel_item++, "v_end.y", "%.2f", &in.v_end.y); + break; + + case MENU_CHROMOSOME: + recompute |= panel_slider (x, y, panel_item++, "rho", "%.2f", &ch.rho, 1, 1000); + recompute |= panel_slider (x, y, panel_item++, "tau_1", "%.2f", &ch.tau_1, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "alpha_2", "%.2f", &ch.alp_2, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "beta_2", "%+.2f", &ch.bet_2, -5, 5); + recompute |= panel_slider (x, y, panel_item++, "alpha_3", "%.2f", &ch.alp_3, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "beta_3", "%+.2f", &ch.bet_3, -5, 5); + recompute |= panel_slider (x, y, panel_item++, "tau_4", "%.2f", &ch.tau_4, 0, 10); + break; + + case MENU_WEIGHTS: + recompute |= panel_slider (x, y, panel_item++, "w_time", "%.2f", &w.time, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "w_length", "%.2f", &w.length, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "w_max_kappa", "%.2f", &w.max_abs_kappa, 0, 100); + recompute |= panel_slider (x, y, panel_item++, "w_max_dkappa", "%.2f", &w.max_abs_dkappa, 0, 100); + recompute |= panel_slider (x, y, panel_item++, "w_max_a", "%.2f", &w.max_abs_a, 0, 100); + recompute |= panel_slider (x, y, panel_item++, "w_max_j", "%.2f", &w.max_abs_j, 0, 100); + recompute |= panel_slider (x, y, panel_item++, "w_rms_kappa", "%.2f", &w.rms_kappa, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "w_rms_dkappa", "%.2f", &w.rms_dkappa, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "w_rms_a", "%.2f", &w.rms_a, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "w_rms_j", "%.2f", &w.rms_j, 0, 1); + recompute |= panel_slider (x, y, panel_item++, "w_violation_a", "%.2f", &w.violation_a, 0, 10); + recompute |= panel_slider (x, y, panel_item++, "w_violation_j", "%.2f", &w.violation_j, 0, 1); + recompute |= panel_slider (x, y, panel_item++, "w_terminal", "%.2f", &w.terminal, 0, 100); + break; + + case MENU_METRICS: + panel_var (x, y, panel_item++, "Length", "%.2f", &pt.s[PATH_SAMPLE_COUNT - 1]); + panel_var (x, y, panel_item++, "Duration", "%.2f", &mp.t[PATH_SAMPLE_COUNT - 1]); + panel_var (x, y, panel_item++, "Cost", "%.2f", &fb.total_cost); + + panel_var (x, y, panel_item++, "v_max", "%.2f", &mp.v_max); + panel_var (x, y, panel_item++, "a_max", "%.2f", &mp.a_max); + panel_var (x, y, panel_item++, "j_max", "%.2f", &mp.j_max); + + panel_var (x, y, panel_item++, "time_cost", "%.2f", &fb.time_cost); + panel_var (x, y, panel_item++, "length_cost", "%.2f", &fb.length_cost); + panel_var (x, y, panel_item++, "kappa_cost", "%.2f", &fb.kappa_cost); + panel_var (x, y, panel_item++, "dkappa_cost", "%.2f", &fb.dkappa_cost); + panel_var (x, y, panel_item++, "accel_rms_cost", "%.2f", &fb.accel_rms_cost); + panel_var (x, y, panel_item++, "jerk_rms_cost", "%.2f", &fb.jerk_rms_cost); + panel_var (x, y, panel_item++, "accel_violation_cost", "%.2f", &fb.accel_violation_cost); + panel_var (x, y, panel_item++, "jerk_violation_cost", "%.2f", &fb.jerk_violation_cost); + panel_var (x, y, panel_item++, "terminal_cost", "%.2f", &fb.terminal_cost); + panel_var (x, y, panel_item++, "failure_cost", "%.2f", &fb.failure_cost); + panel_var (x, y, panel_item++, "duration", "%.2f", &fb.duration); + panel_var (x, y, panel_item++, "length", "%.2f", &fb.length); + panel_var (x, y, panel_item++, "kappa_rms", "%.2f", &fb.kappa_rms); + panel_var (x, y, panel_item++, "dkappa_rms", "%.2f", &fb.dkappa_rms); + panel_var (x, y, panel_item++, "accel_rms", "%.2f", &fb.accel_rms); + panel_var (x, y, panel_item++, "jerk_rms", "%.2f", &fb.jerk_rms); + panel_var (x, y, panel_item++, "accel_violation", "%.2f", &fb.accel_violation); + panel_var (x, y, panel_item++, "jerk_violation", "%.2f", &fb.jerk_violation); + break; + default: break; + } + } + GuiUnlock (); + + if (show_graph) { + Rectangle bb; + bb.x = 2; + bb.width = screen.x - 4; + bb.height = graph_height; + bb.y = screen.y - 2 - bb.height; + GuiPanel (bb, "GRAPH"); + bb.y += RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT; + bb.height -= RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT; + plot_motion_profile (bb, &mp, in.v_max, in.a_max, in.j_max); + } + + if (show_fps) + DrawFPS (screen.x - 75, 0); + EndDrawing (); + } + + CloseWindow (); + + return EXIT_SUCCESS; +} -- cgit v1.3.1