You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

32 lines
785 B

module Ray
( Ray (..),
rayAt,
calculateRayNormal,
buildRay,
buildRayAA,
)
where
import Control.Monad.Random
import Linear.V3
import Linear.Vector
import Maths
data Ray = Ray {origin :: V3 Double, direction :: V3 Double}
-- P(t) = A + tB; A is origin, B is direction
rayAt :: Ray -> Double -> V3 Double
rayAt (Ray origin dir) t = origin + (t *^ dir)
-- get the normal of the point at t
calculateRayNormal :: Ray -> Double -> V3 Double
calculateRayNormal r t = unitVector (rayAt r t ^-^ V3 0.0 0.0 1.0)
buildRayAA :: (RandomGen g) => Double -> Double -> Rand g Ray
buildRayAA u v = do
ur <- rand
vr <- rand
return (Ray (V3 0.0 0.0 0.0) (V3 (v + vr) (u + ur) (-1.0)))
buildRay :: Double -> Double -> Ray
buildRay u v = Ray (V3 0.0 0.0 0.0) (V3 v u (-1.0))