20 #include "Geometry/mathlib.h"
53 centroid = (pMin + pMax) / 2.0f;
61 centroid = (pMin + pMax) / 2.0f;
87 centroid = (pMin + pMax) / 2.0f;
94 centroid = (pMin + pMax) / 2.0f;
100 vec3 d = pMax - pMin;
101 return 2 * (d.x * d.y + d.x * d.z + d.y * d.z);
135 ret.
pMax.x = max(pMax.x, p.x);
136 ret.
pMax.y = max(pMax.y, p.y);
137 ret.
pMax.z = max(pMax.z, p.z);
164 ret.
pMax.x = max(pMax.x, b2.
pMax.x);
165 ret.
pMax.y = max(pMax.y, b2.
pMax.y);
166 ret.
pMax.z = max(pMax.z, b2.
pMax.z);
197 return p.x >= pMin.x && p.y >= pMin.y && p.z >= pMin.z && p.x <= pMax.x && p.y <= pMax.y &&
211 bool x = (pMax.x >= box.
pMin.x) && (pMin.x <= box.
pMax.x);
212 bool y = (pMax.y >= box.
pMin.y) && (pMin.y <= box.
pMax.y);
213 bool z = (pMax.z >= box.
pMin.z) && (pMin.z <= box.
pMax.z);
214 return (x && y && z);
220 vec3 diag = pMax - pMin;
221 if (diag.x > diag.y && diag.x > diag.z)
225 else if (diag.y > diag.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;
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;
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;
298 t0 = tNear > t0 ? tNear : t0;
299 t1 = tFar < t1 ? tFar : t1;
355 return sqrt((pMax.x - pMin.x) * (pMax.x - pMin.x) + (pMax.y - pMin.y) * (pMax.y - pMin.y) +
356 (pMax.z - pMin.z) * (pMax.z - pMin.z));
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