35 Point Min; GetMin(Min);
36 Point Tmp; aabb.
GetMin(Tmp);
39 Point Max; GetMax(Max);
54 float AABB::MakeCube(
AABB& cube)
const
57 Point Ext; GetExtents(Ext);
58 float Max = Ext.Max();
60 Point Cnt; GetCenter(Cnt);
70 void AABB::MakeSphere(Sphere& sphere)
const
73 GetExtents(sphere.mCenter);
74 sphere.mRadius = sphere.mCenter.Magnitude() * 1.00001f;
75 GetCenter(sphere.mCenter);
84 bool AABB::IsInside(
const AABB&
box)
const
87 if(
box.GetMin(0)>GetMin(0))
return false;
88 if(
box.GetMin(1)>GetMin(1))
return false;
89 if(
box.GetMin(2)>GetMin(2))
return false;
90 if(
box.GetMax(0)<GetMax(0))
return false;
91 if(
box.GetMax(1)<GetMax(1))
return false;
92 if(
box.GetMax(2)<GetMax(2))
return false;
102 bool AABB::ComputePlanes(
Plane* planes)
const
106 if(!planes)
return false;
108 Point Center, Extents;
113 planes[0].
n = Point(1.0
f, 0.0
f, 0.0
f);
114 planes[1].
n = Point(-1.0
f, 0.0
f, 0.0
f);
115 planes[2].
n = Point(0.0
f, 1.0
f, 0.0
f);
116 planes[3].
n = Point(0.0
f, -1.0
f, 0.0
f);
117 planes[4].
n = Point(0.0
f, 0.0
f, 1.0
f);
118 planes[5].
n = Point(0.0
f, 0.0
f, -1.0
f);
121 Point p0 = Point(Center.x+Extents.x, Center.y, Center.z);
122 Point p1 = Point(Center.x-Extents.x, Center.y, Center.z);
123 Point p2 = Point(Center.x, Center.y+Extents.y, Center.z);
124 Point p3 = Point(Center.x, Center.y-Extents.y, Center.z);
125 Point p4 = Point(Center.x, Center.y, Center.z+Extents.z);
126 Point p5 = Point(Center.x, Center.y, Center.z-Extents.z);
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;
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}
354 const sbyte* AABB::ComputeOutline(
const Point& local_eye,
sdword&
num)
const
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);
371 if(!
num)
return null;
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]);