| | | 1 | | //======================================================================= |
| | | 2 | | // ResponseBody3D.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 ResponseBody3D |
| | | 17 | | { |
| | | 18 | | private ResponseBody3D(SolidBody body, Fixed64 inverseMass) |
| | | 19 | | { |
| | 317412 | 20 | | Body = body; |
| | 317412 | 21 | | InverseMass = inverseMass; |
| | 317412 | 22 | | } |
| | | 23 | | |
| | | 24 | | public SolidBody? Body { get; } |
| | | 25 | | |
| | | 26 | | public Fixed64 InverseMass { get; } |
| | | 27 | | |
| | 621795 | 28 | | public bool HasSolverMobility => Body?.HasSolverMobility == true; |
| | | 29 | | |
| | | 30 | | public Fixed64 GetConstrainedInverseMass(Vector3d axis) => |
| | 127576 | 31 | | Body?.GetConstrainedInverseMass(axis) ?? Fixed64.Zero; |
| | | 32 | | |
| | | 33 | | public static ResponseBody3D Create(LSCollider collider) |
| | | 34 | | { |
| | 531318 | 35 | | SolidBody? body = collider.Body; |
| | 531318 | 36 | | return body == null ? default : new ResponseBody3D(body, body.EffectiveInverseMass); |
| | | 37 | | } |
| | | 38 | | } |