diff options
author | Joe Crayne <joe@jerkface.net> | 2019-05-30 15:59:18 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-05-30 15:59:18 -0400 |
commit | 87249534efb636cc094d46a869c28c7269031223 (patch) | |
tree | 94fd729f07729b2729d8736308e6d8c9cff5579a | |
parent | 3688556416bb02c278802e0b988058a102bd1b3a (diff) |
Compute height of pixel at distance.
-rw-r--r-- | MeshSketch.hs | 7 |
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 | |||
471 | unit :: (Linear t c, Fractional t, Normed (c t)) => c t -> c t | 471 | unit :: (Linear t c, Fractional t, Normed (c t)) => c t -> c t |
472 | unit v = scale (1/realToFrac (norm_2 v)) v | 472 | unit v = scale (1/realToFrac (norm_2 v)) v |
473 | 473 | ||
474 | -- | Compute the height of a pixel at the given 3d point. | ||
475 | pixelDelta :: Camera -> Vector Float -> Float | ||
476 | pixelDelta 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. |
476 | computeDirection :: Camera -> Double -> Double -> Vector Float | 483 | computeDirection :: Camera -> Double -> Double -> Vector Float |