Some finitions

This commit is contained in:
Yann Esposito 2012-06-14 18:01:34 +02:00
parent 79409a8a72
commit c0900ea16c
3 changed files with 20 additions and 10 deletions

View file

@ -6,8 +6,11 @@ Some points:
In particular the `mainLoop` function is a direct link to the C library (FFI). In particular the `mainLoop` function is a direct link to the C library (FFI).
This function is clearly far from the functional paradigm. This function is clearly far from the functional paradigm.
Could we make this better? Could we make this better?
We will have two choices, or create our own `mainLoop` function to make it more functional. We will have two choices:
Or deal with the imperative nature of the GLUT `mainLoop` function.
- create our own `mainLoop` function to make it more functional.
- deal with the imperative nature of the GLUT `mainLoop` function.
As one of the goal of this article is to understand how to deal with existing libraries and particularly the one coming from imperative languages, we will continue to use the `mainLoop` function. As one of the goal of this article is to understand how to deal with existing libraries and particularly the one coming from imperative languages, we will continue to use the `mainLoop` function.
2. Our main problem come from user interaction. 2. Our main problem come from user interaction.
If you ask "the Internet", If you ask "the Internet",
@ -237,9 +240,9 @@ The rest is similar to the preceding sections.
> ymandel :: Point -> Point -> Point -> Point > ymandel :: Point -> Point -> Point -> Point
> ymandel x y z = fromIntegral (mandel x y z 64) / 64 > ymandel x y z = fromIntegral (mandel x y z 64) / 64
I won't put how the magic occurs directly here. I won't explain how the magic occurs here.
But all the magic occurs in the file `YGL.hs`. If you are interested, just read the file [`YGL.hs`](code/05_Mandelbulb/YGL.hs).
This file is commented a lot. It is commented a lot.
- [`YGL.hs`](code/05_Mandelbulb/YGL.hs), the 3D rendering framework - [`YGL.hs`](code/05_Mandelbulb/YGL.hs), the 3D rendering framework
- [`Mandel`](code/05_Mandelbulb/Mandel.hs), the mandel function - [`Mandel`](code/05_Mandelbulb/Mandel.hs), the mandel function

View file

@ -1,6 +1,3 @@
-- The languages include needed because I wanted to use
-- (Point,Point,Point) instead of
-- data Point3D = Point3D (Point,Point,Point) deriving ...
{- {-
The module YGL will contains most boilerplate The module YGL will contains most boilerplate
And display details. And display details.
@ -37,11 +34,20 @@ module YGL (
-- The main loop function to call -- The main loop function to call
, yMainLoop) where , yMainLoop) where
import Numeric (readHex) -- A bunch of imports
import Numeric (readHex) -- to read hexadecimal values
-- Import of OpenGL and GLUT
-- but, I use my own Color type, therefore I hide the definition
-- of Color inside GLUT and OpenGL packages
import Graphics.Rendering.OpenGL hiding (Color) import Graphics.Rendering.OpenGL hiding (Color)
import Graphics.UI.GLUT hiding (Color) import Graphics.UI.GLUT hiding (Color)
import Data.IORef import Data.IORef
-- I use Map to deal with user interaction
import qualified Data.Map as Map import qualified Data.Map as Map
-- Some standard stuff
import Control.Monad (when) import Control.Monad (when)
import Data.Maybe (isNothing) import Data.Maybe (isNothing)
@ -49,6 +55,7 @@ import Data.Maybe (isNothing)
- Just take the time to follow me. - Just take the time to follow me.
--} --}
-- | A 1D point -- | A 1D point
type Point = GLfloat type Point = GLfloat
-- | A Scalar value -- | A Scalar value

View file

@ -22,4 +22,4 @@ Such an optimization would have been harder by using directly the OpenGL library
You should also want to make a more precise object. Because, the Mandelbulb is You should also want to make a more precise object. Because, the Mandelbulb is
clearly not convex. But a precise rendering might be very long from clearly not convex. But a precise rendering might be very long from
\\(O(n^2log n)\\) to \\(O(n^3)\\). O(n².log(n)) to O(n³).