24 using namespace Opcode;
56 float AABB::MakeCube(
AABB& cube)
const
60 float Max = Ext.
Max();
72 void AABB::MakeSphere(
Sphere& sphere)
const
86 bool AABB::IsInside(
const AABB& box)
const
104 bool AABB::ComputePlanes(
Plane* planes)
const
108 if(!planes)
return false;
110 Point Center, Extents;
115 planes[0].
n =
Point(1.0f, 0.0f, 0.0f);
116 planes[1].
n =
Point(-1.0f, 0.0f, 0.0f);
117 planes[2].
n =
Point(0.0f, 1.0f, 0.0f);
118 planes[3].
n =
Point(0.0f, -1.0f, 0.0f);
119 planes[4].
n =
Point(0.0f, 0.0f, 1.0f);
120 planes[5].
n =
Point(0.0f, 0.0f, -1.0f);
131 planes[0].
d = -(planes[0].
n|p0);
132 planes[1].
d = -(planes[1].
n|p1);
133 planes[2].
d = -(planes[2].
n|p2);
134 planes[3].
d = -(planes[3].
n|p3);
135 planes[4].
d = -(planes[4].
n|p4);
136 planes[5].
d = -(planes[5].
n|p5);
147 bool AABB::ComputePoints(
Point* pts)
const
151 if(!pts)
return false;
167 pts[0] =
Point(min.
x, min.
y, min.
z);
168 pts[1] =
Point(max.
x, min.
y, min.
z);
169 pts[2] =
Point(max.
x, max.
y, min.
z);
170 pts[3] =
Point(min.
x, max.
y, min.
z);
171 pts[4] =
Point(min.
x, min.
y, max.
z);
172 pts[5] =
Point(max.
x, min.
y, max.
z);
173 pts[6] =
Point(max.
x, max.
y, max.
z);
174 pts[7] =
Point(min.
x, max.
y, max.
z);
185 const Point* AABB::GetVertexNormals()
const
188 static float VertexNormals[] =
199 return (
const Point*)VertexNormals;
207 const udword* AABB::GetEdges()
const
210 static udword Indices[] = {
211 0, 1, 1, 2, 2, 3, 3, 0,
212 7, 6, 6, 5, 5, 4, 4, 7,
224 const Point* AABB::GetEdgeNormals()
const
227 static float EdgeNormals[] =
244 return (
const Point*)EdgeNormals;
290 {-1,-1,-1,-1,-1,-1,-1, 0},
291 { 0, 4, 7, 3, 0,-1,-1, 4},
292 { 1, 2, 6, 5, 1,-1,-1, 4},
293 {-1,-1,-1,-1,-1,-1,-1, 0},
294 { 0, 1, 5, 4, 0,-1,-1, 4},
295 { 0, 1, 5, 4, 7, 3, 0, 6},
296 { 0, 1, 2, 6, 5, 4, 0, 6},
297 {-1,-1,-1,-1,-1,-1,-1, 0},
298 { 2, 3, 7, 6, 2,-1,-1, 4},
299 { 0, 4, 7, 6, 2, 3, 0, 6},
300 { 1, 2, 3, 7, 6, 5, 1, 6},
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 {-1,-1,-1,-1,-1,-1,-1, 0},
305 {-1,-1,-1,-1,-1,-1,-1, 0},
306 { 0, 3, 2, 1, 0,-1,-1, 4},
307 { 0, 4, 7, 3, 2, 1, 0, 6},
308 { 0, 3, 2, 6, 5, 1, 0, 6},
309 {-1,-1,-1,-1,-1,-1,-1, 0},
310 { 0, 3, 2, 1, 5, 4, 0, 6},
311 { 1, 5, 4, 7, 3, 2, 1, 6},
312 { 0, 3, 2, 6, 5, 4, 0, 6},
313 {-1,-1,-1,-1,-1,-1,-1, 0},
314 { 0, 3, 7, 6, 2, 1, 0, 6},
315 { 0, 4, 7, 6, 2, 1, 0, 6},
316 { 0, 3, 7, 6, 5, 1, 0, 6},
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 {-1,-1,-1,-1,-1,-1,-1, 0},
321 {-1,-1,-1,-1,-1,-1,-1, 0},
322 { 4, 5, 6, 7, 4,-1,-1, 4},
323 { 0, 4, 5, 6, 7, 3, 0, 6},
324 { 1, 2, 6, 7, 4, 5, 1, 6},
325 {-1,-1,-1,-1,-1,-1,-1, 0},
326 { 0, 1, 5, 6, 7, 4, 0, 6},
327 { 0, 1, 5, 6, 7, 3, 0, 6},
328 { 0, 1, 2, 6, 7, 4, 0, 6},
329 {-1,-1,-1,-1,-1,-1,-1, 0},
330 { 2, 3, 7, 4, 5, 6, 2, 6},
331 { 0, 4, 5, 6, 2, 3, 0, 6},
332 { 1, 2, 3, 7, 4, 5, 1, 6},
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},
352 {-1,-1,-1,-1,-1,-1,-1, 0},
353 {-1,-1,-1,-1,-1,-1,-1, 0}
356 const sbyte* AABB::ComputeOutline(
const Point& local_eye,
sdword& num)
const
363 int pos = ((local_eye.
x < min.
x) ? 1 : 0)
364 + ((local_eye.
x > max.
x) ? 2 : 0)
365 + ((local_eye.
y < min.
y) ? 4 : 0)
366 + ((local_eye.
y > max.
y) ? 8 : 0)
367 + ((local_eye.
z < min.
z) ? 16 : 0)
368 + ((local_eye.
z > max.
z) ? 32 : 0);
373 if(!num)
return null;
387 if(!Outline)
return -1.0f;
390 Point vertexBox[8], dst[8];
391 ComputePoints(vertexBox);
402 float Sum = (dst[num-1][0] - dst[0][0]) * (dst[num-1][1] + dst[0][1]);
404 for(i=0; i<num-1; i++)
405 Sum += (dst[i][0] - dst[i+1][0]) * (dst[i][1] + dst[i+1][1]);