module Main where import Physics import World import RayTrace -- The octTree to be used. -- Looks like this from above. s = sphere L = light -- --------------- -- | | 4 5 6 | -- | L2 | 2 3 | -- |-------|-------| -- | | | -- | L1 | 1 | -- |-------|-------| obj1 = Object (Sphere (Pt (2.0,2.0,2.0)) 0.5) 0.3 0.7 white obj2 = Object (Sphere (Pt (2.0,2.0,8.0)) 0.5) 0.3 0.7 red obj3 = Object (Sphere (Pt (4.0,2.0,8.0)) 0.5) 0.3 0.7 green obj4 = Object (Sphere (Pt (2.0,2.0,10.0)) 0.5) 0.3 0.7 blue -- Object 5 is yellow obj5 = Object (Sphere (Pt (4.0,2.0,10.0)) 0.5) 0.3 0.7 (Col (1.0,1.0,0.0)) -- Object 6 is magenta obj6 = Object (Sphere (Pt (6.0,2.0,10.0)) 0.5) 0.3 0.7 (Col (1.0,0.0,1.0)) boundVox = (Pt (-8.0,-8.0,-2.0),16.0) vox0 = (Pt (-8.0,-8.0,-2.0),8.0) vox1 = (Pt (0.0,-8.0,-2.0),8.0) vox2 = (Pt (-8.0,0.0,-2.0),8.0) vox3 = (Pt (0.0,0.0,-2.0),8.0) vox4 = (Pt (-8.0,-8.0,6.0),8.0) vox5 = (Pt (0.0,-8.0,6.0),8.0) vox6 = (Pt (-8.0,0.0,6.0),8.0) vox7 = (Pt (0.0,0.0,6.0),8.0) leaf0 = Leaf vox0 [] leaf1 = Leaf vox1 [] leaf2 = Leaf vox2 [] leaf3 = Leaf vox3 [obj1] leaf4 = Leaf vox4 [] leaf5 = Leaf vox5 [] leaf6 = Leaf vox6 [] leaf7 = Leaf vox7 [obj2, obj3, obj4, obj5, obj6] octTree = Node boundVox [ leaf0, leaf1, leaf2, leaf3 , leaf4, leaf5, leaf6, leaf7 ] (width, height) = (100,100) worldWidth = 4 pixelWidth = worldWidth / width -- View plane is from -2 to 2 in width and -2 to 2 in height topLeft = (-2.0,2.0) minSize = 8.0 -- only got divided once. -- the lights are both white light1 = Light (Pt (-4,2,2)) white light2 = Light (Pt (-4,2,8)) white lights =[ light1, light2] ambient = Col (0.1, 0.1, 0.1) scene = Scene octTree minSize ambient lights -- Rays -- This one passes through leaves 3 and 7 ray1 = Ray (Pt (2, 2, -1)) (Vec (0,0,1)) -- This one passes through leaves 3 and 7 ray2 = Ray (Pt (4, 2, -1)) (Vec (0,0,1)) -- Ray from between obj2 and obj3 that points in direction of light 2 ray3 = Ray (Pt (3, 2, 8)) (Vec (-1,0,0)) ray4 = Ray (Pt (0,2,0)) (unit (Vec (1,0,1))) ray5 = Ray (Pt (0,2,12)) (unit (Vec (1,0,-1))) ------------------------------------------------------------------------- -- rayForPixel rfp1 = rayForPixel worldWidth pixelWidth topLeft (0,0) rfp2 = rayForPixel worldWidth pixelWidth topLeft (50,50) -- ambientComponent a1 = let Just (t, vec) = intersect ray1 (getPureObj obj1) in ambientComponent scene ray1 (obj1, t, vec) -- intersectsInVoxel -- should intersect obj2 and obj4 iiv1 = let objs = [obj2, obj3, obj4, obj5, obj6] in intersectsInVoxel objs vox7 ray1 -- intersectsInVoxel -- should intersect obj3 and obj5 iiv2 = let objs = [obj2, obj3, obj4, obj5, obj6] in intersectsInVoxel objs vox7 ray2 -- firstIntersect -- should be on obj1 fi1 = firstIntersect scene leaf3 ray1 -- firstIntersect -- should be on obj3 fi2 = firstIntersect scene leaf3 ray2 -- checkShadowIntersect -- For this one we shoot a ray from between objects 2 and 3 out towards light 1 -- Naturally it's going to to hit obj2 csi1 = checkShadowIntersect scene (Pt (3,2,8)) light2 ray3 -- Diffuse component dc1 = let Just (t, vec) = intersect ray4 (getPureObj obj1) in diffuseComponent scene ray4 (obj1, t, vec) dc2 = let Just (t, vec) = intersect ray5 (getPureObj obj4) in diffuseComponent scene ray5 (obj4, t, vec) -- specular component sc1 = let Just (t, vec) = intersect ray4 (getPureObj obj1) in specularComponent scene ray4 (obj1, t, vec) sc2 = let Just (t, vec) = intersect ray5 (getPureObj obj4) in specularComponent scene ray5 (obj4, t, vec) tests = [ ("rfp1", show rfp1) , ("rfp2", show rfp2) , ("a1", show a1) , ("iiv1", show iiv1) , ("iiv2", show iiv2) , ("fi1", show fi1) , ("fi2", show fi2) , ("csi1", show csi1) , ("dc1", show dc1) , ("dc2", show dc2) , ("sc1", show sc1) , ("sc2", show sc2) ] showTest (description, result) = description ++ ": " ++ result main :: IO () main = putStr (unlines (map showTest tests))