| | | 1 | | //======================================================================= |
| | | 2 | | // ContactEffectiveMassTerms3D.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 | | /// Stores each body's linear and angular contributions to 3D contact effective mass. |
| | | 14 | | /// </summary> |
| | | 15 | | internal readonly struct ContactEffectiveMassTerms3D |
| | | 16 | | { |
| | | 17 | | internal ContactEffectiveMassTerms3D( |
| | | 18 | | Fixed64 linearA, |
| | | 19 | | Fixed64 linearB, |
| | | 20 | | Fixed64 angularA, |
| | | 21 | | Fixed64 angularB) |
| | | 22 | | { |
| | 613638 | 23 | | LinearA = linearA; |
| | 613638 | 24 | | LinearB = linearB; |
| | 613638 | 25 | | AngularA = angularA; |
| | 613638 | 26 | | AngularB = angularB; |
| | 613638 | 27 | | } |
| | | 28 | | |
| | | 29 | | internal Fixed64 LinearA { get; } |
| | | 30 | | |
| | | 31 | | internal Fixed64 LinearB { get; } |
| | | 32 | | |
| | | 33 | | internal Fixed64 AngularA { get; } |
| | | 34 | | |
| | | 35 | | internal Fixed64 AngularB { get; } |
| | | 36 | | |
| | | 37 | | internal Fixed64 SaturatedSum => |
| | 594868 | 38 | | LinearA + LinearB + AngularA + AngularB; |
| | | 39 | | |
| | | 40 | | internal bool TryGetValue(out Fixed64 value) |
| | | 41 | | { |
| | 18768 | 42 | | bool resolved = |
| | 18768 | 43 | | Fixed64.TryAdd(LinearA, LinearB, out Fixed64 linear); |
| | 18768 | 44 | | resolved &= Fixed64.TryAdd( |
| | 18768 | 45 | | linear, |
| | 18768 | 46 | | AngularA, |
| | 18768 | 47 | | out Fixed64 first); |
| | 18768 | 48 | | resolved &= Fixed64.TryAdd(first, AngularB, out value); |
| | 18768 | 49 | | if (!resolved) |
| | 3 | 50 | | value = default; |
| | 18768 | 51 | | return resolved; |
| | | 52 | | } |
| | | 53 | | } |