Add check to cylinder segment collision, break rocket projectiles

This commit is contained in:
2025-10-12 00:26:48 +01:00
parent 8245115763
commit 33de1f79b6
9 changed files with 147 additions and 91 deletions
+6 -9
View File
@@ -360,24 +360,21 @@ intersectCircLine c r x y =
f :: Float -> Point2
f a = x + (a *.* (y - x))
intersectCylSeg ::
Point3 ->
Float ->
Float ->
Point3 ->
Point3 ->
intersectCylSeg :: Point3 -> Float -> Float -> Point3 -> Point3 ->
(Maybe (Point3, Point3), Maybe (Point3, Point3))
intersectCylSeg p r h s e = fromMaybe (Nothing, Nothing) $ do
(a, b) <- intersectCircLineAlong (p ^. _xy) r (s ^. _xy) (e ^. _xy)
return (f min a, f max b)
where
mtopx = intersectLinePlaneAlong s e (V3 0 0 h) (V3 0 0 1)
mbotx = intersectLinePlaneAlong s e (V3 0 0 0) (V3 0 0 1)
mtopx = intersectLinePlaneAlong s e (V3 0 0 (h + p ^. _z)) (V3 0 0 1)
mbotx = intersectLinePlaneAlong s e (V3 0 0 (p^._z)) (V3 0 0 1)
v = e - s
f mm a = do
let x = s + a *.*.* v
if x ^. _z < (h + p ^. _z) && x ^. _z > (p ^. _z)
then return (x, v & _xy %~ reflectInNormal (x ^. _xy - p ^. _xy))
then do
guard $ a >= 0 && a < 1
return (x, v & _xy %~ reflectInNormal (x ^. _xy - p ^. _xy))
else do
topx <- mtopx
botx <- mbotx