fix: MIN MAX definitions;
refactor: reduce t variables to Vec4
This commit is contained in:
@@ -15,6 +15,9 @@
|
|||||||
#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() {}
|
||||||
@@ -33,15 +36,11 @@ float Ray::distanceToPoint(const Vec4& point) const {
|
|||||||
|
|
||||||
bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
|
bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
|
||||||
float* outputDistance) const {
|
float* outputDistance) const {
|
||||||
float t1 = (min->x - origin->x) / dir->x;
|
Vec4 _min = (minCorner - this->origin) / this->invDir();
|
||||||
float t2 = (max->x - origin->x) / dir->x;
|
Vec4 _max = (minCorner - this->origin) / this->invDir();
|
||||||
float t3 = (min->y - origin->y) / dir->y;
|
|
||||||
float t4 = (max->y - origin->y) / dir->y;
|
float tmin = MAX(MAX(MIN(_min.x, _max.x), MIN(_min.y, _max.y)), MIN(_min.z, _max.z));
|
||||||
float t5 = (min->z - origin->z) / dir->z;
|
float tmax = MIN(MIN(MAX(_min.x, _max.x), MAX(_min.y, _max.y)), MAX(_min.z, _max.z));
|
||||||
float t6 = (max->z - origin->z) / dir->z;
|
|
||||||
|
|
||||||
float tmin = MAX(MAX(MIN(t1, t2), MIN(t3, t4)), MIN(t5, t6));
|
|
||||||
float tmax = MIN(MIN(MAX(t1, t2), MAX(t3, t4)), MAX(t5, t6));
|
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user