From 49351afc99f6a553d37974201419d14d4e8e303d Mon Sep 17 00:00:00 2001 From: FooB4r Date: Fri, 12 May 2017 14:59:49 +0200 Subject: [PATCH 1/2] fix ball collision 2 --- backend.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend.ml b/backend.ml index 50ba505..b92fa1e 100644 --- a/backend.ml +++ b/backend.ml @@ -191,7 +191,9 @@ let rec apply_constraints b sumForces colList linkList = let compute_position pos colList linkList = List.fold_left (fun acc e -> match e with - | Ball(b) -> pos + | Ball(b) -> + let d = direction b.position pos in + b.position +: 2. *. Mlgrope.ball_radius *: d | Rope(r) -> if List.mem e linkList && distance pos r.position >= r.length then r.length *: (direction r.position pos) +: r.position @@ -199,7 +201,7 @@ let compute_position pos colList linkList = | Block(bl) -> let l = Collide.polygon_circle bl.vertices pos Mlgrope.ball_radius in let (a,b) = List.hd l in let n = Collide.circle_seg_norm a b pos in - (-2. *. Mlgrope.ball_radius *: n) + (2. *. Mlgrope.ball_radius *: n) (* List.fold_left (fun acc (a,b) -> let n = Collide.circle_seg_norm a b pos in From cb846f9d1822cc57e4078048e675d0d1d86dd381 Mon Sep 17 00:00:00 2001 From: FooB4r Date: Fri, 12 May 2017 15:44:29 +0200 Subject: [PATCH 2/2] fix Failure --- backend.ml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/backend.ml b/backend.ml index b92fa1e..32f92ed 100644 --- a/backend.ml +++ b/backend.ml @@ -199,15 +199,14 @@ let compute_position pos colList linkList = then r.length *: (direction r.position pos) +: r.position else pos | Block(bl) -> let l = Collide.polygon_circle bl.vertices pos Mlgrope.ball_radius in - let (a,b) = List.hd l in + begin + try + let (a,b) = List.hd l in let n = Collide.circle_seg_norm a b pos in (2. *. Mlgrope.ball_radius *: n) - (* - List.fold_left (fun acc (a,b) -> - let n = Collide.circle_seg_norm a b pos in - acc +: (2. *. Mlgrope.ball_radius *: n) - ) pos l - *) + with + | Failure(_) -> pos + end | _ -> pos ) pos colList