summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-30 01:53:04 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-30 01:53:04 -0400
commit6487a71bf4a3192e7dc5720b81caaebe25e6af83 (patch)
tree7710b337d25042cb004f4dcc75406db1d0664d29
parentbb4cfebd31ad44bd0a31e0959e145fced3078760 (diff)
Faster feedback for pen drawing.
-rw-r--r--MeshSketch.hs78
1 files changed, 44 insertions, 34 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs
index 8660119..89f6581 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -59,7 +59,8 @@ import LoadMesh
59import InfinitePlane 59import InfinitePlane
60import MtlParser (ObjMaterial(..)) 60import MtlParser (ObjMaterial(..))
61import Matrix 61import Matrix
62import GPURing as GPU 62import qualified GPURing as GPU
63import qualified VectorRing as Vector
63import RingBuffer 64import RingBuffer
64import MaskableStream (AttributeKey,(@<-)) 65import MaskableStream (AttributeKey,(@<-))
65import SmallRing 66import SmallRing
@@ -619,7 +620,9 @@ worldCoordinates st h k mplane = do
619 -- Write on the camDistance sphere. 620 -- Write on the camDistance sphere.
620 Nothing -> p + scale (camDistance cam) d̂ 621 Nothing -> p + scale (camDistance cam) d̂
621 622
622pushRing :: IsWidget w => w -> State -> Bool -> Double -> Double -> Vector Float -> IO (Vector Float) 623pushRing :: IsWidget w => w -> State
624 -> Bool -- ^ True when press/release.
625 -> Double -> Double -> Vector Float -> IO (Vector Float)
623pushRing w st endpt h k c = do 626pushRing w st endpt h k c = do
624 plane <- readIORef (stPlane st) 627 plane <- readIORef (stPlane st)
625 d <- worldCoordinates st h k plane 628 d <- worldCoordinates st h k plane
@@ -631,38 +634,45 @@ pushRing w st endpt h k c = do
631 maybe id chk mf $ do 634 maybe id chk mf $ do
632 g <- pushFront hk <$> readIORef (stRecentPts st) 635 g <- pushFront hk <$> readIORef (stRecentPts st)
633 writeIORef (stRecentPts st) g 636 writeIORef (stRecentPts st) g
634 if endpt then do 637 let withTriple a b cc = do
635 pushBack (stRingBuffer st) $ \RingPoint{..} -> do 638 let û = unit $ a-b
636 rpColor @<- yellow -- white 639 v̂ = unit $ b-cc
637 rpPosition @<- d 640 δ = norm_1 $ (a-b)^2
638 windowInvalidateRect win Nothing False 641 dt = det $ fromRows [û,v̂]
639 putStrLn $ "EndPoint: " ++ show d 642 x = dot û v̂
640 else with3 g $ \a b cc -> do 643 uv = û + v̂
641 let û = unit $ a-b 644 θ = atan2 (uv!0) (uv!1)
642 v̂ = unit $ b-cc 645 n = round $ θ/(pi/6)
643 δ = norm_1 $ (a-b)^2 646 m <- readIORef (stAngle st)
644 dt = det $ fromRows [û,v̂] 647 let isSpecial = x<0.3 -- || δ<0.5
645 x = dot û v̂ 648 go <- if (m /= n || isSpecial) then do
646 uv = û + v̂ 649 bb <- worldCoordinates st (b!0) (b!1) plane
647 θ = atan2 (uv!0) (uv!1) 650 updateBack (stRingBuffer st) $ \RingPoint{..} -> do
648 n = round $ θ/(pi/6) 651 rpPosition @<- bb
649 {- 652 rpColor @<- if isSpecial then yellow
650 putStrLn $ "(dt,x) = " ++ show (dt,x) 653 else if dt<0 then blue else red
651 updateBack (stRingBuffer st) $ \RingPoint{..} -> do 654 writeIORef (stAngle st) n
652 rpColor @<- if x < 0.3 || δ<0.5 then yellow 655 -- sz <- readIORef (rSize $ stRingBuffer st)
653 else if dt<0 then blue else red 656 -- putStrLn $ "pushBack" ++ show (sz,isSpecial,dt)
654 -} 657 return pushBack
655 m <- readIORef (stAngle st) 658 else do
656 let isSpecial = x<0.3 -- || δ<0.5 659 -- sz <- readIORef (rSize $ stRingBuffer st)
657 when (m /= n || isSpecial) $ do 660 -- putStrLn $ "updateBack " ++ show sz
658 bb <- worldCoordinates st (b!0) (b!1) plane 661 return updateBack
662 aa <- worldCoordinates st (a!0) (a!1) plane
663 go (stRingBuffer st) $ \RingPoint{..} -> do
664 rpPosition @<- aa
665 rpColor @<- yellow
666 withEndpt = do
659 pushBack (stRingBuffer st) $ \RingPoint{..} -> do 667 pushBack (stRingBuffer st) $ \RingPoint{..} -> do
660 rpPosition @<- bb 668 rpPosition @<- d
661 rpColor @<- if isSpecial then yellow 669 rpColor @<- yellow -- white
662 else if dt<0 then blue else red 670 if endpt then do
663 windowInvalidateRect win Nothing False 671 withEndpt
664 putStrLn $ "point: " ++ show bb 672 -- putStrLn $ "EndPoint: " ++ show d
665 writeIORef (stAngle st) n 673 else do
674 fromMaybe withEndpt $ take3 withTriple g
675 windowInvalidateRect win Nothing False
666 return d 676 return d
667 677
668white,red,yellow,blue :: Vector Float 678white,red,yellow,blue :: Vector Float
@@ -678,7 +688,7 @@ onEvent w realized ev = do
678 src <- get src #inputSource 688 src <- get src #inputSource
679 return src 689 return src
680 etype <- get ev #type 690 etype <- get ev #type
681 putStrLn $ "onEvent! " ++ show (etype,inputSource) 691 -- putStrLn $ "onEvent! " ++ show (etype,inputSource)
682 let put x = putStrLn (show inputSource ++ " " ++ show x) 692 let put x = putStrLn (show inputSource ++ " " ++ show x)
683 st = stState realized 693 st = stState realized
684 case etype of 694 case etype of