Working element buffer object

This commit is contained in:
2021-09-20 12:36:35 +01:00
parent c605ac74ff
commit 5cbcbec101
22 changed files with 242 additions and 212 deletions
+1
View File
@@ -29,6 +29,7 @@ data RenderData = RenderData
, _barrelShader :: FullShader , _barrelShader :: FullShader
, _grayscaleShader :: FullShader , _grayscaleShader :: FullShader
, _shapeShader :: FullShader , _shapeShader :: FullShader
, _shapeEBO :: EBO
, _pictureShaders :: MV.MVector (PrimState IO) FullShader , _pictureShaders :: MV.MVector (PrimState IO) FullShader
, _fbo2 :: (FramebufferObject, TextureObject) , _fbo2 :: (FramebufferObject, TextureObject)
, _fbo3 :: (FramebufferObject, TextureObject) , _fbo3 :: (FramebufferObject, TextureObject)
+10 -16
View File
@@ -34,7 +34,7 @@ basicCrPict
-> Creature -> Creature
-> World -> World
-> SPic -> SPic
basicCrPict col cr w = SPic (basicCrShape col cr) $ pictures $ basicCrPict col cr w = (,) (basicCrShape col cr) $ pictures $
targetingPic ++ targetingPic ++
[ creatureDisplayText w cr [ creatureDisplayText w cr
, tr . rotdir $ _spPicture $ drawEquipment cr , tr . rotdir $ _spPicture $ drawEquipment cr
@@ -125,6 +125,7 @@ damageModSH :: Creature -> Shape -> Shape
damageModSH _ = id damageModSH _ = id
feet :: Creature -> Shape feet :: Creature -> Shape
{-# INLINE feet #-}
feet cr = case cr ^? crStance . carriage of feet cr = case cr ^? crStance . carriage of
Just (Walking sa LeftForward) -> mconcat Just (Walking sa LeftForward) -> mconcat
[ translateSHf ( f sa) off aFoot [ translateSHf ( f sa) off aFoot
@@ -146,6 +147,7 @@ feet cr = case cr ^? crStance . carriage of
f i = 6 * fromIntegral (sLen - i) / fromIntegral sLen f i = 6 * fromIntegral (sLen - i) / fromIntegral sLen
arms :: Creature -> Shape arms :: Creature -> Shape
{-# INLINE arms #-}
arms cr arms cr
| oneH cr = shoulderSH . translateSHf 11 (-3) . rotateSH (-0.5) $ scaleSH (V3 1 1.5 1) aHand | oneH cr = shoulderSH . translateSHf 11 (-3) . rotateSH (-0.5) $ scaleSH (V3 1 1.5 1) aHand
| twists cr = shoulderSH . translateSHf 0 (0.5* crad) . rotateSH (-1) $ mconcat | twists cr = shoulderSH . translateSHf 0 (0.5* crad) . rotateSH (-1) $ mconcat
@@ -165,6 +167,7 @@ arms cr
f i = negate 2 + negate 6 * fromIntegral (sLen - i) / fromIntegral sLen f i = negate 2 + negate 6 * fromIntegral (sLen - i) / fromIntegral sLen
scalp :: Creature -> Shape scalp :: Creature -> Shape
{-# INLINE scalp #-}
scalp cr scalp cr
| twists cr = translateSHf 0 (0.5*crad) . rotateSH (-1) $ translateSHf (negate 0.25 * crad) 0.25 fhead | twists cr = translateSHf 0 (0.5*crad) . rotateSH (-1) $ translateSHf (negate 0.25 * crad) 0.25 fhead
| oneH cr = rotateSH 0.5 $ translateSHf (0.25 * crad) 0 fhead | oneH cr = rotateSH 0.5 $ translateSHf (0.25 * crad) 0 fhead
@@ -184,6 +187,7 @@ twists cr = crIsAiming' cr && crIt ^? itAimStance == Just TwoHandTwist
crIt = _crInv cr IM.! _crInvSel cr crIt = _crInv cr IM.! _crInvSel cr
torso :: Creature -> Shape torso :: Creature -> Shape
{-# INLINE torso #-}
torso cr torso cr
| oneH cr = rotateSH 0.5 $ mconcat | oneH cr = rotateSH 0.5 $ mconcat
[ translateSHf 0 3 . rotateSH (negate 0.2) $ aShoulder [ translateSHf 0 3 . rotateSH (negate 0.2) $ aShoulder
@@ -203,27 +207,16 @@ torso cr
crad = _crRad cr crad = _crRad cr
baseShoulder :: Shape baseShoulder :: Shape
{-# INLINE baseShoulder #-}
baseShoulder = translateSHz (-10) . scaleSH (V3 0.5 1 1) . upperPrismPoly 10 $ polyCirc 3 1 baseShoulder = translateSHz (-10) . scaleSH (V3 0.5 1 1) . upperPrismPoly 10 $ polyCirc 3 1
upperBody :: Color -> Creature -> Shape upperBody :: Color -> Creature -> Shape
{-# INLINE upperBody #-}
upperBody col cr = colorSH (light4 col) $ mconcat upperBody col cr = colorSH (light4 col) $ mconcat
[ arms cr [ arms cr
, shoulderSH $ torso cr , shoulderSH $ torso cr
] ]
--naked :: Color -> Creature -> Picture
--naked _ cr
-- | strikeMelee = shoulderH . color white $ circleSolid $ _crRad cr
-- | pdam > 200 = shoulderH . color red $ circleSolid $ _crRad cr
-- | pdam > 99 = shoulderH . color white $ circleSolid $ _crRad cr
-- | otherwise = []
-- where
-- strikeMelee = _crMeleeCooldown cr > 5
-- pdam = sum $ concatMap (map _dmAmount) pastDams
-- pastDams = _crPastDamage $ _crState cr
shoulderSH :: Shape -> Shape shoulderSH :: Shape -> Shape
shoulderSH = translateSHz 20 shoulderSH = translateSHz 20
waistSH :: Shape -> Shape waistSH :: Shape -> Shape
@@ -244,6 +237,7 @@ light4 = light . light . light . light
drawEquipment drawEquipment
:: Creature :: Creature
-> SPic -> SPic
{-# INLINE drawEquipment #-}
drawEquipment cr = mconcat $ map f $ IM.toList (_crInv cr) drawEquipment cr = mconcat $ map f $ IM.toList (_crInv cr)
where where
f (i,it) = case it ^? itEquipPict of f (i,it) = case it ^? itEquipPict of
@@ -255,8 +249,8 @@ circLine x = line [V2 0 0,V2 x 0]
picAtCrPos :: Picture -> Creature -> World -> SPic picAtCrPos :: Picture -> Creature -> World -> SPic
--{-# INLINE picAtCrPos #-} --{-# INLINE picAtCrPos #-}
picAtCrPos thePic cr _ = SPic emptySH $ tranRot (_crPos cr) (_crDir cr) thePic picAtCrPos thePic cr _ = (,) emptySH $ tranRot (_crPos cr) (_crDir cr) thePic
picAtCrPosNoRot :: Picture -> Creature -> World -> SPic picAtCrPosNoRot :: Picture -> Creature -> World -> SPic
--{-# INLINE picAtCrPos #-} --{-# INLINE picAtCrPos #-}
picAtCrPosNoRot thePic cr _ = SPic emptySH $ uncurryV translate (_crPos cr) thePic picAtCrPosNoRot thePic cr _ = (,) emptySH $ uncurryV translate (_crPos cr) thePic
+8 -8
View File
@@ -19,7 +19,7 @@ import Dodge.SoundLogic.LoadSound
import Dodge.Picture.Layer import Dodge.Picture.Layer
import Geometry import Geometry
import Picture import Picture
import ShapePicture --import ShapePicture
import Shape import Shape
import Control.Lens import Control.Lens
@@ -36,7 +36,7 @@ defaultCreature = Creature
, _crOldDir = 0 , _crOldDir = 0
, _crMvDir = 0 , _crMvDir = 0
, _crID = 1 , _crID = 1
, _crPict = \_ _ -> SPic (flatCirc 10) blank , _crPict = \_ _ -> (,) (flatCirc 10) blank
, _crUpdate = \cr _ -> (Endo id , Just cr) , _crUpdate = \cr _ -> (Endo id , Just cr)
, _crRad = 10 , _crRad = 10
, _crMass = 10 , _crMass = 10
@@ -130,8 +130,8 @@ defaultEquipment = Equipment
, _itName = "genericEquipment" , _itName = "genericEquipment"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ setLayer 0 $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ setLayer 0 $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \_ _ -> SPic emptySH blank , _itEquipPict = \_ _ -> (,) emptySH blank
, _itEffect = NoItEffect , _itEffect = NoItEffect
, _itHammer = HammerUp , _itHammer = HammerUp
, _itID = Nothing , _itID = Nothing
@@ -152,8 +152,8 @@ defaultConsumable = Consumable
, _itMaxStack = 9 , _itMaxStack = 9
, _itAmount = 1 , _itAmount = 1
, _cnEffect = \_ _ -> Nothing , _cnEffect = \_ _ -> Nothing
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color blue $ circleSolid 3 , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color blue $ circleSolid 3
, _itEquipPict = \_ _ -> SPic emptySH blank , _itEquipPict = \_ _ -> (,) emptySH blank
, _itID = Nothing , _itID = Nothing
, _itInvColor = blue , _itInvColor = blue
, _itInvDisplay = \it -> _itName it ++ " x" ++ show (_itAmount it) , _itInvDisplay = \it -> _itName it ++ " x" ++ show (_itAmount it)
@@ -199,8 +199,8 @@ defaultIt = Consumable
, _itMaxStack = 3 , _itMaxStack = 3
, _itAmount = 2 , _itAmount = 2
, _cnEffect = const return , _cnEffect = const return
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \_ _ -> SPic emptySH $ blank , _itEquipPict = \_ _ -> (,) emptySH $ blank
, _itID = Nothing , _itID = Nothing
, _itInvDisplay = _itName , _itInvDisplay = _itName
, _itInvColor = blue , _itInvColor = blue
+5 -5
View File
@@ -7,7 +7,7 @@ import Dodge.Default
import Dodge.Picture import Dodge.Picture
import Picture import Picture
import Geometry.Data import Geometry.Data
import ShapePicture --import ShapePicture
import Shape import Shape
keyToken :: Int -> Item keyToken :: Int -> Item
@@ -16,8 +16,8 @@ keyToken n = defaultEquipment
, _itName = "KEYTOKEN "++show n , _itName = "KEYTOKEN "++show n
, _itMaxStack = 5 , _itMaxStack = 5
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ setDepth 0.5 keyPic , _itFloorPict = (,) emptySH $ setDepth 0.5 keyPic
, _itEquipPict = \_ _ -> SPic emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) keyPic , _itEquipPict = \_ _ -> (,) emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) keyPic
, _itEffect = NoItEffect , _itEffect = NoItEffect
, _itHammer = HammerUp , _itHammer = HammerUp
, _itID = Nothing , _itID = Nothing
@@ -40,8 +40,8 @@ latchkey n = defaultEquipment
, _itName = "KEY "++show n , _itName = "KEY "++show n
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ setDepth 0.5 latchkeyPic , _itFloorPict = (,) emptySH $ setDepth 0.5 latchkeyPic
, _itEquipPict = \_ _ -> SPic emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) latchkeyPic , _itEquipPict = \_ _ -> (,) emptySH $ setDepth 0 $ translate (-5) (-5) $ rotate (pi/2.5) latchkeyPic
, _itEffect = NoItEffect , _itEffect = NoItEffect
, _itHammer = HammerUp , _itHammer = HammerUp
, _itID = Nothing , _itID = Nothing
+3 -3
View File
@@ -8,7 +8,7 @@ import Dodge.Default
import Dodge.SoundLogic import Dodge.SoundLogic
import Dodge.SoundLogic.LoadSound import Dodge.SoundLogic.LoadSound
import Shape import Shape
import ShapePicture --import ShapePicture
import Dodge.Item.Draw import Dodge.Item.Draw
import Picture import Picture
@@ -22,8 +22,8 @@ medkit i = defaultConsumable
, _itMaxStack = 9 , _itMaxStack = 9
, _itAmount = 1 , _itAmount = 1
, _cnEffect = heal i , _cnEffect = heal i
, _itFloorPict = SPic emptySH $ setLayer 0 . onLayer FlItLayer . color blue $ circleSolid 3 , _itFloorPict = (,) emptySH $ setLayer 0 . onLayer FlItLayer . color blue $ circleSolid 3
, _itEquipPict = pictureItem $ SPic emptySH $ color blue $ circleSolid 3 , _itEquipPict = pictureItem $ (,) emptySH $ color blue $ circleSolid 3
, _itID = Nothing , _itID = Nothing
} }
+9 -9
View File
@@ -6,7 +6,7 @@ import Dodge.Default
import Dodge.Picture.Layer import Dodge.Picture.Layer
import Picture import Picture
import Geometry import Geometry
import ShapePicture --import ShapePicture
import Shape import Shape
magShield :: Item magShield :: Item
@@ -15,8 +15,8 @@ magShield = defaultEquipment
, _itName = "MAGSHIELD" , _itName = "MAGSHIELD"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \_ _ -> SPic emptySH $ blank , _itEquipPict = \_ _ -> (,) emptySH $ blank
, _itID = Nothing , _itID = Nothing
} }
flameShield :: Item flameShield :: Item
@@ -25,8 +25,8 @@ flameShield = defaultEquipment
, _itName = "FLAMESHIELD" , _itName = "FLAMESHIELD"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \cr _ -> SPic emptySH $ onLayer CrLayer $ pictures [color cyan $ circle (_crRad cr+2)] , _itEquipPict = \cr _ -> (,) emptySH $ onLayer CrLayer $ pictures [color cyan $ circle (_crRad cr+2)]
, _itID = Nothing , _itID = Nothing
} }
{- | Slows you down, blocks forward projectiles. -} {- | Slows you down, blocks forward projectiles. -}
@@ -36,11 +36,11 @@ frontArmour = defaultEquipment
, _itName = "FARMOUR" , _itName = "FARMOUR"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ translate 0 (-5) $ pictures , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ translate 0 (-5) $ pictures
[color (greyN 0.1) $ thickArc 0 (pi/2) 10 5 [color (greyN 0.1) $ thickArc 0 (pi/2) 10 5
,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5 ,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5
] ]
, _itEquipPict = \_ _ -> SPic emptySH $ onLayer CrLayer $ pictures , _itEquipPict = \_ _ -> (,) emptySH $ onLayer CrLayer $ pictures
[color (greyN 0.1) $ thickArc 0 (pi/2) 10 5 [color (greyN 0.1) $ thickArc 0 (pi/2) 10 5
,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5 ,color (greyN 0.1) $ thickArc (3*pi/2) (2*pi) 10 5
] ]
@@ -54,8 +54,8 @@ jetPack = defaultEquipment
, _itName = "JETPACK" , _itName = "JETPACK"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color yellow $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color yellow $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \_ _ -> SPic emptySH $ onLayer CrLayer , _itEquipPict = \_ _ -> (,) emptySH $ onLayer CrLayer
$ pictures [color yellow $ polygon $ rectNSEW 5 (-5) (-3) (-11) ] $ pictures [color yellow $ polygon $ rectNSEW 5 (-5) (-3) (-11) ]
, _itEffect = NoItEffect , _itEffect = NoItEffect
, _itID = Nothing , _itID = Nothing
+44 -44
View File
@@ -77,13 +77,13 @@ pistol = defaultGun
, _wpSpread = 0.02 , _wpSpread = 0.02
, _wpRange = 20 , _wpRange = 20
, _itHammer = HammerUp , _itHammer = HammerUp
, _itFloorPict = SPic emptySH $ onLayer FlItLayer pistolPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer pistolPic
, _itAmount = 1 , _itAmount = 1
, _itMaxStack = 1 , _itMaxStack = 1
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH pistolPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH pistolPic
, _itAttachment = NoItAttachment , _itAttachment = NoItAttachment
, _itID = Nothing , _itID = Nothing
, _itEffect = wpRecock , _itEffect = wpRecock
@@ -121,13 +121,13 @@ rezGun = defaultGun
[] []
, _wpSpread = 0.001 , _wpSpread = 0.001
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color chartreuse $ pictures , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color chartreuse $ pictures
[polygon $ rectNESW 7 3 1 (-3) [polygon $ rectNESW 7 3 1 (-3)
,polygon $ rectNESW (-1) 3 (-7) (-3) ,polygon $ rectNESW (-1) 3 (-7) (-3)
] ]
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itAimingRange = 0 , _itAimingRange = 0
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH $ color chartreuse $ pictures , _itEquipPict = pictureWeaponOnAim $ (,) emptySH $ color chartreuse $ pictures
[polygon $ rectNESW 7 3 1 (-3) [polygon $ rectNESW 7 3 1 (-3)
,polygon $ rectNESW (-1) 3 (-7) (-3) ,polygon $ rectNESW (-1) 3 (-7) (-3)
] ]
@@ -152,11 +152,11 @@ teslaGun = defaultGun
] ]
, _wpSpread = 0.001 , _wpSpread = 0.001
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer teslaGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer teslaGunPic
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itAimingRange = 0 , _itAimingRange = 0
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH teslaGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH teslaGunPic
} }
teslaGunPic :: Picture teslaGunPic :: Picture
teslaGunPic = color blue $ pictures teslaGunPic = color blue $ pictures
@@ -187,10 +187,10 @@ lasGun = defaultAutoGun
] ]
, _wpSpread = 0.001 , _wpSpread = 0.001
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer lasGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer lasGunPic
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itAimingRange = 1 , _itAimingRange = 1
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH lasGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH lasGunPic
, _itAttachment = ItCharMode $ Seq.fromList "/VZ" , _itAttachment = ItCharMode $ Seq.fromList "/VZ"
, _itScroll = scrollCharMode , _itScroll = scrollCharMode
, _itInvDisplay = basicWeaponDisplay , _itInvDisplay = basicWeaponDisplay
@@ -210,7 +210,7 @@ forceFieldGun = defaultGun
, _itUse = undefined , _itUse = undefined
, _wpSpread = 0.02 , _wpSpread = 0.02
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-4,-4),(-4,4),(4,4),(4,0),(0,0),(0,-4)]
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itAimingRange = 0.5 , _itAimingRange = 0.5
} }
@@ -249,10 +249,10 @@ tractorGun = defaultAutoGun
] ]
, _wpSpread = 0.00001 , _wpSpread = 0.00001
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ]
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itAimingRange = 0.5 , _itAimingRange = 0.5
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ] , _itEquipPict = pictureWeaponOnAim $ (,) emptySH $ color blue $ pictures [polygon $ rectNESW 1.5 6 (-1.5) 0 ]
} }
@@ -278,10 +278,10 @@ remoteLauncher = defaultGun
] ]
, _wpSpread = 0.02 , _wpSpread = 0.02
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5) , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5)
, _itAimingSpeed = 0.2 , _itAimingSpeed = 0.2
, _itAimingRange = 0.5 , _itAimingRange = 0.5
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5) , _itEquipPict = pictureWeaponOnAim $ (,) emptySH $ color cyan $ polygon $ rectNESW 5 5 (-5) (-5)
, _itAttachment = ItScope (V2 0 0) 0 1 True , _itAttachment = ItScope (V2 0 0) 0 1 True
} }
hvAutoGun :: Item hvAutoGun :: Item
@@ -303,10 +303,10 @@ hvAutoGun = defaultAutoGun
, withMuzFlareI , withMuzFlareI
] ]
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer hvAutoGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer hvAutoGunPic
, _itAimingSpeed = 0.2 , _itAimingSpeed = 0.2
, _itAimingRange = 1 , _itAimingRange = 1
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH hvAutoGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH hvAutoGunPic
, _wpAmmo = hvBullet , _wpAmmo = hvBullet
} }
hvAutoGunPic :: Picture hvAutoGunPic :: Picture
@@ -334,11 +334,11 @@ ltAutoGun = defaultAutoGun
] ]
, _wpSpread = 0.5 , _wpSpread = 0.5
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer ltAutoGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer ltAutoGunPic
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH ltAutoGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH ltAutoGunPic
, _itAimStance = OneHand , _itAimStance = OneHand
, _wpAmmo = ltBullet , _wpAmmo = ltBullet
} }
@@ -393,10 +393,10 @@ miniGun = defaultAutoGun
, withSmoke 1 black 20 200 5 , withSmoke 1 black 20 200 5
] ]
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer miniGunPict , _itFloorPict = (,) emptySH $ onLayer FlItLayer miniGunPict
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itAimingRange = 1 , _itAimingRange = 1
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH miniGunPict , _itEquipPict = pictureWeaponOnAim $ (,) emptySH miniGunPict
, _wpAmmo = basicBullet , _wpAmmo = basicBullet
} }
where where
@@ -440,10 +440,10 @@ spreadGun = defaultGun
] ]
, _wpSpread = spreadGunSpread , _wpSpread = spreadGunSpread
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer spreadGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer spreadGunPic
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH spreadGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH spreadGunPic
, _wpAmmo = basicBullet , _wpAmmo = basicBullet
, _wpNumBarrels = 50 , _wpNumBarrels = 50
} }
@@ -472,12 +472,12 @@ multGun = defaultGun
] ]
, _wpSpread = spreadGunSpread , _wpSpread = spreadGunSpread
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer multGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer multGunPic
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itAimingRange = 1 , _itAimingRange = 1
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomFac = 1.5} , _itAimZoom = defaultItZoom {_itZoomFac = 1.5}
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH multGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH multGunPic
, _itAimStance = TwoHandTwist , _itAimStance = TwoHandTwist
, _wpAmmo = basicBullet , _wpAmmo = basicBullet
, _wpNumBarrels = 5 , _wpNumBarrels = 5
@@ -517,12 +517,12 @@ longGun = defaultGun
, withMuzFlareI , withMuzFlareI
] ]
, _wpRange = 200 , _wpRange = 200
, _itFloorPict = SPic emptySH $ onLayer FlItLayer longGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer longGunPic
, _itAimingSpeed = 0.2 , _itAimingSpeed = 0.2
, _itAimingRange = 1 , _itAimingRange = 1
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5} , _itAimZoom = defaultItZoom {_itZoomMax = 0.5, _itZoomMin = 0.5}
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH longGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH longGunPic
, _itScroll = zoomLongGun , _itScroll = zoomLongGun
, _itAttachment = ItScope (V2 0 0) 0 1 False , _itAttachment = ItScope (V2 0 0) 0 1 False
, _itEffect = itemLaserScopeEffect , _itEffect = itemLaserScopeEffect
@@ -561,11 +561,11 @@ poisonSprayer = defaultAutoGun
, spreadNumI , spreadNumI
] ]
, _wpRange = 8 , _wpRange = 8
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4) , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4)
, _itAimingSpeed = 0.2 , _itAimingSpeed = 0.2
, _itAimingRange = 0 , _itAimingRange = 0
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4) , _itEquipPict = pictureWeaponOnAim $ (,) emptySH $ color yellow $ polygon $ rectNESW 4 4 (-4) (-4)
, _wpSpread = 0.1 , _wpSpread = 0.1
, _wpNumBarrels = 3 , _wpNumBarrels = 3
} }
@@ -588,12 +588,12 @@ flamer = defaultAutoGun
] ]
, _wpSpread = 0 , _wpSpread = 0
, _wpRange = 8 , _wpRange = 8
, _itFloorPict = SPic emptySH $ onLayer FlItLayer flamerPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer flamerPic
, _itAimingSpeed = 0.5 , _itAimingSpeed = 0.5
, _itAimingRange = 0 , _itAimingRange = 0
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5} , _itAimZoom = defaultItZoom {_itZoomMax = 5, _itZoomMin = 1.5}
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH flamerPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH flamerPic
, _itAttachment = NoItAttachment , _itAttachment = NoItAttachment
} }
flamerPic :: Picture flamerPic :: Picture
@@ -619,7 +619,7 @@ blinkGun = defaultGun
, _itLeftClickUse = Just $ hammerCheckL $ shootL aSelfL , _itLeftClickUse = Just $ hammerCheckL $ shootL aSelfL
, _wpSpread = 0.05 , _wpSpread = 0.05
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2[(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2[(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)]
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
} }
@@ -637,7 +637,7 @@ boosterGun = defaultGun
, _itLeftClickUse = Just $ boostSelfL 10 , _itLeftClickUse = Just $ boostSelfL 10
, _wpSpread = 0.05 , _wpSpread = 0.05
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-2,-2),(-2,2),(2,2),(2,0),(0,0),(0,-2)]
, _itAimingSpeed = 1 , _itAimingSpeed = 1
, _itAimingRange = 0 , _itAimingRange = 0
, _itEffect = resetAttachmentID , _itEffect = resetAttachmentID
@@ -810,7 +810,7 @@ grenade = Throwable
, _itIdentity = Grenade , _itIdentity = Grenade
, _itMaxStack = 8 , _itMaxStack = 8
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _twMaxRange = 150 , _twMaxRange = 150
, _twAccuracy = 30 , _twAccuracy = 30
, _itUse = \_ -> throwGrenade makeExplosionAt , _itUse = \_ -> throwGrenade makeExplosionAt
@@ -863,7 +863,7 @@ remoteBomb = defaultThrowable
, _itIdentity = RemoteBomb , _itIdentity = RemoteBomb
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _twMaxRange = 150 , _twMaxRange = 150
, _twAccuracy = 30 , _twAccuracy = 30
, _itUse = const throwRemoteBomb , _itUse = const throwRemoteBomb
@@ -871,7 +871,7 @@ remoteBomb = defaultThrowable
[ hammerCheckI [ hammerCheckI
] ]
, _itAttachment = ItScope (V2 0 0) 0 1 True , _itAttachment = ItScope (V2 0 0) 0 1 True
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH remoteBombUnarmedPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH remoteBombUnarmedPic
} }
fireRemoteLauncher :: Creature -> World -> World fireRemoteLauncher :: Creature -> World -> World
@@ -1020,7 +1020,7 @@ explodeRemoteBomb itid pjid cr w
cid = _crID cr cid = _crID cr
resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEBOMB" resetName = set (creatures . ix cid . crInv . ix j . itName) "REMOTEBOMB"
resetPict = set (creatures . ix cid . crInv . ix j . itEquipPict ) resetPict = set (creatures . ix cid . crInv . ix j . itEquipPict )
(pictureWeaponOnAim $ SPic emptySH remoteBombUnarmedPic) (pictureWeaponOnAim $ (,) emptySH remoteBombUnarmedPic)
-- resetScope = creatures . ix cid . crInv . ix j . itScope . _Just . scopePos .~ (0,0) -- resetScope = creatures . ix cid . crInv . ix j . itScope . _Just . scopePos .~ (0,0)
j = _crInvSel $ _creatures w IM.! cid j = _crInvSel $ _creatures w IM.! cid
remoteBombPic remoteBombPic
@@ -1042,7 +1042,7 @@ pipe = Craftable
, _itName = "PIPE" , _itName = "PIPE"
, _itMaxStack = 3 , _itMaxStack = 3
, _itAmount = 3 , _itAmount = 3
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \_ _ -> emptyBlank , _itEquipPict = \_ _ -> emptyBlank
, _itID = Nothing , _itID = Nothing
, _itInvDisplay = _itName , _itInvDisplay = _itName
@@ -1068,13 +1068,13 @@ radar = defaultGun
, _wpSpread = autogunSpread , _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
, _itHammer = HammerUp , _itHammer = HammerUp
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
, _itAmount = 1 , _itAmount = 1
, _itMaxStack = 1 , _itMaxStack = 1
, _itAimingRange = 1 , _itAimingRange = 1
, _itZoom = defaultItZoom { _itZoomMax = 1} , _itZoom = defaultItZoom { _itZoomMax = 1}
, _itAimZoom = defaultItZoom { _itZoomMax = 1} , _itAimZoom = defaultItZoom { _itZoomMax = 1}
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itEquipPict = pictureWeaponOnAim $ (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
} }
{- | {- |
Sends out pulses that display creatures. -} Sends out pulses that display creatures. -}
@@ -1094,13 +1094,13 @@ sonar = defaultGun
] ]
, _wpRange = 20 , _wpRange = 20
, _itHammer = HammerUp , _itHammer = HammerUp
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
, _itAmount = 1 , _itAmount = 1
, _itMaxStack = 1 , _itMaxStack = 1
, _itAimingRange = 1 , _itAimingRange = 1
, _itZoom = defaultItZoom {_itZoomMax = 1} , _itZoom = defaultItZoom {_itZoomMax = 1}
, _itAimZoom = defaultItZoom {_itZoomMax = 1} , _itAimZoom = defaultItZoom {_itZoomMax = 1}
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5) , _itEquipPict = pictureWeaponOnAim $ (,) emptySH $ color blue $ polygon $ rectNESW 5 5 (-5) (-5)
} }
{- | {- |
Automatically sends out pulses that display creatures. -} Automatically sends out pulses that display creatures. -}
@@ -1110,8 +1110,8 @@ autoSonar = defaultEquipment
, _itName = "AUTOSONAR" , _itName = "AUTOSONAR"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color yellow $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color yellow $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \_ _ -> SPic emptySH $ blank , _itEquipPict = \_ _ -> (,) emptySH $ blank
, _itEffect = autoSonarEffect , _itEffect = autoSonarEffect
, _itID = Nothing , _itID = Nothing
, _itAimingSpeed = 1 , _itAimingSpeed = 1
@@ -1127,8 +1127,8 @@ autoRadar = defaultEquipment
, _itName = "AUTORADAR" , _itName = "AUTORADAR"
, _itMaxStack = 1 , _itMaxStack = 1
, _itAmount = 1 , _itAmount = 1
, _itFloorPict = SPic emptySH $ onLayer FlItLayer $ color yellow $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)] , _itFloorPict = (,) emptySH $ onLayer FlItLayer $ color yellow $ polygon $ map toV2 [(-3,-3),(-3,3),(3,3),(3,-3)]
, _itEquipPict = \_ _ -> SPic emptySH $ blank , _itEquipPict = \_ _ -> (,) emptySH $ blank
, _itEffect = autoRadarEffect , _itEffect = autoRadarEffect
, _itID = Nothing , _itID = Nothing
, _itAimingSpeed = 1 , _itAimingSpeed = 1
+3 -3
View File
@@ -16,7 +16,7 @@ import Dodge.Item.Weapon.TriggerType
import Dodge.SoundLogic.LoadSound import Dodge.SoundLogic.LoadSound
import Picture import Picture
import Geometry import Geometry
import ShapePicture --import ShapePicture
import Shape import Shape
import qualified Data.Sequence as Seq import qualified Data.Sequence as Seq
@@ -51,12 +51,12 @@ autoGun = defaultAutoGun
, _wpSpread = autogunSpread , _wpSpread = autogunSpread
, _wpRange = 20 , _wpRange = 20
, _itHammer = HammerUp , _itHammer = HammerUp
, _itFloorPict = SPic emptySH $ onLayer FlItLayer autoGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer autoGunPic
, _itAimingSpeed = 0.4 , _itAimingSpeed = 0.4
, _itAimingRange = 1 , _itAimingRange = 1
, _itZoom = defaultItZoom , _itZoom = defaultItZoom
, _itAimZoom = defaultItZoom {_itZoomFac = 1.5} , _itAimZoom = defaultItZoom {_itZoomFac = 1.5}
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH autoGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH autoGunPic
, _itEffect = wpRecock , _itEffect = wpRecock
, _itAttachment = ItCharMode $ Seq.fromList "MS" , _itAttachment = ItCharMode $ Seq.fromList "MS"
, _itScroll = scrollCharMode , _itScroll = scrollCharMode
+3 -3
View File
@@ -18,7 +18,7 @@ import Dodge.Picture.Layer
import Dodge.SoundLogic.LoadSound import Dodge.SoundLogic.LoadSound
import Picture import Picture
import Geometry import Geometry
import ShapePicture --import ShapePicture
import Shape import Shape
--import System.Random --import System.Random
@@ -37,8 +37,8 @@ bezierGun = defaultGun
. withRecoilI 40 . withRecoilI 40
. torqueBefore 0.05 . torqueBefore 0.05
] ]
, _itFloorPict = SPic emptySH $ onLayer FlItLayer bezierGunPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer bezierGunPic
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH bezierGunPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH bezierGunPic
, _itAttachment = NoItAttachment , _itAttachment = NoItAttachment
, _itScroll = \_ _ -> removeItTarget , _itScroll = \_ _ -> removeItTarget
, _itHammer = HammerUp , _itHammer = HammerUp
+2 -2
View File
@@ -52,7 +52,7 @@ moveGrenade time dir pID w = case hitWl of
grenadePic :: Int -> SPic grenadePic :: Int -> SPic
grenadePic x = SPic emptySH $ pictures grenadePic x = (,) emptySH $ pictures
[ color (dark $ dark green) $ circleSolid 5 [ color (dark $ dark green) $ circleSolid 5
, color green $ arc (degToRad $ (179 * fromIntegral x / 50) - 180 ) , color green $ arc (degToRad $ (179 * fromIntegral x / 50) - 180 )
(degToRad $ 180 - (179 * fromIntegral x / 50) ) (degToRad $ 180 - (179 * fromIntegral x / 50) )
@@ -79,7 +79,7 @@ throwGrenade explosion cr w = setWp $ removePict $ over projectiles addG w
, _pjPayload = explosion , _pjPayload = explosion
} }
j = _crInvSel cr j = _crInvSel cr
removePict = set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> SPic emptySH blank removePict = set (creatures . ix n . crInv . ix j . itEquipPict) $ \ _ _ -> (,) emptySH blank
i = newProjectileKey w i = newProjectileKey w
--(_, g) = randomR (-grenadeAccA,grenadeAccA::Float) (_randGen w) --(_, g) = randomR (-grenadeAccA,grenadeAccA::Float) (_randGen w)
--(_, _) = randomR (1 - 2*grenadeAccL,1+grenadeAccL::Float) g --(_, _) = randomR (1 - 2*grenadeAccL,1+grenadeAccL::Float) g
+3 -3
View File
@@ -22,7 +22,7 @@ import Geometry.Vector3D
import Picture import Picture
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import Padding import Padding
import ShapePicture --import ShapePicture
import Shape import Shape
import Data.Maybe import Data.Maybe
@@ -50,10 +50,10 @@ launcher = defaultGun
] ]
, _wpSpread = 0.02 , _wpSpread = 0.02
, _wpRange = 20 , _wpRange = 20
, _itFloorPict = SPic emptySH $ onLayer FlItLayer launcherPic , _itFloorPict = (,) emptySH $ onLayer FlItLayer launcherPic
, _itAimingSpeed = 0.2 , _itAimingSpeed = 0.2
, _itAimingRange = 0.5 , _itAimingRange = 0.5
, _itEquipPict = pictureWeaponOnAim $ SPic emptySH launcherPic , _itEquipPict = pictureWeaponOnAim $ (,) emptySH launcherPic
, _itHammer = NoHammer , _itHammer = NoHammer
, _itEffect = NoItEffect , _itEffect = NoItEffect
, _wpAmmo = defaultShellAmmo , _wpAmmo = defaultShellAmmo
+2 -3
View File
@@ -79,11 +79,10 @@ setupWorldBounds w = w
setupForegroundEdgeVerxs :: World -> World setupForegroundEdgeVerxs :: World -> World
setupForegroundEdgeVerxs w = w & foregroundEdgeVerx .~ polyhedrasToEdges (_foregroundDecorations w) setupForegroundEdgeVerxs w = w & foregroundEdgeVerx .~ polyhedrasToEdges (_foregroundDecorations w)
& foregroundShape .~ Shape vs es & foregroundShape .~ (vs,es)
where where
vs = shVfromList $ concatMap (polyToTris . map toShape) $ concatMap _pyFaces $ _foregroundDecorations w vs = shVfromList $ map pairToSV $ concatMap polyToTris $ concatMap _pyFaces $ _foregroundDecorations w
es = shEfromList $ polyhedrasToEdges (_foregroundDecorations w) es = shEfromList $ polyhedrasToEdges (_foregroundDecorations w)
toShape (p3,p4) = ShapeV p3 p4
polyhedrasToEdges :: [Polyhedra] -> [Point3] polyhedrasToEdges :: [Polyhedra] -> [Point3]
polyhedrasToEdges = concatMap tflat4 . concatMap polyToEdges polyhedrasToEdges = concatMap tflat4 . concatMap polyToEdges
+27 -16
View File
@@ -20,7 +20,8 @@ import Shader.Data
import MatrixHelper import MatrixHelper
--import Polyhedra.Data --import Polyhedra.Data
import Polyhedra import Polyhedra
import Shape.Data import Shader.ExtraPrimitive
import Shader.Parameters
import Foreign import Foreign
--import Control.Applicative --import Control.Applicative
@@ -38,7 +39,7 @@ import Control.Monad
import Graphics.Rendering.OpenGL hiding (color,scale,translate,rotate) import Graphics.Rendering.OpenGL hiding (color,scale,translate,rotate)
import qualified SDL import qualified SDL
import qualified Data.Vector.Unboxed.Mutable as UMV import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector.Fusion.Stream.Monadic as VS import Graphics.GL.Core43
doDrawing :: RenderData -> World -> IO Word32 doDrawing :: RenderData -> World -> IO Word32
doDrawing pdata w = do doDrawing pdata w = do
@@ -56,21 +57,15 @@ doDrawing pdata w = do
-- bind as much data into vbos as feasible at this point -- bind as much data into vbos as feasible at this point
-- poke wall points and colors -- poke wall points and colors
nWalls <- poke224s (shadVBOptr $ _wallTextureShader pdata) wallPointsCol nWalls <- poke224s (shadVBOptr $ _wallTextureShader pdata) wallPointsCol
nSils <- pokePoint3s (shadVBOptr $ _lightingLineShadowShader pdata) (numShapeVs,nSils) <- pokeShape
$ VS.fromList (_vboPtr $ _vaoVBO $ _shadVAO $ _shapeShader pdata)
$ (shEList $ worldShape w) (shadVBOptr $ _lightingLineShadowShader pdata)
-- -- poke foreground geometry for caps (_eboPtr $ _shapeEBO pdata)
-- nCaps <- pokePoint3s (shadVBOptr $ _lightingCapShader pdata) $ worldShape w
-- $ VS.fromList
-- (fmap _svPos (shVList $ worldShape w))
numShapeVs <- pokeShapeVs (_vboPtr $ _vaoVBO $ _shadVAO $ _shapeShader pdata)
$ VS.fromList $ shVList $ worldShape w
let nCaps = numShapeVs
-- bind wall points, silhouette data, surface geometry -- bind wall points, silhouette data, surface geometry
uncurry bindShaderBuffers $ unzip uncurry bindShaderBuffers $ unzip
[ ( _wallTextureShader pdata, nWalls) [ ( _wallTextureShader pdata, nWalls)
, (_lightingLineShadowShader pdata, nSils) , (_lightingLineShadowShader pdata, nSils)
-- , (_lightingCapShader pdata, nCaps)
, (_shapeShader pdata, numShapeVs) , (_shapeShader pdata, numShapeVs)
] ]
-- set the coordinate uniform ready for drawing elements using world coordinates -- set the coordinate uniform ready for drawing elements using world coordinates
@@ -95,7 +90,22 @@ doDrawing pdata w = do
pokeBindFoldableLayer shadV layerCounts $ worldPictures w pokeBindFoldableLayer shadV layerCounts $ worldPictures w
renderLayer 0 shadV layerCounts renderLayer 0 shadV layerCounts
drawShader (_shapeShader pdata) numShapeVs -- drawShader (_shapeShader pdata) numShapeVs
let fs = _shapeShader pdata
currentProgram $= Just (_shadProg fs)
bindVertexArrayObject $= Just (_vao $ _shadVAO fs)
bindBuffer ElementArrayBuffer $= Just (_ebo $ _shapeEBO pdata)
bufferSubData
ElementArrayBuffer
WriteToBuffer
0
(fromIntegral $ glushortSize * numShapeVs)
(_eboPtr $ _shapeEBO pdata)
glDrawElements
(marshalEPrimitiveMode $ _shadPrim fs)
(fromIntegral numShapeVs)
(GL_UNSIGNED_SHORT)
nullPtr
--draw floor onto base buffer --draw floor onto base buffer
nTextArrayVs <- pokePoint33s (shadVBOptr $ _textureArrayShader pdata) (_floorTiles w) nTextArrayVs <- pokePoint33s (shadVBOptr $ _textureArrayShader pdata) (_floorTiles w)
@@ -103,7 +113,8 @@ doDrawing pdata w = do
drawShader (_textureArrayShader pdata) nTextArrayVs drawShader (_textureArrayShader pdata) nTextArrayVs
--draw lightmap for base buffer --draw lightmap for base buffer
bindFramebuffer Framebuffer $= fst (_fboLighting pdata) bindFramebuffer Framebuffer $= fst (_fboLighting pdata)
createLightMap pdata lightPoints nWalls nSils nCaps (snd $ snd $ _fboBase pdata) --createLightMap pdata lightPoints nWalls nSils numShapeVs (snd $ snd $ _fboBase pdata)
createLightMap pdata lightPoints nWalls 0 0 (snd $ snd $ _fboBase pdata)
colorMask $= Color4 Enabled Enabled Enabled Enabled colorMask $= Color4 Enabled Enabled Enabled Enabled
clearColor $= Color4 0 0 0 0 clearColor $= Color4 0 0 0 0
--apply lightmap to base buffer --apply lightmap to base buffer
@@ -157,7 +168,7 @@ doDrawing pdata w = do
depthMask $= Disabled depthMask $= Disabled
blend $= Enabled blend $= Enabled
bindFramebuffer Framebuffer $= fst (_fboLighting pdata) bindFramebuffer Framebuffer $= fst (_fboLighting pdata)
createLightMap pdata lightPoints nWalls nSils nCaps (snd $ snd $ _fboCloud pdata) createLightMap pdata lightPoints nWalls nSils numShapeVs (snd $ snd $ _fboCloud pdata)
colorMask $= Color4 Enabled Enabled Enabled Enabled colorMask $= Color4 Enabled Enabled Enabled Enabled
clearColor $= Color4 0 0 0 0 clearColor $= Color4 0 0 0 0
--apply lightmap to cloud buffer --apply lightmap to cloud buffer
+16 -4
View File
@@ -29,7 +29,7 @@ preloadRender = do
-- set up uniform buffer object -- set up uniform buffer object
theUBO <- genObjectName theUBO <- genObjectName
bindBuffer UniformBuffer $= Just theUBO bindBuffer UniformBuffer $= Just theUBO
bufferData UniformBuffer $= (64, nullPtr, DynamicDraw) bufferData UniformBuffer $= (64, nullPtr, StreamDraw)
bindBufferBase IndexedUniformBuffer 0 $= Just theUBO bindBufferBase IndexedUniformBuffer 0 $= Just theUBO
-- setup wall points VBO, VAOs and shaders -- setup wall points VBO, VAOs and shaders
wpVBOname <- genObjectName wpVBOname <- genObjectName
@@ -38,7 +38,7 @@ preloadRender = do
bufferData ArrayBuffer $= bufferData ArrayBuffer $=
(fromIntegral $ floatSize * numDrawableWalls * 8 (fromIntegral $ floatSize * numDrawableWalls * 8
, nullPtr , nullPtr
, DynamicDraw , StreamDraw
) )
let wpVBO = VBO {_vbo = wpVBOname, _vboPtr = wpVBOptr, _vboAttribSizes = [4,4], _vboStride = 8} let wpVBO = VBO {_vbo = wpVBOname, _vboPtr = wpVBOptr, _vboAttribSizes = [4,4], _vboStride = 8}
wpVAOname <- genObjectName wpVAOname <- genObjectName
@@ -58,7 +58,7 @@ preloadRender = do
bufferData ArrayBuffer $= bufferData ArrayBuffer $=
(fromIntegral $ floatSize * numDrawableWalls * 8 (fromIntegral $ floatSize * numDrawableWalls * 8
, nullPtr , nullPtr
, DynamicDraw , StreamDraw
) )
let winVBO = VBO {_vbo = winVBOname, _vboPtr = winVBOptr, _vboAttribSizes = [4,4], _vboStride = 8} let winVBO = VBO {_vbo = winVBOname, _vboPtr = winVBOptr, _vboAttribSizes = [4,4], _vboStride = 8}
winColVAOname <- genObjectName winColVAOname <- genObjectName
@@ -67,13 +67,23 @@ preloadRender = do
setupVertexAttribPointer 1 4 8 4 setupVertexAttribPointer 1 4 8 4
let winColVAO = VAO {_vao = winColVAOname, _vaoVBO = winVBO} let winColVAO = VAO {_vao = winColVAOname, _vaoVBO = winVBO}
-- setup shape geometry/cap VBO and two VAOs -- setup shape geometry/cap VBO and two VAOs
-- TODO when making shaders that use these VAOs, don't mallocate ptr space
shEBOname <- genObjectName
shEBOptr <- mallocArray numDrawableElements
bindBuffer ElementArrayBuffer $= Just shEBOname
bufferData ElementArrayBuffer $=
( fromIntegral $ glushortSize * numDrawableElements
, nullPtr
, StreamDraw
)
let shEBO = EBO {_ebo = shEBOname, _eboPtr = shEBOptr}
shVBOname <- genObjectName shVBOname <- genObjectName
shVBOptr <- mallocArray (7 * numDrawableElements) shVBOptr <- mallocArray (7 * numDrawableElements)
bindBuffer ArrayBuffer $= Just shVBOname bindBuffer ArrayBuffer $= Just shVBOname
bufferData ArrayBuffer $= bufferData ArrayBuffer $=
( fromIntegral $ floatSize * numDrawableElements * 7 ( fromIntegral $ floatSize * numDrawableElements * 7
, nullPtr , nullPtr
, DynamicDraw , StreamDraw
) )
let shVBO = VBO {_vbo = shVBOname, _vboPtr = shVBOptr, _vboAttribSizes = [4,4], _vboStride = 8} let shVBO = VBO {_vbo = shVBOname, _vboPtr = shVBOptr, _vboAttribSizes = [4,4], _vboStride = 8}
shPosColVAOname <- genObjectName shPosColVAOname <- genObjectName
@@ -81,6 +91,7 @@ preloadRender = do
bindBuffer ArrayBuffer $= Just shVBOname bindBuffer ArrayBuffer $= Just shVBOname
setupVertexAttribPointer 0 3 7 0 setupVertexAttribPointer 0 3 7 0
setupVertexAttribPointer 1 4 7 3 setupVertexAttribPointer 1 4 7 3
bindBuffer ElementArrayBuffer $= Just shEBOname
shPosVAOname <- genObjectName shPosVAOname <- genObjectName
bindVertexArrayObject $= Just shPosVAOname bindVertexArrayObject $= Just shPosVAOname
bindBuffer ArrayBuffer $= Just shVBOname bindBuffer ArrayBuffer $= Just shVBOname
@@ -169,6 +180,7 @@ preloadRender = do
return $ RenderData return $ RenderData
{ _pictureShaders = shadV { _pictureShaders = shadV
, _shapeShader = bslista {_shadVAO = shPosColVAO } , _shapeShader = bslista {_shadVAO = shPosColVAO }
, _shapeEBO = shEBO
, _lightingCapShader = lightingCapShad { _shadVAO = shPosVAO } , _lightingCapShader = lightingCapShad { _shadVAO = shPosVAO }
, _lightingLineShadowShader = lightingLineShadowShad , _lightingLineShadowShader = lightingLineShadowShad
, _lightingOccludeShader = wsShad {_shadVAO = wpVAO} , _lightingOccludeShader = wsShad {_shadVAO = wpVAO}
+2 -2
View File
@@ -148,7 +148,7 @@ setupVBO sizes = do
bufferData ArrayBuffer $= bufferData ArrayBuffer $=
(fromIntegral $ floatSize * numDrawableElements * strd (fromIntegral $ floatSize * numDrawableElements * strd
, nullPtr , nullPtr
, DynamicDraw , StreamDraw
) )
return $ VBO return $ VBO
{ _vbo = vboName { _vbo = vboName
@@ -171,7 +171,7 @@ setupVBOSized sizes ndraw = do
bufferData ArrayBuffer $= bufferData ArrayBuffer $=
(fromIntegral $ floatSize * ndraw * strd (fromIntegral $ floatSize * ndraw * strd
, nullPtr , nullPtr
, DynamicDraw , StreamDraw
) )
return $ VBO return $ VBO
{ _vbo = vboName { _vbo = vboName
+8
View File
@@ -4,6 +4,7 @@
module Shader.Data module Shader.Data
( VAO (..) ( VAO (..)
, VBO (..) , VBO (..)
, EBO (..)
, FullShader (..) , FullShader (..)
, ShaderTexture (..) , ShaderTexture (..)
, EPrimitiveMode (..) , EPrimitiveMode (..)
@@ -19,6 +20,8 @@ module Shader.Data
, vboPtr , vboPtr
, vboAttribSizes , vboAttribSizes
, vboStride , vboStride
, ebo
, eboPtr
-- | Synonyms -- | Synonyms
, vert , vert
, geom , geom
@@ -51,6 +54,10 @@ data VBO = VBO
, _vboAttribSizes :: [Int] -- ^ It is not clear to me if this is necessary to store or not , _vboAttribSizes :: [Int] -- ^ It is not clear to me if this is necessary to store or not
, _vboStride :: Int , _vboStride :: Int
} }
data EBO = EBO
{ _ebo :: BufferObject
, _eboPtr :: Ptr GLushort
}
{- | Datatype containing the reference to a texture object. -} {- | Datatype containing the reference to a texture object. -}
newtype ShaderTexture = ShaderTexture newtype ShaderTexture = ShaderTexture
{ _textureObject :: TextureObject } { _textureObject :: TextureObject }
@@ -75,3 +82,4 @@ frag = FragmentShader
makeLenses ''VAO makeLenses ''VAO
makeLenses ''VBO makeLenses ''VBO
makeLenses ''FullShader makeLenses ''FullShader
makeLenses ''EBO
+9
View File
@@ -2,6 +2,7 @@ module Shader.Parameters
( floatSize ( floatSize
, numDrawableElements , numDrawableElements
, numSubElements , numSubElements
, glushortSize
) where ) where
import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight) import Graphics.Rendering.OpenGL hiding (Point,translate,scale,imageHeight)
import Foreign import Foreign
@@ -10,6 +11,14 @@ floatSize :: Int
floatSize = sizeOf (0.5 :: GLfloat) floatSize = sizeOf (0.5 :: GLfloat)
{-# INLINE floatSize #-} {-# INLINE floatSize #-}
--intSize :: Int
--intSize = sizeOf (1 :: GLuint)
--{-# INLINE intSize #-}
glushortSize :: Int
glushortSize = sizeOf (0 :: GLushort)
{-# INLINE glushortSize #-}
numDrawableElements :: Int numDrawableElements :: Int
{-# INLINE numDrawableElements #-} {-# INLINE numDrawableElements #-}
numDrawableElements = 60000 numDrawableElements = 60000
+22 -11
View File
@@ -7,7 +7,6 @@ module Shader.Poke
, pokePoint33s , pokePoint33s
, poke224s , poke224s
, pokeShape , pokeShape
, pokeShapeVs
, pokePoint3s , pokePoint3s
) where ) where
import Shader.Data import Shader.Data
@@ -16,11 +15,13 @@ import Picture.Data
import Shape.Data import Shape.Data
import Geometry.Data import Geometry.Data
import Graphics.Rendering.OpenGL hiding (color,scale,translate,rotate)
import Foreign import Foreign
import qualified Data.Vector.Unboxed.Mutable as UMV import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Fusion.Stream.Monadic as VS import qualified Data.Vector.Fusion.Stream.Monadic as VS
import Control.Monad.Primitive import Control.Monad.Primitive
import Data.Bifoldable
--import qualified Data.DList as DL --import qualified Data.DList as DL
pokeVerxs pokeVerxs
@@ -41,17 +42,25 @@ pokeVerx vbos offsets Verx{_vxPos=thePos,_vxCol=theCol,_vxExt=ext,_vxShadNum=the
where where
sn = _unShadNum theShadNum sn = _unShadNum theShadNum
pokeShape :: Ptr Float -> Ptr Float -> Shape -> IO (Int,Int) pokeShape :: Ptr Float -> Ptr Float -> Ptr GLushort -> Shape -> IO (Int,Int)
pokeShape vptr eptr sh = do pokeShape vptr eptr iptr = bifoldlM (pokeShapeVs' vptr iptr) (pokeShapeEs' eptr) (0,0)
nVs <- pokeShapeVs vptr (VS.fromList $ shVList sh)
nEs <- pokePoint3s eptr (VS.fromList $ shEList sh)
return (nVs,nEs)
pokeShapeVs :: Ptr Float -> VS.Stream IO ShapeV -> IO Int pokeShapeVs' :: Ptr Float -> Ptr GLushort -> (Int,Int) -> [ShapeV] -> IO (Int, Int)
pokeShapeVs ptr = VS.foldlM' (pokeShapeV ptr) 0 pokeShapeVs' ptr iptr count = VS.foldlM' (pokeShapeV' ptr iptr) count . VS.fromList
pokeShapeV :: Ptr Float -> Int -> ShapeV -> IO Int pokeShapeEs' :: Ptr Float -> (Int,Int) -> [Point3] -> IO (Int, Int)
pokeShapeV ptr n sh = do pokeShapeEs' ptr count = VS.foldlM' (pokeShapeE' ptr) count . VS.fromList
pokeShapeE' :: Ptr Float -> (Int,Int) -> Point3 -> IO (Int,Int)
pokeShapeE' ptr (nv,n) (V3 a b c) = do
pokeElemOff ptr (n * 3) a
pokeElemOff ptr (n * 3 + 1) b
pokeElemOff ptr (n * 3 + 2) c
return $ (nv,n + 1)
pokeShapeV' :: Ptr Float -> Ptr GLushort -> (Int,Int) -> ShapeV -> IO (Int,Int)
pokeShapeV' ptr iptr (n,ne) sh = do
pokeElemOff ptr (off 0) a pokeElemOff ptr (off 0) a
pokeElemOff ptr (off 1) b pokeElemOff ptr (off 1) b
pokeElemOff ptr (off 2) c pokeElemOff ptr (off 2) c
@@ -59,12 +68,14 @@ pokeShapeV ptr n sh = do
pokeElemOff ptr (off 4) e pokeElemOff ptr (off 4) e
pokeElemOff ptr (off 5) f pokeElemOff ptr (off 5) f
pokeElemOff ptr (off 6) g pokeElemOff ptr (off 6) g
return (n+1) pokeElemOff iptr n (fromIntegral n)
return (n+1,ne)
where where
off i = n*7 + i off i = n*7 + i
V3 a b c = _svPos sh V3 a b c = _svPos sh
V4 d e f g = _svCol sh V4 d e f g = _svCol sh
pokePoint3s :: Ptr Float -> VS.Stream IO Point3 -> IO Int pokePoint3s :: Ptr Float -> VS.Stream IO Point3 -> IO Int
pokePoint3s ptr = VS.foldlM' (pokePoint3 ptr) 0 pokePoint3s ptr = VS.foldlM' (pokePoint3 ptr) 0
+24 -39
View File
@@ -20,12 +20,11 @@ import Geometry.ConvexPoly
import Shape.Data import Shape.Data
import Color import Color
--import qualified Data.Vector.Fusion.Stream.Monadic as VS import Data.Bifunctor
--import qualified Data.DList as DL
emptySH :: Shape emptySH :: Shape
{-# INLINE emptySH #-} {-# INLINE emptySH #-}
emptySH = Shape mempty mempty emptySH = mempty
flatCirc :: Float -> Shape flatCirc :: Float -> Shape
{-# INLINE flatCirc #-} {-# INLINE flatCirc #-}
@@ -40,16 +39,16 @@ upperPrismPoly
-> [Point2] -> [Point2]
-> Shape -> Shape
{-# INLINE upperPrismPoly #-} {-# INLINE upperPrismPoly #-}
upperPrismPoly h ps = Shape upperPrismPoly h ps =
{ _shVertices = topFace <> sideFaces ( topFace <> sideFaces
, _shEdges = topEdges <> bottomEdges <> sideEdges , topEdges <> bottomEdges <> sideEdges
} )
where where
topFace = shVfromList $ polyToTris $ map f' ps topFace = shVfromList $ polyToTris $ map f' ps
f' (V2 x y) = ShapeV {_svPos = V3 x y h, _svCol = black } f' (V2 x y) = pairToSV (V3 x y h, black)
sideFaces = shVfromList $ map addCol $ concat sideFaces = shVfromList $ map addCol $ concat
$ zipWith (\a b -> polyToTris (extendSide a b)) ps (tail ps ++ [head ps]) $ zipWith (\a b -> polyToTris (extendSide a b)) ps (tail ps ++ [head ps])
addCol x = ShapeV {_svPos = x, _svCol = black} addCol x = pairToSV ( x, black)
extendSide (V2 x y) (V2 x' y') = [V3 x y 0, V3 x' y' 0, V3 x' y' h, V3 x y h] extendSide (V2 x y) (V2 x' y') = [V3 x y 0, V3 x' y' 0, V3 x' y' h, V3 x y h]
topEdges = shEfromList $ concat $ zipWith makeTopEdge ps (tail ps ++ [head ps]) topEdges = shEfromList $ concat $ zipWith makeTopEdge ps (tail ps ++ [head ps])
makeTopEdge (V2 x y) (V2 x' y') = [V3 x y h,V3 x' y' h,V3 x y 0,V3 xcen ycen h] makeTopEdge (V2 x y) (V2 x' y') = [V3 x y h,V3 x' y' h,V3 x y 0,V3 xcen ycen h]
@@ -64,18 +63,18 @@ prismPoly
-> [Point2] -> [Point2]
-> Shape -> Shape
{-# INLINE prismPoly #-} {-# INLINE prismPoly #-}
prismPoly h ps = Shape prismPoly h ps =
{ _shVertices = topFace <> bottomFace <> sideFaces ( topFace <> bottomFace <> sideFaces
, _shEdges = topEdges <> bottomEdges <> sideEdges , topEdges <> bottomEdges <> sideEdges
} )
where where
topFace = shVfromList $ polyToTris $ map f' ps topFace = shVfromList $ polyToTris $ map f' ps
f' (V2 x y) = ShapeV {_svPos = V3 x y h, _svCol = black } f' (V2 x y) = pairToSV ( V3 x y h, black )
f (V2 x y) = ShapeV {_svPos = V3 x y 0, _svCol = black } f (V2 x y) = pairToSV ( V3 x y 0, black )
bottomFace = shVfromList $ polyToTris $ map f $ reverse ps bottomFace = shVfromList $ polyToTris $ map f $ reverse ps
sideFaces = shVfromList $ map addCol $ concat sideFaces = shVfromList $ map addCol $ concat
$ zipWith (\a b -> polyToTris (extendSide a b)) ps (tail ps ++ [head ps]) $ zipWith (\a b -> polyToTris (extendSide a b)) ps (tail ps ++ [head ps])
addCol x = ShapeV {_svPos = x, _svCol = black} addCol x = pairToSV ( x, black)
extendSide (V2 x y) (V2 x' y') = [V3 x y 0, V3 x' y' 0, V3 x' y' h, V3 x y h] extendSide (V2 x y) (V2 x' y') = [V3 x y 0, V3 x' y' 0, V3 x' y' h, V3 x y h]
topEdges = shEfromList $ concat $ zipWith makeTopEdge ps (tail ps ++ [head ps]) topEdges = shEfromList $ concat $ zipWith makeTopEdge ps (tail ps ++ [head ps])
makeTopEdge (V2 x y) (V2 x' y') = [V3 x y h,V3 x' y' h,V3 x y 0,V3 xcen ycen h] makeTopEdge (V2 x y) (V2 x' y') = [V3 x y h,V3 x' y' h,V3 x y 0,V3 xcen ycen h]
@@ -86,12 +85,12 @@ prismPoly h ps = Shape
makeSideEdge (V2 xl yl) (V2 x y) (V2 xr yr) = [V3 x y 0, V3 x y h, V3 xr yr 0, V3 xl yl h] makeSideEdge (V2 xl yl) (V2 x y) (V2 xr yr) = [V3 x y 0, V3 x y h, V3 xr yr 0, V3 xl yl h]
flatPoly :: [Point2] -> Shape flatPoly :: [Point2] -> Shape
flatPoly ps = Shape flatPoly ps =
{ _shVertices = shVfromList $ polyToTris $ map f ps ( shVfromList $ polyToTris $ map f ps
, _shEdges = shEfromList $ concat $ zipWith g ps (tail ps ++ [head ps]) , shEfromList $ concat $ zipWith g ps (tail ps ++ [head ps])
} )
where where
f (V2 x y) = ShapeV {_svPos = V3 x y 0, _svCol = black } f (V2 x y) = pairToSV ( V3 x y 0, black )
g (V2 x y) (V2 a b) = g (V2 x y) (V2 a b) =
[ V3 x y 0 [ V3 x y 0
, V3 a b 0 , V3 a b 0
@@ -100,8 +99,6 @@ flatPoly ps = Shape
] ]
where where
n = addZ 0 $ vNormal (V2 (a-x) (b-y)) n = addZ 0 $ vNormal (V2 (a-x) (b-y))
-- where
--n =
colorSH :: Color -> Shape -> Shape colorSH :: Color -> Shape -> Shape
{-# INLINE colorSH #-} {-# INLINE colorSH #-}
@@ -109,17 +106,11 @@ colorSH col = overCol $ const col
overCol :: (Point4 -> Point4) -> Shape -> Shape overCol :: (Point4 -> Point4) -> Shape -> Shape
{-# INLINE overCol #-} {-# INLINE overCol #-}
overCol f Shape{_shVertices=vs,_shEdges=es} = Shape overCol f = first (fmap $ overColVertex f)
{_shVertices = fmap (overColVertex f) vs
,_shEdges = es
}
overPos :: (Point3 -> Point3) -> Shape -> Shape overPos :: (Point3 -> Point3) -> Shape -> Shape
{-# INLINE overPos #-} {-# INLINE overPos #-}
overPos f Shape{_shVertices=vs,_shEdges=es} = Shape overPos f = bimap (fmap $ overPosVertex f) (fmap f)
{_shVertices = fmap (overPosVertex f) vs
,_shEdges = fmap f es
}
translateSH :: Point3 -> Shape -> Shape translateSH :: Point3 -> Shape -> Shape
{-# INLINE translateSH #-} {-# INLINE translateSH #-}
@@ -143,14 +134,8 @@ scaleSH !(V3 a b c) = overPos (\(V3 x y z) -> V3 (x*a) (y*b) (z*c))
overColVertex :: (Point4 -> Point4) -> ShapeV -> ShapeV overColVertex :: (Point4 -> Point4) -> ShapeV -> ShapeV
{-# INLINE overColVertex #-} {-# INLINE overColVertex #-}
overColVertex f ShapeV{_svPos=pos,_svCol=col} = ShapeV overColVertex f (ShapeV a b) = ShapeV a (f b)
{_svPos = pos
,_svCol = f col
}
overPosVertex :: (Point3 -> Point3) -> ShapeV -> ShapeV overPosVertex :: (Point3 -> Point3) -> ShapeV -> ShapeV
{-# INLINE overPosVertex #-} {-# INLINE overPosVertex #-}
overPosVertex f ShapeV{_svPos=pos,_svCol=col} = ShapeV overPosVertex f (ShapeV a b) = ShapeV (f a) b
{_svPos = f pos
,_svCol = col
}
+26 -19
View File
@@ -1,40 +1,47 @@
{-# OPTIONS_GHC -Wno-missing-signatures #-} {-# OPTIONS_GHC -Wno-missing-signatures #-}
{-# LANGUAGE StrictData #-} {-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
module Shape.Data module Shape.Data
where where
import Geometry.Data import Geometry.Data
import Control.Lens --import qualified Data.DList as DL
--import qualified Data.Vector.Fusion.Stream.Monadic as VS
import qualified Data.DList as DL
--import Data.Monoid type Shape = ([ShapeV], [Point3])
data Shape = Shape _shVertices :: Shape -> [ShapeV]
{ _shVertices :: DL.DList ShapeV {-# INLINE _shVertices #-}
, _shEdges :: DL.DList Point3 _shVertices = fst
} _shEdges :: Shape -> [Point3]
instance Semigroup Shape where {-# INLINE _shEdges #-}
(<>) (Shape sv1 se1) (Shape sv2 se2) = Shape (sv1 <> sv2) (se1 <> se2) _shEdges = snd
--(<>) (Shape sv1 se1) (Shape sv2 se2) = Shape (sv1 VS.++ sv2) (se1 VS.++ se2)
instance Monoid Shape where
mempty = Shape mempty mempty
shVList :: Shape -> [ShapeV] shVList :: Shape -> [ShapeV]
{-# INLINE shVList #-} {-# INLINE shVList #-}
shVList = DL.toList . _shVertices shVList = _shVertices
--shVList = DL.toList . _shVertices
shEList :: Shape -> [Point3] shEList :: Shape -> [Point3]
{-# INLINE shEList #-} {-# INLINE shEList #-}
shEList = DL.toList . _shEdges shEList = _shEdges
--shEList = DL.toList . _shEdges
{-# INLINE shVfromList #-} {-# INLINE shVfromList #-}
shVfromList = DL.fromList shVfromList = id
--shVfromList = DL.fromList
{-# INLINE shEfromList #-} {-# INLINE shEfromList #-}
shEfromList = DL.fromList shEfromList = id
--shEfromList = DL.fromList
-- edges are given by four consecutive points -- edges are given by four consecutive points
data ShapeV = ShapeV data ShapeV = ShapeV
{_svPos :: Point3 {_svPos :: Point3
,_svCol :: Point4 ,_svCol :: Point4
} }
makeLenses ''ShapeV pairToSV :: (Point3,Point4) -> ShapeV
makeLenses ''Shape {-# INLINE pairToSV #-}
pairToSV = uncurry ShapeV
--_svPos :: ShapeV -> Point3
--_svPos = fst
--_svCol :: ShapeV -> Point4
--_svCol = snd
+6 -8
View File
@@ -8,19 +8,17 @@ import ShapePicture.Data
import Picture import Picture
import Geometry import Geometry
import Data.Bifunctor
emptyBlank :: SPic emptyBlank :: SPic
emptyBlank = SPic emptySH blank emptyBlank = (emptySH,blank)
translateSPf :: Float -> Float -> SPic -> SPic translateSPf :: Float -> Float -> SPic -> SPic
translateSPf x y (SPic sh pic) = SPic translateSPf x y = bimap (translateSH (V3 x y 0)) (translate x y)
(translateSH (V3 x y 0) sh)
(translate x y pic)
-- TODO make this uniform: currently the shape translates and the picture is set to a constant -- TODO make this uniform: currently the shape translates and the picture is set to a constant
translateSPz :: Float -> SPic -> SPic translateSPz :: Float -> SPic -> SPic
translateSPz z (SPic sh pic) = SPic translateSPz z = bimap (translateSH (V3 0 0 z)) (setDepth z)
(translateSH (V3 0 0 z) sh)
(setDepth z pic)
rotateSP :: Float -> SPic -> SPic rotateSP :: Float -> SPic -> SPic
rotateSP a (SPic sh pic) = SPic (rotateSH a sh) (rotate a pic) rotateSP a = bimap (rotateSH a) (rotate a)
+7 -12
View File
@@ -1,19 +1,14 @@
{-# LANGUAGE StrictData #-} {-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-} --{-# LANGUAGE TemplateHaskell #-}
module ShapePicture.Data module ShapePicture.Data
where where
import Shape import Shape
import Picture import Picture
import Control.Lens --import Control.Lens
data SPic = SPic
{ _spShape :: Shape
, _spPicture :: Picture
}
instance Semigroup SPic where type SPic = (Shape, Picture)
(<>) (SPic a b) (SPic x y) = SPic (a <> x) (b <>y)
instance Monoid SPic where _spShape :: SPic -> Shape
mempty = SPic emptySH blank _spShape = fst
_spPicture :: SPic -> Picture
makeLenses ''SPic _spPicture = snd