Files
loop/src/Dodge/Item/HeldOffset.hs
T

95 lines
3.1 KiB
Haskell

module Dodge.Item.HeldOffset (
turretItemOffset,
twoFlatHRot,
heldItemOffset,
heldItemRelativeOrient,
heldItemOrient2D,
) where
import Dodge.Item.AimStance
import qualified Quaternion as Q
import Data.Maybe
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 = fromMaybe id $ do
V2 x y <- itm ^? itUse . heldAim . aimHandlePos
return (-.-.- V3 x y 0)
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)
| isTwoHandFlat =
( V3 (_crRad cr) 0 handD + rotate3 (twoFlatHRot cr) (transToHandle itm p)
, Q.axisAngle (V3 0 0 1) (twoFlatHRot cr) * q
)
| isOneHand =
( 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
isOneHand = aStance itm == OneHand
-- itm ^? itUseAimStance == Just OneHand
-- || isNothing (itm ^? itUseAimStance)
isTwoHandFlat = aStance itm == TwoHandFlat
--itm ^? itUseAimStance == Just TwoHandFlat
--itUseAimStance = itUse . heldAim . aimStance
f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen
sLen = _strideLength $ _crStance cr
aimingWeaponZeroPos :: Creature -> Item -> Point2
aimingWeaponZeroPos cr it =
aimingWeaponHandlePos cr it
- fromMaybe 0 (it ^? itUse . heldAim . aimHandlePos)
-- the position of a weapon handle
aimingWeaponHandlePos :: Creature -> Item -> Point2
aimingWeaponHandlePos _ 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