Updated better colors

This commit is contained in:
Yann Esposito 2012-05-23 14:17:24 +02:00
parent 7cd0311be3
commit a643a17f7d
2 changed files with 19 additions and 18 deletions

View file

@ -50,10 +50,12 @@ The mapping between user input and actions.
> ,(Press 's' , translate xdir (-0.1)) > ,(Press 's' , translate xdir (-0.1))
> ,(Press 'e' , translate ydir 0.1) > ,(Press 'e' , translate ydir 0.1)
> ,(Press 'd' , translate ydir (-0.1)) > ,(Press 'd' , translate ydir (-0.1))
> ,(Press 'z' , translate zdir 0.1)
> ,(Press 'r' , translate zdir (-0.1))
> ,(Press '+' , zoom 1.1) > ,(Press '+' , zoom 1.1)
> ,(Press '-' , zoom (1/1.1)) > ,(Press '-' , zoom (1/1.1))
> ,(Press 'r' , resize 1.2) > ,(Press 'h' , resize 1.2)
> ,(Press 'z' , resize (1/1.2)) > ,(Press 'g' , resize (1/1.2))
> ] > ]
The type of each couple should be of the form The type of each couple should be of the form
@ -67,7 +69,7 @@ And of course a type design the World State:
> angle :: Point3D > angle :: Point3D
> , scale :: Scalar > , scale :: Scalar
> , position :: Point3D > , position :: Point3D
> , shape :: Function3D > , shape :: Scalar -> Function3D
> , box :: Box3D > , box :: Box3D
> } > }
@ -76,7 +78,10 @@ And of course a type design the World State:
> camPos = position w, > camPos = position w,
> camDir = angle w, > camDir = angle w,
> camZoom = scale w } > camZoom = scale w }
> objects w = [XYFunc (shape w) (box w)] > objects w = [XYSymFunc ((shape w) res) defbox]
> where
> res = resolution $ box w
> defbox = box w
With all associated functions: With all associated functions:
@ -104,7 +109,7 @@ With all associated functions:
> resize :: Scalar -> World -> World > resize :: Scalar -> World -> World
> resize r world = world { > resize r world = world {
> box = (box world) { > box = (box world) {
> resolution = (resolution (box world)) * r }} > resolution = sqrt ((resolution (box world))**2 * r) }}
- [`YBoiler.hs`](code/04_Mandelbulb/YBoiler.hs), the 3D rendering - [`YBoiler.hs`](code/04_Mandelbulb/YBoiler.hs), the 3D rendering
- [`Mandel`](code/04_Mandelbulb/Mandel.hs), the mandel function - [`Mandel`](code/04_Mandelbulb/Mandel.hs), the mandel function
@ -122,21 +127,22 @@ With all associated functions:
> -- And the shape function > -- And the shape function
> initialWorld :: World > initialWorld :: World
> initialWorld = World { > initialWorld = World {
> angle = makePoint3D (0,1,0) > angle = makePoint3D (-30,0,0)
> , position = makePoint3D (0,0,0) > , position = makePoint3D (0,0,0)
> , scale = 0.2 > , scale = 0.8
> , shape = shapeFunc > , shape = shapeFunc
> , box = Box3D { minPoint = makePoint3D (-2,-2,-2) > , box = Box3D { minPoint = makePoint3D (-2,-2,-2)
> , maxPoint = makePoint3D (2,2,2) > , maxPoint = makePoint3D (2,2,2)
> , resolution = 0.2 } > , resolution = 0.2 }
> } > }
> >
> shapeFunc :: Function3D > shapeFunc :: Scalar -> Function3D
> shapeFunc x y = > shapeFunc res x y =
> let > let
> z = findMaxOrdFor (ymandel x y) 0 1 20 > z = findMaxOrdFor (ymandel x y) 0 1 20
> in > in
> if z < 0.000001 > if and [ findMaxOrdFor (ymandel (x+xeps) (y+yeps)) 0 1 20 < 0.000001 |
> val <- [res], xeps <- [-val,val], yeps<-[-val,val]]
> then Nothing > then Nothing
> else Just z > else Just z
> >

View file

@ -211,13 +211,9 @@ yMainLoop winTitle
displayCallback $= display worldRef displayCallback $= display worldRef
-- Lights -- Lights
lighting $= Enabled lighting $= Enabled
ambient (Light 0) $= Color4 0.7 0.6 0.3 1 ambient (Light 1) $= Color4 0.99 0.98 0.62 1
diffuse (Light 0) $= Color4 1 1 1 1 diffuse (Light 1) $= Color4 0.99 0.98 0.62 1
position (Light 0) $= Vertex4 0.5 0.5 0.3 1 position (Light 1) $= Vertex4 0 0 1 0.1
light (Light 0) $= Enabled
ambient (Light 1) $= Color4 0.7 0.6 0.3 1
diffuse (Light 1) $= Color4 1 1 1 1
position (Light 1) $= Vertex4 (-0.5) (-0.5) (-0.3) 1
light (Light 1) $= Enabled light (Light 1) $= Enabled
-- We enter the main loop -- We enter the main loop
mainLoop mainLoop
@ -310,7 +306,6 @@ drawObject shape = do
where where
trinorm = (getNormal tri) trinorm = (getNormal tri)
drawTriangles _ = return () drawTriangles _ = return ()
unityBox = makeBox (-2,-2,-2) (2,2,2) 0.05
getNormal :: [Point3D] -> Point3D getNormal :: [Point3D] -> Point3D
getNormal (p0:p1:p2:_) = (p1 - p0) * (p2 - p0) getNormal (p0:p1:p2:_) = (p1 - p0) * (p2 - p0)