| | | 1 | | //======================================================================= |
| | | 2 | | // ExactNormalResponse3D.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 normal |
| | | 14 | | /// response. |
| | | 15 | | /// </summary> |
| | | 16 | | internal readonly struct ExactNormalResponse3D |
| | | 17 | | { |
| | | 18 | | private readonly Fixed64 _normalVelocity; |
| | | 19 | | private readonly Fixed64 _appliedImpulse; |
| | | 20 | | private readonly Fixed64 _accumulatedImpulse; |
| | | 21 | | private readonly byte _projectionFlags; |
| | | 22 | | |
| | | 23 | | internal ExactNormalResponse3D( |
| | | 24 | | bool isClosing, |
| | | 25 | | bool hasAppliedImpulse, |
| | | 26 | | Vector3d firstLinearVelocityDelta, |
| | | 27 | | Vector3d firstAngularVelocityDelta, |
| | | 28 | | Vector3d secondLinearVelocityDelta, |
| | | 29 | | Vector3d secondAngularVelocityDelta, |
| | | 30 | | bool hasNormalVelocity, |
| | | 31 | | Fixed64 normalVelocity, |
| | | 32 | | bool hasAppliedImpulseProjection, |
| | | 33 | | Fixed64 appliedImpulse, |
| | | 34 | | bool hasAccumulatedImpulse, |
| | | 35 | | Fixed64 accumulatedImpulse) |
| | | 36 | | { |
| | 1645 | 37 | | IsClosing = isClosing; |
| | 1645 | 38 | | HasAppliedImpulse = hasAppliedImpulse; |
| | 1645 | 39 | | FirstLinearVelocityDelta = firstLinearVelocityDelta; |
| | 1645 | 40 | | FirstAngularVelocityDelta = firstAngularVelocityDelta; |
| | 1645 | 41 | | SecondLinearVelocityDelta = secondLinearVelocityDelta; |
| | 1645 | 42 | | SecondAngularVelocityDelta = secondAngularVelocityDelta; |
| | 1645 | 43 | | _normalVelocity = normalVelocity; |
| | 1645 | 44 | | _appliedImpulse = appliedImpulse; |
| | 1645 | 45 | | _accumulatedImpulse = accumulatedImpulse; |
| | 1645 | 46 | | _projectionFlags = (byte)( |
| | 1645 | 47 | | (hasNormalVelocity ? 1 : 0) |
| | 1645 | 48 | | | (hasAppliedImpulseProjection ? 2 : 0) |
| | 1645 | 49 | | | (hasAccumulatedImpulse ? 4 : 0)); |
| | 1645 | 50 | | } |
| | | 51 | | |
| | | 52 | | internal bool IsClosing { get; } |
| | | 53 | | |
| | | 54 | | internal bool HasAppliedImpulse { get; } |
| | | 55 | | |
| | | 56 | | internal Vector3d FirstLinearVelocityDelta { get; } |
| | | 57 | | |
| | | 58 | | internal Vector3d FirstAngularVelocityDelta { get; } |
| | | 59 | | |
| | | 60 | | internal Vector3d SecondLinearVelocityDelta { get; } |
| | | 61 | | |
| | | 62 | | internal Vector3d SecondAngularVelocityDelta { get; } |
| | | 63 | | |
| | | 64 | | internal bool TryGetNormalVelocity(out Fixed64 value) |
| | | 65 | | { |
| | 1619 | 66 | | value = _normalVelocity; |
| | 1619 | 67 | | return (_projectionFlags & 1) != 0; |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | internal bool TryGetAppliedImpulse(out Fixed64 value) |
| | | 71 | | { |
| | 1459 | 72 | | value = _appliedImpulse; |
| | 1459 | 73 | | return (_projectionFlags & 2) != 0; |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | internal bool TryGetAccumulatedImpulse(out Fixed64 value) |
| | | 77 | | { |
| | 1458 | 78 | | value = _accumulatedImpulse; |
| | 1458 | 79 | | return (_projectionFlags & 4) != 0; |
| | | 80 | | } |
| | | 81 | | } |