refactor: apply std min/max

This commit is contained in:
Wellinator
2022-08-14 17:37:55 -03:00
parent 0d15d0c7c8
commit 83f07f4789
+7 -6
View File
@@ -15,9 +15,6 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
namespace Tyra { namespace Tyra {
Ray::Ray() {} Ray::Ray() {}
@@ -38,9 +35,13 @@ bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
float* outputDistance) const { float* outputDistance) const {
Vec4 _min = (minCorner - this->origin) / this->invDir(); Vec4 _min = (minCorner - this->origin) / this->invDir();
Vec4 _max = (minCorner - this->origin) / this->invDir(); Vec4 _max = (minCorner - this->origin) / this->invDir();
float tmin = MAX(MAX(MIN(_min.x, _max.x), MIN(_min.y, _max.y)), MIN(_min.z, _max.z)); float tmin =
float tmax = MIN(MIN(MAX(_min.x, _max.x), MAX(_min.y, _max.y)), MAX(_min.z, _max.z)); std::max(std::max(std::min(_min.x, _max.x), std::min(_min.y, _max.y)),
std::min(_min.z, _max.z));
float tmax =
std::min(std::min(std::max(_min.x, _max.x), std::max(_min.y, _max.y)),
std::max(_min.z, _max.z));
// if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behing us // if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behing us
if (tmax < 0) { if (tmax < 0) {