From 85f4f2e66631dc377a08201f2566b17a31995b43 Mon Sep 17 00:00:00 2001 From: Wellinator Date: Mon, 18 Jul 2022 16:11:46 -0300 Subject: [PATCH] refactor: moves isInFrustum from RenderBBox to CoreBBox --- .../inc/renderer/core/3d/bbox/core_bbox.hpp | 3 ++ .../inc/renderer/core/3d/bbox/render_bbox.hpp | 3 -- .../src/renderer/core/3d/bbox/core_bbox.cpp | 33 +++++++++++++++++++ .../src/renderer/core/3d/bbox/render_bbox.cpp | 33 ------------------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/engine/inc/renderer/core/3d/bbox/core_bbox.hpp b/engine/inc/renderer/core/3d/bbox/core_bbox.hpp index 7e0c4b1..b4314df 100644 --- a/engine/inc/renderer/core/3d/bbox/core_bbox.hpp +++ b/engine/inc/renderer/core/3d/bbox/core_bbox.hpp @@ -36,6 +36,9 @@ class CoreBBox { void print(const std::string& name) const { print(name.c_str()); } std::string getPrint(const char* name = nullptr) const; + CoreBBoxFrustum isInFrustum(const Plane* frustumPlanes, const M4x4& model, + const float* margins = nullptr) const; + protected: Vec4 _vertices[8]; }; diff --git a/engine/inc/renderer/core/3d/bbox/render_bbox.hpp b/engine/inc/renderer/core/3d/bbox/render_bbox.hpp index e45f092..b4904b0 100644 --- a/engine/inc/renderer/core/3d/bbox/render_bbox.hpp +++ b/engine/inc/renderer/core/3d/bbox/render_bbox.hpp @@ -25,9 +25,6 @@ class RenderBBox : public CoreBBox { explicit RenderBBox(const std::vector& t_bboxes, const u32& startIndex, const u32& stopIndex); - CoreBBoxFrustum isInFrustum(const Plane* frustumPlanes, const M4x4& model, - const float* margins = nullptr) const; - CoreBBoxFrustum clipIsInFrustum(const Plane* frustumPlanes, const M4x4& model) const; }; diff --git a/engine/src/renderer/core/3d/bbox/core_bbox.cpp b/engine/src/renderer/core/3d/bbox/core_bbox.cpp index 7341784..4903314 100644 --- a/engine/src/renderer/core/3d/bbox/core_bbox.cpp +++ b/engine/src/renderer/core/3d/bbox/core_bbox.cpp @@ -166,4 +166,37 @@ std::string CoreBBox::getPrint(const char* name) const { return res.str(); } +CoreBBoxFrustum CoreBBox::isInFrustum(const Plane* frustumPlanes, + const M4x4& model, + const float* margins) const { + CoreBBoxFrustum result = IN_FRUSTUM; + Vec4 boxCalcTemp; + u8 boxIn = 0, boxOut = 0; + + for (u8 i = 0; i < 6; i++) { + const auto margin = margins == nullptr ? 0.0F : margins[i]; + boxOut = 0; + boxIn = 0; + // for each corner of the box do ... + // get out of the cycle as soon as a box as corners + // both inside and out of the frustum + for (u8 y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++) { + boxCalcTemp = model * _vertices[y]; + + auto isOut = frustumPlanes[i].distanceTo(boxCalcTemp) < margin; + + if (isOut) + boxOut++; + else + boxIn++; + } + // if all corners are out + if (!boxIn) + return OUTSIDE_FRUSTUM; + else if (boxOut) + result = PARTIALLY_IN_FRUSTUM; + } + return result; +} + } // namespace Tyra diff --git a/engine/src/renderer/core/3d/bbox/render_bbox.cpp b/engine/src/renderer/core/3d/bbox/render_bbox.cpp index dc1465b..1d2cd1a 100644 --- a/engine/src/renderer/core/3d/bbox/render_bbox.cpp +++ b/engine/src/renderer/core/3d/bbox/render_bbox.cpp @@ -58,37 +58,4 @@ CoreBBoxFrustum RenderBBox::clipIsInFrustum(const Plane* frustumPlanes, return isInFrustum(frustumPlanes, model, margins); // Let's check it again } -CoreBBoxFrustum RenderBBox::isInFrustum(const Plane* frustumPlanes, - const M4x4& model, - const float* margins) const { - CoreBBoxFrustum result = IN_FRUSTUM; - Vec4 boxCalcTemp; - u8 boxIn = 0, boxOut = 0; - - for (u8 i = 0; i < 6; i++) { - const auto margin = margins == nullptr ? 0.0F : margins[i]; - boxOut = 0; - boxIn = 0; - // for each corner of the box do ... - // get out of the cycle as soon as a box as corners - // both inside and out of the frustum - for (u8 y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++) { - boxCalcTemp = model * _vertices[y]; - - auto isOut = frustumPlanes[i].distanceTo(boxCalcTemp) < margin; - - if (isOut) - boxOut++; - else - boxIn++; - } - // if all corners are out - if (!boxIn) - return OUTSIDE_FRUSTUM; - else if (boxOut) - result = PARTIALLY_IN_FRUSTUM; - } - return result; -} - } // namespace Tyra