20 #include "Geometry/mathlib.h"
101 return 2 * (d.x * d.y + d.x * d.z + d.y * d.z);
116 ret.
pMax.x = std::max(b.
pMax.x, p.x);
117 ret.
pMax.y = std::max(b.
pMax.y, p.y);
118 ret.
pMax.z = std::max(b.
pMax.z, p.z);
214 return (x && y && z);
252 decimal invRayDir, tNear, tFar;
256 invRayDir = 1 / rayDir.x;
257 tNear = (
pMin.x - rayPos.x) * invRayDir;
258 tFar = (
pMax.x - rayPos.x) * invRayDir;
262 std::swap(tNear, tFar);
264 t0 = tNear > t0 ? tNear : t0;
265 t1 = tFar < t1 ? tFar : t1;
273 invRayDir = 1 / rayDir.y;
274 tNear = (
pMin.y - rayPos.y) * invRayDir;
275 tFar = (
pMax.y - rayPos.y) * invRayDir;
279 std::swap(tNear, tFar);
281 t0 = tNear > t0 ? tNear : t0;
282 t1 = tFar < t1 ? tFar : t1;
290 invRayDir = 1 / rayDir.z;
291 tNear = (
pMin.z - rayPos.z) * invRayDir;
292 tFar = (
pMax.z - rayPos.z) * invRayDir;
296 std::swap(tNear, tFar);
298 t0 = tNear > t0 ? tNear : t0;
299 t1 = tFar < t1 ? tFar : t1;
362 return (pt.x >=
pMin.x && pt.x <=
pMax.x && pt.y >=
pMin.y && pt.y <=
pMax.y && pt.z >=
pMin.z &&
Definition of a bounding box which is aligned along the axis (BBox AABB).
vec3 pMax
Upper point of the BBox.
bool IntersectP(vec3 rayPos, vec3 rayDir, decimal *hitt0=NULL, decimal *hitt1=NULL) const
Compute the intersection between a Ray and this BBox.
BBox Union(const BBox &b, const vec3 &p)
Union of a point and a BBox. A new BBox is created.
decimal diag()
Diagonal length of the BBox.
void setBBMax(vec3 &_pMax)
Set the upper point (center point is recomputed)
BBox Union(const BBox &b2)
Union of a BBox and the current one. A new BBox is created.
vec3 centroid
Center point of the BBox.
vec3 getCentroid()
Return the center point.
bool Inside(const vec3 &pt) const
Return true if the point pt is inside the BBox.
vec3 pMin
Lower point of the BBox.
BBox(const BBox &other)
Copy constructor.
double SurfaceArea() const
Return the BBox area (sum of the lateral areas). Used for the SAH calculation of the accelerators.
BBox(const vec3 &_pMin, const vec3 &_pMax)
Constructor with initialization of the 3 points of the BBox.
void setBBMin(vec3 &_pMin)
Set the lower point (center point is recomputed)
bool intersectBox(const BBox &box)
Test the intersection of a BBox with this one.
BBox Union(const BBox &b1, const BBox &b2)
Union of two BBox. A new BBox is created.
vec3 getBBMax()
Return the upper point.
int MaximumExtend() const
Return the index of the dominant direction (maximal dimension). Index is 0 for x, 1 for y,...
const vec3 & operator[](int i) const
Return the lower (0) or upper (1) point.
bool isNull
True if the BBox is initialized, false if not.
BBox()
Default constructor.
bool isInBox(const vec3 &p) const
Check if a point is inside the BBox.
vec3 getBBMin()
Return the lower point.
BBox Union(const vec3 &p)
Union of a point and the current (this) BBox. A new BBox is created.
vec3 & operator[](int i)
Return the lower (0) or upper (1) point.
base_vec3< decimal > vec3