Move configuration from world to universe
This commit is contained in:
+22
-20
@@ -15,55 +15,57 @@ printRotPoint r p = color white
|
||||
. uncurryV translate p
|
||||
$ pictures [circle 3 , rotate (negate r) $ scale 0.1 0.1 $ text (show p)]
|
||||
|
||||
outsideScreenPolygon :: World -> [Point2]
|
||||
outsideScreenPolygon w = [tr,tl,bl,br]
|
||||
outsideScreenPolygon :: Configuration -> World -> [Point2]
|
||||
outsideScreenPolygon cfig w = [tr,tl,bl,br]
|
||||
where
|
||||
scRot = rotateV (_cameraRot w)
|
||||
scZoom p | _cameraZoom w /= 0 = (1/_cameraZoom w) *.* p
|
||||
| otherwise = error "Trying to set screen zoom to zero"
|
||||
scTran p = p +.+ _cameraCenter w
|
||||
tr = scTran $ scRot $ scZoom $ V2 ( 3*halfWidth w ) ( 3* halfHeight w)
|
||||
tl = scTran $ scRot $ scZoom $ V2 (- (3*halfWidth w)) ( 3* halfHeight w)
|
||||
br = scTran $ scRot $ scZoom $ V2 ( 3*halfWidth w ) (- (3* halfHeight w))
|
||||
bl = scTran $ scRot $ scZoom $ V2 (- (3*halfWidth w)) (- (3* halfHeight w))
|
||||
tr = f 3 3
|
||||
tl = f (-3) 3
|
||||
br = f 3 (-3)
|
||||
bl = f (-3) (-3)
|
||||
f a b = scTran $ scRot $ scZoom $ V2 (a*halfWidth cfig) (b* halfHeight cfig)
|
||||
|
||||
-- cannot only test if walls are on screen, but also if they are on the cone
|
||||
-- towards the center of sight
|
||||
lineOnScreenCone :: World -> Point2 -> Point2 -> Bool
|
||||
lineOnScreenCone w p1 p2 = pointInPolygon p1 sp
|
||||
lineOnScreenCone :: Configuration -> World -> Point2 -> Point2 -> Bool
|
||||
lineOnScreenCone cfig w p1 p2 = pointInPolygon p1 sp
|
||||
|| pointInPolygon p2 sp
|
||||
|| any (isJust . uncurry (intersectSegSeg p1 p2)) sps
|
||||
where
|
||||
sp' = screenPolygon w
|
||||
sp' = screenPolygon cfig w
|
||||
vp = _cameraViewFrom w
|
||||
sp | pointInPolygon vp sp' = sp'
|
||||
| otherwise = orderPolygon (_cameraViewFrom w : sp')
|
||||
sps = zip sp (tail sp ++ [head sp])
|
||||
|
||||
|
||||
drawWallFace :: World -> Wall -> Picture
|
||||
drawWallFace w wall
|
||||
drawWallFace :: Configuration -> World -> Wall -> Picture
|
||||
drawWallFace cfig w wall
|
||||
| isRHS sightFrom x y || _wlOpacity wall /= Opaque = blank
|
||||
| otherwise = setDepth (-1) . color (withAlpha 0 black) . polygon $ points
|
||||
where
|
||||
(x,y) = _wlLine wall
|
||||
points = extendConeToScreenEdge w sightFrom (x,y)
|
||||
points = extendConeToScreenEdge cfig w sightFrom (x,y)
|
||||
sightFrom = _cameraViewFrom w
|
||||
|
||||
extendConeToScreenEdge :: World -> Point2 -> (Point2,Point2) -> [Point2]
|
||||
extendConeToScreenEdge w c (x,y) = orderPolygon $ wallScreenIntersect ++ [x,y] ++ borderPs ++ cornerPs
|
||||
extendConeToScreenEdge :: Configuration -> World -> Point2 -> (Point2,Point2) -> [Point2]
|
||||
extendConeToScreenEdge cfig w c (x,y) = orderPolygon $ wallScreenIntersect ++ [x,y] ++ borderPs ++ cornerPs
|
||||
where
|
||||
borderPs = mapMaybe (intersectLinefromScreen w c) [x,y]
|
||||
cornerPs = filter (pointIsInCone c (x,y)) $ screenPolygon w
|
||||
borderPs = mapMaybe (intersectLinefromScreen cfig w c) [x,y]
|
||||
scpoly = screenPolygon cfig w
|
||||
cornerPs = filter (pointIsInCone c (x,y)) scpoly
|
||||
wallScreenIntersect = mapMaybe (uncurry $ intersectSegSeg y ((2*.*y) -.- x))
|
||||
. loopPairs $ screenPolygon w
|
||||
. loopPairs $ scpoly
|
||||
|
||||
-- the following assumes that the point a is inside the screen
|
||||
-- it still works otherwise, but it might intersect two points:
|
||||
-- it is not obvious which will be returned
|
||||
intersectLinefromScreen :: World -> Point2 -> Point2 -> Maybe Point2
|
||||
intersectLinefromScreen w a b = listToMaybe
|
||||
intersectLinefromScreen :: Configuration -> World -> Point2 -> Point2 -> Maybe Point2
|
||||
intersectLinefromScreen cfig w a b = listToMaybe
|
||||
. mapMaybe (\(x,y) -> intersectSegLineFrom x y b (b +.+ b -.- a))
|
||||
. loopPairs
|
||||
$ screenPolygon w
|
||||
$ screenPolygon cfig w
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import Dodge.Creature
|
||||
|
||||
import Control.Lens
|
||||
|
||||
applyTerminalString :: String -> World -> World
|
||||
applyTerminalString :: String -> Universe -> Universe
|
||||
applyTerminalString "NOCLIP" w = w & config . debug_noclip %~ not
|
||||
applyTerminalString "LOADME" w = w & creatures . ix 0 . crInv .~ stackedInventory
|
||||
applyTerminalString "LM" w = w & creatures . ix 0 . crInv .~ stackedInventory
|
||||
applyTerminalString "LOADME" w = w & uvWorld . creatures . ix 0 . crInv .~ stackedInventory
|
||||
applyTerminalString "LM" w = applyTerminalString "LOADME" w
|
||||
applyTerminalString _ w = w
|
||||
|
||||
loadme :: a
|
||||
|
||||
Reference in New Issue
Block a user