Fix incorrect rendering when out of range

- Fix position calculation assignment when target is out of range
- Add decreasing thick to each link
master
BeardedBread 2021-08-17 22:42:51 +08:00
parent 2a0bc4764b
commit d9646390d5
1 changed files with 8 additions and 4 deletions

View File

@ -81,8 +81,12 @@ void update_body(Body *body){
// Check distance // Check distance
float dist = Vector2Distance(body->joints[0].pos, body->target); float dist = Vector2Distance(body->joints[0].pos, body->target);
if (dist >= body->total_length){ if (dist >= body->total_length){
for(unsigned int i = 1; i< body->N; ++i){ for(int i = 0; i< body->N-1; ++i){
body->joints[i].pos = _get_new_pos(body->target, body->joints[i-1].pos, body->links_lengths[i]); body->joints[i+1].pos = _get_new_pos(
body->target,
body->joints[i].pos,
body->links_lengths[i]
);
} }
return; return;
} }
@ -132,9 +136,9 @@ void update_body(Body *body){
void draw_body(Body* body){ void draw_body(Body* body){
DrawCircleV(body->joints[0].pos, 5, BLACK); 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){ 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 #ifdef DEBUG
DrawCircleV(body->joints[i].pos, 5, BLUE); DrawCircleV(body->joints[i].pos, 5, BLUE);
#endif #endif