interaction in y direction works
This commit is contained in:
parent
0a2e3f05d4
commit
337fcf9cd0
1 changed files with 13 additions and 6 deletions
|
@ -182,14 +182,14 @@ class (Show c, Mass c) => Collidible c where
|
||||||
NoCollision ->
|
NoCollision ->
|
||||||
if overlap
|
if overlap
|
||||||
then
|
then
|
||||||
let xoverlap = floor (minimum
|
let xoverlap = floor (maximum (filter (0 >)
|
||||||
[ pm2b2x - pm2b1x
|
[ pm2b2x - pm2b1x
|
||||||
, pm2b1x - pm1b2x
|
, pm2b1x - pm1b2x
|
||||||
])
|
]))
|
||||||
yoverlap = floor (minimum
|
yoverlap = floor (maximum (filter (0 >)
|
||||||
[ pm2b1y - pm1b2y
|
[ pm2b1y - pm1b2y
|
||||||
, pm2b2y - pm1b1y
|
, pm2b2y - pm1b1y
|
||||||
])
|
]))
|
||||||
in
|
in
|
||||||
if xoverlap < yoverlap
|
if xoverlap < yoverlap
|
||||||
then
|
then
|
||||||
|
@ -201,7 +201,7 @@ class (Show c, Mass c) => Collidible c where
|
||||||
else
|
else
|
||||||
if yoverlap < 0
|
if yoverlap < 0
|
||||||
then OverlapCollision
|
then OverlapCollision
|
||||||
(V2 yoverlap 0)
|
(V2 0 yoverlap)
|
||||||
else NoCollision
|
else NoCollision
|
||||||
else NoCollision
|
else NoCollision
|
||||||
_ -> A.log
|
_ -> A.log
|
||||||
|
@ -259,6 +259,13 @@ elasticCollision damping mo1 (mo2, OverlapCollision depth) dt =
|
||||||
v1y' = 2 * (m1 * dy + m2 * (-dy)) / (m1 + m2) - dy
|
v1y' = 2 * (m1 * dy + m2 * (-dy)) / (m1 + m2) - dy
|
||||||
nvel = if m1 == recip 0
|
nvel = if m1 == recip 0
|
||||||
then V2 0 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
|
in
|
||||||
velocityUpdater mo1 nvel
|
velocityUpdater mo1 nvel
|
||||||
|
|
Loading…
Reference in a new issue