{-# LANGUAGE LambdaCase #-} module Dodge.Item.HeldOffset ( turretItemOffset, twoFlatHRot, heldItemOffset, heldItemRelativeOrient, heldItemOrient2D, ) where import Dodge.Data.AimStance import Dodge.Item.AimStance import qualified Quaternion as Q import Dodge.Data.Creature import Dodge.Data.Machine import Geometry import LensHelp turretItemOffset :: Item -> Turret -> Machine -> Point3 -> Point3 turretItemOffset it tu mc = rotate3 (_tuDir tu - _mcDir mc) . (+.+.+ V3 0 0 shoulderHeight) . transToHandle it transToHandle :: Item -> Point3 -> Point3 transToHandle itm = (-.-.- V3 x y 0) where V2 x y = handlePos itm heldItemOrient2D :: Item -> Creature -> Point2 -> Float -> (Point2, Float) heldItemOrient2D itm cr p a = (V2 x y, argV . Q.qToV2 $ q ) where (V3 x y _,q) = heldItemRelativeOrient itm cr (p `v2z` 0, Q.axisAngle (V3 0 0 1) a) heldItemRelativeOrient :: Item -> Creature -> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float) heldItemRelativeOrient itm cr (p,q) | Aiming {} <- _posture (_crStance cr) = (p + aimingWeaponZeroPos cr itm `v2z` shoulderHeight, Q.qID * q) | TwoHandFlat <- aStance itm = ( V3 (_crRad cr) 0 handD + rotate3 (twoFlatHRot cr) (transToHandle itm p) , Q.axisAngle (V3 0 0 1) (twoFlatHRot cr) * q ) | OneHand <- aStance itm = ( V3 (_crRad cr * 0.7 + handPos) (_crRad cr * negate 0.7) handD + transToHandle itm p , Q.qID * q ) | otherwise = ( V3 (_crRad cr) 0 handD + rotate3 (strideRot cr + 1.2) (V3 (-8) 0 0 + transToHandle itm p) , Q.axisAngle (V3 0 0 1) (strideRot cr + 1.2) * q ) where handD = 15 handPos = case cr ^? crStance . carriage of Just (Walking x LeftForward) -> f x * 50 -2 _ -> 0 - 2 f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen sLen = _strideLength $ _crStance cr aimingWeaponZeroPos :: Creature -> Item -> Point2 aimingWeaponZeroPos cr it = aimStanceHandlePos cr it - handlePos it -- the position of a weapon handle aimStanceHandlePos :: Creature -> Item -> Point2 aimStanceHandlePos _ it = case aStance it of TwoHandUnder -> V2 (-2) 0 TwoHandOver -> V2 (-7) 0 OneHand -> V2 10 (-2) TwoHandFlat -> V2 10 0 heldItemOffset :: Item -> Creature -> Point3 -> Point3 heldItemOffset itm cr p = fst (heldItemRelativeOrient itm cr (p,Q.qID)) shoulderHeight :: Float shoulderHeight = 18 strideRot :: Creature -> Float strideRot cr = case cr ^? crStance . carriage of Just (Walking x LeftForward) -> f x Just (Walking x RightForward) -> - f x _ -> 0 where f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen sLen = _strideLength $ _crStance cr twoFlatHRot :: Creature -> Float twoFlatHRot = (2 *) . strideRot handlePos :: Item -> Point2 handlePos itm = case itm ^. itType of HELD hit -> heldHandlePos hit _ -> 0 heldHandlePos :: HeldItemType -> Point2 heldHandlePos = \case BANGSTICK{} -> V2 3 0 REWINDER -> V2 3 0 TIMESTOPPER -> V2 3 0 TIMESCROLLER -> V2 3 0 PISTOL -> V2 3 0 MACHINEPISTOL -> V2 3 0 AUTOPISTOL -> V2 3 0 SMG -> V2 3 0 BANGCONE -> V2 3 0 BLUNDERBUSS -> V2 3 0 GRAPECANNON{} -> V2 3 0 MINIGUNX{} -> V2 3 0 VOLLEYGUN{} -> V2 3 0 RIFLE -> V2 3 0 ALTERIFLE -> V2 3 0 AUTORIFLE -> V2 3 0 BURSTRIFLE -> V2 3 0 BANGROD -> V2 3 0 ELEPHANTGUN -> V2 3 0 AMR -> V2 3 0 AUTOAMR -> V2 3 0 SNIPERRIFLE -> V2 3 0 FLAMESPITTER -> V2 3 0 FLAMETHROWER -> V2 3 0 FLAMETORRENT -> V2 3 0 FLAMEWALL -> V2 3 0 BLOWTORCH -> V2 3 0 SPARKGUN -> V2 3 0 TESLAGUN -> V2 3 0 LASER -> V2 3 0 TRACTORGUN -> V2 3 0 RLAUNCHER -> V2 3 0 RLAUNCHERX{} -> V2 3 0 GLAUNCHER -> V2 3 0 POISONSPRAYER -> V2 3 0 SHATTERGUN -> V2 3 0 TORCH -> V2 3 0 FLATSHIELD -> V2 3 0 KEYCARD {} -> V2 3 0 BLINKER -> V2 3 0 BLINKERUNSAFE -> V2 3 0