Move towards being able to orient positions on attached items

This commit is contained in:
2024-10-01 20:13:08 +01:00
parent fa4e117f93
commit 8df6b31062
9 changed files with 61 additions and 199 deletions
+28 -47
View File
@@ -2,9 +2,10 @@ module Dodge.Item.HeldOffset (
turretItemOffset,
twoFlatHRot,
heldItemOffset,
heldItemRelativeOrient,
) where
import qualified Linear.Quaternion as Q
import qualified Quaternion as Q
import Data.Maybe
import Dodge.Creature.HandPos
import Dodge.Data.Creature
@@ -22,24 +23,33 @@ transToHandle itm = fromMaybe id $ do
V2 x y <- itm ^? itUse . heldAim . aimHandlePos
return (-.-.- V3 x y 0)
-- there is a lot of duplication going on here, and also need to check
-- rotations
heldItemRelativeOrient :: Item -> Creature -> (Point3, Q.Quaternion Float) -> (Point3, Q.Quaternion Float)
heldItemRelativeOrient itm cr (p,q)
| _posture (_crStance cr) == Aiming = (p,q)
| isTwoHandFlat = (p,q)
-- (+.+.+ V3 (_crRad cr) 0 handD)
-- . rotate3 (twoFlatHRot cr)
-- . transToHandle itm
| isOneHand = (p,q)
-- (+.+.+ V3 0 0 handD)
-- . (+.+.+ V3 (_crRad cr * 0.7 + handPos) (_crRad cr * negate 0.7) 0)
-- . (+.+.+ V3 (-2) 0 0)
-- . transToHandle itm
| otherwise = (p,q)
-- (+.+.+ V3 0 0 handD)
-- . (+.+.+ V3 (_crRad cr) 0 0)
-- . rotate3 (strideRot cr + 1.2)
-- . (+.+.+ V3 (-8) 0 0)
-- . transToHandle itm
| _posture (_crStance cr) == Aiming =
(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 0 0 handD)
. (+.+.+ V3 (_crRad cr * 0.7 + handPos) (_crRad cr * negate 0.7) 0)
. (+.+.+ V3 (-2) 0 0)
$ transToHandle itm p
, Q.qID * q
)
| otherwise =
( (+.+.+ V3 0 0 handD)
. (+.+.+ V3 (_crRad cr) 0 0)
. 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
@@ -54,36 +64,7 @@ heldItemRelativeOrient itm cr (p,q)
sLen = _strideLength $ _crStance cr
heldItemOffset :: Item -> Creature -> Point3 -> Point3
heldItemOffset itm cr
| _posture (_crStance cr) == Aiming =
(+.+.+ aimingWeaponZeroPos cr itm `v2z` shoulderHeight)
| isTwoHandFlat =
(+.+.+ V3 (_crRad cr) 0 handD)
. rotate3 (twoFlatHRot cr)
. transToHandle itm
| isOneHand =
(+.+.+ V3 0 0 handD)
. (+.+.+ V3 (_crRad cr * 0.7 + handPos) (_crRad cr * negate 0.7) 0)
. (+.+.+ V3 (-2) 0 0)
. transToHandle itm
| otherwise =
(+.+.+ V3 0 0 handD)
. (+.+.+ V3 (_crRad cr) 0 0)
. rotate3 (strideRot cr + 1.2)
. (+.+.+ V3 (-8) 0 0)
. transToHandle itm
where
handD = 15
handPos = case cr ^? crStance . carriage of
Just (Walking x LeftForward) -> f x * 50
_ -> 0
isOneHand =
itm ^? itUseAimStance == Just OneHand
|| isNothing (itm ^? itUseAimStance)
isTwoHandFlat = itm ^? itUseAimStance == Just TwoHandFlat
itUseAimStance = itUse . heldAim . aimStance
f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen
sLen = _strideLength $ _crStance cr
heldItemOffset itm cr p = fst (heldItemRelativeOrient itm cr (p,Q.qID))
shoulderHeight :: Float
shoulderHeight = 18