summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-30 15:59:18 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-30 15:59:18 -0400
commit87249534efb636cc094d46a869c28c7269031223 (patch)
tree94fd729f07729b2729d8736308e6d8c9cff5579a
parent3688556416bb02c278802e0b988058a102bd1b3a (diff)
Compute height of pixel at distance.
-rw-r--r--MeshSketch.hs7
1 files changed, 7 insertions, 0 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs
index 02c813d..0c1b4a2 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -471,6 +471,13 @@ onResize glarea realized w h = do
471unit :: (Linear t c, Fractional t, Normed (c t)) => c t -> c t 471unit :: (Linear t c, Fractional t, Normed (c t)) => c t -> c t
472unit v = scale (1/realToFrac (norm_2 v)) v 472unit v = scale (1/realToFrac (norm_2 v)) v
473 473
474-- | Compute the height of a pixel at the given 3d point.
475pixelDelta :: Camera -> Vector Float -> Float
476pixelDelta cam x = realToFrac $ frustumHeight eyeToPoint / realToFrac (camHeight cam)
477 where
478 eyeToPoint = norm_2 (x - camPos cam)
479 frustumHeight d = 2 * d * tan (realToFrac $ camHeightAngle cam / 2)
480
474-- This computes a point in world coordinates on the view screen if 481-- This computes a point in world coordinates on the view screen if
475-- we assume the camera is located at the origin. 482-- we assume the camera is located at the origin.
476computeDirection :: Camera -> Double -> Double -> Vector Float 483computeDirection :: Camera -> Double -> Double -> Vector Float