From 3d1a4e7cd8260f9d472613d78f572027f45b899d Mon Sep 17 00:00:00 2001 From: BeardedBread Date: Sun, 12 Sep 2021 16:30:05 +0800 Subject: [PATCH] Tidy up drawing and limit iteration - Limit FABRIK iteration to 100 - Fill background to GREEN for greenscreen purposes - Draw circles at joints to smooth out the inter-joints --- joints.c | 11 +++++++++-- main.c | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/joints.c b/joints.c index 0b5a739..fb1290b 100644 --- a/joints.c +++ b/joints.c @@ -15,7 +15,7 @@ Body* init_body(int N, float link_length, float root_x, float root_y){ body->current_length = link_length * (N - 1); body->target = (Vector2){root_x, body->total_length}; body->final_target = (Vector2){root_x, body->total_length}; - body->angle_limit = PI/6; + body->angle_limit = PI; body->root_pos = (Vector2){root_x, root_y}; @@ -106,9 +106,12 @@ void update_body(Body *body){ return; } + // Perform FABRIK double error = 1; + int iterations = 0; Vector2 prev_pos; - while (error > 1e-2){ + while (error > 1e-2 && iterations < 100){ + ++iterations; prev_pos = body->joints[body->N-1].pos; // Backward Pass @@ -156,9 +159,13 @@ void draw_body(Body* body){ DrawLineEx(body->joints[i].pos, body->joints[i+1].pos, body->N - i, BLACK); #ifdef DEBUG DrawCircleV(body->joints[i].pos, 5, BLUE); +#else + DrawCircleV(body->joints[i].pos,(int)((body->N - i) / 2), BLACK); #endif } +#ifdef DEBUG DrawCircleV(body->target, 3, RED); +#endif } void free_body(Body *body){ diff --git a/main.c b/main.c index 67e7d0e..e5a2624 100644 --- a/main.c +++ b/main.c @@ -26,7 +26,7 @@ int main(int argc, char** argv) { update_body(body); BeginDrawing(); - ClearBackground(RAYWHITE); + ClearBackground(GREEN); draw_body(body); EndDrawing(); }