change distance to output distance pointer

This commit is contained in:
h4570
2022-08-14 20:29:56 +02:00
parent 156973714b
commit d5261dbb0c
2 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -45,11 +45,11 @@ class Ray {
/**
* @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.
* @param outputDistance - optional - distance the box to intersect with.
* @return Vec4 point of intersection
*/
bool intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
const float& distance) const;
float* outputDistance = nullptr) const;
/** Returns inverse direction */
Vec4 invDir() const;
+9 -9
View File
@@ -32,7 +32,7 @@ float Ray::distanceToPoint(const Vec4& point) const {
}
bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
const float& distance) const {
float* outputDistance) const {
auto inv = invDir();
inv.normalize();
@@ -42,8 +42,7 @@ bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
float tymax = (maxCorner.y - this->origin.y) * inv.y;
if ((tmin > tymax) || (tymin > tmax)) {
distance = -1.0f;
return 0;
return false;
}
if (tymin > tmin) tmin = tymin;
@@ -54,8 +53,7 @@ bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
float tzmax = (maxCorner.z - this->origin.z) * inv.z;
if ((tmin > tzmax) || (tzmin > tmax)) {
distance = -1.0f;
return 0;
return false;
}
if (tzmin > tmin) tmin = tzmin;
@@ -63,12 +61,14 @@ bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
if (tzmax < tmax) tmax = tzmax;
if (tmax < 0) {
distance = -1.0f;
return 0;
return false;
}
distance = tmin >= 0 ? tmin : tmax;
return 1;
if (outputDistance != nullptr) {
*outputDistance = tmin >= 0 ? tmin : tmax;
}
return true;
}
Vec4 Ray::invDir() const {