{- | Drawing of creatures. Takes into account damage etc. -} module Dodge.Creature.Picture ( basicCrPict, deadScalp, deadUpperBody, deadFeet, ) where import Shape import Control.Lens import Dodge.Creature.HandPos (translateToLeftHand, translateToRightHand) import Dodge.Creature.Test import Dodge.Damage import Dodge.Data.Creature import Dodge.Item.Draw import Geometry import Picture import qualified Quaternion as Q --import Shape import ShapePicture basicCrPict :: Creature -> SPic basicCrPict cr = uncurryV translateSPf (_crPos cr) (rotateSP (_crDir cr) $ drawEquipment cr) <> (basicCrShape cr, mempty) --testShape :: Shape --testShape = translateSHz 10 . rotateSHx 0 . upperCylinder 20 $ polyCirc 2 10 basicCrShape :: Creature -> Shape basicCrShape cr | _crCamouflage cr == Invisible = mempty -- | otherwise = colorSH white $ tr $ rotdir testShape | otherwise = tr . scaleSH (V3 crsize crsize crsize) $ mconcat [ rotdir . colorSH (_skinHead cskin) . translateSHz 20 $ scalp cr , rotdir $ colorSH (_skinUpper cskin) $ upperBody cr , rotmdir $ colorSH (_skinLower cskin) $ feet cr ] where cskin = _crType cr crsize = 0.1 * _crRad cr tr = uncurryV translateSHf (_crPos cr) rotdir = rotateSH (_crDir cr) rotmdir = rotateSH (_crMvDir cr) feet :: Creature -> Shape {-# INLINE feet #-} feet cr = case cr ^? crStance . carriage of Just (Walking sa LeftForward) -> mconcat [ translateSHf (f sa) off aFoot , translateSHf (- f sa) (- off) aFoot ] Just (Walking sa RightForward) -> mconcat [ translateSHf (- f sa) off aFoot , translateSHf (f sa) (- off) aFoot ] _ -> mconcat [ translateSHf 0 off aFoot , translateSHf 0 (- off) aFoot ] where aFoot :: Shape aFoot = upperPrismPoly 10 $ polyCirc 3 4 off = 5 sLen = _strideLength $ _crStance cr f i = 6 * fromIntegral (sLen - i) / fromIntegral sLen deadFeet :: Creature -> Shape {-# INLINE deadFeet #-} deadFeet cr = case cr ^? crStance . carriage of Just (Walking sa LeftForward) -> mconcat [ translateSHf (f sa) off aFoot , translateSHf (- f sa) (- off) aFoot ] Just (Walking sa RightForward) -> mconcat [ translateSHf (- f sa) off aFoot , translateSHf (f sa) (- off) aFoot ] _ -> mconcat [ translateSHf 0 off aFoot , translateSHf 0 (- off) aFoot ] where aFoot :: Shape aFoot = upperPrismPoly 3 $ polyCirc 3 4 off = 5 sLen = _strideLength $ _crStance cr f i = 6 * fromIntegral (sLen - i) / fromIntegral sLen arms :: Creature -> Shape {-# INLINE arms #-} arms cr = fst $ translateToRightHand cr aHand <> translateToLeftHand cr aHand where aHand = noPic $ translateSHz (-4) . upperPrismPolyHalf 4 $ polyCirc 3 4 deadScalp :: Creature -> Shape deadScalp cr = deadRot cr . translateSHz 10 . scalp $ cr deadRot :: Creature -> Shape -> Shape deadRot cr = overPosSH (Q.rotateToZ d) where d = maybe (V3 1 0 0) (addZ 0 . unitVectorAtAngle . subtract (_crDir cr + pi)) (damageDirection . _csDamage $ _crState cr) scalp :: Creature -> Shape {-# INLINE scalp #-} scalp cr | twists cr = translateSHf 0 5 . rotateSH (-1) $ translateSHf (negate 2.5) 0.25 fhead | oneH cr = rotateSH 0.5 $ translateSHf 2.5 0 fhead | otherwise = translateSHf 2.5 0 fhead where fhead = colorSH (greyN 0.9) . upperPrismPolyHalf 5 $ polyCirc 4 5 torso :: Creature -> Shape {-# INLINE torso #-} torso cr | oneH cr = rotateSH 0.5 $ mconcat [ translateSHf 0 3 . rotateSH (negate 0.2) $ aShoulder , translateSHf 0 (negate 3) . rotateSH 0.2 $ aShoulder ] | twists cr = translateSHf 0 5 . rotateSH (-1) $ mconcat [ rotateSH (negate 0.2) . translateSHf 2 3 . rotateSH (negate 0.4) $ aShoulder , rotateSH (negate 0.2) . translateSHf 0 (negate 3) . rotateSH 0.2 $ aShoulder ] | otherwise = mconcat [ translateSHf 0 3 . rotateSH (negate 0.2) $ aShoulder , translateSHf 0 (negate 3) . rotateSH 0.2 $ aShoulder ] where aShoulder = scaleSH (V3 10 10 1) baseShoulder deadUpperBody :: Creature -> Shape deadUpperBody cr = deadRot cr . translateSHz (negate 10) . upperBody $ cr baseShoulder :: Shape {-# INLINE baseShoulder #-} baseShoulder = translateSHz (-10) . scaleSH (V3 0.5 1 1) . upperPrismPolyHalf 10 $ polyCirc 3 1 upperBody :: Creature -> Shape {-# INLINE upperBody #-} upperBody cr = mconcat [ arms cr , shoulderSH $ torso cr ] shoulderSH :: Shape -> Shape shoulderSH = translateSHz 20 drawEquipment :: Creature -> SPic {-# INLINE drawEquipment #-} drawEquipment cr = foldMap (itemEquipPict cr) (_crInv cr)