Fix bug in attached item position orienting

This commit is contained in:
2024-10-02 22:57:10 +01:00
parent 6bcd5bc591
commit 49ffbfafc2
8 changed files with 105 additions and 97 deletions
+26 -15
View File
@@ -3,6 +3,8 @@ module Dodge.Creature.State (
doDamage,
) where
import Dodge.LightSource
import Dodge.WorldEvent.Flash
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Monoid
@@ -25,7 +27,7 @@ import Dodge.Item.Grammar
import Dodge.Item.HeldOffset
import Dodge.Prop.Gib
import Dodge.SoundLogic
import Dodge.WorldEvent.Flash
--import Dodge.WorldEvent.Flash
import Dodge.Zoning.Creature
import FoldableHelp
import Geometry
@@ -176,31 +178,40 @@ updateRootItem' itmtree cr =
chainLinkOrientation
chainLinkOrientation
(updateItemWithOrientation cr)
(Just (heldItemRelativeOrient (_ldtValue itmtree) cr (0, Q.qID)))
(heldItemRelativeOrient (_ldtValue itmtree) cr (0, Q.qID))
itmtree
-- need to check rotation
chainLinkOrientation ::
Maybe (Point3, Q.Quaternion Float) ->
(Point3, Q.Quaternion Float) ->
Item ->
ItemLink ->
Item ->
Maybe (Point3, Q.Quaternion Float)
chainLinkOrientation mo par (ILink lt f) child = do
(p, q) <- mo
(p1, q1) <- f par lt child
return (p + Q.rotate q1 p1, q * q1)
(Point3, Q.Quaternion Float)
chainLinkOrientation mo par (ILink lt f) child = (p + Q.rotate q p1, q * q1)
where
(p, q) = mo
(p1, q1) = f par lt child
updateItemWithOrientation :: Creature -> Maybe (Point3, Q.Quaternion Float) -> Item -> World -> World
updateItemWithOrientation :: Creature -> (Point3, Q.Quaternion Float) -> Item -> World -> World
updateItemWithOrientation cr m itm = case _itType itm of
HELD TORCH -> testtorch cr m
HELD TORCH -> testtorch cr itm m
_ -> id
testtorch :: Creature -> Maybe (Point3, Q.Quaternion Float) -> World -> World
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
testtorch :: Creature -> Item -> (Point3, Q.Quaternion Float) -> World -> World
testtorch cr itm (p,q) = --createTorchLightOffset cr itm pos' .
muzFlareAt yellow pos'' d
.( cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 250 0.7 pos''
)
where
--pos = (_crPos cr `v2z` 0 + rotate3 cdir p)
pos = (_crPos cr `v2z` 0 + rotate3 cdir p)
--pos'' = pos
pos'' = pos + rotate3 d (V3 8 0 1.5)
cdir = _crDir cr
a = argV (Q.qToV2 q)
d = _crDir cr + a
itemInvSideEffect :: Creature -> Item -> World -> World
itemInvSideEffect cr itm = case _itType itm of
+1 -1
View File
@@ -44,7 +44,7 @@ type ComposedItem = (Item, ItemStructuralFunction)
data ItemLink = ILink
{ _iatType :: ComposeLinkType
, _iatOrient :: Item -> ComposeLinkType -> Item -> Maybe (Point3, Quaternion Float)
, _iatOrient :: Item -> ComposeLinkType -> Item -> (Point3, Quaternion Float)
}
data LinkTest lt = LTest
+2 -2
View File
@@ -4,7 +4,6 @@ import qualified IntMapHelp as IM
import Control.Lens
import Dodge.Data.World
import Dodge.Euse
import Dodge.LightSource.Torch
doInvEffect :: ItInvEffect -> Item -> Creature -> World -> World
doInvEffect iie = case iie of
@@ -65,4 +64,5 @@ chargeIfEquipped itm cr
maxcharge = itm ^?! itUse . leftConsumption . wpMaxCharge
createHeldLight :: Item -> Creature -> World -> World
createHeldLight itm cr = createTorchLightOffset cr itm 0
createHeldLight itm cr = id
--createHeldLight itm cr = createTorchLightOffset cr itm 0
+2 -3
View File
@@ -25,10 +25,9 @@ itemTreeSPic (LDT (itm, _) l r) =
<> foldMap (itemRotTreeSPic itm) (l <> r)
itemRotTreeSPic :: Item -> (ItemLink, LabelDoubleTree ItemLink ComposedItem) -> SPic
itemRotTreeSPic par (il, t) = fromMaybe mempty $ do
(p, q) <- _iatOrient il par (_iatType il) itm
return . translateSP p . overPosSP (Q.rotate q) $ itemTreeSPic t
itemRotTreeSPic par (il, t) = translateSP p . overPosSP (Q.rotate q) $ itemTreeSPic t
where
(p, q) = _iatOrient il par (_iatType il) itm
itm = t ^. ldtValue . _1
itemSPic :: Item -> SPic
+2 -2
View File
@@ -19,8 +19,8 @@ orientByLink itm lt = case (_itType itm,lt) of
(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 $ case (_itType par,lnk,_itType ch) of
orientAttachment :: Item -> ComposeLinkType -> Item -> (Point3, Q.Quaternion Float)
orientAttachment par lnk ch = 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)
-16
View File
@@ -1,16 +0,0 @@
module Dodge.LightSource.Torch
( createTorchLightOffset
) where
import Dodge.Data.World
import Dodge.Item.Draw -- heldItemOffset needs to be moved somewhere more sensible
import Dodge.LightSource -- this needs to be split!
import Geometry
import LensHelp
createTorchLightOffset :: Creature -> Item -> Point3 -> World -> World
createTorchLightOffset cr it off = cWorld . lWorld . tempLightSources .:~
tlsTimeRadColPos 1 250 0.7 pos
where
pos = (p +.+.+ rotate3 (_crDir cr) (heldItemOffset it cr (off +.+.+ V3 8 0 1.5)))
p = addZ 0 $ _crPos cr