Allow determination of attach item relative positions
This commit is contained in:
@@ -280,6 +280,7 @@ testInventory =
|
||||
stackedInventory :: [Item]
|
||||
stackedInventory =
|
||||
[ torch
|
||||
, torch
|
||||
, remoteScreen
|
||||
, megaShellMag
|
||||
, targetingScope TARGETLASER
|
||||
|
||||
@@ -266,7 +266,7 @@ chainLinkOrientation
|
||||
chainLinkOrientation mo par (ILink lt f) child = do
|
||||
(p,q) <- mo
|
||||
(p1,q1) <- f par lt child
|
||||
return (p + Q.rotate q p1, q * q1)
|
||||
return (p + Q.rotate q1 p1, q * q1)
|
||||
|
||||
updateRootItem' :: LabelDoubleTree ItemLink Item -> Creature -> World -> World
|
||||
updateRootItem' itmtree cr = ldtPropagateFold chainLinkOrientation chainLinkOrientation
|
||||
@@ -280,7 +280,10 @@ updateItemWithOrientation cr m itm = case _itType itm of
|
||||
_ -> id
|
||||
|
||||
testtorch :: Creature -> Maybe (Point3, Q.Quaternion Float) -> World -> World
|
||||
testtorch cr = maybe id $ \(pos,_) -> muzFlareAt yellow (_crPos cr `v2z` 0 + rotate3z (_crDir cr) pos) (_crDir cr)
|
||||
testtorch cr m = fromMaybe id $ do
|
||||
(pos,q) <- m
|
||||
let d = _crDir cr + argV (Q.qToV2 q)
|
||||
return $ muzFlareAt yellow (_crPos cr `v2z` 0 + rotate3z d pos) d
|
||||
|
||||
itemInvSideEffect :: Creature -> Item -> World -> World
|
||||
itemInvSideEffect cr itm = case _itType itm of
|
||||
|
||||
@@ -5,22 +5,25 @@ module Dodge.Item.Orientation
|
||||
import Dodge.Data.ComposedItem
|
||||
import Geometry.Data
|
||||
import Dodge.Data.Item
|
||||
import qualified Linear.Quaternion as Q
|
||||
import qualified Quaternion as Q
|
||||
|
||||
orientChild :: Item -> (Point3, Q.Quaternion Float)
|
||||
orientChild itm = case _itType itm of
|
||||
HELD TORCH -> (V3 5 0 0,Q.axisAngle (V3 1 0 0) 0)
|
||||
_ -> (0,Q.axisAngle (V3 1 0 0) 0)
|
||||
HELD TORCH -> (V3 0 20 0,Q.qID)
|
||||
_ -> (0,Q.qID)
|
||||
|
||||
orientByLink :: Item -> ComposeLinkType -> (Point3, Q.Quaternion Float)
|
||||
orientByLink itm lt = case (_itType itm,lt) of
|
||||
(HELD FLAMETHROWER, AmmoInLink{}) -> (V3 4 (-6) 0, Q.axisAngle (V3 1 0 0) 0)
|
||||
(HELD _,AmmoInLink{}) -> (V3 7 (-2) 0, Q.axisAngle (V3 1 0 0) 0)
|
||||
(HELD _,WeaponScopeLink) -> (V3 5 0 5, Q.axisAngle (V3 1 0 0) 0)
|
||||
_ -> (0,Q.axisAngle (V3 1 0 0) 0)
|
||||
(HELD FLAMETHROWER, AmmoInLink{}) -> (V3 4 (-6) 0, Q.qID)
|
||||
(HELD _,AmmoInLink{}) -> (V3 7 (-2) 0, Q.qID)
|
||||
(HELD _,WeaponScopeLink) -> (V3 5 0 5, Q.qID)
|
||||
_ -> (0,Q.qID)
|
||||
|
||||
orientAttachment :: Item -> ComposeLinkType -> Item -> Maybe (Point3, Q.Quaternion Float)
|
||||
orientAttachment par lnk ch = Just (t1 + Q.rotate q1 t2, q1 * q2)
|
||||
orientAttachment par lnk ch = Just $ case (_itType par,lnk,_itType ch) of
|
||||
(HELD BURSTRIFLE,_,HELD TORCH) -> (V3 20 0 0, Q.qID)
|
||||
(HELD LAUNCHER,_,HELD TORCH) -> (V3 0 20 0, Q.qID)
|
||||
_ -> (t1 + Q.rotate q1 t2, q1 * q2)
|
||||
where
|
||||
(t1,q1) = orientByLink par lnk
|
||||
(t2,q2) = orientChild ch
|
||||
|
||||
@@ -11,6 +11,8 @@ The warnings have been disabled.
|
||||
-}
|
||||
module Quaternion (
|
||||
qID,
|
||||
qToV3,
|
||||
qToV2,
|
||||
rotateToZ,
|
||||
vToQuat,
|
||||
module Linear.Quaternion,
|
||||
@@ -43,6 +45,12 @@ vToQuat a b
|
||||
where
|
||||
cprod = crossProd a b
|
||||
|
||||
qToV3 :: Q.Quaternion Float -> Point3
|
||||
qToV3 q = Q.rotate q (V3 1 0 0)
|
||||
|
||||
qToV2 :: Q.Quaternion Float -> Point2
|
||||
qToV2 = (\(V3 x y _) -> V2 x y) . qToV3
|
||||
|
||||
qID :: Q.Quaternion Float
|
||||
qID = Q.axisAngle (V3 1 0 0) 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user