From 53c134b0d526907710c03e4ee9282e4ffdf06bbc Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 13:38:26 +0100 Subject: [PATCH] Added: Integrated new BoundingBox class implentation with mesh_frame boundingbox calculations. --- src/engine/include/models/mesh_frame.hpp | 3 +++ src/engine/models/mesh_frame.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index 99ec249..f57b581 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -13,6 +13,7 @@ #include #include +#include "bounding_box.hpp" #include "math/point.hpp" #include "math/vector3.hpp" #include "./mesh_material.hpp" @@ -139,7 +140,9 @@ public: void calculateBoundingBoxes(); private: + /** Deprecated. It is advised to use BoundingBox class instead. */ Vector3 boundingBox[8]; + BoundingBox *boundingBoxObj; u8 _areSTsAllocated, _areVerticesAllocated, _areNormalsAllocated, diff --git a/src/engine/models/mesh_frame.cpp b/src/engine/models/mesh_frame.cpp index ff9883d..2180a57 100644 --- a/src/engine/models/mesh_frame.cpp +++ b/src/engine/models/mesh_frame.cpp @@ -37,6 +37,7 @@ MeshFrame::~MeshFrame() delete[] normals; if (_areMaterialsAllocated) delete[] materials; + delete boundingBoxObj; } // ---- @@ -121,6 +122,7 @@ void MeshFrame::calculateBoundingBoxes() if (hiZ < vertices[i].z) hiZ = vertices[i].z; } + boundingBox[0].set(lowX, lowY, lowZ); boundingBox[1].set(lowX, lowY, hiZ); boundingBox[2].set(lowX, hiY, lowZ); @@ -131,4 +133,12 @@ void MeshFrame::calculateBoundingBoxes() boundingBox[6].set(hiX, hiY, lowZ); boundingBox[7].set(hiX, hiY, hiZ); _isBoundingBoxCalculated = true; + + //Function temporarily is a hybrid between old Vector3[8] boundingbox and + //the new class implementation. Upon confirmation that new implementation + //works correctly, delete the old code. + + //BoundingBox is declared on the heap to prevent any ill-formed default + //constructor instantiated BoundingBox objects. + boundingBoxObj = new BoundingBox(boundingBox); }