| | | 1 | | //======================================================================= |
| | | 2 | | // CollisionDetection2D.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | using FixedMathSharp; |
| | | 11 | | using FixedMathSharp.Geometry; |
| | | 12 | | using Gravitas.Colliders; |
| | | 13 | | |
| | | 14 | | namespace Gravitas.CollisionHandling; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Deterministic pure 2D narrow-phase collision checks. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <content>Owns planar shape dispatch, contact generation and pair-level recovery admission.</content> |
| | | 20 | | internal static partial class CollisionDetection2D |
| | | 21 | | { |
| | | 22 | | internal static bool TryCollide(LSCollider2D colliderA, LSCollider2D colliderB, out Contact2D contact) |
| | | 23 | | { |
| | 4315 | 24 | | ChronicleGuard.ThrowIfNull(colliderA, nameof(colliderA)); |
| | 4315 | 25 | | ChronicleGuard.ThrowIfNull(colliderB, nameof(colliderB)); |
| | | 26 | | |
| | 4315 | 27 | | CollisionType2D collisionType = ColliderSettings2D.GetCollisionType(colliderA.Shape, colliderB.Shape); |
| | 4315 | 28 | | return TryCollide(new CollisionWorkItem2D(colliderA, colliderB, collisionType), out contact); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | internal static bool TryCollide(CollisionPair2D pair, ContactManifold2D manifold, long frame) |
| | | 32 | | { |
| | 7070 | 33 | | ChronicleGuard.ThrowIfNull(pair, nameof(pair)); |
| | 7070 | 34 | | ChronicleGuard.ThrowIfNull(manifold, nameof(manifold)); |
| | 7070 | 35 | | var previous = pair.BeginCollisionLayerUpdate(manifold); |
| | 7070 | 36 | | bool overlaps = TryCollidePairCore(pair, manifold, frame); |
| | 7068 | 37 | | pair.CompleteCollisionLayerUpdate(manifold, previous); |
| | 7068 | 38 | | return overlaps; |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | private static bool TryCollidePairCore(CollisionPair2D pair, ContactManifold2D manifold, long frame) |
| | | 42 | | { |
| | 7070 | 43 | | pair.ClearRecovery(); |
| | 7070 | 44 | | bool overlaps = TryCollide(CollisionWorkItem2D.Create(pair), manifold, frame); |
| | 14117 | 45 | | if (!overlaps || !manifold.NeedsSurfaceRecovery) return overlaps; |
| | 23 | 46 | | LSCollider2D member = pair.ColliderA.StaticSurface != null ? pair.ColliderA : pair.ColliderB; |
| | 23 | 47 | | LSCollider2D mover = member == pair.ColliderA ? pair.ColliderB : pair.ColliderA; |
| | 26 | 48 | | if (mover.Body is not { HasSolverMobility: true }) return overlaps; |
| | 20 | 49 | | StaticSurface2D surface = member.StaticSurface!; |
| | | 50 | | // Noncarriers retain their overlap events; only the genuine carrier can recover the body. |
| | 20 | 51 | | if (mover is LSCompoundCollider2D || !surface.TryGetRecovery(mover, out Vector2d center)) |
| | 2 | 52 | | throw new InvalidOperationException("Pure 2D static-surface overlap has no exposed response constraint or ce |
| | 18 | 53 | | pair.SetRecovery(mover, center); |
| | 18 | 54 | | return true; |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | internal static bool TryCollide(CollisionWorkItem2D item, ContactManifold2D manifold, long frame) |
| | | 58 | | { |
| | 7629 | 59 | | ChronicleGuard.ThrowIfNull(manifold, nameof(manifold)); |
| | 7629 | 60 | | manifold.BeginUpdate(frame); |
| | 7629 | 61 | | return TryCollide(item, manifold); |
| | | 62 | | } |
| | | 63 | | |
| | | 64 | | internal static bool TryCollide(CollisionWorkItem2D item, out Contact2D contact) |
| | | 65 | | { |
| | 4317 | 66 | | LSCollider2D colliderA = item.ColliderA; |
| | 4317 | 67 | | LSCollider2D colliderB = item.ColliderB; |
| | 4317 | 68 | | if (!BoundsOverlap(colliderA, colliderB)) |
| | | 69 | | { |
| | 1826 | 70 | | contact = default; |
| | 1826 | 71 | | return false; |
| | | 72 | | } |
| | | 73 | | |
| | 2491 | 74 | | switch (item.CollisionType) |
| | | 75 | | { |
| | | 76 | | case CollisionType2D.Circle_Circle: |
| | 303 | 77 | | return TryCircleCircle((LSCircleCollider2D)colliderA, (LSCircleCollider2D)colliderB, out contact); |
| | | 78 | | case CollisionType2D.Circle_Convex: |
| | 120 | 79 | | return TryCircleConvex((LSCircleCollider2D)colliderA, colliderB, out contact); |
| | | 80 | | case CollisionType2D.Convex_Circle: |
| | 815 | 81 | | bool result = TryCircleConvex((LSCircleCollider2D)colliderB, colliderA, out Contact2D reversed); |
| | 815 | 82 | | contact = result |
| | 815 | 83 | | ? new Contact2D( |
| | 815 | 84 | | reversed.AnchorB, |
| | 815 | 85 | | reversed.AnchorA, |
| | 815 | 86 | | -reversed.Normal, |
| | 815 | 87 | | reversed.Depth, |
| | 815 | 88 | | reversed.DepthIsClamped) |
| | 815 | 89 | | : default; |
| | 815 | 90 | | return result; |
| | | 91 | | case CollisionType2D.Convex_Convex: |
| | 1040 | 92 | | return TryConvexConvex(colliderA, colliderB, out contact); |
| | | 93 | | case CollisionType2D.Capsule_Circle: |
| | 7 | 94 | | return TryCapsuleCircle((LSCapsuleCollider2D)colliderA, (LSCircleCollider2D)colliderB, out contact); |
| | | 95 | | case CollisionType2D.Circle_Capsule: |
| | 17 | 96 | | bool circleCapsule = TryCapsuleCircle((LSCapsuleCollider2D)colliderB, (LSCircleCollider2D)colliderA, out |
| | 17 | 97 | | contact = circleCapsule |
| | 17 | 98 | | ? new Contact2D( |
| | 17 | 99 | | circleCapsuleReversed.AnchorB, |
| | 17 | 100 | | circleCapsuleReversed.AnchorA, |
| | 17 | 101 | | -circleCapsuleReversed.Normal, |
| | 17 | 102 | | circleCapsuleReversed.Depth, |
| | 17 | 103 | | circleCapsuleReversed.DepthIsClamped) |
| | 17 | 104 | | : default; |
| | 17 | 105 | | return circleCapsule; |
| | | 106 | | case CollisionType2D.Capsule_Convex: |
| | 92 | 107 | | return TryCapsuleConvex((LSCapsuleCollider2D)colliderA, colliderB, out contact); |
| | | 108 | | case CollisionType2D.Convex_Capsule: |
| | 7 | 109 | | bool convexCapsule = TryCapsuleConvex((LSCapsuleCollider2D)colliderB, colliderA, out Contact2D convexCap |
| | 7 | 110 | | contact = convexCapsule |
| | 7 | 111 | | ? new Contact2D( |
| | 7 | 112 | | convexCapsuleReversed.AnchorB, |
| | 7 | 113 | | convexCapsuleReversed.AnchorA, |
| | 7 | 114 | | -convexCapsuleReversed.Normal, |
| | 7 | 115 | | convexCapsuleReversed.Depth, |
| | 7 | 116 | | convexCapsuleReversed.DepthIsClamped) |
| | 7 | 117 | | : default; |
| | 7 | 118 | | return convexCapsule; |
| | | 119 | | case CollisionType2D.Capsule_Capsule: |
| | 10 | 120 | | return TryCapsuleCapsule((LSCapsuleCollider2D)colliderA, (LSCapsuleCollider2D)colliderB, out contact); |
| | | 121 | | case CollisionType2D.Compound: |
| | 79 | 122 | | return TryCompound(colliderA, colliderB, out contact); |
| | | 123 | | default: |
| | 1 | 124 | | contact = default; |
| | 1 | 125 | | return false; |
| | | 126 | | } |
| | | 127 | | } |
| | | 128 | | |
| | | 129 | | private static bool TryCollide(CollisionWorkItem2D item, ContactManifold2D manifold) |
| | | 130 | | { |
| | 7774 | 131 | | LSCollider2D colliderA = item.ColliderA; |
| | 7774 | 132 | | LSCollider2D colliderB = item.ColliderB; |
| | 7774 | 133 | | if (!BoundsOverlap(colliderA, colliderB)) |
| | 29 | 134 | | return false; |
| | | 135 | | |
| | 7745 | 136 | | if (!colliderA.IsTrigger && !colliderB.IsTrigger && item.CollisionType != CollisionType2D.Compound) |
| | | 137 | | { |
| | 7530 | 138 | | StaticSurface2D? surface = colliderB.StaticSurface ?? colliderA.StaticSurface; |
| | 7530 | 139 | | if (surface != null && (colliderA.StaticSurface == null || colliderB.StaticSurface == null)) |
| | | 140 | | { |
| | 3497 | 141 | | bool reverse = colliderA.StaticSurface != null; |
| | 3960 | 142 | | if (!HasSurfaceOverlap(reverse ? colliderB : colliderA, reverse ? colliderA : colliderB)) return false; |
| | 3034 | 143 | | surface.Reduce(reverse ? colliderB : colliderA, reverse ? colliderA : colliderB, manifold, reverse); |
| | 3034 | 144 | | return true; |
| | | 145 | | } |
| | | 146 | | } |
| | | 147 | | |
| | 4248 | 148 | | return item.CollisionType switch |
| | 4248 | 149 | | { |
| | 812 | 150 | | CollisionType2D.Circle_Circle => TryCircleCircle((LSCircleCollider2D)colliderA, (LSCircleCollider2D)collider |
| | 8 | 151 | | CollisionType2D.Circle_Convex => TryCircleConvex((LSCircleCollider2D)colliderA, colliderB, manifold), |
| | 1054 | 152 | | CollisionType2D.Convex_Circle => TryCircleConvexReversed((LSCircleCollider2D)colliderB, colliderA, manifold) |
| | 1414 | 153 | | CollisionType2D.Convex_Convex => TryConvexConvex(colliderA, colliderB, manifold), |
| | 11 | 154 | | CollisionType2D.Capsule_Circle => TryCapsuleCircle((LSCapsuleCollider2D)colliderA, (LSCircleCollider2D)colli |
| | 4 | 155 | | CollisionType2D.Circle_Capsule => TryCapsuleCircleReversed((LSCapsuleCollider2D)colliderB, (LSCircleCollider |
| | 14 | 156 | | CollisionType2D.Capsule_Convex => TryCapsuleConvex((LSCapsuleCollider2D)colliderA, colliderB, manifold), |
| | 790 | 157 | | CollisionType2D.Convex_Capsule => TryCapsuleConvexReversed((LSCapsuleCollider2D)colliderB, colliderA, manifo |
| | 7 | 158 | | CollisionType2D.Capsule_Capsule => TryCapsuleCapsule((LSCapsuleCollider2D)colliderA, (LSCapsuleCollider2D)co |
| | 133 | 159 | | CollisionType2D.Compound => TryCompound(colliderA, colliderB, manifold), |
| | 1 | 160 | | _ => false |
| | 4248 | 161 | | }; |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | // Declared pieces are committed convex filled polygons. Overlap truth needs |
| | | 165 | | // exact classification, not discarded ordinary normals/depths/anchors. |
| | | 166 | | internal static bool HasSurfaceOverlap(LSCollider2D mover, LSCollider2D member) |
| | | 167 | | { |
| | 4425 | 168 | | if (!BoundsOverlap(mover, member)) return false; |
| | 7490 | 169 | | Span<Vector2d> targetBox = stackalloc Vector2d[4], movingBox = stackalloc Vector2d[4]; |
| | 3745 | 170 | | ReadOnlySpan<Vector2d> target = GetConvexVertexOffsets(member, targetBox); |
| | 3745 | 171 | | if (mover is LSCircleCollider2D or LSCapsuleCollider2D) |
| | | 172 | | { |
| | 3418 | 173 | | Fixed64 core = mover is LSCapsuleCollider2D capsule ? capsule.AxisLength : Fixed64.Zero; |
| | 3418 | 174 | | Fixed64 radius = mover is LSCircleCollider2D circle ? circle.ScaledRadius : ((LSCapsuleCollider2D)mover).Sca |
| | 3418 | 175 | | Vector2d axis = Vector2d.Forward; |
| | 4460 | 176 | | if (core != Fixed64.Zero) _ = Vector2d.TryRotate(axis, mover.Rotation, out axis); |
| | 3418 | 177 | | return WideCenteredCapsule2dRelations.DoesCapsuleOverlapConvex(mover.Center, axis, core, radius, |
| | 3418 | 178 | | member.Center, member.ConvexRotation, target, strict: false); |
| | | 179 | | } |
| | 327 | 180 | | return WideConvex2dRelations.DoConvexesOverlap(mover.Center, mover.ConvexRotation, GetConvexVertexOffsets(mover, |
| | 327 | 181 | | member.Center, member.ConvexRotation, target, strict: false); |
| | | 182 | | } |
| | | 183 | | |
| | | 184 | | private static bool TryCircleCircle(LSCircleCollider2D colliderA, LSCircleCollider2D colliderB, out Contact2D contac |
| | | 185 | | { |
| | | 186 | | // Circles are zero-core capsules. Keep classification and depth wide, |
| | | 187 | | // and retain exact radial anchor terms rather than rounded offsets. |
| | | 188 | | // A zero core needs no rotated axis; rotation still owns its anchor frame. |
| | 1115 | 189 | | if (!FixedSegment2d.TryGetCenteredCapsulesContact( |
| | 1115 | 190 | | colliderA.Center, |
| | 1115 | 191 | | colliderA.Rotation, |
| | 1115 | 192 | | Vector2d.Forward, |
| | 1115 | 193 | | Fixed64.Zero, |
| | 1115 | 194 | | colliderA.ScaledRadius, |
| | 1115 | 195 | | colliderB.Center, |
| | 1115 | 196 | | colliderB.Rotation, |
| | 1115 | 197 | | Vector2d.Forward, |
| | 1115 | 198 | | Fixed64.Zero, |
| | 1115 | 199 | | colliderB.ScaledRadius, |
| | 1115 | 200 | | Vector2d.Right, |
| | 1115 | 201 | | out FixedContactAnchors2d fixedContact)) |
| | | 202 | | { |
| | 43 | 203 | | contact = default; |
| | 43 | 204 | | return false; |
| | | 205 | | } |
| | | 206 | | |
| | 1072 | 207 | | contact = new Contact2D( |
| | 1072 | 208 | | new ContactAnchor2D(fixedContact.FirstAnchor), |
| | 1072 | 209 | | new ContactAnchor2D(fixedContact.SecondAnchor), |
| | 1072 | 210 | | fixedContact.Normal, |
| | 1072 | 211 | | fixedContact.Depth, |
| | 1072 | 212 | | fixedContact.DepthIsClamped); |
| | 1072 | 213 | | return true; |
| | | 214 | | } |
| | | 215 | | |
| | | 216 | | private static bool TryCircleCircle( |
| | | 217 | | LSCircleCollider2D colliderA, |
| | | 218 | | LSCircleCollider2D colliderB, |
| | | 219 | | ContactManifold2D manifold) |
| | | 220 | | { |
| | 812 | 221 | | if (!TryCircleCircle(colliderA, colliderB, out Contact2D contact)) |
| | 13 | 222 | | return false; |
| | | 223 | | |
| | 799 | 224 | | AddContact(manifold, contact, colliderA, colliderB); |
| | 799 | 225 | | return true; |
| | | 226 | | } |
| | | 227 | | |
| | | 228 | | private static bool TryCircleConvex(LSCircleCollider2D circle, LSCollider2D convex, out Contact2D contact) |
| | | 229 | | { |
| | 1997 | 230 | | Span<Vector2d> convexOffsets = stackalloc Vector2d[4]; |
| | 1997 | 231 | | ReadOnlySpan<Vector2d> convexVertexOffsets = |
| | 1997 | 232 | | GetConvexVertexOffsets(convex, convexOffsets); |
| | 1997 | 233 | | if (!FixedConvex2dRelations.TryGetCircleContact( |
| | 1997 | 234 | | circle.Center, |
| | 1997 | 235 | | circle.Rotation, |
| | 1997 | 236 | | circle.ScaledRadius, |
| | 1997 | 237 | | convex.Center, |
| | 1997 | 238 | | convex.ConvexRotation, |
| | 1997 | 239 | | convexVertexOffsets, |
| | 1997 | 240 | | out FixedPointAnchor2d circleAnchor, |
| | 1997 | 241 | | out FixedPointAnchor2d convexAnchor, |
| | 1997 | 242 | | out Vector2d normal, |
| | 1997 | 243 | | out Fixed64 depth, |
| | 1997 | 244 | | out bool depthIsClamped)) |
| | | 245 | | { |
| | 405 | 246 | | contact = default; |
| | 405 | 247 | | return false; |
| | | 248 | | } |
| | | 249 | | |
| | 1592 | 250 | | contact = new Contact2D( |
| | 1592 | 251 | | new ContactAnchor2D(circleAnchor), |
| | 1592 | 252 | | new ContactAnchor2D(convexAnchor), |
| | 1592 | 253 | | normal, |
| | 1592 | 254 | | depth, |
| | 1592 | 255 | | depthIsClamped); |
| | 1592 | 256 | | return true; |
| | | 257 | | } |
| | | 258 | | |
| | | 259 | | private static bool TryCircleConvex( |
| | | 260 | | LSCircleCollider2D circle, |
| | | 261 | | LSCollider2D convex, |
| | | 262 | | ContactManifold2D manifold) |
| | | 263 | | { |
| | 8 | 264 | | if (!TryCircleConvex(circle, convex, out Contact2D contact)) |
| | 1 | 265 | | return false; |
| | | 266 | | |
| | 7 | 267 | | AddContact(manifold, contact, circle, convex); |
| | 7 | 268 | | return true; |
| | | 269 | | } |
| | | 270 | | |
| | | 271 | | private static bool TryCircleConvexReversed( |
| | | 272 | | LSCircleCollider2D circle, |
| | | 273 | | LSCollider2D convex, |
| | | 274 | | ContactManifold2D manifold) |
| | | 275 | | { |
| | 1054 | 276 | | if (!TryCircleConvex(circle, convex, out Contact2D contact)) |
| | 1 | 277 | | return false; |
| | | 278 | | |
| | 1053 | 279 | | manifold.AddContact( |
| | 1053 | 280 | | contact.AnchorB, |
| | 1053 | 281 | | contact.AnchorA, |
| | 1053 | 282 | | contact.Depth, |
| | 1053 | 283 | | -contact.Normal, |
| | 1053 | 284 | | convex.Material, |
| | 1053 | 285 | | circle.Material, |
| | 1053 | 286 | | contact.DepthIsClamped); |
| | 1053 | 287 | | return true; |
| | | 288 | | } |
| | | 289 | | |
| | | 290 | | private static bool TryCapsuleCircle(LSCapsuleCollider2D capsule, LSCircleCollider2D circle, out Contact2D contact) |
| | | 291 | | { |
| | 39 | 292 | | Vector2d fallbackNormal = capsule.GetNormalFromCenteredAxis(circle.Center); |
| | 39 | 293 | | if (!FixedSegment2d.TryGetCenteredCapsulesContact( |
| | 39 | 294 | | capsule.Center, |
| | 39 | 295 | | capsule.Rotation, |
| | 39 | 296 | | capsule.AxisLength, |
| | 39 | 297 | | capsule.ScaledRadius, |
| | 39 | 298 | | circle.Center, |
| | 39 | 299 | | circle.Rotation, |
| | 39 | 300 | | Fixed64.Zero, |
| | 39 | 301 | | circle.ScaledRadius, |
| | 39 | 302 | | fallbackNormal, |
| | 39 | 303 | | out FixedContactAnchors2d fixedContact)) |
| | | 304 | | { |
| | 4 | 305 | | contact = default; |
| | 4 | 306 | | return false; |
| | | 307 | | } |
| | | 308 | | |
| | 35 | 309 | | contact = new Contact2D( |
| | 35 | 310 | | new ContactAnchor2D(fixedContact.FirstAnchor), |
| | 35 | 311 | | new ContactAnchor2D(fixedContact.SecondAnchor), |
| | 35 | 312 | | fixedContact.Normal, |
| | 35 | 313 | | fixedContact.Depth, |
| | 35 | 314 | | fixedContact.DepthIsClamped); |
| | 35 | 315 | | return true; |
| | | 316 | | } |
| | | 317 | | |
| | | 318 | | private static bool TryCapsuleCircle( |
| | | 319 | | LSCapsuleCollider2D capsule, |
| | | 320 | | LSCircleCollider2D circle, |
| | | 321 | | ContactManifold2D manifold) |
| | | 322 | | { |
| | 11 | 323 | | if (!TryCapsuleCircle(capsule, circle, out Contact2D contact)) |
| | 1 | 324 | | return false; |
| | | 325 | | |
| | 10 | 326 | | AddContact(manifold, contact, capsule, circle); |
| | 10 | 327 | | return true; |
| | | 328 | | } |
| | | 329 | | |
| | | 330 | | private static bool TryCapsuleCircleReversed( |
| | | 331 | | LSCapsuleCollider2D capsule, |
| | | 332 | | LSCircleCollider2D circle, |
| | | 333 | | ContactManifold2D manifold) |
| | | 334 | | { |
| | 4 | 335 | | if (!TryCapsuleCircle(capsule, circle, out Contact2D contact)) |
| | 1 | 336 | | return false; |
| | | 337 | | |
| | 3 | 338 | | manifold.AddContact( |
| | 3 | 339 | | contact.AnchorB, |
| | 3 | 340 | | contact.AnchorA, |
| | 3 | 341 | | contact.Depth, |
| | 3 | 342 | | -contact.Normal, |
| | 3 | 343 | | circle.Material, |
| | 3 | 344 | | capsule.Material, |
| | 3 | 345 | | contact.DepthIsClamped); |
| | 3 | 346 | | return true; |
| | | 347 | | } |
| | | 348 | | |
| | | 349 | | private static bool TryCapsuleCapsule(LSCapsuleCollider2D colliderA, LSCapsuleCollider2D colliderB, out Contact2D co |
| | | 350 | | { |
| | 17 | 351 | | Vector2d fallbackNormal = colliderB.AxisLength <= Fixed64.Epsilon |
| | 17 | 352 | | ? colliderA.GetNormalFromCenteredAxis(colliderB.Center) |
| | 17 | 353 | | : colliderA.AxisLength <= Fixed64.Epsilon |
| | 17 | 354 | | ? -colliderB.GetNormalFromCenteredAxis(colliderA.Center) |
| | 17 | 355 | | : OrientCoincidentCapsuleNormal(colliderB.Center - colliderA.Center); |
| | 17 | 356 | | if (!FixedSegment2d.TryGetCenteredCapsulesContact( |
| | 17 | 357 | | colliderA.Center, |
| | 17 | 358 | | colliderA.Rotation, |
| | 17 | 359 | | colliderA.AxisLength, |
| | 17 | 360 | | colliderA.ScaledRadius, |
| | 17 | 361 | | colliderB.Center, |
| | 17 | 362 | | colliderB.Rotation, |
| | 17 | 363 | | colliderB.AxisLength, |
| | 17 | 364 | | colliderB.ScaledRadius, |
| | 17 | 365 | | fallbackNormal, |
| | 17 | 366 | | out FixedContactAnchors2d fixedContact)) |
| | | 367 | | { |
| | 2 | 368 | | contact = default; |
| | 2 | 369 | | return false; |
| | | 370 | | } |
| | | 371 | | |
| | 15 | 372 | | contact = new Contact2D( |
| | 15 | 373 | | new ContactAnchor2D(fixedContact.FirstAnchor), |
| | 15 | 374 | | new ContactAnchor2D(fixedContact.SecondAnchor), |
| | 15 | 375 | | fixedContact.Normal, |
| | 15 | 376 | | fixedContact.Depth, |
| | 15 | 377 | | fixedContact.DepthIsClamped); |
| | 15 | 378 | | return true; |
| | | 379 | | } |
| | | 380 | | |
| | | 381 | | private static bool TryCapsuleCapsule( |
| | | 382 | | LSCapsuleCollider2D colliderA, |
| | | 383 | | LSCapsuleCollider2D colliderB, |
| | | 384 | | ContactManifold2D manifold) |
| | | 385 | | { |
| | 7 | 386 | | if (!TryCapsuleCapsule(colliderA, colliderB, out Contact2D contact)) |
| | 1 | 387 | | return false; |
| | | 388 | | |
| | 6 | 389 | | AddContact(manifold, contact, colliderA, colliderB); |
| | 6 | 390 | | return true; |
| | | 391 | | } |
| | | 392 | | |
| | | 393 | | private static bool TryCapsuleConvex(LSCapsuleCollider2D capsule, LSCollider2D convex, out Contact2D contact) |
| | | 394 | | { |
| | 99 | 395 | | Span<FixedPointAnchor2d> capsuleAnchors = |
| | 99 | 396 | | stackalloc FixedPointAnchor2d[2]; |
| | 99 | 397 | | Span<FixedPointAnchor2d> convexAnchors = |
| | 99 | 398 | | stackalloc FixedPointAnchor2d[2]; |
| | 99 | 399 | | if (!TryGetCapsuleConvexContacts( |
| | 99 | 400 | | capsule, |
| | 99 | 401 | | convex, |
| | 99 | 402 | | capsuleAnchors, |
| | 99 | 403 | | convexAnchors, |
| | 99 | 404 | | out _, |
| | 99 | 405 | | out Vector2d normal, |
| | 99 | 406 | | out Fixed64 depth, |
| | 99 | 407 | | out bool depthIsClamped)) |
| | | 408 | | { |
| | 7 | 409 | | contact = default; |
| | 7 | 410 | | return false; |
| | | 411 | | } |
| | | 412 | | |
| | 92 | 413 | | contact = new Contact2D( |
| | 92 | 414 | | new ContactAnchor2D(capsuleAnchors[0]), |
| | 92 | 415 | | new ContactAnchor2D(convexAnchors[0]), |
| | 92 | 416 | | normal, |
| | 92 | 417 | | depth, |
| | 92 | 418 | | depthIsClamped); |
| | 92 | 419 | | return true; |
| | | 420 | | } |
| | | 421 | | |
| | | 422 | | private static bool TryGetCapsuleConvexContacts( |
| | | 423 | | LSCapsuleCollider2D capsule, |
| | | 424 | | LSCollider2D convex, |
| | | 425 | | Span<FixedPointAnchor2d> capsuleAnchors, |
| | | 426 | | Span<FixedPointAnchor2d> convexAnchors, |
| | | 427 | | out int contactCount, |
| | | 428 | | out Vector2d normal, |
| | | 429 | | out Fixed64 depth, |
| | | 430 | | out bool depthIsClamped) |
| | | 431 | | { |
| | 903 | 432 | | Span<Vector2d> vertexOffsets = stackalloc Vector2d[4]; |
| | 903 | 433 | | ReadOnlySpan<Vector2d> convexVertexOffsets = |
| | 903 | 434 | | GetConvexVertexOffsets(convex, vertexOffsets); |
| | 903 | 435 | | return FixedSegment2d.TryGetCenteredCapsuleConvexContacts( |
| | 903 | 436 | | capsule.Center, |
| | 903 | 437 | | capsule.Rotation, |
| | 903 | 438 | | Vector2d.Forward, |
| | 903 | 439 | | capsule.AxisLength, |
| | 903 | 440 | | capsule.ScaledRadius, |
| | 903 | 441 | | convex.Center, |
| | 903 | 442 | | convex.ConvexRotation, |
| | 903 | 443 | | convexVertexOffsets, |
| | 903 | 444 | | capsuleAnchors, |
| | 903 | 445 | | convexAnchors, |
| | 903 | 446 | | out contactCount, |
| | 903 | 447 | | out normal, |
| | 903 | 448 | | out depth, |
| | 903 | 449 | | out depthIsClamped); |
| | | 450 | | } |
| | | 451 | | |
| | | 452 | | private static ReadOnlySpan<Vector2d> GetConvexVertexOffsets( |
| | | 453 | | LSCollider2D convex, |
| | | 454 | | Span<Vector2d> scratch) |
| | | 455 | | { |
| | 12077 | 456 | | if (convex is LSPolygonCollider2D polygon) |
| | 5808 | 457 | | return polygon.ScaledLocalVertices; |
| | | 458 | | |
| | 6269 | 459 | | int vertexCount = convex.VertexCount; |
| | 62690 | 460 | | for (int i = 0; i < vertexCount; i++) |
| | 25076 | 461 | | scratch[i] = convex.GetScaledLocalVertexUnchecked(i); |
| | 6269 | 462 | | return scratch.Slice(0, vertexCount); |
| | | 463 | | } |
| | | 464 | | |
| | | 465 | | private static bool TryCapsuleConvex( |
| | | 466 | | LSCapsuleCollider2D capsule, |
| | | 467 | | LSCollider2D convex, |
| | | 468 | | ContactManifold2D manifold) |
| | | 469 | | { |
| | 14 | 470 | | Span<FixedPointAnchor2d> capsuleAnchors = |
| | 14 | 471 | | stackalloc FixedPointAnchor2d[2]; |
| | 14 | 472 | | Span<FixedPointAnchor2d> convexAnchors = |
| | 14 | 473 | | stackalloc FixedPointAnchor2d[2]; |
| | 14 | 474 | | if (!TryGetCapsuleConvexContacts( |
| | 14 | 475 | | capsule, |
| | 14 | 476 | | convex, |
| | 14 | 477 | | capsuleAnchors, |
| | 14 | 478 | | convexAnchors, |
| | 14 | 479 | | out int contactCount, |
| | 14 | 480 | | out Vector2d normal, |
| | 14 | 481 | | out Fixed64 depth, |
| | 14 | 482 | | out bool depthIsClamped)) |
| | | 483 | | { |
| | 1 | 484 | | return false; |
| | | 485 | | } |
| | | 486 | | |
| | 68 | 487 | | for (int i = 0; i < contactCount; i++) |
| | | 488 | | { |
| | 21 | 489 | | manifold.AddContact( |
| | 21 | 490 | | new ContactAnchor2D(capsuleAnchors[i]), |
| | 21 | 491 | | new ContactAnchor2D(convexAnchors[i]), |
| | 21 | 492 | | depth, |
| | 21 | 493 | | normal, |
| | 21 | 494 | | capsule.Material, |
| | 21 | 495 | | convex.Material, |
| | 21 | 496 | | depthIsClamped); |
| | | 497 | | } |
| | 13 | 498 | | return true; |
| | | 499 | | } |
| | | 500 | | |
| | | 501 | | private static bool TryCapsuleConvexReversed( |
| | | 502 | | LSCapsuleCollider2D capsule, |
| | | 503 | | LSCollider2D convex, |
| | | 504 | | ContactManifold2D manifold) |
| | | 505 | | { |
| | 790 | 506 | | Span<FixedPointAnchor2d> capsuleAnchors = |
| | 790 | 507 | | stackalloc FixedPointAnchor2d[2]; |
| | 790 | 508 | | Span<FixedPointAnchor2d> convexAnchors = |
| | 790 | 509 | | stackalloc FixedPointAnchor2d[2]; |
| | 790 | 510 | | if (!TryGetCapsuleConvexContacts( |
| | 790 | 511 | | capsule, |
| | 790 | 512 | | convex, |
| | 790 | 513 | | capsuleAnchors, |
| | 790 | 514 | | convexAnchors, |
| | 790 | 515 | | out int contactCount, |
| | 790 | 516 | | out Vector2d normal, |
| | 790 | 517 | | out Fixed64 depth, |
| | 790 | 518 | | out bool depthIsClamped)) |
| | | 519 | | { |
| | 1 | 520 | | return false; |
| | | 521 | | } |
| | | 522 | | |
| | 3166 | 523 | | for (int i = 0; i < contactCount; i++) |
| | | 524 | | { |
| | 794 | 525 | | manifold.AddContact( |
| | 794 | 526 | | new ContactAnchor2D(convexAnchors[i]), |
| | 794 | 527 | | new ContactAnchor2D(capsuleAnchors[i]), |
| | 794 | 528 | | depth, |
| | 794 | 529 | | -normal, |
| | 794 | 530 | | convex.Material, |
| | 794 | 531 | | capsule.Material, |
| | 794 | 532 | | depthIsClamped); |
| | | 533 | | } |
| | 789 | 534 | | return true; |
| | | 535 | | } |
| | | 536 | | |
| | | 537 | | private static bool TryConvexConvex(LSCollider2D colliderA, LSCollider2D colliderB, out Contact2D contact) |
| | | 538 | | { |
| | 1040 | 539 | | Span<Vector2d> firstVertexScratch = stackalloc Vector2d[4]; |
| | 1040 | 540 | | Span<Vector2d> secondVertexScratch = stackalloc Vector2d[4]; |
| | 1040 | 541 | | ReadOnlySpan<Vector2d> firstVertexOffsets = |
| | 1040 | 542 | | GetConvexVertexOffsets(colliderA, firstVertexScratch); |
| | 1040 | 543 | | ReadOnlySpan<Vector2d> secondVertexOffsets = |
| | 1040 | 544 | | GetConvexVertexOffsets(colliderB, secondVertexScratch); |
| | 1040 | 545 | | Span<FixedPointAnchor2d> firstContactAnchors = |
| | 1040 | 546 | | stackalloc FixedPointAnchor2d[2]; |
| | 1040 | 547 | | Span<FixedPointAnchor2d> secondContactAnchors = |
| | 1040 | 548 | | stackalloc FixedPointAnchor2d[2]; |
| | 1040 | 549 | | if (!FixedConvex2dRelations.TryGetConvexContacts( |
| | 1040 | 550 | | colliderA.Center, |
| | 1040 | 551 | | colliderA.ConvexRotation, |
| | 1040 | 552 | | firstVertexOffsets, |
| | 1040 | 553 | | colliderB.Center, |
| | 1040 | 554 | | colliderB.ConvexRotation, |
| | 1040 | 555 | | secondVertexOffsets, |
| | 1040 | 556 | | firstContactAnchors, |
| | 1040 | 557 | | secondContactAnchors, |
| | 1040 | 558 | | out _, |
| | 1040 | 559 | | out Vector2d normal, |
| | 1040 | 560 | | out Fixed64 depth, |
| | 1040 | 561 | | out bool depthIsClamped)) |
| | | 562 | | { |
| | 6 | 563 | | contact = default; |
| | 6 | 564 | | return false; |
| | | 565 | | } |
| | | 566 | | |
| | | 567 | | // Keep a matched finite witness pair; support endpoints can lie outside |
| | | 568 | | // the overlap and give sweep/rotational CCD an unrelated lever arm. |
| | 1034 | 569 | | contact = new Contact2D( |
| | 1034 | 570 | | new ContactAnchor2D(firstContactAnchors[0]), |
| | 1034 | 571 | | new ContactAnchor2D(secondContactAnchors[0]), |
| | 1034 | 572 | | normal, |
| | 1034 | 573 | | depth, |
| | 1034 | 574 | | depthIsClamped); |
| | 1034 | 575 | | return true; |
| | | 576 | | } |
| | | 577 | | |
| | | 578 | | private static bool TryConvexConvex( |
| | | 579 | | LSCollider2D colliderA, |
| | | 580 | | LSCollider2D colliderB, |
| | | 581 | | ContactManifold2D manifold) |
| | | 582 | | { |
| | 1414 | 583 | | Span<Vector2d> firstVertexScratch = stackalloc Vector2d[4]; |
| | 1414 | 584 | | Span<Vector2d> secondVertexScratch = stackalloc Vector2d[4]; |
| | 1414 | 585 | | ReadOnlySpan<Vector2d> firstVertexOffsets = |
| | 1414 | 586 | | GetConvexVertexOffsets(colliderA, firstVertexScratch); |
| | 1414 | 587 | | ReadOnlySpan<Vector2d> secondVertexOffsets = |
| | 1414 | 588 | | GetConvexVertexOffsets(colliderB, secondVertexScratch); |
| | 1414 | 589 | | Span<FixedPointAnchor2d> firstContactAnchors = |
| | 1414 | 590 | | stackalloc FixedPointAnchor2d[2]; |
| | 1414 | 591 | | Span<FixedPointAnchor2d> secondContactAnchors = |
| | 1414 | 592 | | stackalloc FixedPointAnchor2d[2]; |
| | 1414 | 593 | | if (!FixedConvex2dRelations.TryGetConvexContacts( |
| | 1414 | 594 | | colliderA.Center, |
| | 1414 | 595 | | colliderA.ConvexRotation, |
| | 1414 | 596 | | firstVertexOffsets, |
| | 1414 | 597 | | colliderB.Center, |
| | 1414 | 598 | | colliderB.ConvexRotation, |
| | 1414 | 599 | | secondVertexOffsets, |
| | 1414 | 600 | | firstContactAnchors, |
| | 1414 | 601 | | secondContactAnchors, |
| | 1414 | 602 | | out int contactCount, |
| | 1414 | 603 | | out Vector2d normal, |
| | 1414 | 604 | | out Fixed64 depth, |
| | 1414 | 605 | | out bool depthIsClamped)) |
| | | 606 | | { |
| | 1 | 607 | | return false; |
| | | 608 | | } |
| | | 609 | | |
| | 8228 | 610 | | for (int i = 0; i < contactCount; i++) |
| | | 611 | | { |
| | 2701 | 612 | | manifold.AddContact( |
| | 2701 | 613 | | new ContactAnchor2D(firstContactAnchors[i]), |
| | 2701 | 614 | | new ContactAnchor2D(secondContactAnchors[i]), |
| | 2701 | 615 | | depth, |
| | 2701 | 616 | | normal, |
| | 2701 | 617 | | colliderA.Material, |
| | 2701 | 618 | | colliderB.Material, |
| | 2701 | 619 | | depthIsClamped); |
| | | 620 | | } |
| | | 621 | | |
| | 1413 | 622 | | return true; |
| | | 623 | | } |
| | | 624 | | |
| | | 625 | | private static bool TryCompound(LSCollider2D colliderA, LSCollider2D colliderB, out Contact2D contact) |
| | | 626 | | { |
| | 79 | 627 | | if (colliderA is LSCompoundCollider2D compoundA) |
| | | 628 | | { |
| | 34 | 629 | | if (colliderB is LSCompoundCollider2D compoundB) |
| | 31 | 630 | | return TryCompoundCompound(compoundA, compoundB, out contact); |
| | | 631 | | |
| | 3 | 632 | | return TryCompoundOther(compoundA, colliderB, compoundIsA: true, out contact); |
| | | 633 | | } |
| | | 634 | | |
| | 45 | 635 | | if (colliderB is LSCompoundCollider2D compound) |
| | 44 | 636 | | return TryCompoundOther(compound, colliderA, compoundIsA: false, out contact); |
| | | 637 | | |
| | 1 | 638 | | contact = default; |
| | 1 | 639 | | return false; |
| | | 640 | | } |
| | | 641 | | |
| | | 642 | | private static bool TryCompoundCompound( |
| | | 643 | | LSCompoundCollider2D compoundA, |
| | | 644 | | LSCompoundCollider2D compoundB, |
| | | 645 | | out Contact2D contact) |
| | | 646 | | { |
| | 31 | 647 | | bool found = false; |
| | 31 | 648 | | Contact2D best = default; |
| | | 649 | | |
| | 128 | 650 | | for (int i = 0; i < compoundA.PartCount; i++) |
| | | 651 | | { |
| | 33 | 652 | | LSCollider2D partA = compoundA.GetPartCollider(i); |
| | 194 | 653 | | for (int j = 0; j < compoundB.PartCount; j++) |
| | | 654 | | { |
| | 64 | 655 | | LSCollider2D partB = compoundB.GetPartCollider(j); |
| | 64 | 656 | | if (!TryCollide(partA, partB, out Contact2D candidate)) |
| | | 657 | | continue; |
| | | 658 | | |
| | 21 | 659 | | if (ContactSelectionPolicy.ShouldReplaceWithDeeper(candidate, found, best)) |
| | | 660 | | { |
| | 11 | 661 | | best = candidate; |
| | 11 | 662 | | found = true; |
| | | 663 | | } |
| | | 664 | | } |
| | | 665 | | } |
| | | 666 | | |
| | 31 | 667 | | if (!found) |
| | | 668 | | { |
| | 20 | 669 | | contact = default; |
| | 20 | 670 | | return false; |
| | | 671 | | } |
| | | 672 | | |
| | 11 | 673 | | contact = best; |
| | 11 | 674 | | return true; |
| | | 675 | | } |
| | | 676 | | |
| | | 677 | | private static bool TryCompoundOther( |
| | | 678 | | LSCompoundCollider2D compound, |
| | | 679 | | LSCollider2D other, |
| | | 680 | | bool compoundIsA, |
| | | 681 | | out Contact2D contact) |
| | | 682 | | { |
| | 47 | 683 | | bool found = false; |
| | 47 | 684 | | Contact2D best = default; |
| | | 685 | | |
| | 278 | 686 | | for (int i = 0; i < compound.PartCount; i++) |
| | | 687 | | { |
| | 92 | 688 | | LSCollider2D part = compound.GetPartCollider(i); |
| | | 689 | | Contact2D candidate; |
| | 92 | 690 | | bool collided = compoundIsA |
| | 92 | 691 | | ? TryCollide(part, other, out candidate) |
| | 92 | 692 | | : TryCollide(other, part, out candidate); |
| | | 693 | | |
| | 92 | 694 | | if (!collided) |
| | | 695 | | continue; |
| | | 696 | | |
| | 38 | 697 | | if (ContactSelectionPolicy.ShouldReplaceWithDeeper(candidate, found, best)) |
| | | 698 | | { |
| | 27 | 699 | | best = candidate; |
| | 27 | 700 | | found = true; |
| | | 701 | | } |
| | | 702 | | } |
| | | 703 | | |
| | 47 | 704 | | if (!found) |
| | | 705 | | { |
| | 21 | 706 | | contact = default; |
| | 21 | 707 | | return false; |
| | | 708 | | } |
| | | 709 | | |
| | 26 | 710 | | contact = best; |
| | 26 | 711 | | return true; |
| | | 712 | | } |
| | | 713 | | |
| | | 714 | | private static bool TryCompound( |
| | | 715 | | LSCollider2D colliderA, |
| | | 716 | | LSCollider2D colliderB, |
| | | 717 | | ContactManifold2D manifold) |
| | | 718 | | { |
| | 133 | 719 | | if (colliderA is LSCompoundCollider2D compoundA) |
| | | 720 | | { |
| | 130 | 721 | | if (colliderB is LSCompoundCollider2D compoundB) |
| | 4 | 722 | | return TryCompoundCompound(compoundA, compoundB, manifold); |
| | | 723 | | |
| | 126 | 724 | | return TryCompoundOther(compoundA, colliderB, compoundIsA: true, manifold); |
| | | 725 | | } |
| | | 726 | | |
| | 3 | 727 | | if (colliderB is LSCompoundCollider2D compound) |
| | 2 | 728 | | return TryCompoundOther(compound, colliderA, compoundIsA: false, manifold); |
| | | 729 | | |
| | 1 | 730 | | return false; |
| | | 731 | | } |
| | | 732 | | |
| | | 733 | | private static bool TryCompoundCompound( |
| | | 734 | | LSCompoundCollider2D compoundA, |
| | | 735 | | LSCompoundCollider2D compoundB, |
| | | 736 | | ContactManifold2D manifold) |
| | | 737 | | { |
| | 4 | 738 | | bool found = false; |
| | 4 | 739 | | ContactManifold2D scratch = compoundA.PartManifoldScratch; |
| | 22 | 740 | | for (int i = 0; i < compoundA.PartCount; i++) |
| | | 741 | | { |
| | 7 | 742 | | LSCollider2D partA = compoundA.GetPartCollider(i); |
| | 32 | 743 | | for (int j = 0; j < compoundB.PartCount; j++) |
| | | 744 | | { |
| | 9 | 745 | | LSCollider2D partB = compoundB.GetPartCollider(j); |
| | 9 | 746 | | CollisionType2D collisionType = ColliderSettings2D.GetCollisionType(partA.Shape, partB.Shape); |
| | 9 | 747 | | scratch.BeginUpdate(manifold.LastUpdatedFrame); |
| | 9 | 748 | | if (!TryCollide(new CollisionWorkItem2D(partA, partB, collisionType), scratch)) |
| | | 749 | | continue; |
| | | 750 | | |
| | 2 | 751 | | found = true; |
| | 2 | 752 | | AddCompoundPartContacts( |
| | 2 | 753 | | manifold, |
| | 2 | 754 | | scratch, |
| | 2 | 755 | | featureNamespaceA: i + 1, |
| | 2 | 756 | | featureNamespaceB: -(j + 1)); |
| | | 757 | | } |
| | | 758 | | } |
| | | 759 | | |
| | 4 | 760 | | return found; |
| | | 761 | | } |
| | | 762 | | |
| | | 763 | | private static bool TryCompoundOther( |
| | | 764 | | LSCompoundCollider2D compound, |
| | | 765 | | LSCollider2D other, |
| | | 766 | | bool compoundIsA, |
| | | 767 | | ContactManifold2D manifold) |
| | | 768 | | { |
| | 128 | 769 | | bool found = false; |
| | 128 | 770 | | ContactManifold2D scratch = compound.PartManifoldScratch; |
| | 528 | 771 | | for (int i = 0; i < compound.PartCount; i++) |
| | | 772 | | { |
| | 136 | 773 | | LSCollider2D part = compound.GetPartCollider(i); |
| | 136 | 774 | | LSCollider2D colliderA = compoundIsA ? part : other; |
| | 136 | 775 | | LSCollider2D colliderB = compoundIsA ? other : part; |
| | 136 | 776 | | CollisionType2D collisionType = ColliderSettings2D.GetCollisionType(colliderA.Shape, colliderB.Shape); |
| | 136 | 777 | | scratch.BeginUpdate(manifold.LastUpdatedFrame); |
| | 136 | 778 | | if (!TryCollide(new CollisionWorkItem2D(colliderA, colliderB, collisionType), scratch)) |
| | | 779 | | continue; |
| | | 780 | | |
| | 132 | 781 | | found = true; |
| | 132 | 782 | | AddCompoundPartContacts( |
| | 132 | 783 | | manifold, |
| | 132 | 784 | | scratch, |
| | 132 | 785 | | featureNamespaceA: compoundIsA ? i + 1 : 0, |
| | 132 | 786 | | featureNamespaceB: compoundIsA ? 0 : -(i + 1)); |
| | | 787 | | } |
| | | 788 | | |
| | 128 | 789 | | return found; |
| | | 790 | | } |
| | | 791 | | |
| | | 792 | | private static void AddCompoundPartContacts( |
| | | 793 | | ContactManifold2D destination, |
| | | 794 | | ContactManifold2D source, |
| | | 795 | | int featureNamespaceA, |
| | | 796 | | int featureNamespaceB) |
| | | 797 | | { |
| | 134 | 798 | | destination.NeedsSurfaceRecovery |= source.NeedsSurfaceRecovery; |
| | 734 | 799 | | for (int groupIndex = 0; groupIndex < source.GroupCount; groupIndex++) |
| | | 800 | | { |
| | 233 | 801 | | ref ContactGroup2D group = ref source.GetGroup(groupIndex); |
| | 1170 | 802 | | for (int i = 0; i < group.Count; i++) |
| | | 803 | | { |
| | 352 | 804 | | ManifoldContact2D contact = group[i]; |
| | 352 | 805 | | destination.AddContact( |
| | 352 | 806 | | contact.AnchorA, |
| | 352 | 807 | | contact.AnchorB, |
| | 352 | 808 | | contact.Depth, |
| | 352 | 809 | | contact.Normal, |
| | 352 | 810 | | contact.MaterialA, |
| | 352 | 811 | | contact.MaterialB, |
| | 352 | 812 | | contact.DepthIsClamped, |
| | 352 | 813 | | featureNamespaceA, |
| | 352 | 814 | | featureNamespaceB, |
| | 352 | 815 | | group.Key); |
| | | 816 | | } |
| | | 817 | | } |
| | 134 | 818 | | } |
| | | 819 | | |
| | | 820 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 821 | | private static void AddContact( |
| | | 822 | | ContactManifold2D manifold, |
| | | 823 | | Contact2D contact, |
| | | 824 | | LSCollider2D colliderA, |
| | | 825 | | LSCollider2D colliderB) => |
| | 822 | 826 | | manifold.AddContact( |
| | 822 | 827 | | contact.AnchorA, |
| | 822 | 828 | | contact.AnchorB, |
| | 822 | 829 | | contact.Depth, |
| | 822 | 830 | | contact.Normal, |
| | 822 | 831 | | colliderA.Material, |
| | 822 | 832 | | colliderB.Material, |
| | 822 | 833 | | contact.DepthIsClamped); |
| | | 834 | | |
| | | 835 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 836 | | internal static bool BoundsOverlap(LSCollider2D colliderA, LSCollider2D colliderB) => |
| | 42981 | 837 | | colliderA.MinX <= colliderB.MaxX |
| | 42981 | 838 | | && colliderA.MaxX >= colliderB.MinX |
| | 42981 | 839 | | && colliderA.MinY <= colliderB.MaxY |
| | 42981 | 840 | | && colliderA.MaxY >= colliderB.MinY; |
| | | 841 | | |
| | | 842 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 843 | | private static Vector2d OrientCoincidentCapsuleNormal(Vector2d direction) => |
| | 9 | 844 | | direction.MagnitudeSquared > Fixed64.Epsilon && direction.X < Fixed64.Zero |
| | 9 | 845 | | ? -Vector2d.Right |
| | 9 | 846 | | : Vector2d.Right; |
| | | 847 | | |
| | | 848 | | } |