This commit is contained in:
nek0 2021-07-09 19:49:09 +02:00
parent 5567b515e8
commit 3f45ae580c
1 changed files with 14 additions and 15 deletions

View File

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