Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

collision_detection: getting rid of the old vertices based structure

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