Add intersection with cylinders

This commit is contained in:
2025-10-10 11:21:40 +01:00
parent 3ea14a4646
commit e00bb0b26e
6 changed files with 256 additions and 200 deletions
+17 -12
View File
@@ -152,23 +152,28 @@ collide3Wall sp wl (ep, mo) = maybe (ep, mo) (,Just (n, OWall wl)) $ intersectSe
collide3Creature :: Point3 -> Creature -> (Point3, MPO) -> (Point3, MPO)
collide3Creature sp cr (ep, m) = fromMaybe (ep, m) $ do
(sp', ep') <- restrictSeg 0 (V3 0 0 1) (sp, ep)
>>= restrictSeg (V3 0 0 25) (V3 0 0 (-1))
(zmin,zmax) <- crZBounds cr
p <- listToMaybe $ intersectCircSeg cpos (crRad $ cr ^. crType) (xyV3 sp') (xyV3 ep')
let z = 0
return (p `v2z` z, Just (normalize $ (p - cpos) `v2z` 0, OCreature cr))
-- (sp', ep') <- restrictSeg 0 (V3 0 0 1) (sp, ep)
-- >>= restrictSeg (V3 0 0 25) (V3 0 0 (-1))
h <- crHeight cr
(p,n) <- fst $ intersectCylSeg
(addZ (cr ^. crZ) cpos)
(crRad $ cr ^. crType)
h
sp
ep
return (p, Just (n,OCreature cr))
-- p <- listToMaybe $ intersectCircSeg cpos (crRad $ cr ^. crType) (xyV3 sp') (xyV3 ep')
-- let z = 0
-- return (p `v2z` z, Just (normalize $ (p - cpos) `v2z` 0, OCreature cr))
where
cpos = cr ^. crPos
crZBounds :: Creature -> Maybe (Float,Float)
crZBounds cr = f <$> case cr ^. crHP of
HP {} -> Just (0,25)
CrIsCorpse {} -> Just (0,5)
crHeight :: Creature -> Maybe Float
crHeight cr = case cr ^. crHP of
HP {} -> Just 25
CrIsCorpse {} -> Just 5
CrIsGibs -> Nothing
CrIsPitted -> Nothing
where
f (a,b) = (a + cr ^. crZ,b + cr ^. crZ)
restrictSeg :: Point3 -> Point3 -> (Point3, Point3) -> Maybe (Point3, Point3)
restrictSeg p n (sp, ep)