Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc @ 5704

Last change on this file since 5704 was 5704, checked in by patrick, 18 years ago

collision_detection: removed some more unused variables

File size: 38.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
17
18#include "obb_tree_node.h"
19#include "list.h"
20#include "obb.h"
21#include "obb_tree.h"
22#include "matrix.h"
23#include "abstract_model.h"
24#include "world_entity.h"
25
26#include "color.h"
27
28#include "debug.h"
29#include "glincl.h"
30
31
32
33using namespace std;
34
35float**  OBBTreeNode::coMat = NULL;
36float**  OBBTreeNode::eigvMat = NULL;
37float*   OBBTreeNode::eigvlMat = NULL;
38int*     OBBTreeNode::rotCount = NULL;
39GLUquadricObj* OBBTreeNode_sphereObj = NULL;
40
41/**
42 *  standard constructor
43 */
44OBBTreeNode::OBBTreeNode (const OBBTree* tree) 
45  : BVTreeNode()
46{
47  this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
48  this->obbTree = tree;
49  this->nodeLeft = NULL;
50  this->nodeRight = NULL;
51  this->bvElement = NULL;
52  this->tmpVert1 = NULL;
53  this->tmpVert2 = NULL;
54
55  if( OBBTreeNode::coMat == NULL)
56  {
57    OBBTreeNode::coMat = new float*[4];
58    for(int i = 0; i < 4; i++)
59      OBBTreeNode::coMat[i] = new float[4];
60  }
61  if( OBBTreeNode::eigvMat == NULL)
62  {
63    OBBTreeNode::eigvMat = new float*[4];
64    for( int i = 0; i < 4; i++)
65      OBBTreeNode::eigvMat[i] = new float[4];
66  }
67  if( OBBTreeNode::eigvlMat == NULL)
68  {
69    OBBTreeNode::eigvlMat = new float[4];
70  }
71  if( OBBTreeNode::rotCount == NULL)
72    OBBTreeNode::rotCount = new int;
73
74  if( OBBTreeNode_sphereObj == NULL)
75    OBBTreeNode_sphereObj = gluNewQuadric();
76}
77
78
79/**
80 *  standard deconstructor
81 */
82OBBTreeNode::~OBBTreeNode ()
83{
84  if( this->nodeLeft)
85  {
86    delete this->nodeLeft;
87    this->nodeLeft = NULL;
88  }
89  if( this->nodeRight)
90  {
91    delete this->nodeRight;
92    this->nodeRight = NULL;
93  }
94  if( this->bvElement)
95    delete this->bvElement;
96  this->bvElement = NULL;
97
98  if (this->tmpVert1 != NULL)
99    delete this->tmpVert1;
100  if (this->tmpVert2 != NULL)
101    delete this->tmpVert2;
102}
103
104
105/**
106 *  creates a new BVTree or BVTree partition
107 * @param depth: how much more depth-steps to go: if == 1 don't go any deeper!
108 * @param modInfo: model informations from the abstrac model
109 *
110 * this function creates the Bounding Volume tree from a modelInfo struct and bases its calculations
111 * on the triangle informations (triangle soup not polygon soup)
112 */
113void OBBTreeNode::spawnBVTree(const int depth, const modelInfo& modelInf, 
114                              const int* triangleIndexes, unsigned int length)
115{
116  sVec3D* verticesList;
117
118  PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);
119  this->depth = depth;
120
121  this->bvElement = new OBB(); 
122  this->bvElement->modelInf = &modelInf;
123  this->bvElement->triangleIndexes = triangleIndexes;
124  this->bvElement->numTriangles = length;
125 
126  this->calculateBoxCovariance(this->bvElement, modelInf, triangleIndexes, length);
127  this->calculateBoxEigenvectors(this->bvElement, modelInf, triangleIndexes, length);
128  this->calculateBoxAxis(this->bvElement, modelInf, triangleIndexes, length);
129
130  /* if this is the first node, the vertices data are the original ones of the model itself,
131     so dont delete them in cleanup */
132  if( likely( this->depth > 0))
133  {
134    this->forkBox(this->bvElement);
135
136
137//     if(this->tmpLen1 > 2)
138//     {
139//       OBBTreeNode* node1 = new OBBTreeNode();
140//       this->nodeLeft = node1;
141//       this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
142//     }
143//     else
144//     {
145//       PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n");
146//     }
147//
148//     if( this->tmpLen2 > 2)
149//     {
150//       OBBTreeNode* node2 = new OBBTreeNode();
151//       this->nodeRight = node2;
152//       this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
153//     }
154//     else
155//     {
156//       PRINTF(3)("Abording tree walk: less than 3 vertices left\n");
157//     }
158
159  }
160}
161
162
163/**
164 *  creates a new BVTree or BVTree partition
165 * @param depth: how much more depth-steps to go: if == 1 don't go any deeper!
166 * @param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle
167 *
168 * this function creates an Bounding Volume tree from a vertices soup (no triangle data)
169 */
170void OBBTreeNode::spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length)
171{
172//   PRINT(3)("\n");
173//   PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);
174//   this->depth = depth;
175//
176//
177//   this->bvElement = new OBB();
178//   this->bvElement->vertices = verticesList;
179//   this->bvElement->numOfVertices = length;
180//   PRINTF(3)("Created OBBox\n");
181//   this->calculateBoxCovariance(this->bvElement, verticesList, length);
182//   PRINTF(3)("Calculated attributes1\n");
183//   this->calculateBoxEigenvectors(this->bvElement, verticesList, length);
184//   PRINTF(3)("Calculated attributes2\n");
185//   this->calculateBoxAxis(this->bvElement, verticesList, length);
186//   PRINTF(3)("Calculated attributes3\n");
187//
188//
189//
190//   if( likely( this->depth > 0))
191//   {
192//     this->forkBox(this->bvElement);
193//
194//
195//     if(this->tmpLen1 > 2)
196//     {
197//       OBBTreeNode* node1 = new OBBTreeNode(this->obbTree);
198//       this->nodeLeft = node1;
199//       this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
200//     }
201//     else
202//     {
203//       PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n");
204//     }
205//
206//     if( this->tmpLen2 > 2)
207//     {
208//       OBBTreeNode* node2 = new OBBTreeNode(this->obbTree);
209//       this->nodeRight = node2;
210//       this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
211//     }
212//     else
213//     {
214//       PRINTF(3)("Abording tree walk: less than 3 vertices left\n");
215//     }
216//   }
217}
218
219
220void OBBTreeNode::calculateBoxCovariance(OBB* box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length)
221{}
222
223
224void OBBTreeNode::calculateBoxCovariance(OBB* box, const sVec3D* verticesList, unsigned int length)
225{
226  PRINTF(3)("Created OBBox\n");
227 
228  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
229  float     face = 0.0f;                             //!< surface area of the entire convex hull
230  Vector    centroid[length];                        //!< centroid of the i'th convex hull
231  Vector    center;                                  //!< the center of the entire hull
232  Vector    p, q, r;                                 //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d
233  Vector    t1, t2;                                  //!< temporary values
234  float     covariance[3][3] = {0,0,0, 0,0,0, 0,0,0};//!< the covariance matrix
235  int       mode = 0;                                //!< mode = 0: vertex soup, no connections, mode = 1: 3 following verteces build a triangle
236
237  this->numOfVertices = length;
238  this->vertices = verticesList;
239
240
241  if( likely(mode == 0))
242  {
243    /* fist compute all the convex hull face/facelets and centroids */
244    for( int i = 0; i+3 < length ; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
245    {
246      p = verticesList[i];
247      q = verticesList[i + 1];
248      r = verticesList[i + 2];
249
250      t1 = p - q; t2 = p - r;
251
252      /* finding the facelet surface via cross-product */
253      facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
254      /* update the entire convex hull surface */
255      face += facelet[i];
256
257      /* calculate the cetroid of the hull triangles */
258      centroid[i] = (p + q + r) * 1/3;
259      /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
260      center += centroid[i] * facelet[i];
261    }
262    /* take the average of the centroid sum */
263    center /= face;
264    PRINTF(3)("-- Calculated Center\n");
265
266
267    /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
268    for( int j = 0; j < 3; ++j)
269    {
270      for( int k = 0; k < 3; ++k)
271      {
272        for( int i = 0; i + 3 < length; i+=3)
273        {
274          p = verticesList[i];
275          q = verticesList[i + 1];
276          r = verticesList[i + 2];
277
278          covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] +
279              q[j] * q[k] + r[j] * r[k]) - center[j] * center[k];
280        }
281      }
282    }
283    PRINTF(3)("-- Calculated Covariance\n");
284  }
285  else if( mode == 1)
286  {
287    for( int i = 0; i + 3 < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
288    {
289      p = verticesList[i];
290      q = verticesList[i + 1];
291      r = verticesList[i + 2];
292
293      centroid[i] = (p + q + r) / 3.0f;
294      center += centroid[i];
295    }
296    center /= length;
297
298    for( int j = 0; j < 3; ++j)
299    {
300      for( int k = 0; k < 3; ++k)
301      {
302        for( int i = 0; i + 3 < length; i+=3)
303        {
304          p = verticesList[i];
305          q = verticesList[i +1];
306          r = verticesList[i + 2];
307
308          covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
309        }
310        covariance[j][k] /= (3.0f * length);
311      }
312    }
313    PRINTF(3)("-- Calculated Covariance\n");
314  }
315  else if( mode == 2)
316  {
317    /* fist compute all the convex hull face/facelets and centroids */
318    for(int i = 0; i + 3 < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
319    {
320      p = verticesList[i];
321      q = verticesList[i + 1];
322      r = verticesList[i + 2];
323
324      t1 = p - q; t2 = p - r;
325
326      /* finding the facelet surface via cross-product */
327      facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
328      /* update the entire convex hull surface */
329      face += facelet[i];
330
331      /* calculate the cetroid of the hull triangles */
332      centroid[i] = (p + q + r) * 1/3;
333      /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
334      center += centroid[i] * facelet[i];
335    }
336    /* take the average of the centroid sum */
337    center /= face;
338    PRINTF(3)("-- Calculated Center\n");
339
340    for( int j = 0; j < 3; ++j)
341    {
342      for( int k = 0; k < 3; ++k)
343      {
344        for( int i = 0; i + 3 < length; i+=3)
345        {
346          p = verticesList[i];
347          q = verticesList[i +1];
348          r = verticesList[i + 2];
349
350          covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
351        }
352        covariance[j][k] /= (3.0f * length);
353      }
354    }
355    PRINTF(3)("-- Calculated Covariance\n");
356  }
357  else
358  {
359    for( int i = 0; i < length; ++i)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
360    {
361      center += verticesList[i];
362    }
363    center /= length;
364
365    for( int j = 0; j < 3; ++j)
366    {
367      for( int k = 0; k < 3; ++k)
368      {
369        for( int i = 0; i + 3 < length; i+=3)
370        {
371          p = verticesList[i];
372          q = verticesList[i +1];
373          r = verticesList[i + 2];
374
375          covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k];
376        }
377        covariance[j][k] /= (3.0f * length);
378      }
379    }
380    PRINTF(3)("-- Calculated Covariance\n");
381  }
382
383  PRINTF(3)("\nVertex Data:\n");
384  for(int i = 0; i < length; i++)
385  {
386    PRINTF(3)("vertex %i: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]);
387  }
388
389
390  PRINTF(3)("\nCovariance Matrix:\n");
391  for(int j = 0; j < 3; ++j)
392  {
393    PRINT(3)(" |");
394    for(int k = 0; k < 3; ++k)
395    {
396      PRINT(3)(" \b%f ", covariance[j][k]);
397    }
398    PRINT(3)(" |\n");
399  }
400
401  PRINTF(3)("center: %f, %f, %f\n", center.x, center.y, center.z);
402
403
404  for(int i = 0; i < 3; ++i)
405  {
406    box->covarianceMatrix[i][0] = covariance[i][0];
407    box->covarianceMatrix[i][1] = covariance[i][1];
408    box->covarianceMatrix[i][2] = covariance[i][2];
409  }
410  *box->center = center;
411  PRINTF(3)("-- Written Result to obb\n");
412}
413
414
415void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const modelInfo& modInfo, 
416                                           const int* triangleIndexes, unsigned int length)
417{}
418
419void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const sVec3D* verticesList, unsigned int length)
420{
421  PRINTF(3)("Calculated attributes1\n");
422  /* now getting spanning vectors of the sub-space:
423  the eigenvectors of a symmertric matrix, such as the
424  covarience matrix are mutually orthogonal.
425  after normalizing them, they can be used as a the basis
426  vectors
427  */
428  Vector axis[3];                //!< the references to the obb axis
429
430  Matrix covMat(  box->covarianceMatrix  );
431  covMat.getEigenVectors(axis[0], axis[1], axis[2] );
432
433
434  /* new jacobi tests */
435//  JacobI(OBBTreeNode::coMat, OBBTreeNode::eigvlMat, OBBTreeNode::eigvMat, OBBTreeNode::rotCount);
436//  PRINTF(3)("-- Done Jacobi Decomposition\n");
437
438
439//   PRINTF(0)("Jacobi\n");
440//   for(int j = 0; j < 3; ++j)
441//   {
442//     printf(" |");
443//     for(int k = 0; k < 3; ++k)
444//     {
445//       printf(" \t%f ", OBBTreeNode::OBBTreeNode::eigvMat[j][k]);
446//     }
447//     printf(" |\n");
448//   }
449
450/*  axis[0].x = OBBTreeNode::eigvMat[0][0]; axis[0].y = OBBTreeNode::eigvMat[1][0]; axis[0].z = OBBTreeNode::eigvMat[2][0];
451  axis[1].x = OBBTreeNode::eigvMat[0][1]; axis[1].y = OBBTreeNode::eigvMat[1][1]; axis[1].z = OBBTreeNode::eigvMat[2][1];
452  axis[2].x = OBBTreeNode::eigvMat[0][2]; axis[2].y = OBBTreeNode::eigvMat[1][2]; axis[2].z = OBBTreeNode::eigvMat[2][2];
453  axis[0].normalize();
454  axis[1].normalize();
455  axis[2].normalize();*/
456  box->axis[0] = axis[0];
457  box->axis[1] = axis[1];
458  box->axis[2] = axis[2];
459
460//   PRINTF(0)("-- Got Axis\n");
461//
462//   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0].x, box->axis[0].y, box->axis[0].z);
463//   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1].x, box->axis[1].y, box->axis[1].z);
464//   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2].x, box->axis[2].y, box->axis[2].z);
465}
466
467
468void OBBTreeNode::calculateBoxAxis(OBB* box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length)
469{
470  this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices);
471}
472
473
474
475void OBBTreeNode::calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length)
476{
477  PRINTF(3)("Calculated attributes3\n");
478  /* now get the axis length */
479  Line                ax[3];                                 //!< the axis
480  float               halfLength[3];                         //!< half length of the axis
481  float               tmpLength;                             //!< tmp save point for the length
482  Plane               p0(box->axis[0], *box->center);        //!< the axis planes
483  Plane               p1(box->axis[1], *box->center);
484  Plane               p2(box->axis[2], *box->center);
485  float               maxLength[3];
486  float               minLength[3];
487
488
489  /* get a bad bounding box */
490  halfLength[0] = -1.0f;
491  for(int j = 0; j < length; ++j)
492    {
493      tmpLength = fabs(p0.distancePoint(vertices[j]));
494      if( tmpLength > halfLength[0])
495        halfLength[0] = tmpLength;
496    }
497
498  halfLength[1] = -1.0f;
499  for(int j = 0; j < length; ++j)
500    {
501      tmpLength = fabs(p1.distancePoint(vertices[j]));
502      if( tmpLength > halfLength[1])
503        halfLength[1] = tmpLength;
504    }
505
506  halfLength[2] = -1.0f;
507  for(int j = 0; j < length; ++j)
508    {
509      tmpLength = fabs(p2.distancePoint(vertices[j]));
510      if( tmpLength > halfLength[2])
511        halfLength[2] = tmpLength;
512    }
513
514
515
516  /* get the maximal dimensions of the body in all directions */
517    maxLength[0] = p0.distancePoint(vertices[0]);
518    minLength[0] = p0.distancePoint(vertices[0]);
519   for(int j = 0; j < length; ++j)
520   {
521     tmpLength = p0.distancePoint(vertices[j]);
522     if( tmpLength > maxLength[0])
523       maxLength[0] = tmpLength;
524     else if( tmpLength < minLength[0])
525       minLength[0] = tmpLength;
526   }
527
528   maxLength[1] = p1.distancePoint(vertices[0]);
529   minLength[1] = p1.distancePoint(vertices[0]);
530   for(int j = 0; j < length; ++j)
531   {
532     tmpLength = p1.distancePoint(vertices[j]);
533     if( tmpLength > maxLength[1])
534       maxLength[1] = tmpLength;
535     else if( tmpLength < minLength[1])
536       minLength[1] = tmpLength;
537   }
538
539   maxLength[2] = p2.distancePoint(vertices[0]);
540   minLength[2] = p2.distancePoint(vertices[0]);
541   for(int j = 0; j < length; ++j)
542   {
543     tmpLength = p2.distancePoint(vertices[j]);
544     if( tmpLength > maxLength[2])
545       maxLength[2] = tmpLength;
546     else if( tmpLength < minLength[2])
547       minLength[2] = tmpLength;
548   }
549
550
551   /* calculate the real centre of the body by using the axis length */
552   float centerOffset[3];
553   float newHalfLength[3];
554   for(int i = 0; i < 3; ++i)
555     {
556       PRINTF(3)("max: %f, min: %f \n", maxLength[i], minLength[i]);
557       centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f;       // min length is negatie
558       newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f;      // min length is negative
559       *box->center +=  (box->axis[i] * centerOffset[i]);            // update the new center vector
560       halfLength[i] = newHalfLength[i];
561     }
562
563
564
565  box->halfLength[0] = halfLength[0];
566  box->halfLength[1] = halfLength[1];
567  box->halfLength[2] = halfLength[2];
568  PRINTF(3)("-- Written Axis to obb\n");
569  PRINTF(3)("-- Finished Calculating Attributes\n");
570}
571
572
573
574/**
575  \brief this separates an ob-box in the middle
576* @param box: the box to separate
577
578  this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
579 */
580void OBBTreeNode::forkBox(OBB* box)
581{
582  /* get the longest axis of the box */
583  float               aLength = -1.0f;                     //!< the length of the longest axis
584  int                 axisIndex = 0;                       //!< this is the nr of the longest axis
585
586  for(int i = 0; i < 3; ++i)
587  {
588    if( aLength < box->halfLength[i])
589    {
590      aLength = box->halfLength[i];
591      axisIndex = i;
592    }
593  }
594
595   PRINTF(3)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
596
597
598  /* get the closest vertex near the center */
599  float               dist = 999999.0f;                    //!< the smallest distance to each vertex
600  float               tmpDist;                             //!< temporary distance
601  int                 vertexIndex;
602  Plane               middlePlane(box->axis[axisIndex], *box->center); //!< the middle plane
603
604  vertexIndex = 0;
605  for(int i = 0; i < box->numOfVertices; ++i)
606  {
607    tmpDist = fabs(middlePlane.distancePoint(box->vertices[i]));
608    if( tmpDist < dist)
609    {
610      dist = tmpDist;
611      vertexIndex = i;
612    }
613  }
614
615  PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
616
617
618  /* now definin the separation plane through this specified nearest point and partition
619  the points depending on which side they are located
620  */
621  tList<const sVec3D>      partition1;                           //!< the vertex partition 1
622  tList<const sVec3D>      partition2;                           //!< the vertex partition 2
623
624
625  PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box->numOfVertices);
626  this->separationPlane = Plane(box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
627  this->sepPlaneCenter = &box->vertices[vertexIndex];
628  this->longestAxisIndex = axisIndex;
629
630  for(int i = 0; i < box->numOfVertices; ++i)
631  {
632    if( i == vertexIndex) continue;
633    tmpDist = this->separationPlane.distancePoint(box->vertices[i]);
634    if( tmpDist > 0.0)
635      partition1.add(&box->vertices[i]); /* positive numbers plus zero */
636    else
637      partition2.add(&box->vertices[i]); /* negatice numbers */
638  }
639  partition1.add(&box->vertices[vertexIndex]);
640  partition2.add(&box->vertices[vertexIndex]);
641
642  PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
643
644
645  /* now comes the separation into two different sVec3D arrays */
646  tIterator<const sVec3D>* iterator;                       //!< the iterator to go through the lists
647  const sVec3D*      element;                              //!< the elements
648  int                index;                                //!< index storage place
649  sVec3D*            vertList1;                            //!< the vertex list 1
650  sVec3D*            vertList2;                            //!< the vertex list 2
651
652  vertList1 = new sVec3D[partition1.getSize()];
653  vertList2 = new sVec3D[partition2.getSize()];
654
655  iterator = partition1.getIterator();
656  element = iterator->firstElement();
657  index = 0;
658  while( element != NULL)
659  {
660    vertList1[index][0] = element[0][0];
661    vertList1[index][1] = element[0][1];
662    vertList1[index][2] = element[0][2];
663    ++index;
664    element = iterator->nextElement();
665  }
666  delete iterator;
667//   PRINTF(0)("\npartition 1:\n");
668//   for(int i = 0; i < partition1.getSize(); ++i)
669//   {
670//     PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList1[i][0], i, vertList1[i][1], i, vertList1[i][2]);
671//   }
672
673  iterator = partition2.getIterator();
674  element = iterator->firstElement();
675  index = 0;
676  while( element != NULL)
677  {
678    vertList2[index][0] = element[0][0];
679    vertList2[index][1] = element[0][1];
680    vertList2[index][2] = element[0][2];
681    ++index;
682    element = iterator->nextElement();
683  }
684
685  if (this->tmpVert1 != NULL)
686    delete[] this->tmpVert1;
687  this->tmpVert1 = vertList1;
688  if (this->tmpVert2 != NULL)
689    delete[] this->tmpVert2;
690  this->tmpVert2 = vertList2;
691  this->tmpLen1 = partition1.getSize();
692  this->tmpLen2 = partition2.getSize();
693
694  delete iterator;
695
696//   PRINTF(0)("\npartition 2:\n");
697//   for(int i = 0; i < partition2.getSize(); ++i)
698//   {
699//     PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList2[i][0], i,  vertList2[i][1], i, vertList2[i][2]);
700//   }
701}
702
703
704
705
706void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB)
707{
708  PRINTF(3)("collideWith\n");
709  /* if the obb overlap, make subtests: check which node is realy overlaping  */
710  PRINT(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
711  if( unlikely(treeNode == NULL)) return;
712
713  if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
714  {
715    PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight);
716
717    /* check if left node overlaps */
718    if( likely( this->nodeLeft != NULL))
719    {
720      PRINT(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
721      if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
722      {
723        this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);
724        this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);
725      }
726    }
727    /* check if right node overlaps */
728    if( likely( this->nodeRight != NULL))
729    {
730      PRINT(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
731      if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
732      {
733       this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);
734       this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);
735      }
736    }
737
738    /* so there is a collision and this is the last box in the tree (i.e. leaf) */
739    if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL))
740    {
741      nodeA->collidesWith(nodeB, *((OBBTreeNode*)treeNode)->bvElement->center);
742
743      nodeB->collidesWith(nodeA, *this->bvElement->center);
744    }
745
746  }
747}
748
749
750
751bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB)
752{
753  /* first check all axis */
754  Vector t;
755  float rA = 0.0f;
756  float rB = 0.0f;
757  Vector l;
758  Vector rotAxisA[3];
759  Vector rotAxisB[3];
760
761  rotAxisA[0] =  nodeA->getAbsDir().apply(boxA->axis[0]);
762  rotAxisA[1] =  nodeA->getAbsDir().apply(boxA->axis[1]);
763  rotAxisA[2] =  nodeA->getAbsDir().apply(boxA->axis[2]);
764
765  rotAxisB[0] =  nodeB->getAbsDir().apply(boxB->axis[0]);
766  rotAxisB[1] =  nodeB->getAbsDir().apply(boxB->axis[1]);
767  rotAxisB[2] =  nodeB->getAbsDir().apply(boxB->axis[2]);
768
769  t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(*boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(*boxB->center));
770
771//   printf("\n");
772//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z);
773//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z);
774//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z);
775//
776//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z);
777//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z);
778//   printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z);
779
780
781  /* All 3 axis of the object A */
782  for( int j = 0; j < 3; ++j)
783  {
784    rA = 0.0f;
785    rB = 0.0f;
786    l = rotAxisA[j];
787
788    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
789    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
790    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
791
792    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
793    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
794    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
795
796    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
797
798    if( (rA + rB) < fabs(t.dot(l)))
799    {
800      PRINT(3)("no Collision\n");
801      return false;
802    }
803  }
804
805  /* All 3 axis of the object B */
806  for( int j = 0; j < 3; ++j)
807  {
808    rA = 0.0f;
809    rB = 0.0f;
810    l = rotAxisB[j];
811
812    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
813    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
814    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
815
816    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
817    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
818    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
819
820    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
821
822    if( (rA + rB) < fabs(t.dot(l)))
823    {
824      PRINT(3)("no Collision\n");
825      return false;
826    }
827  }
828
829
830  /* Now check for all face cross products */
831
832  for( int j = 0; j < 3; ++j)
833  {
834    for(int k = 0; k < 3; ++k )
835    {
836      rA = 0.0f;
837      rB = 0.0f;
838      l = rotAxisA[j].cross(rotAxisB[k]);
839
840      rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
841      rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
842      rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
843
844      rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
845      rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
846      rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
847
848      PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
849
850      if( (rA + rB) < fabs(t.dot(l)))
851      {
852        PRINT(3)("keine Kollision\n");
853        return false;
854      }
855    }
856  }
857
858
859  boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */
860  boxB->bCollided = true;
861  PRINT(3)("Kollision!\n");
862  return true;
863}
864
865
866
867
868
869void OBBTreeNode::drawBV(int depth, int drawMode, const Vector& color,  bool top) const
870{
871
872  /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */
873  if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL)
874  {
875    if( !(drawMode & DRAW_SINGLE && depth != 0))
876    {
877      if( drawMode & DRAW_POINTS)
878        glBegin(GL_POINTS);
879      for(int i = 0; i < this->bvElement->numOfVertices; ++i)
880      {
881        if( drawMode & DRAW_POINTS)
882          glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
883        else
884        {
885          glPushMatrix();
886          glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
887          gluSphere(OBBTreeNode_sphereObj, 0.1, 10, 10);
888          glPopMatrix();
889        }
890      }
891      if( drawMode & DRAW_POINTS)
892        glEnd();
893    }
894  }
895
896  if (top)
897  {
898    glPushAttrib(GL_ENABLE_BIT);
899    glDisable(GL_LIGHTING);
900    glDisable(GL_TEXTURE_2D);
901  }
902  glColor3f(color.x, color.y, color.z);
903
904
905  /* draw world axes */
906  if( drawMode & DRAW_BV_AXIS)
907  {
908    glBegin(GL_LINES);
909    glColor3f(1.0, 0.0, 0.0);
910    glVertex3f(0.0, 0.0, 0.0);
911    glVertex3f(3.0, 0.0, 0.0);
912
913    glColor3f(0.0, 1.0, 0.0);
914    glVertex3f(0.0, 0.0, 0.0);
915    glVertex3f(0.0, 3.0, 0.0);
916
917    glColor3f(0.0, 0.0, 1.0);
918    glVertex3f(0.0, 0.0, 0.0);
919    glVertex3f(0.0, 0.0, 3.0);
920    glEnd();
921  }
922
923
924  if( drawMode & DRAW_BV_AXIS || drawMode & DRAW_ALL)
925  {
926    if( !(drawMode & DRAW_SINGLE && depth != 0))
927    {
928      /* draw the obb axes */
929      glBegin(GL_LINES);
930      glColor3f(0.0, 0.4, 0.3);
931      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
932      glVertex3f(this->bvElement->center->x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
933                 this->bvElement->center->y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
934                 this->bvElement->center->z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
935
936      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
937      glVertex3f(this->bvElement->center->x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
938                 this->bvElement->center->y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
939                 this->bvElement->center->z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
940
941      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
942      glVertex3f(this->bvElement->center->x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
943                 this->bvElement->center->y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
944                 this->bvElement->center->z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
945      glEnd();
946    }
947  }
948
949
950  /* DRAW POLYGONS */
951  if( drawMode & DRAW_BV_POLYGON || drawMode & DRAW_ALL || drawMode & DRAW_BV_BLENDED)
952  {
953    if (top)
954    {
955      glEnable(GL_BLEND);
956      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
957    }
958
959    if(this->nodeLeft == NULL || this->nodeRight == NULL)
960      depth = 0;
961    if( !(drawMode & DRAW_SINGLE && depth != 0))
962    {
963    Vector cen = *this->bvElement->center;
964    Vector* axis = this->bvElement->axis;
965    float* len = this->bvElement->halfLength;
966
967    if( this->bvElement->bCollided)
968    {
969      glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR
970    }
971    else if( drawMode & DRAW_BV_BLENDED)
972    {
973      glColor4f(color.x, color.y, color.z, .5);
974    }
975
976    /* draw bounding box */
977    if( drawMode & DRAW_BV_BLENDED)
978      glBegin(GL_QUADS);
979    else
980      glBegin(GL_LINE_LOOP);
981    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
982               cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
983               cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
984    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
985               cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
986               cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
987    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
988               cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
989               cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
990    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
991               cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
992               cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
993    glEnd();
994
995    if( drawMode & DRAW_BV_BLENDED)
996      glBegin(GL_QUADS);
997    else
998      glBegin(GL_LINE_LOOP);
999    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
1000               cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
1001               cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
1002    glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
1003               cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
1004               cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
1005    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
1006               cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
1007               cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
1008    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
1009               cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
1010               cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
1011    glEnd();
1012
1013    if( drawMode & DRAW_BV_BLENDED)
1014      glBegin(GL_QUADS);
1015    else
1016      glBegin(GL_LINE_LOOP);
1017    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
1018               cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
1019               cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
1020    glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
1021               cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
1022               cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
1023    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1024               cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1025               cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1026    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1027               cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1028               cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1029    glEnd();
1030
1031    if( drawMode & DRAW_BV_BLENDED)
1032      glBegin(GL_QUADS);
1033    else
1034      glBegin(GL_LINE_LOOP);
1035    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1036               cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1037               cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1038    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1039               cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1040               cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1041    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1042               cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1043               cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1044    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1045               cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1046               cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1047    glEnd();
1048
1049
1050    if( drawMode & DRAW_BV_BLENDED)
1051    {
1052      glBegin(GL_QUADS);
1053      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1054                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1055                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1056      glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1057                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1058                 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1059      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
1060                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
1061                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
1062      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
1063                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
1064                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
1065      glEnd();
1066
1067      glBegin(GL_QUADS);
1068      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1069                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1070                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1071      glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1072                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1073                 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1074      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
1075                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
1076                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
1077      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
1078                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
1079                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
1080      glEnd();
1081    }
1082
1083
1084    if( drawMode & DRAW_BV_BLENDED)
1085      glColor3f(color.x, color.y, color.z);
1086    }
1087
1088  }
1089
1090  /* DRAW SEPARATING PLANE */
1091  if( drawMode & DRAW_SEPARATING_PLANE || drawMode & DRAW_ALL)
1092  {
1093    if( !(drawMode & DRAW_SINGLE && depth != 0))
1094    {
1095      if( drawMode & DRAW_BV_BLENDED)
1096        glColor4f(color.x, color.y, color.z, .6);
1097
1098    /* now draw the separation plane */
1099    Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];
1100    Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];
1101    Vector c = *this->bvElement->center;
1102    float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
1103    float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
1104    glBegin(GL_QUADS);
1105    glVertex3f(c.x + a1.x * l1 + a2.x * l2, c.y + a1.y * l1+ a2.y * l2, c.z + a1.z * l1 + a2.z * l2);
1106    glVertex3f(c.x - a1.x * l1 + a2.x * l2, c.y - a1.y * l1+ a2.y * l2, c.z - a1.z * l1 + a2.z * l2);
1107    glVertex3f(c.x - a1.x * l1 - a2.x * l2, c.y - a1.y * l1- a2.y * l2, c.z - a1.z * l1 - a2.z * l2);
1108    glVertex3f(c.x + a1.x * l1 - a2.x * l2, c.y + a1.y * l1- a2.y * l2, c.z + a1.z * l1 - a2.z * l2);
1109    glEnd();
1110
1111    if( drawMode & DRAW_BV_BLENDED)
1112      glColor4f(color.x, color.y, color.z, 1.0);
1113
1114    }
1115  }
1116
1117
1118
1119  if (depth > 0)
1120  {
1121    if( this->nodeLeft != NULL)
1122      this->nodeLeft->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(15.0,0.0,0.0)), false);
1123    if( this->nodeRight != NULL)
1124      this->nodeRight->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(30.0,0.0,0.0)), false);
1125  }
1126  this->bvElement->bCollided = false;
1127
1128  if (top)
1129    glPopAttrib();
1130}
1131
1132
1133
1134void OBBTreeNode::debug() const
1135{
1136
1137  /*
1138  for(int i = 0; i < length; i++)
1139  {
1140  PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
1141}
1142  */
1143}
Note: See TracBrowser for help on using the repository browser.