From 87249534efb636cc094d46a869c28c7269031223 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Thu, 30 May 2019 15:59:18 -0400 Subject: Compute height of pixel at distance. --- MeshSketch.hs | 7 +++++++ 1 file changed, 7 insertions(+) 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 unit :: (Linear t c, Fractional t, Normed (c t)) => c t -> c t unit v = scale (1/realToFrac (norm_2 v)) v +-- | Compute the height of a pixel at the given 3d point. +pixelDelta :: Camera -> Vector Float -> Float +pixelDelta cam x = realToFrac $ frustumHeight eyeToPoint / realToFrac (camHeight cam) + where + eyeToPoint = norm_2 (x - camPos cam) + frustumHeight d = 2 * d * tan (realToFrac $ camHeightAngle cam / 2) + -- This computes a point in world coordinates on the view screen if -- we assume the camera is located at the origin. computeDirection :: Camera -> Double -> Double -> Vector Float -- cgit v1.2.3