| | | 1 | | //======================================================================= |
| | | 2 | | // SolverContact2D.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 FixedMathSharp; |
| | | 9 | | using Gravitas.Materials; |
| | | 10 | | |
| | | 11 | | namespace Gravitas.CollisionHandling; |
| | | 12 | | |
| | | 13 | | |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Solver-ready scalar pure 2D contact data. |
| | | 17 | | /// </summary> |
| | | 18 | | internal readonly struct SolverContact2D |
| | | 19 | | { |
| | | 20 | | public SolverContact2D( |
| | | 21 | | int groupIndex, |
| | | 22 | | int pointIndex, |
| | | 23 | | ulong contactId, |
| | | 24 | | ResponseBody2D bodyA, |
| | | 25 | | ResponseBody2D bodyB, |
| | | 26 | | ContactLever2D relativeA, |
| | | 27 | | ContactLever2D relativeB, |
| | | 28 | | Fixed64 depth, |
| | | 29 | | Vector2d normal, |
| | | 30 | | PhysicsMaterial materialA, |
| | | 31 | | PhysicsMaterial materialB, |
| | | 32 | | Fixed64 cachedNormalImpulse, |
| | | 33 | | Fixed64 cachedTangentImpulse, |
| | | 34 | | ContactGroupKey group = default) |
| | | 35 | | { |
| | 17748 | 36 | | Group = group; |
| | 17748 | 37 | | GroupIndex = groupIndex; |
| | 17748 | 38 | | PointIndex = pointIndex; |
| | 17748 | 39 | | ContactId = contactId; |
| | 17748 | 40 | | A = bodyA; |
| | 17748 | 41 | | B = bodyB; |
| | 17748 | 42 | | RelativeA = relativeA; |
| | 17748 | 43 | | RelativeB = relativeB; |
| | 17748 | 44 | | Depth = depth; |
| | 17748 | 45 | | Normal = normal; |
| | 17748 | 46 | | MaterialA = materialA; |
| | 17748 | 47 | | MaterialB = materialB; |
| | 17748 | 48 | | PhysicsMaterial.CombineFriction(materialA, materialB, out Fixed64 staticFriction, out Fixed64 dynamicFriction); |
| | 17748 | 49 | | StaticFriction = staticFriction; |
| | 17748 | 50 | | DynamicFriction = dynamicFriction; |
| | 17748 | 51 | | Restitution = PhysicsMaterial.CombineRestitution(materialA, materialB); |
| | 17748 | 52 | | Tangent = normal.RightHandNormal; |
| | 17748 | 53 | | CachedNormalImpulse = cachedNormalImpulse; |
| | 17748 | 54 | | CachedTangentImpulse = cachedTangentImpulse; |
| | 17748 | 55 | | } |
| | | 56 | | |
| | | 57 | | // Cache provenance beside the row; repeated manifold lookups cost more than this small copy. |
| | | 58 | | internal ContactGroupKey Group { get; } |
| | | 59 | | |
| | | 60 | | public int GroupIndex { get; } |
| | | 61 | | |
| | | 62 | | public int PointIndex { get; } |
| | | 63 | | |
| | | 64 | | public ulong ContactId { get; } |
| | | 65 | | |
| | | 66 | | public ResponseBody2D A { get; } |
| | | 67 | | |
| | | 68 | | public ResponseBody2D B { get; } |
| | | 69 | | |
| | | 70 | | public ContactLever2D RelativeA { get; } |
| | | 71 | | |
| | | 72 | | public ContactLever2D RelativeB { get; } |
| | | 73 | | |
| | | 74 | | public Fixed64 Depth { get; } |
| | | 75 | | |
| | | 76 | | public Vector2d Normal { get; } |
| | | 77 | | |
| | | 78 | | public PhysicsMaterial MaterialA { get; } |
| | | 79 | | |
| | | 80 | | public PhysicsMaterial MaterialB { get; } |
| | | 81 | | |
| | | 82 | | public Fixed64 StaticFriction { get; } |
| | | 83 | | |
| | | 84 | | public Fixed64 DynamicFriction { get; } |
| | | 85 | | |
| | | 86 | | public Fixed64 Restitution { get; } |
| | | 87 | | |
| | | 88 | | public Vector2d Tangent { get; } |
| | | 89 | | |
| | | 90 | | public Fixed64 CachedNormalImpulse { get; } |
| | | 91 | | |
| | | 92 | | public Fixed64 CachedTangentImpulse { get; } |
| | | 93 | | |
| | | 94 | | } |