Camera position refactor

This commit is contained in:
2022-10-28 15:32:46 +01:00
parent 27fe1c7a96
commit 2e7cd0aec2
24 changed files with 184 additions and 163 deletions
+11 -11
View File
@@ -17,14 +17,14 @@ printRotPoint r p =
. uncurryV translate p
$ pictures [circle 3, rotate (negate r) $ scale 0.1 0.1 $ text (show p)]
outsideScreenPolygon :: Configuration -> World -> [Point2]
outsideScreenPolygon :: Configuration -> CamPos -> [Point2]
outsideScreenPolygon cfig w = [tr, tl, bl, br]
where
scRot = rotateV (w ^. cWorld . lWorld . cwCam . cwcRot)
scRot = rotateV (w ^. camRot)
scZoom p
| (w ^. cWorld . lWorld . cwCam . cwcZoom) /= 0 = (1 / (w ^. cWorld . lWorld . cwCam . cwcZoom)) *.* p
| (w ^. camZoom) /= 0 = (1 / (w ^. camZoom)) *.* p
| otherwise = error "Trying to set screen zoom to zero"
scTran p = p +.+ (w ^. cWorld . lWorld . cwCam . cwcCenter)
scTran p = p +.+ (w ^. camCenter)
tr = f 3 3
tl = f (-3) 3
br = f 3 (-3)
@@ -39,14 +39,14 @@ lineOnScreenCone cfig w p1 p2 =
|| pointInPolygon p2 sp
|| any (isJust . uncurry (intersectSegSeg p1 p2)) sps
where
sp' = screenPolygon cfig w
vp = w ^. cWorld . lWorld . cwCam . cwcViewFrom
sp' = screenPolygon cfig (w ^. cWorld . lWorld . camPos)
vp = w ^. cWorld . lWorld . camPos . camViewFrom
sp
| pointInPolygon vp sp' = sp'
| otherwise = orderPolygon ((w ^. cWorld . lWorld . cwCam . cwcViewFrom) : sp')
| otherwise = orderPolygon ((w ^. cWorld . lWorld . camPos . camViewFrom) : sp')
sps = zip sp (tail sp ++ [head sp])
pointOnScreen :: Configuration -> World -> Point2 -> Bool
pointOnScreen :: Configuration -> CamPos -> Point2 -> Bool
pointOnScreen cfig w p = pointInPolygon p $ screenPolygon cfig w
drawWallFace :: Configuration -> World -> Wall -> Picture
@@ -56,13 +56,13 @@ drawWallFace cfig w wall
where
(x, y) = _wlLine wall
points = extendConeToScreenEdge cfig w sightFrom (x, y)
sightFrom = w ^. cWorld . lWorld . cwCam . cwcViewFrom
sightFrom = w ^. cWorld . lWorld . camPos . camViewFrom
extendConeToScreenEdge :: Configuration -> World -> Point2 -> (Point2, Point2) -> [Point2]
extendConeToScreenEdge cfig w c (x, y) = orderPolygon $ wallScreenIntersect ++ [x, y] ++ borderPs ++ cornerPs
where
borderPs = mapMaybe (intersectLinefromScreen cfig w c) [x, y]
scpoly = reverse $ screenPolygon cfig w
scpoly = reverse $ screenPolygon cfig (w ^. cWorld . lWorld . camPos)
cornerPs = filter (pointIsInCone c (x, y)) scpoly
wallScreenIntersect =
mapMaybe (uncurry $ intersectSegSeg y ((2 *.* y) -.- x))
@@ -77,4 +77,4 @@ intersectLinefromScreen cfig w a b =
listToMaybe
. mapMaybe (\(x, y) -> intersectSegLineFrom x y b (b +.+ b -.- a))
. loopPairs
$ screenPolygon cfig w
$ screenPolygon cfig (w ^. cWorld . lWorld . camPos)