deduplication
This commit is contained in:
parent
7657a35415
commit
9a9408edf3
|
@ -103,42 +103,34 @@ class (Show c, Mass c) => Collidible c where
|
||||||
in
|
in
|
||||||
if broadphaseOverlap
|
if broadphaseOverlap
|
||||||
then
|
then
|
||||||
let collx =
|
let coll xdir =
|
||||||
let (p11, p12, p21, p22) =
|
let (p11, p12, p21, p22) =
|
||||||
if d1x < 0
|
if xdir
|
||||||
then
|
then
|
||||||
(m1p1, m1p2, m2p4, m2p3)
|
if d1x < 0
|
||||||
|
then
|
||||||
|
(m1p1, m1p2, m2p4, m2p3)
|
||||||
|
else
|
||||||
|
(m1p4, m1p3, m2p1, m2p2)
|
||||||
else
|
else
|
||||||
(m1p4, m1p3, m2p1, m2p2)
|
if d1y < 0
|
||||||
(V2 _ g1s) = p11 + ((tx *) <$> d1)
|
then
|
||||||
(V2 _ g1e) = p12 + ((tx *) <$> d1)
|
(m1p1, m1p4, m2p2, m2p3)
|
||||||
(V2 _ g2s) = p21 + ((tx *) <$> d2)
|
else
|
||||||
(V2 _ g2e) = p22 + ((tx *) <$> d2)
|
(m1p2, m1p3, m2p1, m2p4)
|
||||||
|
vselector (V2 x y) = if xdir then y else x
|
||||||
|
tick = if xdir then tx else ty
|
||||||
|
g1s = vselector $ p11 + ((tick *) <$> d1)
|
||||||
|
g1e = vselector $ p12 + ((tick *) <$> d1)
|
||||||
|
g2s = vselector $ p21 + ((tick *) <$> d2)
|
||||||
|
g2e = vselector $ p22 + ((tick *) <$> d2)
|
||||||
s11 = (g1s - g2s) / (g2e - g2s)
|
s11 = (g1s - g2s) / (g2e - g2s)
|
||||||
s12 = (g1e - g2s) / (g2e - g2s)
|
s12 = (g1e - g2s) / (g2e - g2s)
|
||||||
s21 = (g2s - g1s) / (g1e - g1s)
|
s21 = (g2s - g1s) / (g1e - g1s)
|
||||||
s22 = (g2e - g1s) / (g1e - g1s)
|
s22 = (g2e - g1s) / (g1e - g1s)
|
||||||
in
|
in
|
||||||
any (\x -> x > 0 && x < 1) [s11, s12, s21 ,s22]
|
any (\x -> x > 0 && x < 1) [s11, s12, s21 ,s22]
|
||||||
colly =
|
res = case (tx < dt, ty < dt, tx < ty, coll True, coll False) of
|
||||||
let (p11, p12, p21, p22) =
|
|
||||||
if d1y < 0
|
|
||||||
then
|
|
||||||
(m1p1, m1p4, m2p2, m2p3)
|
|
||||||
else
|
|
||||||
(m1p2, m1p3, m2p1, m2p4)
|
|
||||||
(V2 g1s _) = p11 + ((ty *) <$> d1)
|
|
||||||
(V2 g1e _) = p12 + ((ty *) <$> d1)
|
|
||||||
(V2 g2s _) = p21 + ((ty *) <$> d2)
|
|
||||||
(V2 g2e _) = p22 + ((ty *) <$> d2)
|
|
||||||
s11 = (g1s - g2s) / (g2e - g2s)
|
|
||||||
s12 = (g1e - g2s) / (g2e - g2s)
|
|
||||||
s21 = (g2s - g1s) / (g1e - g1s)
|
|
||||||
s22 = (g2e - g1s) / (g1e - g1s)
|
|
||||||
in
|
|
||||||
any (\x -> x > 0 && x < 1) [s11, s12, s21 ,s22]
|
|
||||||
res =
|
|
||||||
case (tx < dt, ty < dt, tx < ty, collx, colly) of
|
|
||||||
(True, _, True, True, _) ->
|
(True, _, True, True, _) ->
|
||||||
Collision tx (V2 (floor $ signum d1x) 0)
|
Collision tx (V2 (floor $ signum d1x) 0)
|
||||||
(_, True, False, _, True) ->
|
(_, True, False, _, True) ->
|
||||||
|
@ -150,10 +142,9 @@ class (Show c, Mass c) => Collidible c where
|
||||||
(_, _, _, False, False) ->
|
(_, _, _, False, False) ->
|
||||||
NoCollision
|
NoCollision
|
||||||
in
|
in
|
||||||
A.log
|
A.log A.Debug
|
||||||
A.Debug
|
|
||||||
(fromString $
|
(fromString $
|
||||||
show (tx < dt, ty < dt, tx < ty, collx, colly))
|
show (tx < dt, ty < dt, tx < ty, coll True, coll False))
|
||||||
res
|
res
|
||||||
else
|
else
|
||||||
NoCollision
|
NoCollision
|
||||||
|
|
Loading…
Reference in New Issue