Skip to content
Snippets Groups Projects
Commit cd8430f6 authored by Yoel's avatar Yoel
Browse files

Made all references const and added a new *-operator for transforming AABBs with matrices

parent 7b78ff1f
No related branches found
No related tags found
No related merge requests found
...@@ -11,12 +11,12 @@ AxisAlignedBoundingBox::AxisAlignedBoundingBox() ...@@ -11,12 +11,12 @@ AxisAlignedBoundingBox::AxisAlignedBoundingBox()
max(Vec3(std::numeric_limits<float>::infinity())) { max(Vec3(std::numeric_limits<float>::infinity())) {
} }
AxisAlignedBoundingBox::AxisAlignedBoundingBox(Vec3& min, Vec3& max) AxisAlignedBoundingBox::AxisAlignedBoundingBox(const Vec3& min, const Vec3& max)
: min(min), max(max) { : min(min), max(max) {
} }
// Operator // Operator
AxisAlignedBoundingBox AxisAlignedBoundingBox::operator+( AxisAlignedBoundingBox AxisAlignedBoundingBox::operator+(
AxisAlignedBoundingBox& rhs) const { const AxisAlignedBoundingBox& rhs) const {
Vec3 min(std::min<float>(min.x(), rhs.min.x()), Vec3 min(std::min<float>(min.x(), rhs.min.x()),
std::min<float>(min.y(), rhs.min.y()), std::min<float>(min.y(), rhs.min.y()),
std::min<float>(min.z(), rhs.min.z())); std::min<float>(min.z(), rhs.min.z()));
...@@ -28,7 +28,7 @@ AxisAlignedBoundingBox AxisAlignedBoundingBox::operator+( ...@@ -28,7 +28,7 @@ AxisAlignedBoundingBox AxisAlignedBoundingBox::operator+(
} }
// Methods // Methods
// https://education.siggraph.org/static/HyperGraph/raytrace/rtinter3.htm // https://education.siggraph.org/static/HyperGraph/raytrace/rtinter3.htm
bool AxisAlignedBoundingBox::intersects(cam::Ray& r) const { bool AxisAlignedBoundingBox::intersects(const cam::Ray& r) const {
float t1x = (min.x() - r.x0.x()) / r.d.x(); float t1x = (min.x() - r.x0.x()) / r.d.x();
float t2x = (max.x() - r.x0.x()) / r.d.x(); float t2x = (max.x() - r.x0.x()) / r.d.x();
float t1y = (min.y() - r.x0.y()) / r.d.y(); float t1y = (min.y() - r.x0.y()) / r.d.y();
...@@ -45,7 +45,7 @@ bool AxisAlignedBoundingBox::intersects(cam::Ray& r) const { ...@@ -45,7 +45,7 @@ bool AxisAlignedBoundingBox::intersects(cam::Ray& r) const {
return tmax >= tmin && r.in_range(tmax); return tmax >= tmin && r.in_range(tmax);
} }
bool AxisAlignedBoundingBox::contains(Vec3& v) const { bool AxisAlignedBoundingBox::contains(const Vec3& v) const {
bool x = min.x() <= v.x() && v.x() <= max.x(); bool x = min.x() <= v.x() && v.x() <= max.x();
bool y = min.y() <= v.y() && v.y() <= max.y(); bool y = min.y() <= v.y() && v.y() <= max.y();
bool z = min.z() <= v.z() && v.z() <= max.z(); bool z = min.z() <= v.z() && v.z() <= max.z();
......
#pragma once #pragma once
#include "../camera/Ray.h" #include "../camera/Ray.h"
#include "Mat4.h"
#include "Vec3.h" #include "Vec3.h"
namespace util { namespace util {
...@@ -8,12 +9,13 @@ namespace util { ...@@ -8,12 +9,13 @@ namespace util {
class AxisAlignedBoundingBox { class AxisAlignedBoundingBox {
public: public:
AxisAlignedBoundingBox(); AxisAlignedBoundingBox();
AxisAlignedBoundingBox(Vec3& min, Vec3& max); AxisAlignedBoundingBox(const Vec3& min, const Vec3& max);
// Operator // Operator
AxisAlignedBoundingBox operator+(AxisAlignedBoundingBox& rhs) const; AxisAlignedBoundingBox operator+(const AxisAlignedBoundingBox& rhs) const;
AxisAlignedBoundingBox operator*(const Mat4& rhs) const;
// Methods // Methods
bool intersects(cam::Ray& r) const; bool intersects(const cam::Ray& r) const;
bool contains(Vec3& v) const; bool contains(const Vec3& v) const;
Vec3 minBound() const; Vec3 minBound() const;
Vec3 maxBound() const; Vec3 maxBound() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment