collision detection finally works! cleanup is next...

This commit is contained in:
nek0 2021-04-17 04:20:34 +02:00
parent 134445ed20
commit 56bf486fbf

View file

@ -167,22 +167,24 @@ class (Show c, Mass c) => Collidible c where
s22 = (g2e - g1s) / (g1e - g1s) s22 = (g2e - g1s) / (g1e - g1s)
in in
any (\x -> x > 0 && x < 1) [s11, s12, s21 ,s22] 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 in
case (tx < dt, ty < dt, tx < ty, collx, colly) of A.log
(_, _, True, True, _) -> A.Debug
Collision tx (V2 (floor $ signum d1x) 0) (fromString $
(_, _, False, _, True) -> show (tx < dt, ty < dt, tx < ty, collx, colly))
Collision ty (V2 0 (floor $ signum d1y)) res
(_, _, _, False, False) ->
NoCollision
--(True, _, _, False, _) ->
-- NoCollision
-- (_, True, _, _, False) ->
-- NoCollision
-- (False, _, _, _, _) ->
-- NoCollision
-- (_, False, _, _, _) ->
-- NoCollision
else else
NoCollision NoCollision
@ -261,18 +263,18 @@ elasticCollision damping mo1 mo2 (Collision ddt (V2 dirx diry)) =
then 0 then 0
else -((abs m1y2 + abs m2y1) - abs dy) else -((abs m1y2 + abs m2y1) - abs dy)
in in
(velocityUpdater mo1 (velocityUpdater
-- ((positionUpdater mo1) ((positionUpdater mo1)
-- (p1 + ((ddt *) <$> v1) (p1 + ((ddt *) <$> v1)
-- -- if ddt == 0 -- if ddt == 0
-- -- then -- then
-- -- if abs bx < abs by -- if abs bx < abs by
-- -- then -- then
-- -- V2 bx 0 -- V2 bx 0
-- -- else -- else
-- -- V2 0 by -- V2 0 by
-- -- else -- else
-- -- V2 0 0 -- V2 0 0
-- ) )
-- ) )
) nvel ) nvel