| | | 1 | | //======================================================================= |
| | | 2 | | // ExactCoulombResponse3D.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 | | /// Contains atomically materialized velocity deltas from an exact Coulomb |
| | | 14 | | /// response. |
| | | 15 | | /// </summary> |
| | | 16 | | internal readonly struct ExactCoulombResponse3D |
| | | 17 | | { |
| | | 18 | | private readonly Fixed64 _primaryAccumulatedImpulse; |
| | | 19 | | private readonly Fixed64 _secondaryAccumulatedImpulse; |
| | | 20 | | private readonly byte _projectionFlags; |
| | | 21 | | |
| | | 22 | | internal ExactCoulombResponse3D( |
| | | 23 | | bool hasAppliedImpulse, |
| | | 24 | | Vector3d firstLinearVelocityDelta, |
| | | 25 | | Vector3d firstAngularVelocityDelta, |
| | | 26 | | Vector3d secondLinearVelocityDelta, |
| | | 27 | | Vector3d secondAngularVelocityDelta, |
| | | 28 | | bool hasPrimaryAccumulatedImpulse, |
| | | 29 | | Fixed64 primaryAccumulatedImpulse, |
| | | 30 | | bool hasSecondaryAccumulatedImpulse, |
| | | 31 | | Fixed64 secondaryAccumulatedImpulse) |
| | | 32 | | { |
| | 483 | 33 | | HasAppliedImpulse = hasAppliedImpulse; |
| | 483 | 34 | | FirstLinearVelocityDelta = firstLinearVelocityDelta; |
| | 483 | 35 | | FirstAngularVelocityDelta = firstAngularVelocityDelta; |
| | 483 | 36 | | SecondLinearVelocityDelta = secondLinearVelocityDelta; |
| | 483 | 37 | | SecondAngularVelocityDelta = secondAngularVelocityDelta; |
| | 483 | 38 | | _primaryAccumulatedImpulse = primaryAccumulatedImpulse; |
| | 483 | 39 | | _secondaryAccumulatedImpulse = secondaryAccumulatedImpulse; |
| | 483 | 40 | | _projectionFlags = (byte)( |
| | 483 | 41 | | (hasPrimaryAccumulatedImpulse ? 1 : 0) |
| | 483 | 42 | | | (hasSecondaryAccumulatedImpulse ? 2 : 0)); |
| | 483 | 43 | | } |
| | | 44 | | |
| | | 45 | | internal bool HasAppliedImpulse { get; } |
| | | 46 | | |
| | | 47 | | internal Vector3d FirstLinearVelocityDelta { get; } |
| | | 48 | | |
| | | 49 | | internal Vector3d FirstAngularVelocityDelta { get; } |
| | | 50 | | |
| | | 51 | | internal Vector3d SecondLinearVelocityDelta { get; } |
| | | 52 | | |
| | | 53 | | internal Vector3d SecondAngularVelocityDelta { get; } |
| | | 54 | | |
| | | 55 | | internal bool TryGetPrimaryAccumulatedImpulse(out Fixed64 value) |
| | | 56 | | { |
| | 429 | 57 | | value = _primaryAccumulatedImpulse; |
| | 429 | 58 | | return (_projectionFlags & 1) != 0; |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | internal bool TryGetSecondaryAccumulatedImpulse(out Fixed64 value) |
| | | 62 | | { |
| | 394 | 63 | | value = _secondaryAccumulatedImpulse; |
| | 394 | 64 | | return (_projectionFlags & 2) != 0; |
| | | 65 | | } |
| | | 66 | | } |