| | | 1 | | //======================================================================= |
| | | 2 | | // ResponseBody.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 | | /// Represents a body involved in a collision response, containing necessary information for collision resolution. |
| | | 15 | | /// </summary> |
| | | 16 | | internal readonly struct ResponseBody |
| | | 17 | | { |
| | | 18 | | private ResponseBody(SolidBody body, Fixed64 inverseMass) |
| | | 19 | | { |
| | 17678 | 20 | | Body = body; |
| | 17678 | 21 | | InverseMass = inverseMass; |
| | 17678 | 22 | | } |
| | | 23 | | |
| | | 24 | | public SolidBody Body { get; } |
| | | 25 | | |
| | | 26 | | public Fixed64 InverseMass { get; } |
| | | 27 | | |
| | 33641 | 28 | | public bool HasSolverMobility => Body.HasSolverMobility; |
| | | 29 | | |
| | 12305 | 30 | | public bool CanRotate => Body.CanRotate; |
| | | 31 | | |
| | | 32 | | public Fixed64 GetConstrainedInverseMass(Vector3d axis) => |
| | 13510 | 33 | | Body.GetConstrainedInverseMass(axis); |
| | | 34 | | |
| | | 35 | | public static ResponseBody Create(LSCollider collider) |
| | | 36 | | { |
| | 17678 | 37 | | SolidBody body = collider.Body!; |
| | 17678 | 38 | | return Create(body); |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public static ResponseBody Create(SolidBody body) |
| | | 42 | | { |
| | 17678 | 43 | | Fixed64 inverseMass = body.EffectiveInverseMass; |
| | 17678 | 44 | | return new ResponseBody(body, inverseMass); |
| | | 45 | | } |
| | | 46 | | } |