summaryrefslogtreecommitdiff
path: root/MeshSketch.hs
diff options
context:
space:
mode:
Diffstat (limited to 'MeshSketch.hs')
-rw-r--r--MeshSketch.hs47
1 files changed, 29 insertions, 18 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs
index dc0adf1..4ddfec0 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -96,21 +96,22 @@ ringPointAttr ('r':'p':c:cs) = toLower c : cs
96 96
97-- State created by uploadState. 97-- State created by uploadState.
98data State = State 98data State = State
99 { stAnimator :: Animator 99 { stAnimator :: Animator
100 , stCamera :: IORef Camera 100 , stCamera :: IORef Camera
101 , stFullscreen :: IO () 101 , stFullscreen :: IO ()
102 , stSkyboxes :: Skyboxes 102 , stSkyboxes :: Skyboxes
103 , stSkybox :: IORef Int 103 , stSkybox :: IORef Int
104 , stSkyTexture :: IORef TextureCubeData 104 , stSkyTexture :: IORef TextureCubeData
105 , stDragFrom :: IORef (Maybe (Vector Float,Camera)) 105 , stDragFrom :: IORef (Maybe (Vector Float,Camera))
106 , stDataPoints :: MV.MVector RealWorld Vector.Point 106 , stDataPoints :: MV.MVector RealWorld Vector.Point
107 , stDataRing :: RingBuffer Vector.Point 107 , stDataRing :: RingBuffer Vector.Point
108 , stRingBuffer :: RingBuffer (GPU.Update RingPoint) 108 , stRingBuffer :: RingBuffer (GPU.Update RingPoint)
109 , stPenDown :: IORef Bool 109 , stCurveSpecial :: RingBuffer (GPU.Update RingPoint)
110 , stPlane :: IORef (Maybe Plane) 110 , stPenDown :: IORef Bool
111 , stDragPlane :: IORef (Maybe (Vector Float,Plane)) 111 , stPlane :: IORef (Maybe Plane)
112 , stRecentPts :: IORef (Giver (Vector Double)) 112 , stDragPlane :: IORef (Maybe (Vector Float,Plane))
113 , stAngle :: IORef Int 113 , stRecentPts :: IORef (Giver (Vector Double))
114 , stAngle :: IORef Int
114 } 115 }
115 116
116initCamera :: Camera 117initCamera :: Camera
@@ -172,7 +173,8 @@ uploadState obj glarea storage = do
172 let bufsize = 1000 173 let bufsize = 1000
173 v <- MV.unsafeNew bufsize 174 v <- MV.unsafeNew bufsize
174 pts <- newRing bufsize (Vector.new v) 175 pts <- newRing bufsize (Vector.new v)
175 ring <- newRing bufsize (GPU.new "Points" storage ringPointAttr bufsize) 176 ring <- newRing bufsize (GPU.new LineStrip "Curve" storage ringPointAttr bufsize)
177 cpts <- newRing 100 (GPU.new PointList "Points" storage ringPointAttr 100)
176 178
177 -- setup FrameClock 179 -- setup FrameClock
178 w <- toWidget glarea 180 w <- toWidget glarea
@@ -215,6 +217,7 @@ uploadState obj glarea storage = do
215 , stDataPoints = v 217 , stDataPoints = v
216 , stDataRing = pts 218 , stDataRing = pts
217 , stRingBuffer = ring 219 , stRingBuffer = ring
220 , stCurveSpecial = cpts
218 , stPenDown = pendown 221 , stPenDown = pendown
219 , stPlane = plane 222 , stPlane = plane
220 , stDragPlane = dragPlane 223 , stDragPlane = dragPlane
@@ -294,7 +297,10 @@ new = do
294 "uvw" @: Attribute_V3F 297 "uvw" @: Attribute_V3F
295 defObjectArray "plane" Triangles $ do 298 defObjectArray "plane" Triangles $ do
296 "position" @: Attribute_V4F 299 "position" @: Attribute_V4F
297 defObjectArray "Points" Lines $ do 300 defObjectArray "Curve" Lines $ do
301 "position" @: Attribute_V3F
302 "color" @: Attribute_V3F
303 defObjectArray "Points" Points $ do
298 "position" @: Attribute_V3F 304 "position" @: Attribute_V3F
299 "color" @: Attribute_V3F 305 "color" @: Attribute_V3F
300 defUniforms $ do 306 defUniforms $ do
@@ -607,8 +613,8 @@ pushRing w st endpt h k c = do
607 n = round $ θ/(pi/12) 613 n = round $ θ/(pi/12)
608 m <- readIORef (stAngle st) 614 m <- readIORef (stAngle st)
609 let isSpecial = x<0.3 -- || δ<0.5 615 let isSpecial = x<0.3 -- || δ<0.5
616 bb <- worldCoordinates st (b!0) (b!1) plane
610 go <- if (m /= n || isSpecial) then do 617 go <- if (m /= n || isSpecial) then do
611 bb <- worldCoordinates st (b!0) (b!1) plane
612 updateBack (stDataRing st) (Vector.Point (b!0) (b!1)) 618 updateBack (stDataRing st) (Vector.Point (b!0) (b!1))
613 updateBack (stRingBuffer st) $ \RingPoint{..} -> do 619 updateBack (stRingBuffer st) $ \RingPoint{..} -> do
614 rpPosition @<- bb 620 rpPosition @<- bb
@@ -627,6 +633,10 @@ pushRing w st endpt h k c = do
627 bool updateBack pushBack go (stRingBuffer st) $ \RingPoint{..} -> do 633 bool updateBack pushBack go (stRingBuffer st) $ \RingPoint{..} -> do
628 rpPosition @<- aa 634 rpPosition @<- aa
629 rpColor @<- yellow 635 rpColor @<- yellow
636 when isSpecial $ do
637 pushBack (stCurveSpecial st) $ \RingPoint{..} -> do
638 rpPosition @<- bb
639 rpColor @<- yellow
630 withEndpt = do 640 withEndpt = do
631 pushBack (stDataRing st) (Vector.Point h k) 641 pushBack (stDataRing st) (Vector.Point h k)
632 pushBack (stRingBuffer st) $ \RingPoint{..} -> do 642 pushBack (stRingBuffer st) $ \RingPoint{..} -> do
@@ -697,6 +707,7 @@ onEvent w realized ev = do
697 writeIORef (stRecentPts st) Give0 707 writeIORef (stRecentPts st) Give0
698 clearRing (stRingBuffer st) 708 clearRing (stRingBuffer st)
699 clearRing (stDataRing st) 709 clearRing (stDataRing st)
710 clearRing (stCurveSpecial st)
700 d <- pushRing w st True h k red 711 d <- pushRing w st True h k red
701 Just win <- getWidgetWindow w 712 Just win <- getWidgetWindow w
702 windowInvalidateRect win Nothing False 713 windowInvalidateRect win Nothing False