Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

collision_detection: adjusted the box splitting algorithm

File size: 38.5 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->numTriangles = 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  //for (element = nameList.begin(); element != nameList.end(); element++)
608//   iterator = partition2.getIterator();
609//   element = iterator->firstElement();
610
611  for(element = partition2.begin(), index = 0; element != partition2.end(); element++, index++)
612  {
613    vertList2[index][0] = (*element)[0][0];
614    vertList2[index][1] = (*element)[0][1];
615    vertList2[index][2] = (*element)[0][2];
616  }
617
618  if (this->tmpVert1 != NULL)
619    delete[] this->tmpVert1;
620  this->tmpVert1 = vertList1;
621  if (this->tmpVert2 != NULL)
622    delete[] this->tmpVert2;
623  this->tmpVert2 = vertList2;
624  this->tmpLen1 = partition1.size();
625  this->tmpLen2 = partition2.size();
626
627
628  //   PRINTF(0)("\npartition 2:\n");
629  //   for(int i = 0; i < partition2.getSize(); ++i)
630  //   {
631  //     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]);
632  //   }
633}
634
635
636
637
638void OBBTreeNode::collideWith(const BVTreeNode& treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const
639{
640  PRINTF(3)("collideWith\n");
641  /* if the obb overlap, make subtests: check which node is realy overlaping  */
642  PRINTF(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode.getIndex());
643  //   if( unlikely(treeNode == NULL)) return;
644
645
646  if( this->overlapTest(*this->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
647  {
648    PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA.getClassName(), nodeB.getClassName(), this->nodeLeft, this->nodeRight);
649
650    /* check if left node overlaps */
651    if( likely( this->nodeLeft != NULL))
652    {
653      PRINTF(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode.getIndex());
654      if( this->overlapTest(*this->nodeLeft->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
655      {
656        this->nodeLeft->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeLeft), nodeA, nodeB);
657        this->nodeLeft->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeRight), nodeA, nodeB);
658      }
659    }
660    /* check if right node overlaps */
661    if( likely( this->nodeRight != NULL))
662    {
663      PRINTF(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode.getIndex());
664      if(this->overlapTest(*this->nodeRight->bvElement, *(((const OBBTreeNode*)&treeNode)->bvElement), nodeA, nodeB))
665      {
666        this->nodeRight->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeLeft), nodeA, nodeB);
667        this->nodeRight->collideWith(*(((const OBBTreeNode*)&treeNode)->nodeRight), nodeA, nodeB);
668      }
669    }
670
671    /* so there is a collision and this is the last box in the tree (i.e. leaf) */
672    /* FIXME: If we would choose || insead of && there would also be asymmetrical cases supported */
673    if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL))
674    {
675      nodeA.collidesWith(nodeB, (((const OBBTreeNode*)&treeNode)->bvElement->center));
676
677      nodeB.collidesWith(nodeA, this->bvElement->center);
678    }
679
680  }
681}
682
683
684
685bool OBBTreeNode::overlapTest(const OBB& boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const
686{
687  //   if( boxB == NULL || boxA == NULL)
688  //     return false;
689
690  /* first check all axis */
691  Vector t;
692  float rA = 0.0f;
693  float rB = 0.0f;
694  Vector l;
695  Vector rotAxisA[3];
696  Vector rotAxisB[3];
697
698  rotAxisA[0] =  nodeA.getAbsDir().apply(boxA.axis[0]);
699  rotAxisA[1] =  nodeA.getAbsDir().apply(boxA.axis[1]);
700  rotAxisA[2] =  nodeA.getAbsDir().apply(boxA.axis[2]);
701
702  rotAxisB[0] =  nodeB.getAbsDir().apply(boxB.axis[0]);
703  rotAxisB[1] =  nodeB.getAbsDir().apply(boxB.axis[1]);
704  rotAxisB[2] =  nodeB.getAbsDir().apply(boxB.axis[2]);
705
706
707  t = nodeA.getAbsCoor() + nodeA.getAbsDir().apply(boxA.center) - ( nodeB.getAbsCoor() + nodeB.getAbsDir().apply(boxB.center));
708
709  //   printf("\n");
710  //   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);
711  //   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);
712  //   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);
713  //
714  //   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);
715  //   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);
716  //   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);
717
718
719  /* All 3 axis of the object A */
720  for( int j = 0; j < 3; ++j)
721  {
722    rA = 0.0f;
723    rB = 0.0f;
724    l = rotAxisA[j];
725
726    rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
727    rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
728    rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
729
730    rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
731    rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
732    rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
733
734    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
735
736    if( (rA + rB) < fabs(t.dot(l)))
737    {
738      PRINTF(3)("no Collision\n");
739      return false;
740    }
741  }
742
743  /* All 3 axis of the object B */
744  for( int j = 0; j < 3; ++j)
745  {
746    rA = 0.0f;
747    rB = 0.0f;
748    l = rotAxisB[j];
749
750    rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
751    rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
752    rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
753
754    rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
755    rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
756    rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
757
758    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
759
760    if( (rA + rB) < fabs(t.dot(l)))
761    {
762      PRINTF(3)("no Collision\n");
763      return false;
764    }
765  }
766
767
768  /* Now check for all face cross products */
769
770  for( int j = 0; j < 3; ++j)
771  {
772    for(int k = 0; k < 3; ++k )
773    {
774      rA = 0.0f;
775      rB = 0.0f;
776      l = rotAxisA[j].cross(rotAxisB[k]);
777
778      rA += fabs(boxA.halfLength[0] * rotAxisA[0].dot(l));
779      rA += fabs(boxA.halfLength[1] * rotAxisA[1].dot(l));
780      rA += fabs(boxA.halfLength[2] * rotAxisA[2].dot(l));
781
782      rB += fabs(boxB.halfLength[0] * rotAxisB[0].dot(l));
783      rB += fabs(boxB.halfLength[1] * rotAxisB[1].dot(l));
784      rB += fabs(boxB.halfLength[2] * rotAxisB[2].dot(l));
785
786      PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
787
788      if( (rA + rB) < fabs(t.dot(l)))
789      {
790        PRINTF(3)("keine Kollision\n");
791        return false;
792      }
793    }
794  }
795
796  /* FIXME: there is no collision mark set now */
797  //   boxA.bCollided = true; /* use this ONLY(!!!!) for drawing operations */
798  //   boxB.bCollided = true;
799
800
801  PRINTF(3)("Kollision!\n");
802  return true;
803}
804
805
806
807
808
809void OBBTreeNode::drawBV(int depth, int drawMode, const Vector& color,  bool top) const
810{
811
812  /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */
813  if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL)
814  {
815    if( !(drawMode & DRAW_SINGLE && depth != 0))
816    {
817      if( drawMode & DRAW_POINTS)
818        glBegin(GL_POINTS);
819      for(int i = 0; i < this->bvElement->numOfVertices; ++i)
820      {
821        if( drawMode & DRAW_POINTS)
822          glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
823        else
824        {
825          glPushMatrix();
826          glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
827          gluSphere(OBBTreeNode_sphereObj, 0.1, 10, 10);
828          glPopMatrix();
829        }
830      }
831      if( drawMode & DRAW_POINTS)
832        glEnd();
833    }
834  }
835
836  if (top)
837  {
838    glPushAttrib(GL_ENABLE_BIT);
839    glDisable(GL_LIGHTING);
840    glDisable(GL_TEXTURE_2D);
841  }
842  glColor3f(color.x, color.y, color.z);
843
844
845  /* draw world axes */
846  if( drawMode & DRAW_BV_AXIS)
847  {
848    glBegin(GL_LINES);
849    glColor3f(1.0, 0.0, 0.0);
850    glVertex3f(0.0, 0.0, 0.0);
851    glVertex3f(3.0, 0.0, 0.0);
852
853    glColor3f(0.0, 1.0, 0.0);
854    glVertex3f(0.0, 0.0, 0.0);
855    glVertex3f(0.0, 3.0, 0.0);
856
857    glColor3f(0.0, 0.0, 1.0);
858    glVertex3f(0.0, 0.0, 0.0);
859    glVertex3f(0.0, 0.0, 3.0);
860    glEnd();
861  }
862
863
864  if( drawMode & DRAW_BV_AXIS || drawMode & DRAW_ALL)
865  {
866    if( !(drawMode & DRAW_SINGLE && depth != 0))
867    {
868      /* draw the obb axes */
869      glBegin(GL_LINES);
870      glColor3f(0.0, 0.4, 0.3);
871      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
872      glVertex3f(this->bvElement->center.x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
873                 this->bvElement->center.y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
874                 this->bvElement->center.z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
875
876      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
877      glVertex3f(this->bvElement->center.x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
878                 this->bvElement->center.y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
879                 this->bvElement->center.z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
880
881      glVertex3f(this->bvElement->center.x, this->bvElement->center.y, this->bvElement->center.z);
882      glVertex3f(this->bvElement->center.x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
883                 this->bvElement->center.y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
884                 this->bvElement->center.z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
885      glEnd();
886    }
887  }
888
889
890  /* DRAW POLYGONS */
891  if( drawMode & DRAW_BV_POLYGON || drawMode & DRAW_ALL || drawMode & DRAW_BV_BLENDED)
892  {
893    if (top)
894    {
895      glEnable(GL_BLEND);
896      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
897    }
898
899    if(this->nodeLeft == NULL || this->nodeRight == NULL)
900      depth = 0;
901    if( !(drawMode & DRAW_SINGLE && depth != 0))
902    {
903      Vector cen = this->bvElement->center;
904      Vector* axis = this->bvElement->axis;
905      float* len = this->bvElement->halfLength;
906
907      if( this->bvElement->bCollided)
908      {
909        glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR
910      }
911      else if( drawMode & DRAW_BV_BLENDED)
912      {
913        glColor4f(color.x, color.y, color.z, .5);
914      }
915
916      /* draw bounding box */
917      if( drawMode & DRAW_BV_BLENDED)
918        glBegin(GL_QUADS);
919      else
920        glBegin(GL_LINE_LOOP);
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      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
931                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
932                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
933      glEnd();
934
935      if( drawMode & DRAW_BV_BLENDED)
936        glBegin(GL_QUADS);
937      else
938        glBegin(GL_LINE_LOOP);
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      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
949                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
950                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
951      glEnd();
952
953      if( drawMode & DRAW_BV_BLENDED)
954        glBegin(GL_QUADS);
955      else
956        glBegin(GL_LINE_LOOP);
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      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
967                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
968                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
969      glEnd();
970
971      if( drawMode & DRAW_BV_BLENDED)
972        glBegin(GL_QUADS);
973      else
974        glBegin(GL_LINE_LOOP);
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      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      glEnd();
988
989
990      if( drawMode & DRAW_BV_BLENDED)
991      {
992        glBegin(GL_QUADS);
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        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        glEnd();
1006
1007        glBegin(GL_QUADS);
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        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        glEnd();
1021      }
1022
1023
1024      if( drawMode & DRAW_BV_BLENDED)
1025        glColor3f(color.x, color.y, color.z);
1026    }
1027
1028  }
1029
1030  /* DRAW SEPARATING PLANE */
1031  if( drawMode & DRAW_SEPARATING_PLANE || drawMode & DRAW_ALL)
1032  {
1033    if( !(drawMode & DRAW_SINGLE && depth != 0))
1034    {
1035      if( drawMode & DRAW_BV_BLENDED)
1036        glColor4f(color.x, color.y, color.z, .6);
1037
1038      /* now draw the separation plane */
1039      Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];
1040      Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];
1041      Vector c = this->bvElement->center;
1042      float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
1043      float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
1044      glBegin(GL_QUADS);
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      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);
1047      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);
1048      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);
1049      glEnd();
1050
1051      if( drawMode & DRAW_BV_BLENDED)
1052        glColor4f(color.x, color.y, color.z, 1.0);
1053
1054    }
1055  }
1056
1057
1058
1059  if (depth > 0)
1060  {
1061    if( this->nodeLeft != NULL)
1062      this->nodeLeft->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(15.0,0.0,0.0)), false);
1063    if( this->nodeRight != NULL)
1064      this->nodeRight->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(30.0,0.0,0.0)), false);
1065  }
1066  this->bvElement->bCollided = false;
1067
1068  if (top)
1069    glPopAttrib();
1070}
1071
1072
1073
1074void OBBTreeNode::debug() const
1075{
1076  PRINT(0)("========OBBTreeNode::debug()=====\n");
1077  PRINT(0)(" Current depth: %i", this->depth);
1078  PRINT(0)(" ");
1079  PRINT(0)("=================================\n");
1080}
Note: See TracBrowser for help on using the repository browser.