ray class api change
This commit is contained in:
+20
-32
@@ -16,40 +16,28 @@
|
||||
namespace Tyra {
|
||||
|
||||
Ray::Ray() {}
|
||||
Ray::Ray(const Vec4& origin, const Vec4& direction) {
|
||||
this->_origin.set(origin);
|
||||
this->_direction.set(direction);
|
||||
Ray::Ray(const Vec4& t_origin, const Vec4& t_direction) {
|
||||
origin.set(t_origin);
|
||||
direction.set(t_direction);
|
||||
}
|
||||
|
||||
Ray::~Ray() {}
|
||||
|
||||
void Ray::set(const Vec4& origin, const Vec4& direction) {
|
||||
this->_origin.set(origin);
|
||||
this->_direction.set(direction);
|
||||
Vec4 Ray::at(const float& t) const { return (direction * t) + origin; }
|
||||
|
||||
float Ray::distanceToPoint(const Vec4& point) const {
|
||||
return origin.distanceTo(point);
|
||||
}
|
||||
|
||||
void Ray::setOrigin(const Vec4& origin) { this->_origin.set(origin); }
|
||||
bool Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
|
||||
float& distance) const {
|
||||
auto inv = invDir();
|
||||
inv.normalize();
|
||||
|
||||
void Ray::setDirection(const Vec4& direction) {
|
||||
this->_direction.set(direction);
|
||||
}
|
||||
|
||||
Vec4 Ray::at(const float& t) { return (this->_direction * t) + this->_origin; }
|
||||
|
||||
float Ray::distanceToPoint(const Vec4& point) {
|
||||
return this->_origin.distanceTo(point);
|
||||
}
|
||||
|
||||
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;
|
||||
float tmin = (minCorner.x - this->origin.x) * inv.x;
|
||||
float tmax = (maxCorner.x - this->origin.x) * inv.x;
|
||||
float tymin = (minCorner.y - this->origin.y) * inv.y;
|
||||
float tymax = (maxCorner.y - this->origin.y) * inv.y;
|
||||
|
||||
if ((tmin > tymax) || (tymin > tmax)) {
|
||||
distance = -1.0f;
|
||||
@@ -60,8 +48,8 @@ u8 Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
|
||||
|
||||
if (tymax < tmax) tmax = tymax;
|
||||
|
||||
tzmin = (minCorner.z - this->_origin.z) * invDir.z;
|
||||
tzmax = (maxCorner.z - this->_origin.z) * invDir.z;
|
||||
float tzmin = (minCorner.z - this->origin.z) * inv.z;
|
||||
float tzmax = (maxCorner.z - this->origin.z) * inv.z;
|
||||
|
||||
if ((tmin > tzmax) || (tzmin > tmax)) {
|
||||
distance = -1.0f;
|
||||
@@ -81,9 +69,9 @@ u8 Ray::intersectBox(const Vec4& minCorner, const Vec4& maxCorner,
|
||||
return 1;
|
||||
}
|
||||
|
||||
const Vec4 Ray::invDir() {
|
||||
return Vec4(1 / this->_direction.x, 1 / this->_direction.y,
|
||||
1 / this->_direction.z, 1);
|
||||
Vec4 Ray::invDir() const {
|
||||
return Vec4(1 / this->direction.x, 1 / this->direction.y,
|
||||
1 / this->direction.z, 1);
|
||||
}
|
||||
|
||||
} // Namespace Tyra
|
||||
Reference in New Issue
Block a user