From 12ef639516f0c6514e539f391b93eb32476bbbbf Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 13:33:22 +0100 Subject: [PATCH 01/26] Changed: Allowed obj_loader to load different .obj face element configurations. New authorised .obj face elements configurations: v, v/t, v/vt/vn, v//vn --- src/engine/loaders/obj_loader.cpp | 144 ++++++++++++++++++++++++++---- 1 file changed, 128 insertions(+), 16 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index a200589..dcebc70 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -71,31 +71,143 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ } else if (strcmp(lineHeader, "f") == 0) { - int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", - &vertexIndex[0], &coordIndex[0], &normalIndex[0], - &vertexIndex[1], &coordIndex[1], &normalIndex[1], - &vertexIndex[2], &coordIndex[2], &normalIndex[2]); - if (matches != 9) - PRINT_ERR(".obj can't be read by this simple parser. Try exporting with other options"); + + int* x; + fpos_t start; + fgetpos(file,&start); + int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",x,x,x,x,x,x,x,x,x); + fsetpos(file,&start); + int newerMatches =0; + + switch(matches) + { + /* Vs, VTs and VNs all set */ + case 9: + { + printf("Case 9\n\n"); + fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", + &vertexIndex[0], &coordIndex[0], &normalIndex[0], + &vertexIndex[1], &coordIndex[1], &normalIndex[1], + &vertexIndex[2], &coordIndex[2], &normalIndex[2]); + + } + break; + /* Loaded only two digits (V, VT) succesfuly. Not setting VN. */ + case 2: + { + printf("Case 2\n"); + fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n", + &vertexIndex[0], &coordIndex[0], + &vertexIndex[1], &coordIndex[1], + &vertexIndex[2], &coordIndex[2]); + + } + break; + /* Only V set. Checking for existance of VT or VN. */ + case 1: + { + printf("Case 1\n"); + /* Check for existance of V/// configuration.. */ + newerMatches = fscanf(file, "%d/// %d/// %d///\n",x,x,x); + fsetpos(file,&start); + if(newerMatches==3){ + /* Configuration confirmed. */ + fscanf(file, "%d/// %d/// %d///\n",&vertexIndex[0],&vertexIndex[1],&vertexIndex[2]); + + }else + { + /* Failed, checking configuration V//VN */ + newerMatches = fscanf(file, "%d//%d %d//%d %d//%d",x,x,x,x,x,x); + fsetpos(file,&start); + if(newerMatches==6){ + /* Configuration confirmed. */ + newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", + &vertexIndex[0], &normalIndex[0], + &vertexIndex[1], &normalIndex[1], + &vertexIndex[2], &normalIndex[2]); + } + else{ + /*Unknown configuration.*/ + PRINT_ERR("Unknown .obj face for .obj file!"); + printf("Obj file mentioned: \"%s\"\n",path); + } + } + } + default: + PRINT_ERR("Unknown faces format in .obj file!"); + printf(" \"%s\"\n",path); + break; + + } +/* if(ferror(file)) + PRINT_ERR("Failed to load .obj file \"%s\"."); else { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + int result=0; + char line [128]={'\0'}; + fgets(line,128,file); + + //if(fscanf - o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + }*/ + switch(matches) + { + case 9: + { + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + + o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + + o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); + faceI += 3; + break; + } + case 2: + { + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + + o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + + break; + } + case 1: + { + if(newerMatches==3) + { + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + } + else if(newerMatches==6) + { + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + + o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); + + } + break; + } - o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); - faceI += 3; } } } else break; + } o_result->calculateBoundingBoxes(); fclose(file); From d4f2a1e1a224fc5e3f9015afac8a857ccb8bb6d5 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 14:19:23 +0100 Subject: [PATCH 02/26] Restored: Undid the objloader changes, they should be in its own branch. --- src/engine/loaders/obj_loader.cpp | 144 ++++-------------------------- 1 file changed, 16 insertions(+), 128 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index dcebc70..a200589 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -71,143 +71,31 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ } else if (strcmp(lineHeader, "f") == 0) { - - int* x; - fpos_t start; - fgetpos(file,&start); - int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",x,x,x,x,x,x,x,x,x); - fsetpos(file,&start); - int newerMatches =0; - - switch(matches) - { - /* Vs, VTs and VNs all set */ - case 9: - { - printf("Case 9\n\n"); - fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", - &vertexIndex[0], &coordIndex[0], &normalIndex[0], - &vertexIndex[1], &coordIndex[1], &normalIndex[1], - &vertexIndex[2], &coordIndex[2], &normalIndex[2]); - - } - break; - /* Loaded only two digits (V, VT) succesfuly. Not setting VN. */ - case 2: - { - printf("Case 2\n"); - fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n", - &vertexIndex[0], &coordIndex[0], - &vertexIndex[1], &coordIndex[1], - &vertexIndex[2], &coordIndex[2]); - - } - break; - /* Only V set. Checking for existance of VT or VN. */ - case 1: - { - printf("Case 1\n"); - /* Check for existance of V/// configuration.. */ - newerMatches = fscanf(file, "%d/// %d/// %d///\n",x,x,x); - fsetpos(file,&start); - if(newerMatches==3){ - /* Configuration confirmed. */ - fscanf(file, "%d/// %d/// %d///\n",&vertexIndex[0],&vertexIndex[1],&vertexIndex[2]); - - }else - { - /* Failed, checking configuration V//VN */ - newerMatches = fscanf(file, "%d//%d %d//%d %d//%d",x,x,x,x,x,x); - fsetpos(file,&start); - if(newerMatches==6){ - /* Configuration confirmed. */ - newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", - &vertexIndex[0], &normalIndex[0], - &vertexIndex[1], &normalIndex[1], - &vertexIndex[2], &normalIndex[2]); - } - else{ - /*Unknown configuration.*/ - PRINT_ERR("Unknown .obj face for .obj file!"); - printf("Obj file mentioned: \"%s\"\n",path); - } - } - } - default: - PRINT_ERR("Unknown faces format in .obj file!"); - printf(" \"%s\"\n",path); - break; - - } -/* if(ferror(file)) - PRINT_ERR("Failed to load .obj file \"%s\"."); + int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", + &vertexIndex[0], &coordIndex[0], &normalIndex[0], + &vertexIndex[1], &coordIndex[1], &normalIndex[1], + &vertexIndex[2], &coordIndex[2], &normalIndex[2]); + if (matches != 9) + PRINT_ERR(".obj can't be read by this simple parser. Try exporting with other options"); else { - int result=0; - char line [128]={'\0'}; - fgets(line,128,file); - - //if(fscanf + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - }*/ - switch(matches) - { - case 9: - { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - - o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); - - o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); - faceI += 3; - break; - } - case 2: - { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - - o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); - - break; - } - case 1: - { - if(newerMatches==3) - { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - } - else if(newerMatches==6) - { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - - o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); - - } - break; - } + o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); + faceI += 3; } } } else break; - } o_result->calculateBoundingBoxes(); fclose(file); From 44776f7abad3834ee43a5f7003064d7af12550b5 Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 13:13:03 +0100 Subject: [PATCH 03/26] Added: Incomplete implenetation of BoundingBox class and BoundingBoxFace struct. --- src/engine/include/models/bounding_box.hpp | 69 ++++++++++++++++++++++ src/engine/models/bounding_box.cpp | 33 +++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/engine/include/models/bounding_box.hpp create mode 100644 src/engine/models/bounding_box.cpp diff --git a/src/engine/include/models/bounding_box.hpp b/src/engine/include/models/bounding_box.hpp new file mode 100644 index 0000000..98a9128 --- /dev/null +++ b/src/engine/include/models/bounding_box.hpp @@ -0,0 +1,69 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#ifndef _TYRA_BOUNDING_BOX_ +#define _TYRA_BOUNDING_BOX_ + +#include +#include +#include "math/point.hpp" +#include "math/vector3.hpp" + +/** + * Struct containing face data used in + * bounding box class. + */ +struct BoundingBoxFace +{ + BoundingBoxFace(Vector3 t_minCorner, Vector3 t_maxCorner, float t_axisPos) + { + minCorner = t_minCorner; + maxCorner = t_maxCorner; + axisPosition = t_axisPos; + } + /** Position of the face on it's respective axis. */ + float axisPosition; + /** Corner of the face with lower coordinates */ + Vector3 minCorner; + /** Corner of the face with higher coordinates */ + Vector3 maxCorner; +}; + +/** + * Class containing bounding box data + * which can be used for collision detection. + */ + +class BoundingBox +{ +public: + BoundingBox(Vector3 *t_vertices); + ~BoundingBox(); + const float &getHeight() { return _height; }; + const float &getDepth() { return _depth; }; + const float &getWidth() { return _width; }; + /** Return the vector directly in middle of the bounding box. */ + const Vector3 &getCenter() { return _centerVector; }; + /** Return the front face (furhter on z-axis) */ + const BoundingBoxFace &getFrontFace() { return _frontFace; }; + +private: + Vector3 _vertices[8]; + float _height, _depth, _width; + Vector3 _centerVector; + BoundingBoxFace _frontFace; + BoundingBoxFace _backFace; + BoundingBoxFace _leftFace; + BoundingBoxFace _rightFace; + BoundingBoxFace _topFace; + BoundingBoxFace _bottomFace; +}; + +#endif \ No newline at end of file diff --git a/src/engine/models/bounding_box.cpp b/src/engine/models/bounding_box.cpp new file mode 100644 index 0000000..e16f04e --- /dev/null +++ b/src/engine/models/bounding_box.cpp @@ -0,0 +1,33 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Michał Mostowik +*/ + +#include "../include/models/bounding_box.hpp" +#include "../include/utils/debug.hpp" + +BoundingBox::BoundingBox(Vector3 *t_vectorArray) +{ + if (sizeof(t_vectorArray) / sizeof(Vector3) != 8) + PRINT_ERR("Attempted to create bounding box with invalid count of vectors!"); + + //Perform a deep copy of vertex array parameter + for (int i = 0; i < 9; i++) + _vertices[i] = t_vectorArray[i]; + + //This might be shortened with Vector3 operator overloading, but current + //implementation is more human readable. + _height = _vertices[0].y - _vertices[2].y; + _width = _vertices[0].x - _vertices[4].x; + _depth = _vertices[0].z - _vertices[1].z; + + _centerVector = _vertices[0]; + _centerVector.x += (_width / 2); + _centerVector.y += (_height / 2); + _centerVector.z += (_depth / 2); +} \ No newline at end of file From 9b2d39505b9a35c0fd2b94d96eeab970c93f8095 Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 13:24:50 +0100 Subject: [PATCH 04/26] Added: BoundingBoxFaces assignments, calculations and doxygen comments. --- src/engine/include/models/bounding_box.hpp | 20 ++++++++++++++++++-- src/engine/models/bounding_box.cpp | 10 ++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/engine/include/models/bounding_box.hpp b/src/engine/include/models/bounding_box.hpp index 98a9128..b95244c 100644 --- a/src/engine/include/models/bounding_box.hpp +++ b/src/engine/include/models/bounding_box.hpp @@ -22,7 +22,7 @@ */ struct BoundingBoxFace { - BoundingBoxFace(Vector3 t_minCorner, Vector3 t_maxCorner, float t_axisPos) + BoundingBoxFace(const Vector3 &t_minCorner, const Vector3 &t_maxCorner, float t_axisPos) { minCorner = t_minCorner; maxCorner = t_maxCorner; @@ -51,18 +51,34 @@ public: const float &getWidth() { return _width; }; /** Return the vector directly in middle of the bounding box. */ const Vector3 &getCenter() { return _centerVector; }; - /** Return the front face (furhter on z-axis) */ + /** Return the front face (further on z-axis) */ const BoundingBoxFace &getFrontFace() { return _frontFace; }; + /** Return the back face (nearer on z-axis) */ + const BoundingBoxFace &getBackFace() { return _backFace; }; + /** Return the left face (further on x-axis) */ + const BoundingBoxFace &getLeftFace() { return _leftFace; }; + /** Return the right face (nearer on x-axis) */ + const BoundingBoxFace &getRightFace() { return _rightFace; }; + /** Return the top face (further on y-axis) */ + const BoundingBoxFace &getTopFace() { return _frontFace; }; + /** Return the bottom face (nearer on y-axis) */ + const BoundingBoxFace &getBottomFace() { return _bottomFace; }; private: Vector3 _vertices[8]; float _height, _depth, _width; Vector3 _centerVector; + /** Front face (further on z-axis) */ BoundingBoxFace _frontFace; + /** Back face (nearer on z-axis) */ BoundingBoxFace _backFace; + /** Left face (nearer on x-axis) */ BoundingBoxFace _leftFace; + /** Right face (further on x-axis) */ BoundingBoxFace _rightFace; + /** Top face (further on y-axis) */ BoundingBoxFace _topFace; + /** Bottom face (nearer on y-axis) */ BoundingBoxFace _bottomFace; }; diff --git a/src/engine/models/bounding_box.cpp b/src/engine/models/bounding_box.cpp index e16f04e..9191021 100644 --- a/src/engine/models/bounding_box.cpp +++ b/src/engine/models/bounding_box.cpp @@ -30,4 +30,14 @@ BoundingBox::BoundingBox(Vector3 *t_vectorArray) _centerVector.x += (_width / 2); _centerVector.y += (_height / 2); _centerVector.z += (_depth / 2); + + //Z-Axis faces + _frontFace = BoundingBoxFace(_vertices[1], _vertices[7], _vertices[1].z); + _backFace = BoundingBoxFace(_vertices[0], _vertices[6], _vertices[0].z); + //X-Axis faces + _leftFace = BoundingBoxFace(_vertices[0], _vertices[3], _vertices[0].x); + _rightFace = BoundingBoxFace(_vertices[4], _vertices[7], _vertices[4].x); + //Y-Axis faces + _topFace = BoundingBoxFace(_vertices[2], _vertices[7], _vertices[2].y); + _bottomFace = BoundingBoxFace(_vertices[0], _vertices[5], _vertices[0].y); } \ No newline at end of file From 53c134b0d526907710c03e4ee9282e4ffdf06bbc Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 13:38:26 +0100 Subject: [PATCH 05/26] 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); } From 596bf2d89a517cd0e8a7277d9e1c76e8730d6137 Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 13:44:48 +0100 Subject: [PATCH 06/26] Added: Mesh_frame getter for BoundingBox object pointer. --- src/engine/include/models/mesh_frame.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index f57b581..1630078 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -88,6 +88,11 @@ public: */ Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBox[i]; }; + /** + * Returns bounding box (AABB) object pointer. + */ + BoundingBox *getBoundingBoxP() { return boundingBoxObj; }; + // ---- // Setters // ---- From 11a4e2ee7652e26a4dc25cd78af0a6c0fe62f5de Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 14:11:50 +0100 Subject: [PATCH 07/26] Changed: Updated makefile to include new boundingboxes. --- src/engine/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine/Makefile b/src/engine/Makefile index 4164e49..78c621f 100644 --- a/src/engine/Makefile +++ b/src/engine/Makefile @@ -6,6 +6,7 @@ EE_OBJS = \ models/math/point.o \ models/math/vector3.o \ models/mesh_frame.o \ + models/bounding_box.o \ models/mesh_material.o \ models/mesh.o \ models/sprite.o \ From 55d8e445db27a6a5294ef1d6cff5cff367e1b6d4 Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 14:12:52 +0100 Subject: [PATCH 08/26] Fixed: Typo in bounding box getters. --- src/engine/include/models/bounding_box.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/engine/include/models/bounding_box.hpp b/src/engine/include/models/bounding_box.hpp index b95244c..1e7b364 100644 --- a/src/engine/include/models/bounding_box.hpp +++ b/src/engine/include/models/bounding_box.hpp @@ -22,6 +22,9 @@ */ struct BoundingBoxFace { + BoundingBoxFace(){ + + }; BoundingBoxFace(const Vector3 &t_minCorner, const Vector3 &t_maxCorner, float t_axisPos) { minCorner = t_minCorner; @@ -60,7 +63,7 @@ public: /** Return the right face (nearer on x-axis) */ const BoundingBoxFace &getRightFace() { return _rightFace; }; /** Return the top face (further on y-axis) */ - const BoundingBoxFace &getTopFace() { return _frontFace; }; + const BoundingBoxFace &getTopFace() { return _topFace; }; /** Return the bottom face (nearer on y-axis) */ const BoundingBoxFace &getBottomFace() { return _bottomFace; }; From 71ce30a8fca3852fcafa398a0bb180f8af5e6fd8 Mon Sep 17 00:00:00 2001 From: Foxar Date: Sun, 20 Dec 2020 14:13:47 +0100 Subject: [PATCH 09/26] Added: Destructor for boundingbox class. --- src/engine/models/bounding_box.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/engine/models/bounding_box.cpp b/src/engine/models/bounding_box.cpp index 9191021..ec487b2 100644 --- a/src/engine/models/bounding_box.cpp +++ b/src/engine/models/bounding_box.cpp @@ -13,9 +13,6 @@ BoundingBox::BoundingBox(Vector3 *t_vectorArray) { - if (sizeof(t_vectorArray) / sizeof(Vector3) != 8) - PRINT_ERR("Attempted to create bounding box with invalid count of vectors!"); - //Perform a deep copy of vertex array parameter for (int i = 0; i < 9; i++) _vertices[i] = t_vectorArray[i]; @@ -40,4 +37,8 @@ BoundingBox::BoundingBox(Vector3 *t_vectorArray) //Y-Axis faces _topFace = BoundingBoxFace(_vertices[2], _vertices[7], _vertices[2].y); _bottomFace = BoundingBoxFace(_vertices[0], _vertices[5], _vertices[0].y); +} + +BoundingBox::~BoundingBox() +{ } \ No newline at end of file From ae15906c9928d8ea2f854304b844c605ec314a97 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 18:30:18 +0100 Subject: [PATCH 10/26] Added: Accessors in bounding_box class allowing access to vertices array. --- src/engine/include/models/bounding_box.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/engine/include/models/bounding_box.hpp b/src/engine/include/models/bounding_box.hpp index 1e7b364..e2aaccc 100644 --- a/src/engine/include/models/bounding_box.hpp +++ b/src/engine/include/models/bounding_box.hpp @@ -66,6 +66,13 @@ public: const BoundingBoxFace &getTopFace() { return _topFace; }; /** Return the bottom face (nearer on y-axis) */ const BoundingBoxFace &getBottomFace() { return _bottomFace; }; + /** + * Returns bounding box raw vertices array. + * Total length: 8 + */ + Vector3 &getVertex(const u8 &i) { return _vertices[i]; }; + /** Returns single vertex from raw vertices array.*/ + Vector3 *getVertices() { return _vertices; }; private: Vector3 _vertices[8]; From 974138d64eb9514f501b9f1fb8316c985fc53985 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 18:31:23 +0100 Subject: [PATCH 11/26] Changed: Replaced old getBoundingBox and getBoundingBoxVertex functions with new ones, using the new bounding_box class infrastructure. --- src/engine/include/models/mesh_frame.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index 1630078..e3e2466 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -80,13 +80,15 @@ public: * Returns bounding box (AABB). * Total length: 8 */ - Vector3 *getBoundingBox() { return boundingBox; }; + //Vector3 *getBoundingBox() { return boundingBox; }; + Vector3 *getBoundingBox() { return boundingBoxObj->getVertices(); }; /** * Returns bounding box (AABB) vertex. * Total length: 8 */ - Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBox[i]; }; + //Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBox[i]; }; + Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; /** * Returns bounding box (AABB) object pointer. From d835f83e517f2b5a9b33aff5e04360c702bcafc4 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 18:48:11 +0100 Subject: [PATCH 12/26] Added: New BoundingBox infrastructure into mesh_material, analogous to mesh_frame. --- src/engine/include/models/mesh_material.hpp | 13 +++++++++++-- src/engine/models/mesh_material.cpp | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index 0b5447e..976a32b 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -12,6 +12,7 @@ #define _TYRA_MESH_MATERIAL_ #include +#include "bounding_box.hpp" #include "./math/vector3.hpp" #include "./math/plane.hpp" @@ -65,13 +66,20 @@ public: * Returns bounding box (AABB). * Total length: 8 */ - Vector3 *getBoundingBox() { return boundingBox; }; + //Vector3 *getBoundingBox() { return boundingBox; }; + Vector3 *getBoundingBox() { return boundingBoxObj->getVertices(); }; /** * Returns bounding box (AABB) vertex. * Total length: 8 */ - Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBox[i]; }; + //Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBox[i]; }; + Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; + + /** + * Returns bounding box (AABB) object pointer. + */ + BoundingBox *getBoundingBoxP() { return boundingBoxObj; }; // ---- // Setters @@ -120,6 +128,7 @@ public: private: Vector3 boundingBox[8]; + BoundingBox *boundingBoxObj; u32 facesCount, id; u32 *vertexFaces, *stFaces, *normalFaces; u8 _isNameSet, _areFacesAllocated, _isBoundingBoxCalculated; diff --git a/src/engine/models/mesh_material.cpp b/src/engine/models/mesh_material.cpp index f435ce6..bf4667e 100644 --- a/src/engine/models/mesh_material.cpp +++ b/src/engine/models/mesh_material.cpp @@ -9,6 +9,7 @@ */ #include "../include/models/mesh_material.hpp" +#include "../include/models/bounding_box.hpp" #include "../include/utils/debug.hpp" #include "../include/utils/string.hpp" #include @@ -132,4 +133,5 @@ void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount) boundingBox[6].set(hiX, hiY, lowZ); boundingBox[7].set(hiX, hiY, hiZ); _isBoundingBoxCalculated = true; + boundingBoxObj = new BoundingBox(boundingBox); } From 1765885bec0fb94668995ad5530c2053dcee57a4 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 18:57:01 +0100 Subject: [PATCH 13/26] Removed: Commented-out ('disabled') method declarations. --- src/engine/include/models/mesh_frame.hpp | 2 -- src/engine/include/models/mesh_material.hpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index e3e2466..8ffe8e0 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -80,14 +80,12 @@ public: * Returns bounding box (AABB). * Total length: 8 */ - //Vector3 *getBoundingBox() { return boundingBox; }; Vector3 *getBoundingBox() { return boundingBoxObj->getVertices(); }; /** * Returns bounding box (AABB) vertex. * Total length: 8 */ - //Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBox[i]; }; Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; /** diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index 976a32b..dffcf8d 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -66,14 +66,12 @@ public: * Returns bounding box (AABB). * Total length: 8 */ - //Vector3 *getBoundingBox() { return boundingBox; }; Vector3 *getBoundingBox() { return boundingBoxObj->getVertices(); }; /** * Returns bounding box (AABB) vertex. * Total length: 8 */ - //Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBox[i]; }; Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; /** From 1cc1e62ed6c9baab88620bca778ef07fec3528e7 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 19:03:40 +0100 Subject: [PATCH 14/26] Fixed: Fixed incorrect vertex array for-loop iteration. --- src/engine/models/bounding_box.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/models/bounding_box.cpp b/src/engine/models/bounding_box.cpp index ec487b2..271632f 100644 --- a/src/engine/models/bounding_box.cpp +++ b/src/engine/models/bounding_box.cpp @@ -14,7 +14,7 @@ BoundingBox::BoundingBox(Vector3 *t_vectorArray) { //Perform a deep copy of vertex array parameter - for (int i = 0; i < 9; i++) + for (int i = 0; i < 8; i++) _vertices[i] = t_vectorArray[i]; //This might be shortened with Vector3 operator overloading, but current From 02d79169255638f0c1ddf341981b951626542c11 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 19:04:34 +0100 Subject: [PATCH 15/26] Fixed: Fixed incorrect naming of boundingbox constructor parameters. --- src/engine/models/bounding_box.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/models/bounding_box.cpp b/src/engine/models/bounding_box.cpp index 271632f..948bacb 100644 --- a/src/engine/models/bounding_box.cpp +++ b/src/engine/models/bounding_box.cpp @@ -11,11 +11,11 @@ #include "../include/models/bounding_box.hpp" #include "../include/utils/debug.hpp" -BoundingBox::BoundingBox(Vector3 *t_vectorArray) +BoundingBox::BoundingBox(Vector3 *t_vertices) { //Perform a deep copy of vertex array parameter for (int i = 0; i < 8; i++) - _vertices[i] = t_vectorArray[i]; + _vertices[i] = t_vertices[i]; //This might be shortened with Vector3 operator overloading, but current //implementation is more human readable. From 586fe136ea0ef78d58621449eddb8f3fddc64fcc Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 19:05:33 +0100 Subject: [PATCH 16/26] Changed: Removed old vertex array boundingbox declaration, forced usage of temporary vector array in initial boundingbox calculations. --- src/engine/include/models/mesh_frame.hpp | 2 -- src/engine/include/models/mesh_material.hpp | 1 - src/engine/models/mesh_frame.cpp | 5 +---- src/engine/models/mesh_material.cpp | 10 +++++++--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index 8ffe8e0..8b4214f 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -145,8 +145,6 @@ public: void calculateBoundingBoxes(); private: - /** Deprecated. It is advised to use BoundingBox class instead. */ - Vector3 boundingBox[8]; BoundingBox *boundingBoxObj; u8 _areSTsAllocated, _areVerticesAllocated, diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index dffcf8d..b2588f9 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -125,7 +125,6 @@ public: u8 isInFrustum(Plane *t_frustumPlanes, const Vector3 &position); private: - Vector3 boundingBox[8]; BoundingBox *boundingBoxObj; u32 facesCount, id; u32 *vertexFaces, *stFaces, *normalFaces; diff --git a/src/engine/models/mesh_frame.cpp b/src/engine/models/mesh_frame.cpp index 2180a57..0e224cd 100644 --- a/src/engine/models/mesh_frame.cpp +++ b/src/engine/models/mesh_frame.cpp @@ -94,6 +94,7 @@ void MeshFrame::allocateMaterials(const u32 &t_val) void MeshFrame::calculateBoundingBoxes() { + Vector3 boundingBox[8]; if (!_areVerticesAllocated) { PRINT_ERR("Can't calculate bounding box, because vertices were not allocated!"); @@ -134,10 +135,6 @@ void MeshFrame::calculateBoundingBoxes() 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); diff --git a/src/engine/models/mesh_material.cpp b/src/engine/models/mesh_material.cpp index bf4667e..59e5daa 100644 --- a/src/engine/models/mesh_material.cpp +++ b/src/engine/models/mesh_material.cpp @@ -83,9 +83,9 @@ u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position) for (u8 y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++) { boxCalcTemp.set( - boundingBox[y].x + position.x, - boundingBox[y].y + position.y, - boundingBox[y].z + position.z); + boundingBoxObj->getVertices()[y].x + position.x, + boundingBoxObj->getVertices()[y].y + position.y, + boundingBoxObj->getVertices()[y].z + position.z); if (t_frustumPlanes[i].distanceTo(boxCalcTemp) < 0) boxOut++; else @@ -102,6 +102,7 @@ u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position) void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount) { + Vector3 boundingBox[8]; float lowX, lowY, lowZ, hiX, hiY, hiZ; lowX = hiX = t_vertices[vertexFaces[0]].x; lowY = hiY = t_vertices[vertexFaces[0]].y; @@ -133,5 +134,8 @@ void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount) boundingBox[6].set(hiX, hiY, lowZ); boundingBox[7].set(hiX, hiY, hiZ); _isBoundingBoxCalculated = true; + + //BoundingBox is declared on the heap to prevent any ill-formed default + //constructor instantiated BoundingBox objects. boundingBoxObj = new BoundingBox(boundingBox); } From 5c232aebce4b7df964ed219f3864c5bcb52814f6 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 19:32:40 +0100 Subject: [PATCH 17/26] Removed: Newline below a doxygen comment. --- src/engine/include/models/bounding_box.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/include/models/bounding_box.hpp b/src/engine/include/models/bounding_box.hpp index e2aaccc..1dec3ee 100644 --- a/src/engine/include/models/bounding_box.hpp +++ b/src/engine/include/models/bounding_box.hpp @@ -43,7 +43,6 @@ struct BoundingBoxFace * Class containing bounding box data * which can be used for collision detection. */ - class BoundingBox { public: From 9e1a9e8b3c51f0d10a2be3bd2ae16b90be3e8741 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 19:41:29 +0100 Subject: [PATCH 18/26] Changed: Renamed getBoundingBox() to getBoundingBoxVertices() as the function returns the array of vertices from the BoundingBox object. --- src/engine/include/models/mesh.hpp | 2 +- src/engine/include/models/mesh_frame.hpp | 4 ++-- src/engine/include/models/mesh_material.hpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/engine/include/models/mesh.hpp b/src/engine/include/models/mesh.hpp index aec1470..1de33bb 100644 --- a/src/engine/include/models/mesh.hpp +++ b/src/engine/include/models/mesh.hpp @@ -97,7 +97,7 @@ public: Vector3 &getCurrentBoundingBoxVertex(const u8 &i) { return frames[animState.currentFrame].getBoundingBoxVertex(i); }; /** Returns bounding box of current frame. Size: 8 */ - Vector3 *getCurrentBoundingBox() const { return frames[animState.currentFrame].getBoundingBox(); }; + Vector3 *getCurrentBoundingBox() const { return frames[animState.currentFrame].getBoundingBoxVertices(); }; // ---- // Setters diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index 8b4214f..6c33e89 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -80,7 +80,7 @@ public: * Returns bounding box (AABB). * Total length: 8 */ - Vector3 *getBoundingBox() { return boundingBoxObj->getVertices(); }; + Vector3 *getBoundingBoxVertices() { return boundingBoxObj->getVertices(); }; /** * Returns bounding box (AABB) vertex. @@ -91,7 +91,7 @@ public: /** * Returns bounding box (AABB) object pointer. */ - BoundingBox *getBoundingBoxP() { return boundingBoxObj; }; + BoundingBox *getBoundingBox() { return boundingBoxObj; }; // ---- // Setters diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index b2588f9..5099901 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -66,7 +66,7 @@ public: * Returns bounding box (AABB). * Total length: 8 */ - Vector3 *getBoundingBox() { return boundingBoxObj->getVertices(); }; + Vector3 *getBoundingBoxVertices() { return boundingBoxObj->getVertices(); }; /** * Returns bounding box (AABB) vertex. @@ -77,7 +77,7 @@ public: /** * Returns bounding box (AABB) object pointer. */ - BoundingBox *getBoundingBoxP() { return boundingBoxObj; }; + BoundingBox *getBoundingBox() { return boundingBoxObj; }; // ---- // Setters From 13f6a2ecb7a3ba5959234e0169209846f3e87220 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:02:51 +0100 Subject: [PATCH 19/26] Changed: Changed manual deep-copy of parameter vertex array to usage of memcpy() --- src/engine/models/bounding_box.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/models/bounding_box.cpp b/src/engine/models/bounding_box.cpp index 948bacb..15eb78d 100644 --- a/src/engine/models/bounding_box.cpp +++ b/src/engine/models/bounding_box.cpp @@ -10,12 +10,12 @@ #include "../include/models/bounding_box.hpp" #include "../include/utils/debug.hpp" +#include BoundingBox::BoundingBox(Vector3 *t_vertices) { //Perform a deep copy of vertex array parameter - for (int i = 0; i < 8; i++) - _vertices[i] = t_vertices[i]; + memcpy(_vertices, t_vertices, 8 * sizeof(Vector3)); //This might be shortened with Vector3 operator overloading, but current //implementation is more human readable. From cf07cf78c84b95cda6aed982c334653afe7e761f Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:06:55 +0100 Subject: [PATCH 20/26] Added: Comment for BoundingBox constructor parameters. --- src/engine/models/bounding_box.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine/models/bounding_box.cpp b/src/engine/models/bounding_box.cpp index 15eb78d..dc90364 100644 --- a/src/engine/models/bounding_box.cpp +++ b/src/engine/models/bounding_box.cpp @@ -12,6 +12,11 @@ #include "../include/utils/debug.hpp" #include +/** + * Construct a BoundingBox class + * Allows for user friendly access to bounding box data. + * @param t_vertices Array of 8 Vector3 elements. + */ BoundingBox::BoundingBox(Vector3 *t_vertices) { //Perform a deep copy of vertex array parameter From 8137bd56d8b49dc961ab2bf0340281ab21475ea7 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:07:34 +0100 Subject: [PATCH 21/26] Changed: Usage of getVertices()[y] to getVertex(y) --- src/engine/models/mesh_material.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/models/mesh_material.cpp b/src/engine/models/mesh_material.cpp index 59e5daa..d6108da 100644 --- a/src/engine/models/mesh_material.cpp +++ b/src/engine/models/mesh_material.cpp @@ -83,9 +83,9 @@ u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position) for (u8 y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++) { boxCalcTemp.set( - boundingBoxObj->getVertices()[y].x + position.x, - boundingBoxObj->getVertices()[y].y + position.y, - boundingBoxObj->getVertices()[y].z + position.z); + boundingBoxObj->getVertex(y).x + position.x, + boundingBoxObj->getVertex(y).y + position.y, + boundingBoxObj->getVertex(y).z + position.z); if (t_frustumPlanes[i].distanceTo(boxCalcTemp) < 0) boxOut++; else From f8f91c6b4954809675337e20b204ad6a04433d86 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:09:00 +0100 Subject: [PATCH 22/26] Changed: Return type of getVertex() to be const. --- src/engine/include/models/bounding_box.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/include/models/bounding_box.hpp b/src/engine/include/models/bounding_box.hpp index 1dec3ee..9ffafd5 100644 --- a/src/engine/include/models/bounding_box.hpp +++ b/src/engine/include/models/bounding_box.hpp @@ -69,7 +69,7 @@ public: * Returns bounding box raw vertices array. * Total length: 8 */ - Vector3 &getVertex(const u8 &i) { return _vertices[i]; }; + const Vector3 &getVertex(const u8 &i) { return _vertices[i]; }; /** Returns single vertex from raw vertices array.*/ Vector3 *getVertices() { return _vertices; }; From 115dac21bceee17e827be4647ad3025ecc616bc8 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:15:18 +0100 Subject: [PATCH 23/26] Changed: Return types in mesh_frame and mesh_materials for getBoundingBoxVertex() to const. --- src/engine/include/models/mesh_frame.hpp | 2 +- src/engine/include/models/mesh_material.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index 6c33e89..9b57699 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -86,7 +86,7 @@ public: * Returns bounding box (AABB) vertex. * Total length: 8 */ - Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; + const Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; /** * Returns bounding box (AABB) object pointer. diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index 5099901..47cf64b 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -72,7 +72,7 @@ public: * Returns bounding box (AABB) vertex. * Total length: 8 */ - Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; + const Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; /** * Returns bounding box (AABB) object pointer. From 23ea1a28f6a47c9e8ac7e7a9a727601dee25388c Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:22:40 +0100 Subject: [PATCH 24/26] Changed: Comments, boundingbox getters in mesh.hpp --- src/engine/include/models/mesh.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/engine/include/models/mesh.hpp b/src/engine/include/models/mesh.hpp index 1de33bb..1f9e7ea 100644 --- a/src/engine/include/models/mesh.hpp +++ b/src/engine/include/models/mesh.hpp @@ -94,10 +94,13 @@ public: * Returns bounding vertex of current frame. * @param i 0-7. Because, bounding box have 8 corners */ - Vector3 &getCurrentBoundingBoxVertex(const u8 &i) { return frames[animState.currentFrame].getBoundingBoxVertex(i); }; + const Vector3 &getCurrentBoundingBoxVertex(const u8 &i) { return frames[animState.currentFrame].getBoundingBoxVertex(i); }; - /** Returns bounding box of current frame. Size: 8 */ - Vector3 *getCurrentBoundingBox() const { return frames[animState.currentFrame].getBoundingBoxVertices(); }; + /** @returns bounding box vertex array of current frame. Size: 8 */ + const Vector3 *getCurrentBoundingBoxVertices() const { return frames[animState.currentFrame].getBoundingBoxVertices(); }; + + /** @returns bounding box object of current frame. */ + const BoundingBox *getCurrentBoundingBox() const { return frames[animState.currentFrame].getBoundingBox(); }; // ---- // Setters From ae3dd737e5662753d10d6426993a756b4a817ce7 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:28:26 +0100 Subject: [PATCH 25/26] Changed: Multiple const additions. --- src/engine/models/mesh.cpp | 2 +- src/samples/floors/utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/models/mesh.cpp b/src/engine/models/mesh.cpp index 84cddce..5a47159 100644 --- a/src/engine/models/mesh.cpp +++ b/src/engine/models/mesh.cpp @@ -347,7 +347,7 @@ u8 Mesh::isInFrustum(Plane *t_frustumPlanes) { Vector3 boxCalcTemp; u8 boxResult = 1, boxIn = 0, boxOut = 0; - Vector3 *currentBoundingBox = getCurrentBoundingBox(); + const Vector3 *currentBoundingBox = getCurrentBoundingBoxVertices(); for (int i = 0; i < 6; i++) { boxOut = 0; diff --git a/src/samples/floors/utils.cpp b/src/samples/floors/utils.cpp index 5195cf9..d8b1021 100644 --- a/src/samples/floors/utils.cpp +++ b/src/samples/floors/utils.cpp @@ -38,7 +38,7 @@ void Utils::getMinMax(const Mesh &t_mesh, Vector3 &t_min, Vector3 &t_max) { Vector3 calc = Vector3(); u8 isInitialized = 0; - Vector3 *boundingBox = t_mesh.getCurrentBoundingBox(); + const Vector3 *boundingBox = t_mesh.getCurrentBoundingBoxVertices(); for (u32 i = 0; i < 8; i++) { calc.set( From 3af357620372670078023a33e9812b3a7db622e2 Mon Sep 17 00:00:00 2001 From: Foxar Date: Mon, 21 Dec 2020 20:35:09 +0100 Subject: [PATCH 26/26] Added: Multiple doxygen @returns comments. --- src/engine/include/models/bounding_box.hpp | 18 +++++++++--------- src/engine/include/models/mesh_frame.hpp | 6 +++--- src/engine/include/models/mesh_material.hpp | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/engine/include/models/bounding_box.hpp b/src/engine/include/models/bounding_box.hpp index 9ffafd5..cab4a9b 100644 --- a/src/engine/include/models/bounding_box.hpp +++ b/src/engine/include/models/bounding_box.hpp @@ -51,26 +51,26 @@ public: const float &getHeight() { return _height; }; const float &getDepth() { return _depth; }; const float &getWidth() { return _width; }; - /** Return the vector directly in middle of the bounding box. */ + /** @returns the vector directly in middle of the bounding box. */ const Vector3 &getCenter() { return _centerVector; }; - /** Return the front face (further on z-axis) */ + /** @returns the front face (further on z-axis) */ const BoundingBoxFace &getFrontFace() { return _frontFace; }; - /** Return the back face (nearer on z-axis) */ + /** @returns the back face (nearer on z-axis) */ const BoundingBoxFace &getBackFace() { return _backFace; }; - /** Return the left face (further on x-axis) */ + /** @returns the left face (further on x-axis) */ const BoundingBoxFace &getLeftFace() { return _leftFace; }; - /** Return the right face (nearer on x-axis) */ + /** @returns the right face (nearer on x-axis) */ const BoundingBoxFace &getRightFace() { return _rightFace; }; - /** Return the top face (further on y-axis) */ + /** @returns the top face (further on y-axis) */ const BoundingBoxFace &getTopFace() { return _topFace; }; - /** Return the bottom face (nearer on y-axis) */ + /** @returns the bottom face (nearer on y-axis) */ const BoundingBoxFace &getBottomFace() { return _bottomFace; }; /** - * Returns bounding box raw vertices array. + * @returns bounding box raw vertices array. * Total length: 8 */ const Vector3 &getVertex(const u8 &i) { return _vertices[i]; }; - /** Returns single vertex from raw vertices array.*/ + /** @returns single vertex from raw vertices array.*/ Vector3 *getVertices() { return _vertices; }; private: diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index 9b57699..cd7c299 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -77,19 +77,19 @@ public: MeshMaterial *getMaterials() const { return materials; }; /** - * Returns bounding box (AABB). + * @returns bounding box (AABB). * Total length: 8 */ Vector3 *getBoundingBoxVertices() { return boundingBoxObj->getVertices(); }; /** - * Returns bounding box (AABB) vertex. + * @returns bounding box (AABB) vertex. * Total length: 8 */ const Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; /** - * Returns bounding box (AABB) object pointer. + * @returns bounding box (AABB) object pointer. */ BoundingBox *getBoundingBox() { return boundingBoxObj; }; diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index 47cf64b..3ba2621 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -63,19 +63,19 @@ public: u32 *getNormalFaces() const { return normalFaces; }; /** - * Returns bounding box (AABB). + * @returns bounding box (AABB). * Total length: 8 */ Vector3 *getBoundingBoxVertices() { return boundingBoxObj->getVertices(); }; /** - * Returns bounding box (AABB) vertex. + * @returns bounding box (AABB) vertex. * Total length: 8 */ const Vector3 &getBoundingBoxVertex(const u8 &i) { return boundingBoxObj->getVertex(i); }; /** - * Returns bounding box (AABB) object pointer. + * @returns bounding box (AABB) object pointer. */ BoundingBox *getBoundingBox() { return boundingBoxObj; };