From 56bf486fbfc8a968680504aa3821aecb47d46878 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 17 Apr 2021 04:20:34 +0200 Subject: [PATCH] collision detection finally works! cleanup is next... --- src/Classes/Physics/Collidible.hs | 60 ++++++++++++++++--------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/Classes/Physics/Collidible.hs b/src/Classes/Physics/Collidible.hs index c2672d4..2461b56 100644 --- a/src/Classes/Physics/Collidible.hs +++ b/src/Classes/Physics/Collidible.hs @@ -167,22 +167,24 @@ class (Show c, Mass c) => Collidible c where s22 = (g2e - g1s) / (g1e - g1s) in any (\x -> x > 0 && x < 1) [s11, s12, s21 ,s22] + res = + case (tx < dt, ty < dt, tx < ty, collx, colly) of + (True, _, True, True, _) -> + Collision tx (V2 (floor $ signum d1x) 0) + (_, True, False, _, True) -> + Collision ty (V2 0 (floor $ signum d1y)) + (True, _, False, True, False) -> + Collision tx (V2 (floor $ signum d1x) 0) + (_, True, True, False, True) -> + Collision ty (V2 0 (floor $ signum d1y)) + (_, _, _, False, False) -> + NoCollision in - case (tx < dt, ty < dt, tx < ty, collx, colly) of - (_, _, True, True, _) -> - Collision tx (V2 (floor $ signum d1x) 0) - (_, _, False, _, True) -> - Collision ty (V2 0 (floor $ signum d1y)) - (_, _, _, False, False) -> - NoCollision - --(True, _, _, False, _) -> - -- NoCollision - -- (_, True, _, _, False) -> - -- NoCollision - -- (False, _, _, _, _) -> - -- NoCollision - -- (_, False, _, _, _) -> - -- NoCollision + A.log + A.Debug + (fromString $ + show (tx < dt, ty < dt, tx < ty, collx, colly)) + res else NoCollision @@ -261,18 +263,18 @@ elasticCollision damping mo1 mo2 (Collision ddt (V2 dirx diry)) = then 0 else -((abs m1y2 + abs m2y1) - abs dy) in - (velocityUpdater mo1 - -- ((positionUpdater mo1) - -- (p1 + ((ddt *) <$> v1) - -- -- if ddt == 0 - -- -- then - -- -- if abs bx < abs by - -- -- then - -- -- V2 bx 0 - -- -- else - -- -- V2 0 by - -- -- else - -- -- V2 0 0 - -- ) - -- ) + (velocityUpdater + ((positionUpdater mo1) + (p1 + ((ddt *) <$> v1) + -- if ddt == 0 + -- then + -- if abs bx < abs by + -- then + -- V2 bx 0 + -- else + -- V2 0 by + -- else + -- V2 0 0 + ) + ) ) nvel