From f651ec76ac6be73387b3967b0d6fffc3d0ea8b49 Mon Sep 17 00:00:00 2001 From: Wellinator Date: Mon, 18 Jul 2022 16:11:18 -0300 Subject: [PATCH 1/6] feat: implements ray --- engine/inc/physics/ray.hpp | 98 ++++++++++++++++++++++++++++++++++++++ engine/src/physics/ray.cpp | 92 +++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 engine/inc/physics/ray.hpp create mode 100644 engine/src/physics/ray.cpp diff --git a/engine/inc/physics/ray.hpp b/engine/inc/physics/ray.hpp new file mode 100644 index 0000000..af6c2ab --- /dev/null +++ b/engine/inc/physics/ray.hpp @@ -0,0 +1,98 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020-2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Wellington Carvalho +*/ + +#include "math/vec4.hpp" + +#pragma once + +namespace Tyra { + +/** + * Class for raycasting. + */ +class Ray { + public: + /** + * Constructor create a ampty ray + * + */ + Ray(); + + /** + * Constructor + * @param origin The origin of the ray + * @param direction The direction of the ray (normalized Vec4) + * + */ + Ray(Vec4* origin, Vec4* direction); + ~Ray(); + + Vec4 origin; + Vec4 direction; + + // Methods + + /** + * Set origin and direction + */ + void set(Vec4 origin, Vec4 direction); + + /** + * Set origin only + */ + void setOrigin(Vec4 origin); + void setOrigin(const float& t_x, const float& t_y, const float& t_z); + + /** + * Set direction only + */ + void setDirection(Vec4 origin); + void setDirection(const float& t_x, const float& t_y, const float& t_z); + + /** + * Return Vec4 that is a given distance along this Ray + * @param t - the distance along the Ray to retrieve a position for. + */ + Vec4 at(float t); + + /** + * Return the distance from the Vec4 point to the origin + */ + float distanceToPoint(Vec4 point); + + /** + * Returns distance from origin to intersected mesh + */ + float distanceTo(const Vec4& v) const; + + /** + * Returns Vec4 of intersection position + * @param minCorner - pointer to min corner position. (bottom left) + * @param maxCorner - pointer to max corner position. (top right) + * @param distance - the box to intersect with. + * + */ + u8 intersectBox(Vec4* minCorner, Vec4* maxCorner, float& distance); + + /** + * Returns distance from origin to intersected mesh + */ + inline const Vec4 getPosition() { return _position; }; + + /** + * Returns inverse direction + */ + Vec4 invDir(); + + private: + Vec4 _position; +}; + +} // namespace Tyra \ No newline at end of file diff --git a/engine/src/physics/ray.cpp b/engine/src/physics/ray.cpp new file mode 100644 index 0000000..e0bd436 --- /dev/null +++ b/engine/src/physics/ray.cpp @@ -0,0 +1,92 @@ +/* +# ______ ____ ___ +# | \/ ____| |___| +# | | | \ | | +#----------------------------------------------------------------------- +# Copyright 2020-2022, tyra - https://github.com/h4570/tyra +# Licenced under Apache License 2.0 +# Wellinator Carvalho +*/ + +#include "physics/ray.hpp" +#include +#include +#include + +namespace Tyra { + +Ray::Ray() {} +Ray::Ray(Vec4* origin, Vec4* direction) { + this->origin.set(origin->x, origin->y, origin->z); + this->direction.set(direction->x, direction->y, direction->z); +} + +Ray::~Ray() {} + +void Ray::set(Vec4 origin, Vec4 direction) { + this->origin.set(origin); + this->direction.set(direction); +} + +void Ray::setOrigin(Vec4 origin) { this->origin.set(origin); } + +void Ray::setOrigin(const float& t_x, const float& t_y, const float& t_z) { + this->origin.set(t_x, t_y, t_z); +} + +void Ray::setDirection(Vec4 direction) { this->direction.set(direction); } + +void Ray::setDirection(const float& t_x, const float& t_y, const float& t_z) { + this->direction.set(t_x, t_y, t_z); +} + +float Ray::distanceToPoint(Vec4 point) { return origin.distanceTo(point); } + +Vec4 Ray::at(float t) { return (this->direction * t) + this->origin; } + +u8 Ray::intersectBox(Vec4* minCorner, Vec4* maxCorner, float& distance) { + float tmin, tmax, tymin, tymax, tzmin, tzmax; + Vec4 invDir = this->invDir(); + invDir.normalize(); + + tmin = (minCorner->x - this->origin.x) * invDir.x; + tmax = (maxCorner->x - this->origin.x) * invDir.x; + tymin = (minCorner->y - this->origin.y) * invDir.y; + tymax = (maxCorner->y - this->origin.y) * invDir.y; + + if ((tmin > tymax) || (tymin > tmax)) { + distance = -1.0f; + return 0; + } + + if (tymin > tmin) tmin = tymin; + + if (tymax < tmax) tmax = tymax; + + tzmin = (minCorner->z - this->origin.z) * invDir.z; + tzmax = (maxCorner->z - this->origin.z) * invDir.z; + + if ((tmin > tzmax) || (tzmin > tmax)) { + distance = -1.0f; + return 0; + } + + if (tzmin > tmin) tmin = tzmin; + + if (tzmax < tmax) tmax = tzmax; + + if (tmax < 0) { + distance = -1.0f; + return 0; + } + + distance = tmin >= 0 ? tmin : tmax; + return 1; +} + +Vec4 Ray::invDir() { + return Vec4(1 / this->direction.x, 1 / this->direction.y, + 1 / this->direction.z); +} + +} // Namespace Tyra \ No newline at end of file From 85f4f2e66631dc377a08201f2566b17a31995b43 Mon Sep 17 00:00:00 2001 From: Wellinator Date: Mon, 18 Jul 2022 16:11:46 -0300 Subject: [PATCH 2/6] 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 From 07d7db97c24212454c2b8b13110194c469767c03 Mon Sep 17 00:00:00 2001 From: Wellinator Date: Mon, 18 Jul 2022 20:27:32 -0300 Subject: [PATCH 3/6] feat: implements min and max bbox methods --- engine/inc/renderer/3d/bbox/bbox.hpp | 14 +++++- engine/src/renderer/3d/bbox/bbox.cpp | 64 ++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/engine/inc/renderer/3d/bbox/bbox.hpp b/engine/inc/renderer/3d/bbox/bbox.hpp index 35fdd0c..06feaeb 100644 --- a/engine/inc/renderer/3d/bbox/bbox.hpp +++ b/engine/inc/renderer/3d/bbox/bbox.hpp @@ -41,9 +41,21 @@ class BBox : public CoreBBox { /** @returns the bottom face (nearer on y-axis) */ const BBoxFace& getBottomFace() { return _bottomFace; } + /** @returns the lower (x, y, z) boundary of the box. */ + const Vec4 min(); + /** @returns the upper (x, y, z) boundary of the box. */ + const Vec4 max(); + /** + * @returns void; + * @param res_min Vec4 to store the min result + * @param res_max Vec4 to store the min result + * @brief Calc and stores the min and max points of box at a single loop + * */ + void calcMinMax(Vec4& res_min, Vec4& res_max); + protected: float _height, _depth, _width; - Vec4 _centerVector; + Vec4 _centerVector, _min; /** Front face (further on z-axis) */ BBoxFace _frontFace; /** Back face (nearer on z-axis) */ diff --git a/engine/src/renderer/3d/bbox/bbox.cpp b/engine/src/renderer/3d/bbox/bbox.cpp index 64e5d20..07a0219 100644 --- a/engine/src/renderer/3d/bbox/bbox.cpp +++ b/engine/src/renderer/3d/bbox/bbox.cpp @@ -50,4 +50,68 @@ void BBox::setData() { _bottomFace = BBoxFace(_vertices[0], _vertices[5], _vertices[0].y); } +const Vec4 BBox::min() { + Vec4 temp, _min; + u8 isInitialized = 0; + + const Vec4* vertices = getVertices(); + for (u8 i = 0; i < 8; i++) { + temp.set(vertices[i].x, vertices[i].y, vertices[i].z, 1.0F); + if (isInitialized == 0) { + isInitialized = 1; + _min.set(temp); + } + + if (_min.x > temp.x) _min.x = temp.x; + if (_min.y > temp.y) _min.y = temp.y; + if (_min.z > temp.z) _min.z = temp.z; + } + + return _min; +} + +const Vec4 BBox::max() { + Vec4 temp, _max; + u8 isInitialized = 0; + + const Vec4* vertices = getVertices(); + for (u8 i = 0; i < 8; i++) { + temp.set(vertices[i].x, vertices[i].y, vertices[i].z, 1.0F); + if (isInitialized == 0) { + isInitialized = 1; + _max.set(temp); + } + + if (temp.x > _max.x) _max.x = temp.x; + if (temp.y > _max.y) _max.y = temp.y; + if (temp.z > _max.z) _max.z = temp.z; + } + + return _max; +} + +void BBox::calcMinMax(Vec4& res_min, Vec4& res_max) { + Vec4 temp = Vec4(); + + u8 isInitialized = 0; + const Vec4* vertices = getVertices(); + for (u8 i = 0; i < 8; i++) { + temp.set(vertices[i].x, vertices[i].y, vertices[i].z, 1.0F); + if (isInitialized == 0) { + isInitialized = 1; + res_min.set(temp); + res_max.set(temp); + } + + if (res_min.x > temp.x) res_min.x = temp.x; + if (temp.x > res_max.x) res_max.x = temp.x; + + if (res_min.y > temp.y) res_min.y = temp.y; + if (temp.y > res_max.y) res_max.y = temp.y; + + if (res_min.z > temp.z) res_min.z = temp.z; + if (temp.z > res_max.z) res_max.z = temp.z; + } +} + } // namespace Tyra From 86c11034bfccd3e16340ebad1ab0d6251bf7f414 Mon Sep 17 00:00:00 2001 From: h4570 Date: Tue, 19 Jul 2022 08:56:13 +0200 Subject: [PATCH 4/6] roadmap update --- ROADMAP.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ROADMAP.txt b/ROADMAP.txt index 114b9a2..28df7fa 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -1,11 +1,10 @@ ------------ Tyra's v2.0 roadmap to publish on GitHub ------------ --- H4570 -- [Renderer] Move clipping algorithm into VU1 -- [Renderer] Move animation calcs into VU1 -- [Renderer] Dbufferring during mesh unroll +- [Renderer] Static and dynamic pipeline +- [Renderer] Add possibility to on/off frustum check in all pipelines (renderOptions?) - [Loaders] Think about ".tyrobj" format - implement it (add multicolor support) -- [Loaders] DFF loader +- [Loaders] DFF loader as static Mesh loader - [Texture] Test cache hits with large amount of textures (dolphin sample?) - [Demo] Create cool demo which will show all features of Tyra (I will take this one) @@ -37,10 +36,10 @@ because this lines will be removed on make-release. Only debug stuff should be c - [Tutorials] 3. Minecraft cube - explain this pipeline, and explain that there are many 3D pipelines -- [Tutorials] 4. Mesh rendering - explain stdPipeline, render .tyrobj file via Mesh class, explain that this is high-level +- [Tutorials] 4. Mesh rendering - explain staticPipeline, render .tyrobj file via Mesh class, explain that this is high-level abstract 3D object class, and what it have (animation etc) -- [Tutorials] 5. Manual rendering via stdPipeline - via Render3DBag (core.render()), render simple poly, +- [Tutorials] 5. Manual rendering via staticPipeline - via Render3DBag (core.render()), render simple poly, explain that this is lower-level abstract rendering, it have the all the features as Mesh rendering, because Mesh rendering uses only core.render() From e7e4f375ba853291820fe74da5fa5e7f1bff2f28 Mon Sep 17 00:00:00 2001 From: Wellinator Date: Tue, 19 Jul 2022 08:59:04 -0300 Subject: [PATCH 5/6] refactor: apply review changes --- engine/inc/physics/ray.hpp | 79 ++++++++++++++------------------------ engine/src/physics/ray.cpp | 49 +++++++++++------------ 2 files changed, 52 insertions(+), 76 deletions(-) diff --git a/engine/inc/physics/ray.hpp b/engine/inc/physics/ray.hpp index af6c2ab..c940145 100644 --- a/engine/inc/physics/ray.hpp +++ b/engine/inc/physics/ray.hpp @@ -19,80 +19,59 @@ namespace Tyra { */ class Ray { public: - /** - * Constructor create a ampty ray - * - */ + /** @brief Constructor create a ampty ray */ Ray(); - /** - * Constructor + /** * @param origin The origin of the ray * @param direction The direction of the ray (normalized Vec4) - * */ - Ray(Vec4* origin, Vec4* direction); + Ray(const Vec4& origin, const Vec4& direction); ~Ray(); - Vec4 origin; - Vec4 direction; - // Methods /** - * Set origin and direction + * @param origin Vec4 starting point of the ray; + * @param direction Vec4 normalized vector pointing to direction; */ - void set(Vec4 origin, Vec4 direction); + void set(const Vec4& origin, const Vec4& direction); + + /** + * @brief Set origin of the ray; + * @param origin Vec4 starting point of the ray; + */ + void setOrigin(const Vec4& origin); + + /** + * @brief Set direction of the ray; + * @param direction Vec4 normalized vector pointing to direction; + */ + void setDirection(const Vec4& direction); /** - * Set origin only - */ - void setOrigin(Vec4 origin); - void setOrigin(const float& t_x, const float& t_y, const float& t_z); - - /** - * Set direction only - */ - void setDirection(Vec4 origin); - void setDirection(const float& t_x, const float& t_y, const float& t_z); - - /** - * Return Vec4 that is a given distance along this Ray + * @return Vec4 that is a given distance along this Ray * @param t - the distance along the Ray to retrieve a position for. */ - Vec4 at(float t); + Vec4 at(const float& t); + + /** @return Distance from the Vec4 point to the origin */ + float distanceToPoint(const Vec4& point); /** - * Return the distance from the Vec4 point to the origin - */ - float distanceToPoint(Vec4 point); - - /** - * Returns distance from origin to intersected mesh - */ - float distanceTo(const Vec4& v) const; - - /** - * Returns Vec4 of intersection position * @param minCorner - pointer to min corner position. (bottom left) * @param maxCorner - pointer to max corner position. (top right) * @param distance - the box to intersect with. - * + * @return Vec4 point of intersection */ - u8 intersectBox(Vec4* minCorner, Vec4* maxCorner, float& distance); + u8 intersectBox(const Vec4& minCorner, const Vec4& maxCorner, float& distance); - /** - * Returns distance from origin to intersected mesh - */ - inline const Vec4 getPosition() { return _position; }; - - /** - * Returns inverse direction - */ - Vec4 invDir(); + /** Returns inverse direction */ + const Vec4 invDir(); private: - Vec4 _position; + Vec4 _origin; + Vec4 _direction; }; } // namespace Tyra \ No newline at end of file diff --git a/engine/src/physics/ray.cpp b/engine/src/physics/ray.cpp index e0bd436..333c701 100644 --- a/engine/src/physics/ray.cpp +++ b/engine/src/physics/ray.cpp @@ -16,43 +16,40 @@ namespace Tyra { Ray::Ray() {} -Ray::Ray(Vec4* origin, Vec4* direction) { - this->origin.set(origin->x, origin->y, origin->z); - this->direction.set(direction->x, direction->y, direction->z); +Ray::Ray(const Vec4& origin, const Vec4& direction) { + this->_origin.set(origin); + this->_direction.set(direction); } Ray::~Ray() {} -void Ray::set(Vec4 origin, Vec4 direction) { - this->origin.set(origin); - this->direction.set(direction); +void Ray::set(const Vec4& origin, const Vec4& direction) { + this->_origin.set(origin); + this->_direction.set(direction); } -void Ray::setOrigin(Vec4 origin) { this->origin.set(origin); } +void Ray::setOrigin(const Vec4& origin) { this->_origin.set(origin); } -void Ray::setOrigin(const float& t_x, const float& t_y, const float& t_z) { - this->origin.set(t_x, t_y, t_z); +void Ray::setDirection(const Vec4& direction) { + this->_direction.set(direction); } -void Ray::setDirection(Vec4 direction) { this->direction.set(direction); } +Vec4 Ray::at(const float& t) { return (this->_direction * t) + this->_origin; } -void Ray::setDirection(const float& t_x, const float& t_y, const float& t_z) { - this->direction.set(t_x, t_y, t_z); +float Ray::distanceToPoint(const Vec4& point) { + return this->_origin.distanceTo(point); } -float Ray::distanceToPoint(Vec4 point) { return origin.distanceTo(point); } - -Vec4 Ray::at(float t) { return (this->direction * t) + this->origin; } - -u8 Ray::intersectBox(Vec4* minCorner, Vec4* maxCorner, float& distance) { +u8 Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner, + float& distance) { float tmin, tmax, tymin, tymax, tzmin, tzmax; Vec4 invDir = this->invDir(); invDir.normalize(); - tmin = (minCorner->x - this->origin.x) * invDir.x; - tmax = (maxCorner->x - this->origin.x) * invDir.x; - tymin = (minCorner->y - this->origin.y) * invDir.y; - tymax = (maxCorner->y - this->origin.y) * invDir.y; + tmin = (minCorner.x - this->_origin.x) * invDir.x; + tmax = (maxCorner.x - this->_origin.x) * invDir.x; + tymin = (minCorner.y - this->_origin.y) * invDir.y; + tymax = (maxCorner.y - this->_origin.y) * invDir.y; if ((tmin > tymax) || (tymin > tmax)) { distance = -1.0f; @@ -63,8 +60,8 @@ u8 Ray::intersectBox(Vec4* minCorner, Vec4* maxCorner, float& distance) { if (tymax < tmax) tmax = tymax; - tzmin = (minCorner->z - this->origin.z) * invDir.z; - tzmax = (maxCorner->z - this->origin.z) * invDir.z; + tzmin = (minCorner.z - this->_origin.z) * invDir.z; + tzmax = (maxCorner.z - this->_origin.z) * invDir.z; if ((tmin > tzmax) || (tzmin > tmax)) { distance = -1.0f; @@ -84,9 +81,9 @@ u8 Ray::intersectBox(Vec4* minCorner, Vec4* maxCorner, float& distance) { return 1; } -Vec4 Ray::invDir() { - return Vec4(1 / this->direction.x, 1 / this->direction.y, - 1 / this->direction.z); +const Vec4 Ray::invDir() { + return Vec4(1 / this->_direction.x, 1 / this->_direction.y, + 1 / this->_direction.z, 1); } } // Namespace Tyra \ No newline at end of file From 81686a8033ef15a5e9e754edeefbe16b70f33d45 Mon Sep 17 00:00:00 2001 From: Wellinator Date: Tue, 19 Jul 2022 09:12:00 -0300 Subject: [PATCH 6/6] refactor: apply review changes --- engine/inc/renderer/3d/bbox/bbox.hpp | 9 ++++----- engine/src/renderer/3d/bbox/bbox.cpp | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/engine/inc/renderer/3d/bbox/bbox.hpp b/engine/inc/renderer/3d/bbox/bbox.hpp index 06feaeb..57777d1 100644 --- a/engine/inc/renderer/3d/bbox/bbox.hpp +++ b/engine/inc/renderer/3d/bbox/bbox.hpp @@ -42,20 +42,19 @@ class BBox : public CoreBBox { const BBoxFace& getBottomFace() { return _bottomFace; } /** @returns the lower (x, y, z) boundary of the box. */ - const Vec4 min(); + Vec4 min(); /** @returns the upper (x, y, z) boundary of the box. */ - const Vec4 max(); + Vec4 max(); /** - * @returns void; * @param res_min Vec4 to store the min result * @param res_max Vec4 to store the min result * @brief Calc and stores the min and max points of box at a single loop * */ - void calcMinMax(Vec4& res_min, Vec4& res_max); + void getMinMax(Vec4* res_min, Vec4* res_max); protected: float _height, _depth, _width; - Vec4 _centerVector, _min; + Vec4 _centerVector; /** Front face (further on z-axis) */ BBoxFace _frontFace; /** Back face (nearer on z-axis) */ diff --git a/engine/src/renderer/3d/bbox/bbox.cpp b/engine/src/renderer/3d/bbox/bbox.cpp index 07a0219..db8b4ad 100644 --- a/engine/src/renderer/3d/bbox/bbox.cpp +++ b/engine/src/renderer/3d/bbox/bbox.cpp @@ -50,7 +50,7 @@ void BBox::setData() { _bottomFace = BBoxFace(_vertices[0], _vertices[5], _vertices[0].y); } -const Vec4 BBox::min() { +Vec4 BBox::min() { Vec4 temp, _min; u8 isInitialized = 0; @@ -70,7 +70,7 @@ const Vec4 BBox::min() { return _min; } -const Vec4 BBox::max() { +Vec4 BBox::max() { Vec4 temp, _max; u8 isInitialized = 0; @@ -90,7 +90,7 @@ const Vec4 BBox::max() { return _max; } -void BBox::calcMinMax(Vec4& res_min, Vec4& res_max) { +void BBox::getMinMax(Vec4* res_min, Vec4* res_max) { Vec4 temp = Vec4(); u8 isInitialized = 0; @@ -99,18 +99,18 @@ void BBox::calcMinMax(Vec4& res_min, Vec4& res_max) { temp.set(vertices[i].x, vertices[i].y, vertices[i].z, 1.0F); if (isInitialized == 0) { isInitialized = 1; - res_min.set(temp); - res_max.set(temp); + res_min->set(temp); + res_max->set(temp); } - if (res_min.x > temp.x) res_min.x = temp.x; - if (temp.x > res_max.x) res_max.x = temp.x; + if (res_min->x > temp.x) res_min->x = temp.x; + if (temp.x > res_max->x) res_max->x = temp.x; - if (res_min.y > temp.y) res_min.y = temp.y; - if (temp.y > res_max.y) res_max.y = temp.y; + if (res_min->y > temp.y) res_min->y = temp.y; + if (temp.y > res_max->y) res_max->y = temp.y; - if (res_min.z > temp.z) res_min.z = temp.z; - if (temp.z > res_max.z) res_max.z = temp.z; + if (res_min->z > temp.z) res_min->z = temp.z; + if (temp.z > res_max->z) res_max->z = temp.z; } }