summaryrefslogtreecommitdiff
path: root/MeshSketch.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-24 21:11:14 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-24 21:11:14 -0400
commit786e58ccbb05ced78c5421b53fbc469971d7db82 (patch)
tree0c60c0bbfd357c3d21d849dd61ecfb50d7ac1cc7 /MeshSketch.hs
parenta2aa65ffc5a4fc6cd0f41ccab1516f85a27989b2 (diff)
Add curvature-coloring.
Diffstat (limited to 'MeshSketch.hs')
-rw-r--r--MeshSketch.hs24
1 files changed, 20 insertions, 4 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs
index 8df74b3..ea8fbe6 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -60,6 +60,7 @@ import MtlParser (ObjMaterial(..))
60import Matrix 60import Matrix
61import PointPrimitiveRing 61import PointPrimitiveRing
62import MaskableStream (AttributeKey,(@<-)) 62import MaskableStream (AttributeKey,(@<-))
63import SmallRing
63 64
64 65
65prettyDebug :: GL.DebugMessage -> String 66prettyDebug :: GL.DebugMessage -> String
@@ -105,6 +106,7 @@ data State = State
105 , stPenDown :: IORef Bool 106 , stPenDown :: IORef Bool
106 , stPlane :: IORef (Maybe Plane) 107 , stPlane :: IORef (Maybe Plane)
107 , stDragPlane :: IORef (Maybe (Vector Float,Plane)) 108 , stDragPlane :: IORef (Maybe (Vector Float,Plane))
109 , stRecentPts :: IORef (Giver (Vector Double))
108 } 110 }
109 111
110data Camera = Camera 112data Camera = Camera
@@ -229,6 +231,7 @@ uploadState obj glarea storage = do
229 dragPlane <- newIORef Nothing 231 dragPlane <- newIORef Nothing
230 pendown <- newIORef False 232 pendown <- newIORef False
231 plane <- newIORef $ Just (xzPlaneVector G.// [(3,-1)]) 233 plane <- newIORef $ Just (xzPlaneVector G.// [(3,-1)])
234 recentPts <- newIORef Give0
232 235
233 let st = State 236 let st = State
234 { stAnimator = tm 237 { stAnimator = tm
@@ -242,6 +245,7 @@ uploadState obj glarea storage = do
242 , stPenDown = pendown 245 , stPenDown = pendown
243 , stPlane = plane 246 , stPlane = plane
244 , stDragPlane = dragPlane 247 , stDragPlane = dragPlane
248 , stRecentPts = recentPts
245 } 249 }
246 -- _ <- addAnimation tm (whirlingCamera st) 250 -- _ <- addAnimation tm (whirlingCamera st)
247 251
@@ -615,14 +619,23 @@ pushRing w st h k c = do
615 plane <- readIORef (stPlane st) 619 plane <- readIORef (stPlane st)
616 d <- worldCoordinates st h k plane 620 d <- worldCoordinates st h k plane
617 Just win <- getWidgetWindow w 621 Just win <- getWidgetWindow w
622 g <- pushFront (fromList [h,k]) <$> readIORef (stRecentPts st)
623 writeIORef (stRecentPts st) g
624 with3 g $ \a b c -> do
625 let d = det $ fromRows [(b-c),(a-b)]
626 putStrLn $ "d = " ++ show d
627 updateBack (stRingBuffer st) $ \RingPoint{..} -> do
628 rpColor @<- if d<0 then blue else red
618 pushBack (stRingBuffer st) $ \RingPoint{..} -> do 629 pushBack (stRingBuffer st) $ \RingPoint{..} -> do
619 rpPosition @<- d 630 rpPosition @<- d
620 rpColor @<- c 631 rpColor @<- c
621 windowInvalidateRect win Nothing False 632 windowInvalidateRect win Nothing False
622 return d 633 return d
623 634
624yellow = fromList [1,1,0] :: Vector Float 635red,yellow,blue :: Vector Float
625red = fromList [1,0,0] :: Vector Float 636yellow = fromList [1,1,0]
637blue = fromList [0,0,1]
638red = fromList [1,0,0]
626 639
627onEvent :: IsWidget w => w -> Realized -> Event -> IO Bool 640onEvent :: IsWidget w => w -> Realized -> Event -> IO Bool
628onEvent w realized ev = do 641onEvent w realized ev = do
@@ -646,8 +659,11 @@ onEvent w realized ev = do
646 Just InputSourcePen -> do 659 Just InputSourcePen -> do
647 isDown <- readIORef (stPenDown st) 660 isDown <- readIORef (stPenDown st)
648 when isDown $ do 661 when isDown $ do
649 d <- pushRing w st h k yellow 662 -- TODO: Read prior two points and example the angle.
650 put (etype,(h,k),d) 663 -- If it is small, reclassify the prior point.
664 d <- pushRing w st h k blue
665 -- put (etype,(h,k),d)
666 return ()
651 _ -> do 667 _ -> do
652 -- put (h,k) 668 -- put (h,k)
653 updateCameraRotation w st h k 669 updateCameraRotation w st h k