Final optimization with symetric shape
This commit is contained in:
parent
bcefcae12e
commit
114bcd2fc8
2 changed files with 11 additions and 47 deletions
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
> import YGL -- Most the OpenGL Boilerplate
|
> import YGL -- Most the OpenGL Boilerplate
|
||||||
> import Mandel -- The 3D Mandelbrot maths
|
> import Mandel -- The 3D Mandelbrot maths
|
||||||
> import Data.Maybe (isNothing)
|
|
||||||
|
|
||||||
|
|
||||||
> -- Centralize all user input interaction
|
> -- Centralize all user input interaction
|
||||||
> inputActionMap :: InputMap World
|
> inputActionMap :: InputMap World
|
||||||
|
@ -33,10 +31,8 @@
|
||||||
> angle :: Point3D
|
> angle :: Point3D
|
||||||
> , scale :: Scalar
|
> , scale :: Scalar
|
||||||
> , position :: Point3D
|
> , position :: Point3D
|
||||||
> , shape :: Scalar -> Function3D
|
|
||||||
> , box :: Box3D
|
> , box :: Box3D
|
||||||
> , told :: Time -- last frame time
|
> , told :: Time -- last frame time
|
||||||
> , toCompute :: Bool
|
|
||||||
> , cache :: [YObject]
|
> , cache :: [YObject]
|
||||||
> }
|
> }
|
||||||
|
|
||||||
|
@ -47,7 +43,7 @@
|
||||||
> camPos = position w,
|
> camPos = position w,
|
||||||
> camDir = angle w,
|
> camDir = angle w,
|
||||||
> camZoom = scale w }
|
> camZoom = scale w }
|
||||||
> objects w = cache w
|
> objects = cache
|
||||||
|
|
||||||
<div style="display:hidden">
|
<div style="display:hidden">
|
||||||
|
|
||||||
|
@ -90,54 +86,21 @@
|
||||||
> angle = makePoint3D (-30,-30,0)
|
> angle = makePoint3D (-30,-30,0)
|
||||||
> , position = makePoint3D (0,0,0)
|
> , position = makePoint3D (0,0,0)
|
||||||
> , scale = 0.8
|
> , scale = 0.8
|
||||||
> , 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.16 }
|
> , resolution = 0.16 }
|
||||||
> , told = 0
|
> , told = 0
|
||||||
> , cache = objectFunctionFromWorld initialWorld
|
> , cache = objectFunctionFromWorld initialWorld
|
||||||
> , toCompute = True
|
|
||||||
> }
|
> }
|
||||||
>
|
>
|
||||||
> objectFunctionFromWorld w = [Atoms $
|
> objectFunctionFromWorld w = [Atoms atomList]
|
||||||
> getObject3DFromShapeFunction (shapeFunc (resolution (box w))) (box w)]
|
> where atomListPositive =
|
||||||
>
|
> getObject3DFromShapeFunction (shapeFunc (resolution (box w))) (box w)
|
||||||
> getObject3DFromShapeFunction :: Function3D -> Box3D -> [Atom]
|
> atomList = atomListPositive ++
|
||||||
> getObject3DFromShapeFunction shape box = do
|
> map negativeTriangle atomListPositive
|
||||||
> x <- [xmin,xmin+res..xmax]
|
> negativeTriangle (ColoredTriangle (p1,p2,p3,c)) =
|
||||||
> y <- [ymin,ymin+res..ymax]
|
> ColoredTriangle (negz p1,negz p2,negz p3,c)
|
||||||
> let
|
> where negz (P (x,y,z)) = P (x,y,-z)
|
||||||
> neighbors = [(x,y),(x+res,y),(x+res,y+res),(x,y+res)]
|
|
||||||
> -- zs are 3D points with found depth and color
|
|
||||||
> -- zs :: [ (Point,Point,Point,Maybe (Point,Color) ]
|
|
||||||
> zs = map (\(u,v) -> (u,v,shape u v)) neighbors
|
|
||||||
> -- ps are 3D opengl points + color value
|
|
||||||
> ps = zs
|
|
||||||
> -- If the point diverged too fast, don't display it
|
|
||||||
> if any (\(_,_,z) -> isNothing z) zs
|
|
||||||
> then []
|
|
||||||
> -- Draw two triangles
|
|
||||||
> -- 3 - 2
|
|
||||||
> -- | / |
|
|
||||||
> -- 0 - 1
|
|
||||||
> -- The order is important
|
|
||||||
> else
|
|
||||||
> [ makeAtom (ps!!0) (ps!!2) (ps!!1)
|
|
||||||
> , makeAtom (ps!!0) (ps!!3) (ps!!2) ]
|
|
||||||
> where
|
|
||||||
> makeAtom (p0x,p0y,Just (p0z,c0)) (p1x,p1y,Just (p1z,_)) (p2x,p2y,Just (p2z,_)) =
|
|
||||||
> ColoredTriangle (makePoint3D (p0x,p0y,p0z)
|
|
||||||
> ,makePoint3D (p1x,p1y,p1z)
|
|
||||||
> ,makePoint3D (p2x,p2y,p2z)
|
|
||||||
> ,c0)
|
|
||||||
> makeAtom _ _ _ = error "Somethings wrong here"
|
|
||||||
> -- some naming to make it
|
|
||||||
> -- easier to read
|
|
||||||
> xmin = xpoint $ minPoint box
|
|
||||||
> xmax = xpoint $ maxPoint box
|
|
||||||
> ymin = ypoint $ minPoint box
|
|
||||||
> ymax = ypoint $ maxPoint box
|
|
||||||
> res = resolution box
|
|
||||||
>
|
>
|
||||||
> idleAction :: Time -> World -> World
|
> idleAction :: Time -> World -> World
|
||||||
> idleAction tnew world =
|
> idleAction tnew world =
|
||||||
|
|
|
@ -16,7 +16,7 @@ module YGL (
|
||||||
, Time
|
, Time
|
||||||
, Scalar
|
, Scalar
|
||||||
, Color
|
, Color
|
||||||
, Point3D
|
, Point3D (..)
|
||||||
, makePoint3D -- helper (x,y,z) -> Point3D
|
, makePoint3D -- helper (x,y,z) -> Point3D
|
||||||
, (-*<) -- scalar product on Point3D
|
, (-*<) -- scalar product on Point3D
|
||||||
, Function3D
|
, Function3D
|
||||||
|
@ -30,6 +30,7 @@ module YGL (
|
||||||
, YObject (..)
|
, YObject (..)
|
||||||
, Box3D (..)
|
, Box3D (..)
|
||||||
, makeBox
|
, makeBox
|
||||||
|
, getObject3DFromShapeFunction
|
||||||
, hexColor
|
, hexColor
|
||||||
, makeColor
|
, makeColor
|
||||||
-- Datas related to user Input
|
-- Datas related to user Input
|
||||||
|
|
Loading…
Reference in a new issue