| | | 1 | | //======================================================================= |
| | | 2 | | // ResponseBody2D.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.Colliders; |
| | | 10 | | |
| | | 11 | | namespace Gravitas.CollisionHandling; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Scalar pure 2D response body data for one collider participant. |
| | | 15 | | /// </summary> |
| | | 16 | | internal readonly struct ResponseBody2D |
| | | 17 | | { |
| | | 18 | | private ResponseBody2D(SolidBody2D? body, Fixed64 inverseMass, Fixed64 inverseMoment) |
| | | 19 | | { |
| | 1964 | 20 | | Body = body; |
| | 1964 | 21 | | InverseMass = inverseMass; |
| | 1964 | 22 | | InverseMoment = inverseMoment; |
| | 1964 | 23 | | } |
| | | 24 | | |
| | | 25 | | public SolidBody2D? Body { get; } |
| | | 26 | | |
| | | 27 | | public Fixed64 InverseMass { get; } |
| | | 28 | | |
| | | 29 | | public Fixed64 InverseMoment { get; } |
| | | 30 | | |
| | 1090 | 31 | | public bool CanTranslate => Body?.CanTranslate == true; |
| | | 32 | | |
| | 216 | 33 | | public bool CanRotate => Body?.CanRotate == true; |
| | | 34 | | |
| | 1614 | 35 | | public bool HasSolverMobility => Body?.HasSolverMobility == true; |
| | | 36 | | |
| | | 37 | | public Fixed64 GetConstrainedInverseMass(Vector2d axis) => |
| | 876 | 38 | | Body?.GetConstrainedInverseMass(axis) ?? Fixed64.Zero; |
| | | 39 | | |
| | | 40 | | public static ResponseBody2D Create(LSCollider2D collider) |
| | | 41 | | { |
| | 1990 | 42 | | SolidBody2D? body = collider.Body; |
| | 1990 | 43 | | if (body == null) |
| | 26 | 44 | | return default; |
| | | 45 | | |
| | 1964 | 46 | | return new ResponseBody2D( |
| | 1964 | 47 | | body, |
| | 1964 | 48 | | body.EffectiveInverseMass, |
| | 1964 | 49 | | body.EffectiveInverseMomentOfInertia); |
| | | 50 | | } |
| | | 51 | | } |