19 #define AABB_COMMON_METHODS \ 20 AABB& Add(const AABB& aabb); \ 21 float MakeCube(AABB& cube) const; \ 22 void MakeSphere(Sphere& sphere) const; \ 23 const sbyte* ComputeOutline(const Point& local_eye, sdword& num) const; \ 24 float ComputeBoxArea(const Point& eye, const Matrix4x4& mat, float width, float height, sdword& num) const; \ 25 bool IsInside(const AABB& box) const; \ 26 bool ComputePlanes(Plane* planes) const; \ 27 bool ComputePoints(Point* pts) const; \ 28 const Point* GetVertexNormals() const; \ 29 const udword* GetEdges() const; \ 30 const Point* GetEdgeNormals() const; \ 31 inline_ BOOL ContainsPoint(const Point& p) const \ 33 if(p.x > GetMax(0) || p.x < GetMin(0)) return FALSE; \ 34 if(p.y > GetMax(1) || p.y < GetMin(1)) return FALSE; \ 35 if(p.z > GetMax(2) || p.z < GetMin(2)) return FALSE; \ 81 void SetCenterExtents(
const Point&
c,
const Point& e) { mMin = c - e; mMax = c + e; }
95 void SetPoint(
const Point& pt) { mMin = mMax = pt; }
103 float GetSize()
const {
Point e; GetExtents(e);
return e.
Max(); }
111 void Extend(
const Point& p)
114 if(p.
x > mMax.x) mMax.x = p.
x;
115 if(p.
x < mMin.x) mMin.x = p.
x;
117 if(p.
y > mMax.y) mMax.y = p.
y;
118 if(p.
y < mMin.y) mMin.y = p.
y;
120 if(p.
z > mMax.z) mMax.z = p.
z;
121 if(p.
z < mMin.z) mMin.z = p.
z;
131 inline_ float GetMin(
udword axis)
const {
return mMin[axis]; }
133 inline_ float GetMax(
udword axis)
const {
return mMax[axis]; }
136 inline_ void GetCenter(
Point& center)
const { center = (mMax + mMin)*0.5
f; }
138 inline_ void GetExtents(
Point& extents)
const { extents = (mMax - mMin)*0.5
f; }
141 inline_ float GetCenter(
udword axis)
const {
return (mMax[axis] + mMin[axis])*0.5f; }
143 inline_ float GetExtents(
udword axis)
const {
return (mMax[axis] - mMin[axis])*0.5f; }
146 inline_ void GetDiagonal(
Point& diagonal)
const { diagonal = mMax - mMin; }
147 inline_ float GetWidth()
const {
return mMax.x - mMin.x; }
148 inline_ float GetHeight()
const {
return mMax.y - mMin.y; }
149 inline_ float GetDepth()
const {
return mMax.z - mMin.z; }
152 inline_ float GetVolume()
const {
return GetWidth() * GetHeight() * GetDepth(); }
168 || a.mMax.z < mMin.z)
return FALSE;
183 if(mMax[axis] < a.mMin[axis] || a.mMax[axis] < mMin[axis])
return FALSE;
200 mtx.
GetRow(0, vx); vx *= (mMax.x - mMin.x);
201 mtx.
GetRow(1, vy); vy *= (mMax.y - mMin.y);
202 mtx.
GetRow(2, vz); vz *= (mMax.z - mMin.z);
205 aabb.mMin = aabb.mMax = mMin * mtx;
229 if(mMin.x > mMax.x)
return FALSE;
230 if(mMin.y > mMax.y)
return FALSE;
231 if(mMin.z > mMax.z)
return FALSE;
236 inline_ AABB& operator*=(
float s)
238 Point Center; GetCenter(Center);
239 Point Extents; GetExtents(Extents);
240 SetCenterExtents(Center, Extents * s);
245 inline_ AABB& operator/=(
float s)
247 Point Center; GetCenter(Center);
248 Point Extents; GetExtents(Extents);
249 SetCenterExtents(Center, Extents / s);
293 void SetCenterExtents(
const Point&
c,
const Point& e) { mCenter =
c; mExtents = e; }
307 void SetPoint(
const Point& pt) { mCenter = pt; mExtents.
Zero(); }
315 float GetSize()
const {
return mExtents.
Max(); }
323 void Extend(
const Point& p)
326 Point Max = mCenter + mExtents;
327 Point Min = mCenter - mExtents;
329 if(p.
x > Max.
x) Max.
x = p.
x;
330 if(p.
x < Min.
x) Min.
x = p.
x;
332 if(p.
y > Max.
y) Max.
y = p.
y;
333 if(p.
y < Min.
y) Min.
y = p.
y;
335 if(p.
z > Max.
z) Max.
z = p.
z;
336 if(p.
z < Min.
z) Min.
z = p.
z;
392 inline_ bool GomezIntersect(
const AABB& a)
396 return ((fabsf(T.
x) <= (a.
mExtents.
x + mExtents.x))
397 && (fabsf(T.
y) <= (a.
mExtents.
y + mExtents.y))
398 && (fabsf(T.
z) <= (a.
mExtents.
z + mExtents.z)));
411 float t = mCenter[axis] - a.
mCenter[axis];
412 float e = a.
mExtents[axis] + mExtents[axis];
430 Point Ex(mtx.m[0][0] * mExtents.x, mtx.m[0][1] * mExtents.x, mtx.m[0][2] * mExtents.x);
431 IR(Ex.
x)&=0x7fffffff;
IR(Ex.
y)&=0x7fffffff;
IR(Ex.
z)&=0x7fffffff;
433 Point Ey(mtx.m[1][0] * mExtents.y, mtx.m[1][1] * mExtents.y, mtx.m[1][2] * mExtents.y);
434 IR(Ey.
x)&=0x7fffffff;
IR(Ey.
y)&=0x7fffffff;
IR(Ey.
z)&=0x7fffffff;
436 Point Ez(mtx.m[2][0] * mExtents.z, mtx.m[2][1] * mExtents.z, mtx.m[2][2] * mExtents.z);
437 IR(Ez.
x)&=0x7fffffff;
IR(Ez.
y)&=0x7fffffff;
IR(Ez.
z)&=0x7fffffff;
480 if(p.
x > max.
x) max.
x = p.
x;
481 if(p.
x < min.
x) min.
x = p.
x;
483 if(p.
y > max.
y) max.
y = p.
y;
484 if(p.
y < min.
y) min.
y = p.
y;
486 if(p.
z > max.
z) max.
z = p.
z;
487 if(p.
z < min.
z) min.
z = p.
z;
505 #endif // __ICEAABB_H__ Point mCenter
AABB Center.
inline_ ~AABB()
Destructor.
#define IR(x)
Integer representation of a floating-point value.
inline_ float GetHeight() const
#define IS_NEGATIVE_FLOAT(x)
inline_ void GetMin(Point &min) const
Get min point of the box.
void SetMinMax(const Point &min, const Point &max)
inline_ AABB()
Constructor.
static int min(int a, int b)
inline_ void ComputeMinMax(const Point &p, Point &min, Point &max)
inline_ AABB & operator+=(const Point &trans)
Operator for AABB += Point. Translates the box.
inline_ float GetExtents(udword axis) const
Get component of the box's extents along a given axis.
inline_ float GetCenter(udword axis) const
Get component of the box's center along a given axis.
AABB used for dynamic updates. Not visible == not updated.
inline_ void GetExtents(Point &extents) const
Get box extents.
#define AABB_COMMON_METHODS
Declarations of type-independent methods (most of them implemented in the .cpp)
png_infop png_bytep * trans
int BOOL
Another boolean type.
unsigned int udword
sizeof(udword) must be 4
AABB_COMMON_METHODS
Type-independent methods.
inline_ AABB & operator/=(float s)
Operator for AABB /= float. Scales the extents, keeps same center.
inline_ AABB & operator*=(float s)
Operator for AABB *= float. Scales the extents, keeps same center.
inline_ float GetMin(udword axis) const
Get component of the box's min point along a given axis.
inline_ float GetVolume() const
Volume.
#define MAX_FLOAT
max possible float value
Point mExtents
x, y and z extents
inline_ Point & Set(float _x, float _y, float _z)
Assignment from values.
inline_ void ComputeAABB(AABB &aabb, const Point *list, udword nb_pts)
inline_ void GetCenter(Point ¢er) const
Get box center.
inline_ Point & Zero()
Clears the vector.
inline_ float GetWidth() const
#define AIR(x)
Absolute integer representation of a floating-point value.
inline_ BOOL Intersect(const AABB &a, const SAP_Box &b)
inline_ void GetMax(Point &max) const
Get max point of the box.
inline_ float GetMax(udword axis) const
Get component of the box's max point along a given axis.
inline_ void GetRow(const udword r, HPoint &p) const
Returns a row.
#define MIN_FLOAT
min possible loat value
inline_ void GetDiagonal(Point &diagonal) const
Get box diagonal.
inline_ float GetDepth() const
static int max(int a, int b)
inline_ float Max() const
Returns MAX(x, y, z);.
AABB used for rendering. Not visible == not rendered.