Browse Source

interaction in y direction works

master
nek0 2 months ago
parent
commit
337fcf9cd0
  1. 19
      src/Physics/Classes/Collidible.hs

19
src/Physics/Classes/Collidible.hs

@ -182,14 +182,14 @@ class (Show c, Mass c) => Collidible c where
NoCollision ->
if overlap
then
let xoverlap = floor (minimum
let xoverlap = floor (maximum (filter (0 >)
[ pm2b2x - pm2b1x
, pm2b1x - pm1b2x
])
yoverlap = floor (minimum
]))
yoverlap = floor (maximum (filter (0 >)
[ pm2b1y - pm1b2y
, pm2b2y - pm1b1y
])
]))
in
if xoverlap < yoverlap
then
@ -201,7 +201,7 @@ class (Show c, Mass c) => Collidible c where
else
if yoverlap < 0
then OverlapCollision
(V2 yoverlap 0)
(V2 0 yoverlap)
else NoCollision
else NoCollision
_ -> A.log
@ -259,6 +259,13 @@ elasticCollision damping mo1 (mo2, OverlapCollision depth) dt =
v1y' = 2 * (m1 * dy + m2 * (-dy)) / (m1 + m2) - dy
nvel = if m1 == recip 0
then V2 0 0
else (damping *) <$> V2 v1x' v1y'
else (damping *) <$>
if m2 == recip 0
then
if dx /= 0
then V2 (-v1x') v1y'
else V2 v1x' (-v1y')
else
V2 v1x' v1y'
in
velocityUpdater mo1 nvel

Loading…
Cancel
Save