aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c593
1 files changed, 593 insertions, 0 deletions
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 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <time.h>
4#include <raylib.h>
5#include <rlgl.h>
6#include <raymath.h>
7
8#define RAYGUI_IMPLEMENTATION
9#include <raygui.h>
10
11#include "retiming.h"
12#include "cma-es.h"
13
14#define RGBA(HEX) (Color) { \
15 (HEX) >> 3*8 & 0xFF, \
16 (HEX) >> 2*8 & 0xFF, \
17 (HEX) >> 1*8 & 0xFF, \
18 (HEX) >> 0*8 & 0xFF, \
19 }
20
21// #define LABEL_WIDTH 140
22#define LABEL_WIDTH 300
23#define SLIDER_WIDTH 40
24#define ITEM_WIDTH (LABEL_WIDTH + SLIDER_WIDTH)
25#define ITEM_HEIGHT 15
26#define ITEM_MARGIN 5
27#define PANEL_WIDTH (ITEM_WIDTH + 2*ITEM_MARGIN)
28#define PANEL_HEIGHT(N) (RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + (N)*(ITEM_HEIGHT + ITEM_MARGIN) + ITEM_MARGIN)
29
30#ifdef DARK
31#define BACKGROUND RGBA (0x000000FF)
32#else
33#define BACKGROUND RGBA (0xFFFFFFFF)
34#endif
35
36#define ARROW_THICKNESS 2.5
37#define ARROW_LENGTH 15
38#define ARROW_ANGLE 10
39
40#define CONTROL_POINT_RADIUS 5
41#define CONTROL_POINT_RADIUS_FOCUSED 10
42
43enum menu {
44 MENU_VISUALIZATION,
45 MENU_INPUT,
46 MENU_CHROMOSOME,
47 MENU_METRICS,
48 MENU_WEIGHTS,
49 MENU_COUNT
50} menu = MENU_VISUALIZATION;
51
52const char *menu_to_label[] = {
53 [MENU_VISUALIZATION] = "VISUALIZATION",
54 [MENU_INPUT] = "INPUT",
55 [MENU_CHROMOSOME] = "CHROMOSOME",
56 [MENU_METRICS] = "METRICS",
57 [MENU_WEIGHTS] = "WEIGHTS",
58};
59
60struct fitness_breakdown fb;
61struct fitness_weights w = {
62 .time = 1.5,
63 .length = 1.5,
64 .max_abs_kappa = 30,
65 .max_abs_dkappa = 30,
66 .max_abs_a = 30,
67 .max_abs_j = 25,
68 .rms_kappa = 2,
69 .rms_dkappa = 4,
70 .rms_a = 3,
71 .rms_j = 0.35,
72 .violation_a = 3.5,
73 .violation_j = 0.2,
74 .terminal = 100,
75};
76
77void
78draw_arrow (Vector2 beg, Vector2 end, float thick, Color c)
79{
80 Vector2 off = Vector2Scale (Vector2Normalize (Vector2Subtract (end, beg)),
81 ARROW_LENGTH);
82 Vector2 ahl = Vector2Add (end, Vector2Rotate (off, +ARROW_ANGLE));
83 Vector2 ahr = Vector2Add (end, Vector2Rotate (off, -ARROW_ANGLE));
84
85 DrawLineEx (beg, end, thick, c);
86 DrawLineEx (end, ahl, thick, c);
87 DrawLineEx (end, ahr, thick, c);
88
89 DrawCircleV (beg, thick/2., c);
90 DrawCircleV (end, thick/2., c);
91 DrawCircleV (ahl, thick/2., c);
92 DrawCircleV (ahr, thick/2., c);
93}
94
95void
96draw_bezier5 (bezier5 cp)
97{
98 char text[] = "P0";
99 DrawLineStrip (cp, 6, BLUE);
100 for (int i = 0; i < 6; ++i) {
101 DrawCircleLinesV (cp[i], 4, BLUE);
102 text[1] = '0' + i;
103 DrawText (text, cp[i].x - 5, cp[i].y + 7, 14, BLACK);
104 }
105}
106
107void
108chromosome_to_control_points (bezier5 cp, struct input in, struct chromosome ch)
109{
110 Vector2 e_beg = Vector2Normalize (in.v_beg);
111 Vector2 e_end = Vector2Normalize (in.v_end);
112 Vector2 n_beg = { -e_beg.y, +e_beg.x };
113 Vector2 n_end = { -e_end.y, +e_end.x };
114
115 cp[0] = in.r_beg;
116 cp[1] = Vector2Add (in.r_beg, Vector2Scale (e_beg, +ch.rho*ch.tau_1));
117 cp[2] = Vector2Add (in.r_beg, Vector2Scale (Vector2Add (Vector2Scale (e_beg, ch.alp_2), Vector2Scale (n_beg, ch.bet_2)), +ch.rho));
118 cp[3] = Vector2Add (in.r_end, Vector2Scale (Vector2Add (Vector2Scale (e_end, ch.alp_3), Vector2Scale (n_end, ch.bet_3)), -ch.rho));
119 cp[4] = Vector2Add (in.r_end, Vector2Scale (e_end, -ch.rho*ch.tau_4));
120 cp[5] = in.r_end;
121}
122
123struct chromosome
124rand_chromosome (void)
125{
126 return (struct chromosome) {
127 10 + 50 * (rand () /(float) RAND_MAX),
128 .5 + 5 * (rand () /(float) RAND_MAX),
129 .5 + 5 * (rand () /(float) RAND_MAX),
130 .5 + 5 * (rand () /(float) RAND_MAX),
131 .5 + 5 * (rand () /(float) RAND_MAX),
132 .5 + 5 * (rand () /(float) RAND_MAX),
133 .5 + 5 * (rand () /(float) RAND_MAX),
134 };
135}
136
137float sample_offset = 10;
138float sample_spacing = PATH_SAMPLE_COUNT/4;
139bool sample_dr = true;
140bool sample_ddr = true;
141
142Color
143lerp_color (Color a, Color b, float t)
144{
145 Color c;
146 c.r = (unsigned char) (a.r + (b.r - a.r)*t);
147 c.g = (unsigned char) (a.g + (b.g - a.g)*t);
148 c.b = (unsigned char) (a.b + (b.b - a.b)*t);
149 c.a = (unsigned char) (a.a + (b.a - a.a)*t);
150 return c;
151}
152
153float ease_out_cubic (float x) { return 1 - powf (1 - x, 3); }
154float ease_out_quint (float x) { return 1 - powf (1 - x, 5); }
155float ease_out_sin (float x) { return sinf (PI*x/2); }
156float ease_inout_sin (float x) { return -(cosf (PI*x) - 1)/2; }
157
158void
159compute_ribbon_join (const struct path_table *p, int i, float half,
160 Vector2 *l, Vector2 *r)
161{
162 Vector2 t;
163
164 if (i == 0) {
165 t = Vector2Normalize (Vector2Subtract (p->r[1], p->r[0]));
166 } else if (i == PATH_SAMPLE_COUNT - 1) {
167 t = Vector2Normalize (Vector2Subtract (p->r[i], p->r[i - 1]));
168 } else {
169 t = Vector2Normalize (Vector2Subtract (p->r[i + 1], p->r[i - 1]));
170 }
171
172 Vector2 n = { -t.y, t.x };
173
174 *l = Vector2Add (p->r[i], Vector2Scale (n, half));
175 *r = Vector2Add (p->r[i], Vector2Scale (n, -half));
176}
177
178void
179draw_path_gradient_ribbon (const struct path_table *p,
180 float thick, Color c0, Color c1)
181{
182 if (PATH_SAMPLE_COUNT < 2 || thick <= 0) return;
183
184 float half = thick/2;
185
186 Vector2 l0, r0, l1, r1;
187 compute_ribbon_join (p, 0, half, &l0, &r0);
188
189 rlBegin (RL_TRIANGLES);
190 for (int i = 0; i < PATH_SAMPLE_COUNT - 1; ++i) {
191 compute_ribbon_join (p, i + 1, half, &l1, &r1);
192
193 float u0 = ease_out_cubic (fabsf (p->kappa[i + 0])/p->max_abs_kappa);
194 float u1 = ease_out_cubic (fabsf (p->kappa[i + 1])/p->max_abs_kappa);
195
196 Color col0 = lerp_color (c0, c1, u0);
197 Color col1 = lerp_color (c0, c1, u1);
198
199 rlColor4ub (col0.r, col0.g, col0.b, col0.a); rlVertex2f (l0.x, l0.y);
200 rlColor4ub (col1.r, col1.g, col1.b, col1.a); rlVertex2f (l1.x, l1.y);
201 rlColor4ub (col0.r, col0.g, col0.b, col0.a); rlVertex2f (r0.x, r0.y);
202
203 rlColor4ub (col0.r, col0.g, col0.b, col0.a); rlVertex2f (r0.x, r0.y);
204 rlColor4ub (col1.r, col1.g, col1.b, col1.a); rlVertex2f (l1.x, l1.y);
205 rlColor4ub (col1.r, col1.g, col1.b, col1.a); rlVertex2f (r1.x, r1.y);
206
207 l0 = l1;
208 r0 = r1;
209 } rlEnd ();
210}
211
212void
213draw_path (const struct path_table *p, float thick)
214{
215 const int c = PATH_SAMPLE_COUNT;
216 // DrawCircleV (p->r[ 0], thick/2., BLUE);
217 // DrawCircleV (p->r[c - 1], thick/2., BLUE);
218 draw_path_gradient_ribbon (p, thick, BLUE, RED);
219 for (int i = sample_offset; i < c; i += sample_spacing) {
220 Vector2 r = p->r[i];
221 if (sample_dr ) draw_arrow (r, Vector2Add (r, Vector2Scale (Vector2Normalize (p-> dr[i]), 30)), thick/2, MAGENTA);
222 if (sample_ddr) draw_arrow (r, Vector2Add (r, Vector2Scale (Vector2Normalize (p->ddr[i]), 30)), thick/2, PURPLE);
223 }
224}
225
226void
227plot_motion_profile (Rectangle bb, const struct motion_profile *mp,
228 float v_max, float a_max, float j_max)
229{
230 const int n = PATH_SAMPLE_COUNT;
231 static Vector2 line[PATH_SAMPLE_COUNT];
232
233 float t = mp->t[n - 1];
234 for (int i = 0; i < n; ++i)
235 line[i].x = Lerp (bb.x, bb.x + bb.width, mp->t[i]/t);
236
237 // axis
238 Vector2 origin = { bb.x, bb.y + bb.height /(float) 2 };
239 DrawLineEx (origin, Vector2Add (origin, (Vector2) { bb.width, 0 }), 1, GRAY);
240 for (int i = 0; i < n; ++i) {
241 DrawLineEx ((Vector2) { line[i].x, origin.y + 5 },
242 (Vector2) { line[i].x, origin.y - 5 }, 1, GRAY);
243 }
244
245 // velocity
246 for (int i = 0; i < n; ++i)
247 line[i].y = Lerp (origin.y, bb.y + 2, mp->v[i]/fabsf (mp->v_max));
248 DrawSplineBezierCubic (line, n, 1, BLUE);
249
250 // acceleration
251 for (int i = 0; i < n; ++i)
252 line[i].y = Lerp (origin.y, bb.y + 2, mp->a[i]/fabsf (mp->a_max));
253 DrawSplineBezierCubic (line, n, 1, ORANGE);
254
255 // jerk
256 for (int i = 0; i < n; ++i)
257 line[i].y = Lerp (origin.y, bb.y + 2, mp->j[i]/fabsf (mp->j_max));
258 DrawSplineBezierCubic (line, n, 1, RED);
259}
260
261int
262panel_slider (int x, int y, int c, const char *label, const char *fmt, float *var, float min, float max)
263{
264 GuiLabel ((Rectangle) { x + ITEM_MARGIN, y + c*(ITEM_HEIGHT + ITEM_MARGIN), LABEL_WIDTH, ITEM_HEIGHT }, TextFormat ("%s: %s", label, TextFormat (fmt, *var)));
265 return GuiSliderBar ((Rectangle) { x + ITEM_MARGIN + LABEL_WIDTH, y + c*(ITEM_HEIGHT + ITEM_MARGIN), SLIDER_WIDTH, ITEM_HEIGHT }, NULL, NULL, var, min, max);
266}
267
268int
269panel_var (int x, int y, int c, const char *label, const char *fmt, float *var)
270{
271 GuiLabel ((Rectangle) { x + ITEM_MARGIN, y + c*(ITEM_HEIGHT + ITEM_MARGIN), ITEM_WIDTH, ITEM_HEIGHT },
272 TextFormat ("%s: %s", label, TextFormat (fmt, *var)));
273 return 0;
274}
275
276int
277panel_bool (int x, int y, int c, const char *label, bool *checked)
278{
279 return GuiCheckBox ((Rectangle) {
280 x + ITEM_MARGIN, y + c*(ITEM_HEIGHT + ITEM_MARGIN),
281 ITEM_HEIGHT, ITEM_HEIGHT
282 }, label, checked);
283}
284
285int
286main (int argc, char *argv[])
287{
288 srand (time (NULL));
289
290 SetConfigFlags (FLAG_MSAA_4X_HINT);
291 SetConfigFlags (FLAG_WINDOW_RESIZABLE);
292 InitWindow (800, 450, "GA");
293 SetTargetFPS (60);
294
295 Camera2D camera = {
296 .zoom = 1.0f,
297 };
298
299 Vector2 screen = {
300 .x = GetScreenWidth (),
301 .y = GetScreenHeight (),
302 };
303
304 GuiSetStyle(DEFAULT, TEXT_SIZE, 20);
305 // GuiGetStyle ();
306
307 struct input in = {
308 .r_beg = { 100, 100 },
309 // .r_end = { 100, 100 },
310 .r_end = { 300, 300 },
311 .v_beg = { 100, 10 },
312 .v_end = { 100, 10 },
313 .v_max = 250,
314 .a_max = 500,
315 .j_max = 16,
316 };
317
318 bezier5 cp;
319 struct chromosome ch = rand_chromosome ();
320 struct path_table pt;
321 struct motion_profile mp;
322
323 float arrow_thickness = ARROW_THICKNESS;
324 float spline_thickness = ARROW_THICKNESS;
325 bool move_r_beg = false;
326 bool move_r_end = false;
327 bool move_v_beg = false;
328 bool move_v_end = false;
329 bool recompute = true;
330 bool show_fps = true;
331 bool show_menu = true;
332 bool show_graph = true;
333 bool draw_cp = true;
334 bool animate_sample_offset = false;
335 float animation_speed = 20;
336 int panel_item = 0;
337 bool resizing_graph = false;
338 int graph_height = screen.y/3;
339 while (!WindowShouldClose ()) {
340 screen = (Vector2) {
341 .x = GetScreenWidth (),
342 .y = GetScreenHeight (),
343 };
344 float t = GetTime ();
345 float dt = GetFrameTime ();
346
347 if (IsMouseButtonDown (MOUSE_BUTTON_RIGHT)) {
348 Vector2 delta = GetMouseDelta ();
349 delta = Vector2Scale (delta, -1.0f/camera.zoom);
350 camera.target = Vector2Add (camera.target, delta);
351 }
352
353 if (IsKeyPressed (KEY_LEFT )) menu = menu ? menu - 1 : MENU_COUNT - 1;
354 if (IsKeyPressed (KEY_RIGHT)) menu = menu < MENU_COUNT - 1 ? menu + 1 : 0;
355
356 if (IsKeyPressed (KEY_R)) {
357 ch = rand_chromosome ();
358 recompute = true;
359 }
360
361 if (IsKeyDown (KEY_O)) {
362 struct chromosome res;
363 float cost;
364 example_cmaes_usage (&in, &ch, &w, &res, &cost);
365 ch = res;
366 recompute = true;
367 }
368
369 if (IsKeyPressed (KEY_M)) show_menu = !show_menu;
370 if (IsKeyPressed (KEY_G)) show_graph = !show_graph;
371 if (IsKeyPressed (KEY_F)) show_fps = !show_fps;
372
373 if (recompute) {
374 chromosome_to_control_points (cp, in, ch);
375 build_path_table (&pt, cp);
376 build_motion_profile (&mp, &pt,
377 Vector2Length (in.v_beg),
378 Vector2Length (in.v_end),
379 in.v_max, in.a_max, in.j_max);
380 fb = evaluate_motion_fitness (&pt, &mp,
381 Vector2Length (in.v_beg),
382 Vector2Length (in.v_end),
383 in.v_max, in.a_max, in.j_max, &w);
384
385 recompute = false;
386 }
387
388 float wheel = GetMouseWheelMove();
389 if (wheel != 0) {
390 Vector2 offset = GetMousePosition ();
391 camera.target = GetScreenToWorld2D (offset, camera);
392 camera.offset = offset;
393 camera.zoom = Clamp (expf (logf (camera.zoom) + .2*wheel), .125, 64);
394 }
395
396 Vector2 mouse_hud = GetMousePosition ();
397 Vector2 mouse = GetScreenToWorld2D (mouse_hud, camera);
398
399 if (IsMouseButtonDown (MOUSE_BUTTON_LEFT)
400 && mouse_hud.y > screen.y - graph_height
401 && mouse_hud.y < screen.y - graph_height + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT) {
402 resizing_graph = true;
403 }
404
405 if (resizing_graph) {
406 graph_height = Clamp (RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT + 2, screen.y - 4,
407 screen.y - mouse_hud.y + RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT/2);
408 if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT))
409 resizing_graph = false;
410 }
411
412 BeginDrawing ();
413 ClearBackground (BACKGROUND);
414 BeginMode2D (camera);
415
416 if (CheckCollisionPointCircle (mouse, in.r_beg, 10)) {
417 DrawCircleLinesV (in.r_beg, 10, BLUE);
418 if (!move_v_beg && IsMouseButtonDown (MOUSE_BUTTON_LEFT))
419 move_r_beg = true;
420 } else if (CheckCollisionPointCircle (mouse, in.r_end, 10)) {
421 DrawCircleLinesV (in.r_end, 10, BLUE);
422 if (!move_v_end && IsMouseButtonDown (MOUSE_BUTTON_LEFT))
423 move_r_end = true;
424 } else if (CheckCollisionPointCircle (mouse, Vector2Add (in.r_beg, in.v_beg), 10)) {
425 DrawCircleLinesV (Vector2Add (in.r_beg, in.v_beg), 10, BLUE);
426 if (!move_r_beg && IsMouseButtonDown (MOUSE_BUTTON_LEFT))
427 move_v_beg = true;
428 } else if (CheckCollisionPointCircle (mouse, Vector2Add (in.r_end, in.v_end), 10)) {
429 DrawCircleLinesV (Vector2Add (in.r_end, in.v_end), 10, BLUE);
430 if (!move_r_end && IsMouseButtonDown (MOUSE_BUTTON_LEFT))
431 move_v_end = true;
432 }
433
434 if (move_r_beg) {
435 in.r_beg = mouse;
436 if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT))
437 move_r_beg = false;
438 }
439 if (move_r_end) {
440 in.r_end = mouse;
441 if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT))
442 move_r_end = false;
443 }
444 if (move_v_beg) {
445 in.v_beg = Vector2Subtract (mouse, in.r_beg);
446 if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT))
447 move_v_beg = false;
448 }
449 if (move_v_end) {
450 in.v_end = Vector2Subtract (mouse, in.r_end);
451 if (IsMouseButtonReleased (MOUSE_BUTTON_LEFT))
452 move_v_end = false;
453 }
454
455 if (animate_sample_offset)
456 sample_offset = (int) (animation_speed*t) % (int) sample_spacing;
457
458 // rlPushMatrix ();
459 // rlTranslatef (0, 25*50, 0);
460 // rlRotatef (90, 1, 0, 0);
461 // DrawGrid (100, 50);
462 // rlPopMatrix ();
463
464 draw_path (&pt, spline_thickness);
465 if (draw_cp) draw_bezier5 (cp);
466 draw_arrow (in.r_beg, Vector2Add (in.r_beg, in.v_beg), arrow_thickness, GREEN);
467 draw_arrow (in.r_end, Vector2Add (in.r_end, in.v_end), arrow_thickness, RED);
468
469 EndMode2D ();
470
471 if (move_r_beg ||
472 move_r_end ||
473 move_v_beg ||
474 move_v_end) {
475 GuiLock ();
476 recompute = true;
477 }
478
479 if (show_menu) {
480 int x = 2;
481 int y = 2;
482
483 GuiPanel ((Rectangle) { x, y, PANEL_WIDTH, PANEL_HEIGHT (panel_item) }, menu_to_label[menu]);
484 y += RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT;
485 y += ITEM_MARGIN;
486 panel_item = 0;
487 switch (menu) {
488 case MENU_VISUALIZATION:
489 panel_slider (x, y, panel_item++, "Arrow", "%.2f", &arrow_thickness, 1, 10);
490 panel_slider (x, y, panel_item++, "Spline", "%.2f", &spline_thickness, 1, 10);
491 panel_slider (x, y, panel_item++, "Spacing", "%.0f", &sample_spacing, 2, PATH_SAMPLE_COUNT - 1);
492 panel_slider (x, y, panel_item++, "Offset", "%.0f", &sample_offset, 0, sample_spacing);
493 panel_slider (x, y, panel_item++, "Speed", "%.0f", &animation_speed, 0, 30);
494 panel_bool (x, y, panel_item++, "Animate offset", &animate_sample_offset);
495 panel_bool (x, y, panel_item++, "Draw dr", &sample_dr);
496 panel_bool (x, y, panel_item++, "Draw ddr", &sample_ddr);
497 panel_bool (x, y, panel_item++, "Draw cp", &draw_cp);
498 break;
499
500 case MENU_INPUT:
501 recompute |= panel_slider (x, y, panel_item++, "v_lim", "%.2f", &in.v_max, fmaxf (Vector2Length (in.v_beg), Vector2Length (in.v_beg)), 500);
502 recompute |= panel_slider (x, y, panel_item++, "a_lim", "%.2f", &in.a_max, 1, 500);
503 recompute |= panel_slider (x, y, panel_item++, "j_lim", "%.2f", &in.j_max, 1, 100);
504 panel_var (x, y, panel_item++, "r_beg.x", "%.2f", &in.r_beg.x);
505 panel_var (x, y, panel_item++, "r_beg.y", "%.2f", &in.r_beg.y);
506 panel_var (x, y, panel_item++, "r_end.x", "%.2f", &in.r_end.x);
507 panel_var (x, y, panel_item++, "r_end.y", "%.2f", &in.r_end.y);
508 panel_var (x, y, panel_item++, "v_beg.x", "%.2f", &in.v_beg.x);
509 panel_var (x, y, panel_item++, "v_beg.y", "%.2f", &in.v_beg.y);
510 panel_var (x, y, panel_item++, "v_end.x", "%.2f", &in.v_end.x);
511 panel_var (x, y, panel_item++, "v_end.y", "%.2f", &in.v_end.y);
512 break;
513
514 case MENU_CHROMOSOME:
515 recompute |= panel_slider (x, y, panel_item++, "rho", "%.2f", &ch.rho, 1, 1000);
516 recompute |= panel_slider (x, y, panel_item++, "tau_1", "%.2f", &ch.tau_1, 0, 10);
517 recompute |= panel_slider (x, y, panel_item++, "alpha_2", "%.2f", &ch.alp_2, 0, 10);
518 recompute |= panel_slider (x, y, panel_item++, "beta_2", "%+.2f", &ch.bet_2, -5, 5);
519 recompute |= panel_slider (x, y, panel_item++, "alpha_3", "%.2f", &ch.alp_3, 0, 10);
520 recompute |= panel_slider (x, y, panel_item++, "beta_3", "%+.2f", &ch.bet_3, -5, 5);
521 recompute |= panel_slider (x, y, panel_item++, "tau_4", "%.2f", &ch.tau_4, 0, 10);
522 break;
523
524 case MENU_WEIGHTS:
525 recompute |= panel_slider (x, y, panel_item++, "w_time", "%.2f", &w.time, 0, 10);
526 recompute |= panel_slider (x, y, panel_item++, "w_length", "%.2f", &w.length, 0, 10);
527 recompute |= panel_slider (x, y, panel_item++, "w_max_kappa", "%.2f", &w.max_abs_kappa, 0, 100);
528 recompute |= panel_slider (x, y, panel_item++, "w_max_dkappa", "%.2f", &w.max_abs_dkappa, 0, 100);
529 recompute |= panel_slider (x, y, panel_item++, "w_max_a", "%.2f", &w.max_abs_a, 0, 100);
530 recompute |= panel_slider (x, y, panel_item++, "w_max_j", "%.2f", &w.max_abs_j, 0, 100);
531 recompute |= panel_slider (x, y, panel_item++, "w_rms_kappa", "%.2f", &w.rms_kappa, 0, 10);
532 recompute |= panel_slider (x, y, panel_item++, "w_rms_dkappa", "%.2f", &w.rms_dkappa, 0, 10);
533 recompute |= panel_slider (x, y, panel_item++, "w_rms_a", "%.2f", &w.rms_a, 0, 10);
534 recompute |= panel_slider (x, y, panel_item++, "w_rms_j", "%.2f", &w.rms_j, 0, 1);
535 recompute |= panel_slider (x, y, panel_item++, "w_violation_a", "%.2f", &w.violation_a, 0, 10);
536 recompute |= panel_slider (x, y, panel_item++, "w_violation_j", "%.2f", &w.violation_j, 0, 1);
537 recompute |= panel_slider (x, y, panel_item++, "w_terminal", "%.2f", &w.terminal, 0, 100);
538 break;
539
540 case MENU_METRICS:
541 panel_var (x, y, panel_item++, "Length", "%.2f", &pt.s[PATH_SAMPLE_COUNT - 1]);
542 panel_var (x, y, panel_item++, "Duration", "%.2f", &mp.t[PATH_SAMPLE_COUNT - 1]);
543 panel_var (x, y, panel_item++, "Cost", "%.2f", &fb.total_cost);
544
545 panel_var (x, y, panel_item++, "v_max", "%.2f", &mp.v_max);
546 panel_var (x, y, panel_item++, "a_max", "%.2f", &mp.a_max);
547 panel_var (x, y, panel_item++, "j_max", "%.2f", &mp.j_max);
548
549 panel_var (x, y, panel_item++, "time_cost", "%.2f", &fb.time_cost);
550 panel_var (x, y, panel_item++, "length_cost", "%.2f", &fb.length_cost);
551 panel_var (x, y, panel_item++, "kappa_cost", "%.2f", &fb.kappa_cost);
552 panel_var (x, y, panel_item++, "dkappa_cost", "%.2f", &fb.dkappa_cost);
553 panel_var (x, y, panel_item++, "accel_rms_cost", "%.2f", &fb.accel_rms_cost);
554 panel_var (x, y, panel_item++, "jerk_rms_cost", "%.2f", &fb.jerk_rms_cost);
555 panel_var (x, y, panel_item++, "accel_violation_cost", "%.2f", &fb.accel_violation_cost);
556 panel_var (x, y, panel_item++, "jerk_violation_cost", "%.2f", &fb.jerk_violation_cost);
557 panel_var (x, y, panel_item++, "terminal_cost", "%.2f", &fb.terminal_cost);
558 panel_var (x, y, panel_item++, "failure_cost", "%.2f", &fb.failure_cost);
559 panel_var (x, y, panel_item++, "duration", "%.2f", &fb.duration);
560 panel_var (x, y, panel_item++, "length", "%.2f", &fb.length);
561 panel_var (x, y, panel_item++, "kappa_rms", "%.2f", &fb.kappa_rms);
562 panel_var (x, y, panel_item++, "dkappa_rms", "%.2f", &fb.dkappa_rms);
563 panel_var (x, y, panel_item++, "accel_rms", "%.2f", &fb.accel_rms);
564 panel_var (x, y, panel_item++, "jerk_rms", "%.2f", &fb.jerk_rms);
565 panel_var (x, y, panel_item++, "accel_violation", "%.2f", &fb.accel_violation);
566 panel_var (x, y, panel_item++, "jerk_violation", "%.2f", &fb.jerk_violation);
567 break;
568 default: break;
569 }
570 }
571 GuiUnlock ();
572
573 if (show_graph) {
574 Rectangle bb;
575 bb.x = 2;
576 bb.width = screen.x - 4;
577 bb.height = graph_height;
578 bb.y = screen.y - 2 - bb.height;
579 GuiPanel (bb, "GRAPH");
580 bb.y += RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT;
581 bb.height -= RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT;
582 plot_motion_profile (bb, &mp, in.v_max, in.a_max, in.j_max);
583 }
584
585 if (show_fps)
586 DrawFPS (screen.x - 75, 0);
587 EndDrawing ();
588 }
589
590 CloseWindow ();
591
592 return EXIT_SUCCESS;
593}