Add check to cylinder segment collision, break rocket projectiles
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user