From bbf7896218aebabb93d321619fc4896fe6131924 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 8 Jul 2022 20:17:30 +0200 Subject: [PATCH] Move GetBoxCorners to mathlib Renamed to 'PointsFromAngledBox' (no longer adds origin by default). --- r5dev/mathlib/mathlib.h | 15 ++++++++++- r5dev/mathlib/mathlib_base.cpp | 46 +++++++++++++++++++++++++++++++- r5dev/tier2/renderutils.cpp | 48 ++++++++++------------------------ r5dev/tier2/renderutils.h | 1 - 4 files changed, 73 insertions(+), 37 deletions(-) diff --git a/r5dev/mathlib/mathlib.h b/r5dev/mathlib/mathlib.h index 197b0b5c..90cf5ac9 100644 --- a/r5dev/mathlib/mathlib.h +++ b/r5dev/mathlib/mathlib.h @@ -3126,9 +3126,22 @@ inline float matrix3x4_t::GetSylvestersCriterion()const // | / | / // |/ |/ // 0---4 --> +x -// void PointsFromBox(const Vector3D& mins, const Vector3D& maxs, Vector3D* points); void BuildTransformedBox(Vector3D* v2, Vector3D const& bbmin, Vector3D const& bbmax, const matrix3x4_t& m); +// generate the corner points of a angled box: +// +y*r _+z*u +// ^ /| +// | / +// | 3---7 +// /| /| +// / | / | +// 2---6 | +// | 1|--5 +// | / | / +// |/ |/ +// 0---4 --> +x*f +void PointsFromAngledBox(const QAngle& angles, const Vector3D& mins, const Vector3D& maxs, Vector3D* points); +void BuildTransformedAngledBox(Vector3D* v2, const QAngle& a, Vector3D const& bbmin, Vector3D const& bbmax, const matrix3x4_t& m); diff --git a/r5dev/mathlib/mathlib_base.cpp b/r5dev/mathlib/mathlib_base.cpp index a9894eaf..dc6b6592 100644 --- a/r5dev/mathlib/mathlib_base.cpp +++ b/r5dev/mathlib/mathlib_base.cpp @@ -5826,7 +5826,6 @@ const Quaternion RandomQuaternion(IUniformRandomStream* pRnd) // | / | / // |/ |/ // 0---4 --> +x -// void PointsFromBox(const Vector3D& mins, const Vector3D& maxs, Vector3D* points) { points[0][0] = mins[0]; @@ -5877,5 +5876,50 @@ void BuildTransformedBox(Vector3D* v2, Vector3D const& bbmin, Vector3D const& bb VectorTransform(v[7], m, v2[7]); } +// Generate the corner points of a angled box: +// +y*r _+z*u +// ^ /| +// | / +// | 3---7 +// /| /| +// / | / | +// 2---6 | +// | 1|--5 +// | / | / +// |/ |/ +// 0---4 --> +x*f +void PointsFromAngledBox(const QAngle& angles, const Vector3D& mins, const Vector3D& maxs, Vector3D* points) +{ + Vector3D forward; + Vector3D up; + Vector3D right; + + AngleVectors(angles, &forward, &right, &up); + + points[0] = (forward * mins.x) + (right * maxs.y) + (up * maxs.z); + points[1] = (forward * mins.x) + (right * mins.y) + (up * maxs.z); + points[2] = (forward * maxs.x) + (right * mins.y) + (up * maxs.z); + points[3] = (forward * maxs.x) + (right * maxs.y) + (up * maxs.z); + points[4] = (forward * mins.x) + (right * maxs.y) + (up * mins.z); + points[5] = (forward * mins.x) + (right * mins.y) + (up * mins.z); + points[6] = (forward * maxs.x) + (right * mins.y) + (up * mins.z); + points[7] = (forward * maxs.x) + (right * maxs.y) + (up * mins.z); +} + +void BuildTransformedAngledBox(Vector3D* v2, const QAngle& a, Vector3D const& bbmin, Vector3D const& bbmax, const matrix3x4_t& m) +{ + Vector3D v[8]; + PointsFromAngledBox(a, bbmin, bbmax, v); + + VectorTransform(v[0], m, v2[0]); + VectorTransform(v[1], m, v2[1]); + VectorTransform(v[2], m, v2[2]); + VectorTransform(v[3], m, v2[3]); + VectorTransform(v[4], m, v2[4]); + VectorTransform(v[5], m, v2[5]); + VectorTransform(v[6], m, v2[6]); + VectorTransform(v[7], m, v2[7]); +} + #endif // !defined(__SPU__) diff --git a/r5dev/tier2/renderutils.cpp b/r5dev/tier2/renderutils.cpp index c250e626..39a6b063 100644 --- a/r5dev/tier2/renderutils.cpp +++ b/r5dev/tier2/renderutils.cpp @@ -13,45 +13,25 @@ #include "tier2/renderutils.h" #include "engine/debugoverlay.h" -Vector3D* GetBoxCorners(Vector3D org, QAngle ang, Vector3D mins, Vector3D maxs) +void DrawAngledBox(const Vector3D& origin, const QAngle& angles, Vector3D mins, Vector3D maxs, int r, int g, int b, int a, bool throughSolid) { - Vector3D forward; - Vector3D up; - Vector3D right; - - AngleVectors(ang, &forward, &right, &up); - Vector3D orgs[8]; - orgs[0] = org + (forward * mins.x) + (right * maxs.y) + (up * maxs.z); - orgs[1] = org + (forward * mins.x) + (right * mins.y) + (up * maxs.z); - orgs[2] = org + (forward * maxs.x) + (right * mins.y) + (up * maxs.z); - orgs[3] = org + (forward * maxs.x) + (right * maxs.y) + (up * maxs.z); - orgs[4] = org + (forward * mins.x) + (right * maxs.y) + (up * mins.z); - orgs[5] = org + (forward * mins.x) + (right * mins.y) + (up * mins.z); - orgs[6] = org + (forward * maxs.x) + (right * mins.y) + (up * mins.z); - orgs[7] = org + (forward * maxs.x) + (right * maxs.y) + (up * mins.z); + PointsFromAngledBox(angles, mins, maxs, &*orgs); - return orgs; -} + v_RenderLine(origin + orgs[0], origin + orgs[1], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[1], origin + orgs[2], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[2], origin + orgs[3], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[3], origin + orgs[0], Color(r, g, b, a), throughSolid); -void DrawAngledBox(Vector3D org, QAngle ang, Vector3D mins, Vector3D maxs, int r, int g, int b, int a, bool throughSolid) -{ - Vector3D* orgs = GetBoxCorners(org, ang, mins, maxs); + v_RenderLine(origin + orgs[4], origin + orgs[5], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[5], origin + orgs[6], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[6], origin + orgs[7], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[7], origin + orgs[4], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[0], orgs[1], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[1], orgs[2], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[2], orgs[3], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[3], orgs[0], Color(r, g, b, a), throughSolid); - - v_RenderLine(orgs[4], orgs[5], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[5], orgs[6], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[6], orgs[7], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[7], orgs[4], Color(r, g, b, a), throughSolid); - - v_RenderLine(orgs[0], orgs[4], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[1], orgs[5], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[2], orgs[6], Color(r, g, b, a), throughSolid); - v_RenderLine(orgs[3], orgs[7], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[0], origin + orgs[4], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[1], origin + orgs[5], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[2], origin + orgs[6], Color(r, g, b, a), throughSolid); + v_RenderLine(origin + orgs[3], origin + orgs[7], Color(r, g, b, a), throughSolid); } void RenderCapsule(const Vector3D& vStart, const Vector3D& vEnd, const float& flRadius, Color c) diff --git a/r5dev/tier2/renderutils.h b/r5dev/tier2/renderutils.h index b1ddd62c..8df62e94 100644 --- a/r5dev/tier2/renderutils.h +++ b/r5dev/tier2/renderutils.h @@ -2,7 +2,6 @@ #define RENDERUTILS_H #include "mathlib/vector.h" -Vector3D* GetBoxCorners(Vector3D org, QAngle ang, Vector3D mins, Vector3D maxs); void DrawAngledBox(Vector3D org, QAngle ang, Vector3D mins, Vector3D maxs, int r, int g, int b, int a, bool throughSolid); void RenderCapsule(const Vector3D& vStart, const Vector3D& vEnd, const float& flRadius, Color c);