From d9646390d52d5d8013e7ccf8515fbc5fbe59242f Mon Sep 17 00:00:00 2001 From: BeardedBread Date: Tue, 17 Aug 2021 22:42:51 +0800 Subject: [PATCH] Fix incorrect rendering when out of range - Fix position calculation assignment when target is out of range - Add decreasing thick to each link --- joints.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/joints.c b/joints.c index 601e8f7..0895e30 100644 --- a/joints.c +++ b/joints.c @@ -81,8 +81,12 @@ void update_body(Body *body){ // Check distance float dist = Vector2Distance(body->joints[0].pos, body->target); if (dist >= body->total_length){ - for(unsigned int i = 1; i< body->N; ++i){ - body->joints[i].pos = _get_new_pos(body->target, body->joints[i-1].pos, body->links_lengths[i]); + for(int i = 0; i< body->N-1; ++i){ + body->joints[i+1].pos = _get_new_pos( + body->target, + body->joints[i].pos, + body->links_lengths[i] + ); } return; } @@ -132,9 +136,9 @@ void update_body(Body *body){ void draw_body(Body* body){ DrawCircleV(body->joints[0].pos, 5, BLACK); - DrawLineV(body->joints[0].pos, body->joints[1].pos, BLACK); + DrawLineEx(body->joints[0].pos, body->joints[1].pos, body->N, BLACK); for(int i = 1; i < body->N-1; ++i){ - DrawLineV(body->joints[i].pos, body->joints[i+1].pos, BLACK); + DrawLineEx(body->joints[i].pos, body->joints[i+1].pos, body->N - i, BLACK); #ifdef DEBUG DrawCircleV(body->joints[i].pos, 5, BLUE); #endif