54 float AABB::MakeCube(
AABB& cube)
const 58 float Max = Ext.
Max();
70 void AABB::MakeSphere(
Sphere& sphere)
const 84 bool AABB::IsInside(
const AABB&
box)
const 102 bool AABB::ComputePlanes(
Plane* planes)
const 106 if(!planes)
return false;
108 Point Center, Extents;
129 planes[0].
d = -(planes[0].
n|p0);
130 planes[1].
d = -(planes[1].
n|p1);
131 planes[2].
d = -(planes[2].
n|p2);
132 planes[3].
d = -(planes[3].
n|p3);
133 planes[4].
d = -(planes[4].
n|p4);
134 planes[5].
d = -(planes[5].
n|p5);
145 bool AABB::ComputePoints(
Point* pts)
const 149 if(!pts)
return false;
165 pts[0] =
Point(min.
x, min.
y, min.
z);
166 pts[1] =
Point(max.
x, min.
y, min.
z);
167 pts[2] =
Point(max.
x, max.
y, min.
z);
168 pts[3] =
Point(min.
x, max.
y, min.
z);
169 pts[4] =
Point(min.
x, min.
y, max.
z);
170 pts[5] =
Point(max.
x, min.
y, max.
z);
171 pts[6] =
Point(max.
x, max.
y, max.
z);
172 pts[7] =
Point(min.
x, max.
y, max.
z);
183 const Point* AABB::GetVertexNormals()
const 186 static float VertexNormals[] =
197 return (
const Point*)VertexNormals;
205 const udword* AABB::GetEdges()
const 208 static udword Indices[] = {
209 0, 1, 1, 2, 2, 3, 3, 0,
210 7, 6, 6, 5, 5, 4, 4, 7,
222 const Point* AABB::GetEdgeNormals()
const 225 static float EdgeNormals[] =
242 return (
const Point*)EdgeNormals;
288 {-1,-1,-1,-1,-1,-1,-1, 0},
289 { 0, 4, 7, 3, 0,-1,-1, 4},
290 { 1, 2, 6, 5, 1,-1,-1, 4},
291 {-1,-1,-1,-1,-1,-1,-1, 0},
292 { 0, 1, 5, 4, 0,-1,-1, 4},
293 { 0, 1, 5, 4, 7, 3, 0, 6},
294 { 0, 1, 2, 6, 5, 4, 0, 6},
295 {-1,-1,-1,-1,-1,-1,-1, 0},
296 { 2, 3, 7, 6, 2,-1,-1, 4},
297 { 0, 4, 7, 6, 2, 3, 0, 6},
298 { 1, 2, 3, 7, 6, 5, 1, 6},
299 {-1,-1,-1,-1,-1,-1,-1, 0},
300 {-1,-1,-1,-1,-1,-1,-1, 0},
301 {-1,-1,-1,-1,-1,-1,-1, 0},
302 {-1,-1,-1,-1,-1,-1,-1, 0},
303 {-1,-1,-1,-1,-1,-1,-1, 0},
304 { 0, 3, 2, 1, 0,-1,-1, 4},
305 { 0, 4, 7, 3, 2, 1, 0, 6},
306 { 0, 3, 2, 6, 5, 1, 0, 6},
307 {-1,-1,-1,-1,-1,-1,-1, 0},
308 { 0, 3, 2, 1, 5, 4, 0, 6},
309 { 1, 5, 4, 7, 3, 2, 1, 6},
310 { 0, 3, 2, 6, 5, 4, 0, 6},
311 {-1,-1,-1,-1,-1,-1,-1, 0},
312 { 0, 3, 7, 6, 2, 1, 0, 6},
313 { 0, 4, 7, 6, 2, 1, 0, 6},
314 { 0, 3, 7, 6, 5, 1, 0, 6},
315 {-1,-1,-1,-1,-1,-1,-1, 0},
316 {-1,-1,-1,-1,-1,-1,-1, 0},
317 {-1,-1,-1,-1,-1,-1,-1, 0},
318 {-1,-1,-1,-1,-1,-1,-1, 0},
319 {-1,-1,-1,-1,-1,-1,-1, 0},
320 { 4, 5, 6, 7, 4,-1,-1, 4},
321 { 0, 4, 5, 6, 7, 3, 0, 6},
322 { 1, 2, 6, 7, 4, 5, 1, 6},
323 {-1,-1,-1,-1,-1,-1,-1, 0},
324 { 0, 1, 5, 6, 7, 4, 0, 6},
325 { 0, 1, 5, 6, 7, 3, 0, 6},
326 { 0, 1, 2, 6, 7, 4, 0, 6},
327 {-1,-1,-1,-1,-1,-1,-1, 0},
328 { 2, 3, 7, 4, 5, 6, 2, 6},
329 { 0, 4, 5, 6, 2, 3, 0, 6},
330 { 1, 2, 3, 7, 4, 5, 1, 6},
331 {-1,-1,-1,-1,-1,-1,-1, 0},
332 {-1,-1,-1,-1,-1,-1,-1, 0},
333 {-1,-1,-1,-1,-1,-1,-1, 0},
334 {-1,-1,-1,-1,-1,-1,-1, 0},
335 {-1,-1,-1,-1,-1,-1,-1, 0},
336 {-1,-1,-1,-1,-1,-1,-1, 0},
337 {-1,-1,-1,-1,-1,-1,-1, 0},
338 {-1,-1,-1,-1,-1,-1,-1, 0},
339 {-1,-1,-1,-1,-1,-1,-1, 0},
340 {-1,-1,-1,-1,-1,-1,-1, 0},
341 {-1,-1,-1,-1,-1,-1,-1, 0},
342 {-1,-1,-1,-1,-1,-1,-1, 0},
343 {-1,-1,-1,-1,-1,-1,-1, 0},
344 {-1,-1,-1,-1,-1,-1,-1, 0},
345 {-1,-1,-1,-1,-1,-1,-1, 0},
346 {-1,-1,-1,-1,-1,-1,-1, 0},
347 {-1,-1,-1,-1,-1,-1,-1, 0},
348 {-1,-1,-1,-1,-1,-1,-1, 0},
349 {-1,-1,-1,-1,-1,-1,-1, 0},
350 {-1,-1,-1,-1,-1,-1,-1, 0},
351 {-1,-1,-1,-1,-1,-1,-1, 0}
361 int pos = ((local_eye.
x < min.
x) ? 1 : 0)
362 + ((local_eye.
x > max.
x) ? 2 : 0)
363 + ((local_eye.
y < min.
y) ? 4 : 0)
364 + ((local_eye.
y > max.
y) ? 8 : 0)
365 + ((local_eye.
z < min.
z) ? 16 : 0)
366 + ((local_eye.
z > max.
z) ? 32 : 0);
369 num = (
sdword)gIndexList[pos][7];
371 if(!num)
return null;
373 return &gIndexList[pos][0];
384 const sbyte* Outline = ComputeOutline(eye, num);
385 if(!Outline)
return -1.0f;
388 Point vertexBox[8], dst[8];
389 ComputePoints(vertexBox);
399 float Sum = (dst[num-1][0] - dst[0][0]) * (dst[num-1][1] + dst[0][1]);
401 for(
int i=0;
i<num-1;
i++)
402 Sum += (dst[
i][0] - dst[
i+1][0]) * (dst[
i][1] + dst[
i+1][1]);
inline_ void GetMin(Point &min) const
Get min point of the box.
inline_ void GetCenter(Point ¢er) const
Get box center.
signed int sdword
sizeof(sdword) must be 4
#define INVSQRT2
1 / sqrt(2)
#define null
our own NULL pointer
static int min(int a, int b)
signed char sbyte
sizeof(sbyte) must be 1
inline_ float Magnitude() const
Computes magnitude.
void SetCenterExtents(const Point &c, const Point &e)
png_infop png_uint_32 * width
float mRadius
Sphere radius.
Point mCenter
Sphere center.
unsigned int udword
sizeof(udword) must be 4
Point n
The normal to the plane.
png_infop png_uint_32 png_uint_32 * height
inline_ float Min() const
Returns MIN(x, y, z);.
inline_ void GetMax(Point &max) const
Get max point of the box.
#define INVSQRT3
1 / sqrt(3)
void SetMinMax(const Point &min, const Point &max)
void ProjectToScreen(float halfrenderwidth, float halfrenderheight, const Matrix4x4 &mat, HPoint &projected) const
Projects the point onto the screen.
inline_ float Max() const
Returns MAX(x, y, z);.
inline_ void GetExtents(Point &extents) const
Get box extents.
static const sbyte gIndexList[64][8]
static int max(int a, int b)
float d
The distance from the origin.