Fix bug when forming convex hull of game room bounds
This commit is contained in:
@@ -21,6 +21,7 @@ import Geometry
|
|||||||
--import Geometry.Data
|
--import Geometry.Data
|
||||||
import Geometry.Vector3D
|
import Geometry.Vector3D
|
||||||
import Polyhedra
|
import Polyhedra
|
||||||
|
import Shape
|
||||||
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import qualified Control.Foldl as L
|
import qualified Control.Foldl as L
|
||||||
@@ -119,11 +120,10 @@ explosiveBarrel :: Creature
|
|||||||
explosiveBarrel = defaultInanimate
|
explosiveBarrel = defaultInanimate
|
||||||
{ _crUpdate = updateExpBarrel
|
{ _crUpdate = updateExpBarrel
|
||||||
, _crHP = 400
|
, _crHP = 400
|
||||||
, _crPict = picAtCrPos $ pictures
|
, _crPict = shapeAtCrPos
|
||||||
[ color red $ circleSolid 8
|
. colorSH orange
|
||||||
, setDepth 0.049 . color (greyN 0.5) $ circleSolid 10
|
. upperPrismPoly 20
|
||||||
, color orange $ circleSolid 10
|
$ polyCirc 4 10
|
||||||
]
|
|
||||||
, _crState = defaultState
|
, _crState = defaultState
|
||||||
{_crSpState = Barrel []
|
{_crSpState = Barrel []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module Dodge.Creature.Picture
|
|||||||
( basicCrPict
|
( basicCrPict
|
||||||
, circLine
|
, circLine
|
||||||
, picAtCrPos
|
, picAtCrPos
|
||||||
|
, shapeAtCrPos
|
||||||
, picAtCrPosNoRot
|
, picAtCrPosNoRot
|
||||||
) where
|
) where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
@@ -47,6 +48,12 @@ basicCrPict col cr w = (,) (basicCrShape col cr) $ pictures $
|
|||||||
tr = uncurryV translate (_crPos cr)
|
tr = uncurryV translate (_crPos cr)
|
||||||
rotdir = rotate (_crDir cr)
|
rotdir = rotate (_crDir cr)
|
||||||
|
|
||||||
|
shapeAtCrPos :: Shape -> Creature -> World -> SPic
|
||||||
|
shapeAtCrPos sh cr _ =
|
||||||
|
( uncurryV translateSHf (_crPos cr) $ rotateSH (_crDir cr) sh
|
||||||
|
, mempty
|
||||||
|
)
|
||||||
|
|
||||||
basicCrShape
|
basicCrShape
|
||||||
:: Color -- ^ Creature color
|
:: Color -- ^ Creature color
|
||||||
-> Creature
|
-> Creature
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ defaultRoom = Room
|
|||||||
, _rmFloor = []
|
, _rmFloor = []
|
||||||
, _rmName = "defaultRoom"
|
, _rmName = "defaultRoom"
|
||||||
, _rmShift = (V2 0 0 , 0)
|
, _rmShift = (V2 0 0 , 0)
|
||||||
|
, _rmViewpoints = []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ autoGun = defaultAutoGun
|
|||||||
autoGunPic :: SPic
|
autoGunPic :: SPic
|
||||||
autoGunPic =
|
autoGunPic =
|
||||||
( colorSH red $ prismPoly
|
( colorSH red $ prismPoly
|
||||||
(map (addZ 5) $ rectNESW 2 12 (-2) (-12))
|
(map (addZ 5) $ rectNESW 2 12 (-2) (-8))
|
||||||
(map (addZ 0) $ rectNESW 4 12 (-4) (-12))
|
(map (addZ 0) $ rectNESW 4 12 (-4) (-12))
|
||||||
, mempty
|
, mempty
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-2
@@ -25,6 +25,7 @@ import Tile
|
|||||||
import Polyhedra
|
import Polyhedra
|
||||||
import Polyhedra.Data
|
import Polyhedra.Data
|
||||||
|
|
||||||
|
import Data.List (nub)
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import System.Random
|
import System.Random
|
||||||
@@ -120,9 +121,9 @@ gameRoomsFromRooms :: [Room] -> [GameRoom]
|
|||||||
gameRoomsFromRooms = map f
|
gameRoomsFromRooms = map f
|
||||||
where
|
where
|
||||||
f rm = GameRoom
|
f rm = GameRoom
|
||||||
{ _grViewpoints = map fst . foldl' (flip cutWalls) [] $ _rmPolys rm
|
{ _grViewpoints = _rmViewpoints rm ++ (map fst . foldl' (flip cutWalls) [] $ _rmPolys rm)
|
||||||
, _grViewpointsEx = map fst (_rmLinks rm)
|
, _grViewpointsEx = map fst (_rmLinks rm)
|
||||||
, _grBound = expandPolyByFixed 100 $ orderPolygon $ convexHullSafe $ concat $ _rmBound rm ++ _rmPolys rm
|
, _grBound = expandPolyByFixed 100 . convexHullSafe . nub . concat $ _rmBound rm ++ _rmPolys rm
|
||||||
, _grDir = snd . last $ _rmLinks rm
|
, _grDir = snd . last $ _rmLinks rm
|
||||||
, _grName = _rmName rm
|
, _grName = _rmName rm
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ placeProp pr p a w = (i, w & props %~ addProp)
|
|||||||
where
|
where
|
||||||
i = IM.newKey $ _props w
|
i = IM.newKey $ _props w
|
||||||
addProp prs = IM.insert i (f pr) prs
|
addProp prs = IM.insert i (f pr) prs
|
||||||
f = (pjRot +~ a) . (pjPos %~ ( (p +.+) . (rotateV a) )) . (pjID .~ i)
|
f = (pjRot +~ a) . (pjPos %~ ( (p +.+) . rotateV a )) . (pjID .~ i)
|
||||||
|
|
||||||
placeBt
|
placeBt
|
||||||
:: Button
|
:: Button
|
||||||
@@ -136,7 +136,7 @@ placeBt bt p a w = (i , over buttons addBT w)
|
|||||||
where
|
where
|
||||||
i = IM.newKey $ _buttons w
|
i = IM.newKey $ _buttons w
|
||||||
addBT xs = IM.insert i (f bt) xs
|
addBT xs = IM.insert i (f bt) xs
|
||||||
f = (btRot +~ a) . (btPos %~ ( (p +.+) . (rotateV a) )) . (btID .~ i)
|
f = (btRot +~ a) . (btPos %~ ( (p +.+) . rotateV a )) . (btID .~ i)
|
||||||
--addBT bts = IM.insert (IM.newKey bts) (bt {_btPos = p, _btRot = rot, _btID = IM.newKey bts}) bts
|
--addBT bts = IM.insert (IM.newKey bts) (bt {_btPos = p, _btRot = rot, _btID = IM.newKey bts}) bts
|
||||||
{- Creates a floor item at a given point.
|
{- Creates a floor item at a given point.
|
||||||
Assigns an id correctly. -}
|
Assigns an id correctly. -}
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ doDrawing pdata w = do
|
|||||||
activeTexture $= TextureUnit 1
|
activeTexture $= TextureUnit 1
|
||||||
zipWithM_ (>>) bindings $ map bindDrawDist rds
|
zipWithM_ (>>) bindings $ map bindDrawDist rds
|
||||||
activeTexture $= TextureUnit 0
|
activeTexture $= TextureUnit 0
|
||||||
|
renderLayer 5 shadV layerCounts
|
||||||
-- draw overlay
|
-- draw overlay
|
||||||
depthFunc $= Just Always
|
depthFunc $= Just Always
|
||||||
depthMask $= Disabled
|
depthMask $= Disabled
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
module Dodge.Render.Picture
|
module Dodge.Render.Picture
|
||||||
where
|
where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
import Dodge.Update.Camera
|
||||||
|
import Dodge.GameRoom
|
||||||
import Dodge.Base
|
import Dodge.Base
|
||||||
import Dodge.Base.Window
|
import Dodge.Base.Window
|
||||||
import Dodge.Zone
|
import Dodge.Zone
|
||||||
@@ -62,10 +64,11 @@ customMouseCursor w =
|
|||||||
$ pictures [ line [V2 (-5) 0,V2 5 0] , line [V2 0 (-5),V2 0 5] ]
|
$ pictures [ line [V2 (-5) 0,V2 5 0] , line [V2 0 (-5),V2 0 5] ]
|
||||||
|
|
||||||
testPic :: World -> Picture
|
testPic :: World -> Picture
|
||||||
testPic _ = pictures
|
testPic w = setLayer 5 $ color green (concatMap (polygonWire . _grBound) grs)
|
||||||
[
|
<> color yellow (concatMap (\q -> line [p,q]) $ farWallPoints p w)
|
||||||
-- , fixedSizePicClampArrow 10 50 thepic (mouseWorldPos w) w
|
where
|
||||||
]
|
p = _crPos $ you w
|
||||||
|
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
||||||
-- where
|
-- where
|
||||||
-- thepic = setDepth 20 . color green . polygon $ rectNSEW 5 (-5) (-5) (5)
|
-- thepic = setDepth 20 . color green . polygon $ rectNSEW 5 (-5) (-5) (5)
|
||||||
--testPic _ = blank
|
--testPic _ = blank
|
||||||
|
|||||||
@@ -25,5 +25,6 @@ data Room = Room
|
|||||||
, _rmFloor :: [Tile]
|
, _rmFloor :: [Tile]
|
||||||
, _rmName :: String
|
, _rmName :: String
|
||||||
, _rmShift :: (Point2, Float)
|
, _rmShift :: (Point2, Float)
|
||||||
|
, _rmViewpoints :: [Point2]
|
||||||
}
|
}
|
||||||
makeLenses ''Room
|
makeLenses ''Room
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ shiftRoomBy shift r = r
|
|||||||
. (tileZero %~ shiftPointBy shift )
|
. (tileZero %~ shiftPointBy shift )
|
||||||
. (tileX %~ shiftPointBy shift )
|
. (tileX %~ shiftPointBy shift )
|
||||||
)
|
)
|
||||||
|
& rmViewpoints %~ map (shiftPointBy shift)
|
||||||
|
|
||||||
shiftLinkBy
|
shiftLinkBy
|
||||||
:: (Point2,Float)
|
:: (Point2,Float)
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ twinSlowDoorRoom w h x = defaultRoom
|
|||||||
]
|
]
|
||||||
, _rmBound = ps
|
, _rmBound = ps
|
||||||
, _rmName = "twinSlowDoorRoom"
|
, _rmName = "twinSlowDoorRoom"
|
||||||
|
, _rmViewpoints = [V2 0 h]
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
wlSpeed = 0.5
|
wlSpeed = 0.5
|
||||||
@@ -62,7 +63,7 @@ twinSlowDoorRoom w h x = defaultRoom
|
|||||||
[rectNSWE h 0 (-w) w
|
[rectNSWE h 0 (-w) w
|
||||||
,rectNSWE 20 (-h) (negate x) x
|
,rectNSWE 20 (-h) (negate x) x
|
||||||
]
|
]
|
||||||
cond' btid w' = (_btState $ _buttons w' IM.! btid) == BtOn
|
cond' btid w' = _btState (_buttons w' IM.! btid) == BtOn
|
||||||
col = dim $ dim $ bright red
|
col = dim $ dim $ bright red
|
||||||
|
|
||||||
twinSlowDoorChasers
|
twinSlowDoorChasers
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ Functions controlling the movement of the screen camera:
|
|||||||
and the position that the character sees from: '_cameraViewFrom'. -}
|
and the position that the character sees from: '_cameraViewFrom'. -}
|
||||||
module Dodge.Update.Camera
|
module Dodge.Update.Camera
|
||||||
( updateCamera
|
( updateCamera
|
||||||
|
, farWallPoints
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
@@ -176,6 +177,14 @@ farWallDist p w = (winFac /) . min maxViewDistance $ ssfold (> maxViewDistance)
|
|||||||
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
||||||
wos = wallsOnScreen w
|
wos = wallsOnScreen w
|
||||||
|
|
||||||
|
farWallPoints :: Point2 -> World -> [Point2]
|
||||||
|
farWallPoints p w = concatMap _grViewpoints grs ++ linkvps
|
||||||
|
where
|
||||||
|
grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
||||||
|
linkvps = map extend (concatMap _grViewpointsEx grs)
|
||||||
|
extend :: Point2 -> Point2
|
||||||
|
extend outp = p +.+ maxViewDistance *.* safeNormalizeV (outp -.- p)
|
||||||
|
|
||||||
--farWallDist :: Point2 -> World -> Float
|
--farWallDist :: Point2 -> World -> Float
|
||||||
--farWallDist p w = (winFac /) $ fromMaybe maxViewDistance
|
--farWallDist p w = (winFac /) $ fromMaybe maxViewDistance
|
||||||
-- $ L.fold (L.premap (dist p) L.maximum) vdists
|
-- $ L.fold (L.premap (dist p) L.maximum) vdists
|
||||||
|
|||||||
+6
-1
@@ -121,6 +121,10 @@ orderPolygonAround
|
|||||||
orderPolygonAround _ [] = []
|
orderPolygonAround _ [] = []
|
||||||
orderPolygonAround cen ps = sortOn (\p -> argV (p -.- cen)) ps
|
orderPolygonAround cen ps = sortOn (\p -> argV (p -.- cen)) ps
|
||||||
|
|
||||||
|
orderAroundFirstReverse :: [Point2] -> [Point2]
|
||||||
|
orderAroundFirstReverse [] = []
|
||||||
|
orderAroundFirstReverse (a:as) = a : reverse (orderPolygonAround a as)
|
||||||
|
|
||||||
orderAroundFirst :: [Point2] -> [Point2]
|
orderAroundFirst :: [Point2] -> [Point2]
|
||||||
orderAroundFirst [] = []
|
orderAroundFirst [] = []
|
||||||
orderAroundFirst (a:as) = a : orderPolygonAround a as
|
orderAroundFirst (a:as) = a : orderPolygonAround a as
|
||||||
@@ -141,8 +145,9 @@ convexHull :: [Point2] -> [Point2]
|
|||||||
convexHull (x:y:z:xs) = grahamScan $ orderAroundFirst $ sortOn (\(V2 a b) -> (b,a)) (x:y:z:xs)
|
convexHull (x:y:z:xs) = grahamScan $ orderAroundFirst $ sortOn (\(V2 a b) -> (b,a)) (x:y:z:xs)
|
||||||
convexHull _ = error "Tried to create the convex hull of two or fewer points"
|
convexHull _ = error "Tried to create the convex hull of two or fewer points"
|
||||||
-- | Creates the convex hull of a set of points.
|
-- | Creates the convex hull of a set of points.
|
||||||
-- it appears that the output may NOT be ordered
|
-- assumes no repetition of points: try nubbing!
|
||||||
convexHullSafe :: [Point2] -> [Point2]
|
convexHullSafe :: [Point2] -> [Point2]
|
||||||
|
--convexHullSafe (x:y:z:xs) = grahamScan $ orderAroundFirst $ sortOn (\(V2 a b) -> (b,a)) (x:y:z:xs)
|
||||||
convexHullSafe (x:y:z:xs) = grahamScan $ orderAroundFirst $ sortOn (\(V2 a b) -> (b,a)) (x:y:z:xs)
|
convexHullSafe (x:y:z:xs) = grahamScan $ orderAroundFirst $ sortOn (\(V2 a b) -> (b,a)) (x:y:z:xs)
|
||||||
convexHullSafe _ = []
|
convexHullSafe _ = []
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ module Picture
|
|||||||
, module Color
|
, module Color
|
||||||
, blank
|
, blank
|
||||||
, polygon
|
, polygon
|
||||||
|
, polygonWire
|
||||||
, polygonZ
|
, polygonZ
|
||||||
, polygonCol
|
, polygonCol
|
||||||
, poly3
|
, poly3
|
||||||
@@ -56,6 +57,10 @@ blank :: Picture
|
|||||||
{-# INLINE blank #-}
|
{-# INLINE blank #-}
|
||||||
blank = []
|
blank = []
|
||||||
|
|
||||||
|
polygonWire :: [Point2] -> Picture
|
||||||
|
{-# INLINE polygonWire #-}
|
||||||
|
polygonWire ps = line (ps ++ [head ps])
|
||||||
|
|
||||||
polygon :: [Point2] -> Picture
|
polygon :: [Point2] -> Picture
|
||||||
{-# INLINE polygon #-}
|
{-# INLINE polygon #-}
|
||||||
polygon ps = map f $ polyToTris ps
|
polygon ps = map f $ polyToTris ps
|
||||||
|
|||||||
Reference in New Issue
Block a user