commit bb2c7d6509bd44795b856e6e639c0d41f053db13
parent 1cd22fb31d384d84b6965ca07312f8e7af1eb6c9
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 3 Jan 2023 08:50:10 +0900
ex5: change order of collision handling
Diffstat:
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/ex5/ex5.c b/ex5/ex5.c
@@ -403,8 +403,6 @@ rect_handle_collision_elastic(struct rect *s1, struct rect *s2)
if(!rect_test_collision(s1, s2))
return;
- rect_handle_collision_mm(s1, s2);
-
float v1, v2;
float m1 = s1->m;
float m2 = s2->m;
@@ -423,6 +421,8 @@ rect_handle_collision_elastic(struct rect *s1, struct rect *s2)
s1->vy = 2*m2/(m1+m2)*v2 + (m1-m2)/(m1+m2)*v1;
s2->vy = 2*m1/(m1+m2)*v1 + (m2-m1)/(m1+m2)*v2;
}
+
+ rect_handle_collision_mm(s1, s2);
}
void
@@ -431,8 +431,6 @@ circle_handle_collision_elastic(struct circle *c1, struct circle *c2)
if(!circle_test_collision(c1, c2))
return;
- circle_handle_collision_mm(c1, c2);
-
float col_px = c2->px - c1->px;
float col_py = c2->py - c1->py;
float col_pr = sqrtf(col_px * col_px + col_py * col_py);
@@ -461,6 +459,8 @@ circle_handle_collision_elastic(struct circle *c1, struct circle *c2)
c1->vy = col_1vyn + nor_1vy;
c2->vx = col_2vxn + nor_2vx;
c2->vy = col_2vyn + nor_2vy;
+
+ circle_handle_collision_mm(c1, c2);
}
void
game_play(void)