Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_detection/obb_tree_node.cc @ 6533

Last change on this file since 6533 was 6022, checked in by bensch, 19 years ago

orxonox/trunk: merged the NewModel branche back to the trunk.
merged with command
svn merge branches/newModel/ trunk/ -r 6016:HEAD
no conflicts

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