diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2013-11-29 15:20:12 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2013-11-29 15:20:12 +0100 |
commit | e1b79d47ad855466dd48c29eddf0e061ce99e9c8 (patch) | |
tree | 6432897c8c40203ebd3844353a497e6dbf529a02 | |
parent | 350a586634c69194787cc074016ffb934becca96 (diff) | |
download | haskell-e1b79d47ad855466dd48c29eddf0e061ce99e9c8.tar.gz haskell-e1b79d47ad855466dd48c29eddf0e061ce99e9c8.tar.bz2 haskell-e1b79d47ad855466dd48c29eddf0e061ce99e9c8.zip |
correct sphere ordering
-rw-r--r-- | raytracer.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/raytracer.hs b/raytracer.hs index 9d60e8c..8bc697d 100644 --- a/raytracer.hs +++ b/raytracer.hs @@ -19,10 +19,12 @@ x_of (x, _, _) = x y_of (_, y, _) = y z_of (_, _, z) = z -sphere1 = Sphere (80, 43, 5) 10 (55,255,0) -sphere2 = Sphere (30, 65, -5) 20 (255,60,0) +sphere1 = Sphere (80, 80, 5) 10 (55,255,0) +sphere2 = Sphere (80, -80, -5) 20 (255,60,0) +sphere3 = Sphere (-80, 80, -5) 20 (5,60,200) +sphere4 = Sphere (-80, -80, -5) 20 (0,255,255) -spheres = [sphere1, sphere2] +spheres = [sphere1, sphere2, sphere3, sphere4] alpha1 = 120 * degrees @@ -123,7 +125,10 @@ skycolor source (alpha, beta) = (60, data SphereIntersect = SphereIntersect Double Color deriving (Eq, Show) -- distance color instance Ord SphereIntersect where - (SphereIntersect d1 _) `compare` (SphereIntersect d2 _) = d1 `compare` d2 + (SphereIntersect d1 _) `compare` (SphereIntersect d2 _) + | d2 == 0 = LT + | d1 == 0 = GT + | otherwise = d1 `compare` d2 nearest_sphere :: Coord -> ScreenCoord -> [Sphere] -> SphereIntersect nearest_sphere source scoord spheres = @@ -193,4 +198,5 @@ allpixels = map ov_color ov_pixels image = imgheader ++ (foldr (++) "" (map pixel_to_ppm allpixels)) -main = writeFile "foo.ppm" image +main = do putStrLn "Rendering"; + writeFile "foo.ppm" image |