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)
in
any (\x -> x > 0 && x < 1) [s11, s12, s21 ,s22]
in
res =
case (tx < dt, ty < dt, tx < ty, collx, colly) of
(_, _, True, True, _) ->
(True, _, True, True, _) ->
Collision tx (V2 (floor $ signum d1x) 0)
(_, _, False, _, True) ->
(_, 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
--(True, _, _, False, _) ->
-- NoCollision
-- (_, True, _, _, False) ->
-- NoCollision
-- (False, _, _, _, _) ->
-- NoCollision
-- (_, False, _, _, _) ->
-- NoCollision
in
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