This commit is contained in:
nek0 2021-07-09 19:49:09 +02:00
parent 5567b515e8
commit 3f45ae580c

View file

@ -28,9 +28,9 @@ class (Show c, Mass c) => Collidible c where
-- as collision boundaries. -- as collision boundaries.
boundary boundary
:: c -- ^ Object :: c -- ^ Object
-> ( V2 Double -- ^ Bottom left corner of AABB relative to position -> ( V2 Double
, V2 Double -- ^ Top right corner of AABB relative to position , V2 Double
) ) -- ^ Bottom left and top right corner of AABB relative to position
collisionCheck collisionCheck
:: (Collidible other) :: (Collidible other)
@ -135,15 +135,14 @@ class (Show c, Mass c) => Collidible c where
) )
else else
let coll xdir = let coll xdir =
let (p11, p12, p21, p22) = let (p11, p12, p21, p22)
if xdir | xdir =
then
if d1x < 0 if d1x < 0
then then
(m1p1, m1p2, m2p4, m2p3) (m1p1, m1p2, m2p4, m2p3)
else else
(m1p4, m1p3, m2p1, m2p2) (m1p4, m1p3, m2p1, m2p2)
else | otherwise =
if d1y < 0 if d1y < 0
then then
(m1p1, m1p4, m2p2, m2p3) (m1p1, m1p4, m2p2, m2p3)
@ -177,12 +176,12 @@ class (Show c, Mass c) => Collidible c where
(_, _, _, False, False) -> (_, _, _, False, False) ->
NoCollision NoCollision
(_, _, True, _, _) -> (_, _, True, _, _) ->
A.log A.Debug ("CORNER CASE!") NoCollision A.log A.Debug "CORNER CASE!" NoCollision
(False, False, _, _, _) -> (False, False, _, _, _) ->
NoCollision NoCollision
x -> error $ x -> error $
"Unhandled combination of collision check results: " "Unhandled combination of collision check results: "
<> (fromString $ show x) <> fromString (show x)
in in
res res
-- case res of -- case res of
@ -226,10 +225,10 @@ elasticCollision damping mo1 mo2 (Collision ddt (V2 dirx _)) =
if m2 == recip 0 if m2 == recip 0
then then
if dirx /= 0 if dirx /= 0
then (V2 (-v1x) v1y) then V2 (-v1x) v1y
else (V2 v1x (-v1y)) else V2 v1x (-v1y)
else (V2 v1x' v1y') else V2 v1x' v1y'
in in
(velocityUpdater velocityUpdater
((positionUpdater mo1) (p1 + ((ddt *) <$> v1))) (positionUpdater mo1 (p1 + ((ddt *) <$> v1)))
) nvel nvel