| | | 1 | | //======================================================================= |
| | | 2 | | // ExactContactResponseOperand3D.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 | | |
| | | 10 | | namespace Gravitas.CollisionHandling; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Describes one participant in an exact rigid-body contact response. |
| | | 14 | | /// </summary> |
| | | 15 | | internal readonly struct ExactContactResponseOperand3D |
| | | 16 | | { |
| | | 17 | | internal ExactContactResponseOperand3D( |
| | | 18 | | in ExactLever3D lever, |
| | | 19 | | Vector3d linearVelocity, |
| | | 20 | | Vector3d angularVelocity, |
| | | 21 | | Vector3d linearImpulseAxis, |
| | | 22 | | Fixed64 inverseMass, |
| | | 23 | | Fixed3x3 inverseInertia, |
| | | 24 | | Fixed64? planarAngularVelocity = null) |
| | | 25 | | { |
| | 34390 | 26 | | Lever = lever; |
| | 34390 | 27 | | LinearVelocity = linearVelocity; |
| | 34390 | 28 | | AngularVelocity = angularVelocity; |
| | 34390 | 29 | | LinearImpulseAxis = linearImpulseAxis; |
| | 34390 | 30 | | InverseMass = inverseMass; |
| | 34390 | 31 | | InverseInertia = inverseInertia; |
| | 34390 | 32 | | PlanarAngularVelocity = planarAngularVelocity; |
| | 34390 | 33 | | } |
| | | 34 | | |
| | | 35 | | internal ExactLever3D Lever { get; } |
| | | 36 | | |
| | | 37 | | internal Vector3d LinearVelocity { get; } |
| | | 38 | | |
| | | 39 | | internal Vector3d AngularVelocity { get; } |
| | | 40 | | |
| | | 41 | | // The spatial sign conversion of minimum planar yaw does not fit Fixed64. |
| | | 42 | | internal Fixed64? PlanarAngularVelocity { get; } |
| | | 43 | | |
| | | 44 | | // Positive 2^31 yaw delta cannot be represented by the planar delta API. |
| | | 45 | | internal bool CanRepresentAngularDelta(Vector3d delta) => |
| | 32540 | 46 | | !PlanarAngularVelocity.HasValue || delta.Y != Fixed64.MinValue; |
| | | 47 | | |
| | 351 | 48 | | internal bool CanApplyAngularDelta(Vector3d delta) => PlanarAngularVelocity.HasValue |
| | 351 | 49 | | ? CanRepresentAngularDelta(delta) && Fixed64.TrySubtract(PlanarAngularVelocity.Value, delta.Y, out _) |
| | 351 | 50 | | : Vector3d.TryAdd(AngularVelocity, delta, out _); |
| | | 51 | | |
| | | 52 | | internal Vector3d LinearImpulseAxis { get; } |
| | | 53 | | |
| | | 54 | | internal Fixed64 InverseMass { get; } |
| | | 55 | | |
| | | 56 | | internal Fixed3x3 InverseInertia { get; } |
| | | 57 | | } |