Move towards removal of ssaTri, which was buggy
This commit is contained in:
+30
-40
@@ -193,9 +193,9 @@ newCrKey :: World -> Int
|
||||
newCrKey = IM.newKey . _creatures
|
||||
{- | TODO: determine precisely what this does. -}
|
||||
reflectPointCreature :: Point2 -> Point2 -> Creature -> Maybe (Point2, Point2, Int)
|
||||
reflectPointCreature p1 p2 cr = case collidePointCirc p1 p2 (_crRad cr) (_crPos cr) of
|
||||
reflectPointCreature p1 p2 cr = case intersectCircSegFirst (_crPos cr) (_crRad cr) p1 p2 of
|
||||
Nothing -> Nothing
|
||||
Just _ -> Just
|
||||
Just a -> Just
|
||||
( p1
|
||||
, errorNormalizeV 35 (ssaTriPoint p2 (_crPos cr) p1 (_crRad cr) -.- _crPos cr)
|
||||
+.+ (_crPos cr -.- _crOldPos cr)
|
||||
@@ -214,7 +214,7 @@ reflectCircCreature
|
||||
-> Point2 -- ^ End point
|
||||
-> Creature
|
||||
-> Maybe (Point2, Point2, Int)
|
||||
reflectCircCreature rad p1 p2 cr = case collidePointCirc p1 p2 (rad + _crRad cr) (_crPos cr) of
|
||||
reflectCircCreature rad p1 p2 cr = case intersectCircSegFirst (_crPos cr) (rad + _crRad cr) p1 p2 of
|
||||
Nothing -> Nothing
|
||||
Just _ -> Just
|
||||
( p1
|
||||
@@ -335,55 +335,45 @@ collidePointWallsNorm p1 p2 ws
|
||||
where
|
||||
f (a,_) = magV (p1 -.- a)
|
||||
-- | Returns the first creature, if any, that a point intersects with.
|
||||
collidePointCreatures :: Point2 -> Point2 -> World -> Maybe Int
|
||||
collidePointCreatures p1 p2 w
|
||||
collidePointCreatures :: Point2 -> Point2 -> IM.IntMap Creature -> Maybe Int
|
||||
collidePointCreatures p1 p2 crs
|
||||
= fmap fst
|
||||
. safeMinimumOn snd
|
||||
. IM.toList
|
||||
. IM.mapMaybe (\x -> collidePointCirc' p1 p2 (_crRad x) (_crPos x))
|
||||
$_creatures w
|
||||
. IM.mapMaybe (\x -> fmap (dist p1) $ intersectCircSegFirst (_crPos x) (_crRad x) p1 p2)
|
||||
$ crs
|
||||
-- | As for 'collidePointCreatures', only increases the radius of creatures by a
|
||||
--fixed amount, thus collides a moving circle with creaures.
|
||||
collideCircCreatures :: Point2 -> Point2 -> Float -> World -> Maybe Int
|
||||
collideCircCreatures p1 p2 rad w
|
||||
= fmap fst
|
||||
. safeMinimumOn snd
|
||||
. IM.toList
|
||||
. IM.mapMaybe (\x -> collidePointCirc' p1 p2 (rad + _crRad x) (_crPos x))
|
||||
$ _creatures w
|
||||
collideCircCreatures :: Point2 -> Point2 -> Float -> IM.IntMap Creature -> Maybe Int
|
||||
collideCircCreatures p1 p2 rad = collidePointCreatures p1 p2 . fmap (crRad +~ rad)
|
||||
|
||||
-- | Returns the first creature id, if any, that a point intersects with, gives point
|
||||
--in creature on line.
|
||||
collidePointCrsPoint :: Point2 -> Point2 -> World -> Maybe (Point2,Int)
|
||||
collidePointCrsPoint p1 p2 w
|
||||
collidePointCrsPoint :: Point2 -> Point2 -> IM.IntMap Creature -> Maybe (Point2,Int)
|
||||
collidePointCrsPoint p1 p2 crs
|
||||
= fmap f
|
||||
. safeMinimumOn (snd . snd)
|
||||
. safeMinimumOn (dist p1 . snd)
|
||||
. IM.toList
|
||||
. IM.mapMaybe (\x -> collidePointCirc'' p1 p2 (_crRad x) (_crPos x))
|
||||
$ _creatures w
|
||||
. IM.mapMaybe (\x -> intersectCircSegFirst (_crPos x) (_crRad x) p1 p2)
|
||||
$ crs
|
||||
where
|
||||
f (cID,(p,_)) = (p,cID)
|
||||
f (cID,p) = (p,cID)
|
||||
{- | Finds the first creature hit on a line.
|
||||
Maybe evaluates the creature id and hit point. -}
|
||||
collideCircCrsPoint :: Point2 -> Point2 -> Float -> World -> Maybe (Point2,Int)
|
||||
collideCircCrsPoint p1 p2 rad w
|
||||
= fmap f
|
||||
. safeMinimumOn (snd . snd)
|
||||
. IM.toList
|
||||
. IM.mapMaybe (\x -> collidePointCirc'' p1 p2 (rad + _crRad x) (_crPos x))
|
||||
$ _creatures w
|
||||
where
|
||||
f (cID,(p,_)) = (p,cID)
|
||||
-- | Makes a creature not hittable.
|
||||
collidePointCrsWithoutPoint :: Int -> Point2 -> Point2 -> World -> Maybe (Point2,Int)
|
||||
collidePointCrsWithoutPoint cid p1 p2 w
|
||||
= fmap f
|
||||
. safeMinimumOn (snd . snd)
|
||||
. IM.toList
|
||||
. IM.mapMaybe (\x -> collidePointCirc'' p1 p2 (_crRad x) (_crPos x))
|
||||
. IM.delete cid
|
||||
$ _creatures w
|
||||
where
|
||||
f (cID,(p,_)) = (p,cID)
|
||||
collideCircCrsPoint :: Point2 -> Point2 -> Float -> IM.IntMap Creature -> Maybe (Point2,Int)
|
||||
collideCircCrsPoint p1 p2 rad = collidePointCrsPoint p1 p2 . fmap (crRad +~ rad)
|
||||
|
||||
---- | Makes a creature not hittable.
|
||||
--collidePointCrsWithoutPoint :: Int -> Point2 -> Point2 -> World -> Maybe (Point2,Int)
|
||||
--collidePointCrsWithoutPoint cid p1 p2 w
|
||||
-- = fmap f
|
||||
-- . safeMinimumOn (snd . snd)
|
||||
-- . IM.toList
|
||||
-- . IM.mapMaybe (\x -> collidePointCirc'' p1 p2 (_crRad x) (_crPos x))
|
||||
-- . IM.delete cid
|
||||
-- $ _creatures w
|
||||
-- where
|
||||
-- f (cID,(p,_)) = (p,cID)
|
||||
{- | Test if a circle collides with any wall.
|
||||
- Note no check on whether the wall is walkable. -}
|
||||
circOnSomeWall :: Point2 -> Float -> World -> Bool
|
||||
|
||||
Reference in New Issue
Block a user