From 8a19ade81bb9993a689d88ba45b5b288d5e44357 Mon Sep 17 00:00:00 2001 From: worldspawn Date: Wed, 11 Nov 2026 22:31:20 -0700 Subject: [PATCH] Implement StaticProp:OBBMins/Maxs --- Source.Common/Mathematics/MathLib.cs | 15 +++++++++++++++ Source.Engine/StaticPropMgr.cs | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Source.Common/Mathematics/MathLib.cs b/Source.Common/Mathematics/MathLib.cs index ccb92466..31438bfc 100644 --- a/Source.Common/Mathematics/MathLib.cs +++ b/Source.Common/Mathematics/MathLib.cs @@ -4010,6 +4010,21 @@ public static bool SolveInverseQuadraticMonotonic(float x1, float y1, float x2, } return true; } + + static InlineArray128 tempVectors = default; + static int tempVectorIndex; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ref Vector3 AllocTempVector() { + int Index; + while (true) { + int OldIndex = tempVectorIndex; + Index = (OldIndex + 0x10001) & 0x7F; + + if (Interlocked.CompareExchange(ref tempVectorIndex, Index, OldIndex) == OldIndex) + break; + } + return ref tempVectors[Index]; + } } [StructLayout(LayoutKind.Sequential, Pack = 16, Size = sizeof(float) * 4 * 3)] diff --git a/Source.Engine/StaticPropMgr.cs b/Source.Engine/StaticPropMgr.cs index 8f25ed11..a36bd663 100644 --- a/Source.Engine/StaticPropMgr.cs +++ b/Source.Engine/StaticPropMgr.cs @@ -676,8 +676,23 @@ public void SetRefEHandle(in BaseHandle handle) { public ref readonly Vector3 OBBMinsPreScaled() => ref OBBMins(); public ref readonly Vector3 OBBMaxsPreScaled() => ref OBBMaxs(); - public ref readonly Vector3 OBBMins() => throw new NotImplementedException(); - public ref readonly Vector3 OBBMaxs() => throw new NotImplementedException(); + + public ref readonly Vector3 OBBMins() { + if (GetSolid() == SolidType.VPhysics) { + return ref Model.Mins; + } + ref Vector3 tv = ref MathLib.AllocTempVector(); + MathLib.VectorSubtract(WorldRenderBBoxMin, GetCollisionOrigin(), out tv); + return ref tv; + } + public ref readonly Vector3 OBBMaxs() { + if (GetSolid() == SolidType.VPhysics) { + return ref Model.Maxs; + } + ref Vector3 tv = ref MathLib.AllocTempVector(); + MathLib.VectorSubtract(WorldRenderBBoxMax, GetCollisionOrigin(), out tv); + return ref tv; + } public bool TestCollision(in Ray ray, Contents contentsMask, ref Trace tr) { Assert(false);