Broken commit, just to restore deleted function

This commit is contained in:
2021-09-21 01:28:11 +01:00
parent 7f1a365cac
commit 464b0b16db
6 changed files with 44 additions and 82 deletions
+26 -20
View File
@@ -58,13 +58,27 @@ pokeShapeObjs
:: Ptr Float
-> Ptr GLushort
-> Ptr GLushort -> (Int,Int,Int,Int) -> [ShapeObj] -> IO (Int, Int,Int,Int)
pokeShapeObjs ptr iptr ieptr count = VS.foldlM' (pokeShapeObj ptr iptr) count . VS.fromList
pokeShapeObjs ptr iptr _ count = VS.foldlM' (pokeShapeObj ptr iptr) count . VS.fromList
pokeShapeObj :: Ptr Float -> Ptr GLushort -> (Int,Int,Int,Int) -> ShapeObj -> IO (Int,Int,Int,Int)
pokeShapeObj ptr iptr counts (ShapeObj shType shVerts) = case shType of
ListV -> pokeShapeVs ptr iptr counts shVerts
TopHexahedron -> pokeTopHexahedron ptr iptr counts shVerts
TopPrism size -> pokeTopPrism size ptr iptr counts shVerts
pokeTopPrism :: Int -> Ptr Float -> Ptr GLushort -> (Int,Int,Int,Int) -> [ShapeV] -> IO (Int,Int,Int,Int)
pokeTopPrism size ptr iptr count svs = do
count' <- pokeTopPrismIndices size iptr count
VS.foldlM' (pokeJustV ptr) count' (VS.fromList svs)
pokeTopPrismIndices :: Int -> Ptr GLushort -> (Int,Int,Int,Int) -> IO (Int,Int,Int,Int)
pokeTopPrismIndices size iptr (nv,ne,ni,nei) = do
ni' <- foldM (pokeTopPrismIndex nv iptr) ni (topPrismIndices size)
return (nv,ne,ni',nei)
pokeTopPrismIndex :: Int -> Ptr GLushort -> Int -> Int -> IO Int
pokeTopPrismIndex nv iptr ni ioff = do
pokeElemOff iptr ni (fromIntegral $ nv + ioff)
return (ni + 1)
pokeShapeVs :: Ptr Float -> Ptr GLushort -> (Int,Int,Int,Int) -> [ShapeV] -> IO (Int, Int,Int,Int)
pokeShapeVs ptr iptr count = VS.foldlM' (pokeShapeV ptr iptr) count . VS.fromList
@@ -78,26 +92,18 @@ pokeShapeE eptr ieptr (nv,n,ni,nei) (V3 a b c) = do
pokeElemOff eptr (n * 3) a
pokeElemOff eptr (n * 3 + 1) b
pokeElemOff eptr (n * 3 + 2) c
pokeElemOff ieptr nei (fromIntegral nei)
pokeElemOff ieptr nei (fromIntegral n)
return $ (nv,n + 1,ni,nei+1)
pokeTopHexahedron :: Ptr Float -> Ptr GLushort -> (Int,Int,Int,Int) -> [ShapeV] -> IO (Int,Int,Int,Int)
pokeTopHexahedron ptr iptr count svs = do
count' <- pokeHexahedronIndices iptr count
VS.foldlM' (pokeJustV ptr) count' (VS.fromList svs)
pokeHexahedronIndices :: Ptr GLushort -> (Int,Int,Int,Int) -> IO (Int,Int,Int,Int)
pokeHexahedronIndices iptr (nv,ne,ni,nei) = do
ni' <- foldM (pokeHexhedronIndex nv iptr) ni hexIndices
return (nv,ne,ni',nei)
pokeHexhedronIndex :: Int -> Ptr GLushort -> Int -> Int -> IO Int
pokeHexhedronIndex nv iptr ni ioff = do
pokeElemOff iptr ni (fromIntegral $ nv + ioff)
return (ni + 1)
hexIndices :: [Int]
hexIndices = [0,1,2,0,2,3,0,4,5,0,5,1,1,5,6,1,6,2,2,6,7,2,7,8,3,7,4,3,4,0]
topPrismIndices :: Int -> [Int]
topPrismIndices n = concatMap f [1..n-2] -- triangles on top face
++ [2*n-2,2*n-1,1
,2*n-2,1,0] -- last side triangle (applies mod 2n)
++ concatMap g [0..n-2] -- other triangles on sides
where
f x = [0,2*x,2*x+2]
g x = [2*x,2*x+1,2*x+3
,2*x,2*x+3,2*x+2]
pokeJustV :: Ptr Float -> (Int,Int,Int,Int) -> ShapeV -> IO (Int,Int,Int,Int)
pokeJustV ptr (nv,ne,ni,nei) sh = do