Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5692 was 5692, checked in by bensch, 18 years ago

orxonox/trunk: no more valgrind warnings :)))))))

File size: 38.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION
17
18#include "obb_tree_node.h"
19#include "list.h"
20#include "obb.h"
21#include "obb_tree.h"
22#include "matrix.h"
23#include "abstract_model.h"
24#include "world_entity.h"
25
26#include "color.h"
27
28#include "debug.h"
29#include "glincl.h"
30
31
32
33using namespace std;
34
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[0][0], box->covarianceMatrix[0][1], box->covarianceMatrix[0][2],
431                  box->covarianceMatrix[1][0], box->covarianceMatrix[1][1], box->covarianceMatrix[1][2],
432                  box->covarianceMatrix[2][0], box->covarianceMatrix[2][1], box->covarianceMatrix[2][2] );
433  covMat.getEigenVectors(axis[0], axis[1], axis[2] );
434
435
436  /* new jacobi tests */
437//  JacobI(OBBTreeNode::coMat, OBBTreeNode::eigvlMat, OBBTreeNode::eigvMat, OBBTreeNode::rotCount);
438//  PRINTF(3)("-- Done Jacobi Decomposition\n");
439
440
441//   PRINTF(0)("Jacobi\n");
442//   for(int j = 0; j < 3; ++j)
443//   {
444//     printf(" |");
445//     for(int k = 0; k < 3; ++k)
446//     {
447//       printf(" \t%f ", OBBTreeNode::OBBTreeNode::eigvMat[j][k]);
448//     }
449//     printf(" |\n");
450//   }
451
452/*  axis[0].x = OBBTreeNode::eigvMat[0][0]; axis[0].y = OBBTreeNode::eigvMat[1][0]; axis[0].z = OBBTreeNode::eigvMat[2][0];
453  axis[1].x = OBBTreeNode::eigvMat[0][1]; axis[1].y = OBBTreeNode::eigvMat[1][1]; axis[1].z = OBBTreeNode::eigvMat[2][1];
454  axis[2].x = OBBTreeNode::eigvMat[0][2]; axis[2].y = OBBTreeNode::eigvMat[1][2]; axis[2].z = OBBTreeNode::eigvMat[2][2];
455  axis[0].normalize();
456  axis[1].normalize();
457  axis[2].normalize();*/
458  box->axis = axis;
459
460//   PRINTF(0)("-- Got Axis\n");
461//
462//   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0].x, box->axis[0].y, box->axis[0].z);
463//   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1].x, box->axis[1].y, box->axis[1].z);
464//   PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2].x, box->axis[2].y, box->axis[2].z);
465}
466
467
468void OBBTreeNode::calculateBoxAxis(OBB* box, const modelInfo& modInfo)
469{
470  this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices);
471}
472
473
474
475void OBBTreeNode::calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length)
476{
477
478  /* now get the axis length */
479  Line                ax[3];                                 //!< the axis
480  float*              halfLength = new float[3];             //!< half length of the axis
481  float               tmpLength;                             //!< tmp save point for the length
482  Plane               p0(box->axis[0], *box->center);       //!< the axis planes
483  Plane               p1(box->axis[1], *box->center);
484  Plane               p2(box->axis[2], *box->center);
485  float               maxLength[3];
486  float               minLength[3];
487
488
489  /* get a bad bounding box */
490  halfLength[0] = -1.0f;
491  for(int j = 0; j < length; ++j)
492    {
493      tmpLength = fabs(p0.distancePoint(vertices[j]));
494      if( tmpLength > halfLength[0])
495        halfLength[0] = tmpLength;
496    }
497
498  halfLength[1] = -1.0f;
499  for(int j = 0; j < length; ++j)
500    {
501      tmpLength = fabs(p1.distancePoint(vertices[j]));
502      if( tmpLength > halfLength[1])
503        halfLength[1] = tmpLength;
504    }
505
506  halfLength[2] = -1.0f;
507  for(int j = 0; j < length; ++j)
508    {
509      tmpLength = fabs(p2.distancePoint(vertices[j]));
510      if( tmpLength > halfLength[2])
511        halfLength[2] = tmpLength;
512    }
513
514
515
516  /* get the maximal dimensions of the body in all directions */
517    maxLength[0] = p0.distancePoint(vertices[0]);
518    minLength[0] = p0.distancePoint(vertices[0]);
519   for(int j = 0; j < length; ++j)
520   {
521     tmpLength = p0.distancePoint(vertices[j]);
522     if( tmpLength > maxLength[0])
523       maxLength[0] = tmpLength;
524     else if( tmpLength < minLength[0])
525       minLength[0] = tmpLength;
526   }
527
528   maxLength[1] = p1.distancePoint(vertices[0]);
529   minLength[1] = p1.distancePoint(vertices[0]);
530   for(int j = 0; j < length; ++j)
531   {
532     tmpLength = p1.distancePoint(vertices[j]);
533     if( tmpLength > maxLength[1])
534       maxLength[1] = tmpLength;
535     else if( tmpLength < minLength[1])
536       minLength[1] = tmpLength;
537   }
538
539   maxLength[2] = p2.distancePoint(vertices[0]);
540   minLength[2] = p2.distancePoint(vertices[0]);
541   for(int j = 0; j < length; ++j)
542   {
543     tmpLength = p2.distancePoint(vertices[j]);
544     if( tmpLength > maxLength[2])
545       maxLength[2] = tmpLength;
546     else if( tmpLength < minLength[2])
547       minLength[2] = tmpLength;
548   }
549
550
551   /* calculate the real centre of the body by using the axis length */
552   float centerOffset[3];
553   float newHalfLength[3];
554   for(int i = 0; i < 3; ++i)
555     {
556       PRINTF(3)("max: %f, min: %f \n", maxLength[i], minLength[i]);
557       centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f;       // min length is negatie
558       newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f;      // min length is negative
559       *box->center +=  (box->axis[i] * centerOffset[i]);            // update the new center vector
560       halfLength[i] = newHalfLength[i];
561     }
562
563
564
565  box->halfLength = halfLength;
566  PRINTF(3)("-- Written Axis to obb\n");
567  PRINTF(3)("-- Finished Calculating Attributes\n");
568}
569
570
571
572/**
573  \brief this separates an ob-box in the middle
574* @param box: the box to separate
575
576  this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
577 */
578void OBBTreeNode::forkBox(OBB* box)
579{
580  /* get the longest axis of the box */
581  float               aLength = -1.0f;                     //!< the length of the longest axis
582  int                 axisIndex = 0;                       //!< this is the nr of the longest axis
583
584  for(int i = 0; i < 3; ++i)
585  {
586    if( aLength < box->halfLength[i])
587    {
588      aLength = box->halfLength[i];
589      axisIndex = i;
590    }
591  }
592
593   PRINTF(3)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
594
595
596  /* get the closest vertex near the center */
597  float               dist = 999999.0f;                    //!< the smallest distance to each vertex
598  float               tmpDist;                             //!< temporary distance
599  int                 vertexIndex;
600  Plane               middlePlane(box->axis[axisIndex], *box->center); //!< the middle plane
601
602  vertexIndex = 0;
603  for(int i = 0; i < box->numOfVertices; ++i)
604  {
605    tmpDist = fabs(middlePlane.distancePoint(box->vertices[i]));
606    if( tmpDist < dist)
607    {
608      dist = tmpDist;
609      vertexIndex = i;
610    }
611  }
612
613  PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
614
615
616  /* now definin the separation plane through this specified nearest point and partition
617  the points depending on which side they are located
618  */
619  tList<const sVec3D>      partition1;                           //!< the vertex partition 1
620  tList<const sVec3D>      partition2;                           //!< the vertex partition 2
621
622
623  PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box->numOfVertices);
624  this->separationPlane = new Plane(box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
625  this->sepPlaneCenter = &box->vertices[vertexIndex];
626  this->longestAxisIndex = axisIndex;
627
628  for(int i = 0; i < box->numOfVertices; ++i)
629  {
630    if( i == vertexIndex) continue;
631    tmpDist = this->separationPlane->distancePoint(box->vertices[i]);
632    if( tmpDist > 0.0)
633      partition1.add(&box->vertices[i]); /* positive numbers plus zero */
634    else
635      partition2.add(&box->vertices[i]); /* negatice numbers */
636  }
637  partition1.add(&box->vertices[vertexIndex]);
638  partition2.add(&box->vertices[vertexIndex]);
639
640  PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
641
642
643  /* now comes the separation into two different sVec3D arrays */
644  tIterator<const sVec3D>* iterator;                       //!< the iterator to go through the lists
645  const sVec3D*      element;                              //!< the elements
646  int                index;                                //!< index storage place
647  sVec3D*            vertList1;                            //!< the vertex list 1
648  sVec3D*            vertList2;                            //!< the vertex list 2
649
650  vertList1 = new sVec3D[partition1.getSize()];
651  vertList2 = new sVec3D[partition2.getSize()];
652
653  iterator = partition1.getIterator();
654  element = iterator->firstElement();
655  index = 0;
656  while( element != NULL)
657  {
658    vertList1[index][0] = element[0][0];
659    vertList1[index][1] = element[0][1];
660    vertList1[index][2] = element[0][2];
661    ++index;
662    element = iterator->nextElement();
663  }
664
665//   PRINTF(0)("\npartition 1:\n");
666//   for(int i = 0; i < partition1.getSize(); ++i)
667//   {
668//     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]);
669//   }
670
671  iterator = partition2.getIterator();
672  element = iterator->firstElement();
673  index = 0;
674  while( element != NULL)
675  {
676    vertList2[index][0] = element[0][0];
677    vertList2[index][1] = element[0][1];
678    vertList2[index][2] = element[0][2];
679    ++index;
680    element = iterator->nextElement();
681  }
682
683  this->tmpVert1 = vertList1;
684  this->tmpVert2 = vertList2;
685  this->tmpLen1 = partition1.getSize();
686  this->tmpLen2 = partition2.getSize();
687
688  delete iterator;
689
690//   PRINTF(0)("\npartition 2:\n");
691//   for(int i = 0; i < partition2.getSize(); ++i)
692//   {
693//     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]);
694//   }
695}
696
697
698
699
700void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB)
701{
702  PRINTF(3)("collideWith\n");
703  /* if the obb overlap, make subtests: check which node is realy overlaping  */
704  PRINT(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex());
705  if( unlikely(treeNode == NULL)) return;
706
707  if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
708  {
709    PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight);
710
711    /* check if left node overlaps */
712    if( likely( this->nodeLeft != NULL))
713    {
714      PRINT(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex());
715      if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
716      {
717        this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);
718        this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);
719      }
720    }
721    /* check if right node overlaps */
722    if( likely( this->nodeRight != NULL))
723    {
724      PRINT(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex());
725      if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB))
726      {
727       this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB);
728       this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB);
729      }
730    }
731
732    /* so there is a collision and this is the last box in the tree (i.e. leaf) */
733    if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL))
734    {
735      nodeA->collidesWith(nodeB, *((OBBTreeNode*)treeNode)->bvElement->center);
736
737      nodeB->collidesWith(nodeA, *this->bvElement->center);
738    }
739
740  }
741}
742
743
744
745bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB)
746{
747  /* first check all axis */
748  Vector t;
749  float rA = 0.0f;
750  float rB = 0.0f;
751  Vector l;
752  Vector rotAxisA[3];
753  Vector rotAxisB[3];
754
755  rotAxisA[0] =  nodeA->getAbsDir().apply(boxA->axis[0]);
756  rotAxisA[1] =  nodeA->getAbsDir().apply(boxA->axis[1]);
757  rotAxisA[2] =  nodeA->getAbsDir().apply(boxA->axis[2]);
758
759  rotAxisB[0] =  nodeB->getAbsDir().apply(boxB->axis[0]);
760  rotAxisB[1] =  nodeB->getAbsDir().apply(boxB->axis[1]);
761  rotAxisB[2] =  nodeB->getAbsDir().apply(boxB->axis[2]);
762
763  t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(*boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(*boxB->center));
764
765//   printf("\n");
766//   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);
767//   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);
768//   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);
769//
770//   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);
771//   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);
772//   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);
773
774
775  /* All 3 axis of the object A */
776  for( int j = 0; j < 3; ++j)
777  {
778    rA = 0.0f;
779    rB = 0.0f;
780    l = rotAxisA[j];
781
782    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
783    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
784    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
785
786    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
787    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
788    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
789
790    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
791
792    if( (rA + rB) < fabs(t.dot(l)))
793    {
794      PRINT(3)("no Collision\n");
795      return false;
796    }
797  }
798
799  /* All 3 axis of the object B */
800  for( int j = 0; j < 3; ++j)
801  {
802    rA = 0.0f;
803    rB = 0.0f;
804    l = rotAxisB[j];
805
806    rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
807    rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
808    rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
809
810    rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
811    rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
812    rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
813
814    PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
815
816    if( (rA + rB) < fabs(t.dot(l)))
817    {
818      PRINT(3)("no Collision\n");
819      return false;
820    }
821  }
822
823
824  /* Now check for all face cross products */
825
826  for( int j = 0; j < 3; ++j)
827  {
828    for(int k = 0; k < 3; ++k )
829    {
830      rA = 0.0f;
831      rB = 0.0f;
832      l = rotAxisA[j].cross(rotAxisB[k]);
833
834      rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l));
835      rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l));
836      rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l));
837
838      rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l));
839      rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l));
840      rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l));
841
842      PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB);
843
844      if( (rA + rB) < fabs(t.dot(l)))
845      {
846        PRINT(3)("keine Kollision\n");
847        return false;
848      }
849    }
850  }
851
852
853  boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */
854  boxB->bCollided = true;
855  PRINT(3)("Kollision!\n");
856  return true;
857}
858
859
860
861
862
863void OBBTreeNode::drawBV(int depth, int drawMode, const Vector& color,  bool top) const
864{
865
866  /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */
867  if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL)
868  {
869    if( !(drawMode & DRAW_SINGLE && depth != 0))
870    {
871      if( drawMode & DRAW_POINTS)
872        glBegin(GL_POINTS);
873      for(int i = 0; i < this->bvElement->numOfVertices; ++i)
874      {
875        if( drawMode & DRAW_POINTS)
876          glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
877        else
878        {
879          glPushMatrix();
880          glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
881          gluSphere(OBBTreeNode_sphereObj, 0.1, 10, 10);
882          glPopMatrix();
883        }
884      }
885      if( drawMode & DRAW_POINTS)
886        glEnd();
887    }
888  }
889
890  if (top)
891  {
892    glPushAttrib(GL_ENABLE_BIT);
893    glDisable(GL_LIGHTING);
894    glDisable(GL_TEXTURE_2D);
895  }
896  glColor3f(color.x, color.y, color.z);
897
898
899  /* draw world axes */
900  if( drawMode & DRAW_BV_AXIS)
901  {
902    glBegin(GL_LINES);
903    glColor3f(1.0, 0.0, 0.0);
904    glVertex3f(0.0, 0.0, 0.0);
905    glVertex3f(3.0, 0.0, 0.0);
906
907    glColor3f(0.0, 1.0, 0.0);
908    glVertex3f(0.0, 0.0, 0.0);
909    glVertex3f(0.0, 3.0, 0.0);
910
911    glColor3f(0.0, 0.0, 1.0);
912    glVertex3f(0.0, 0.0, 0.0);
913    glVertex3f(0.0, 0.0, 3.0);
914    glEnd();
915  }
916
917
918  if( drawMode & DRAW_BV_AXIS || drawMode & DRAW_ALL)
919  {
920    if( !(drawMode & DRAW_SINGLE && depth != 0))
921    {
922      /* draw the obb axes */
923      glBegin(GL_LINES);
924      glColor3f(0.0, 0.4, 0.3);
925      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
926      glVertex3f(this->bvElement->center->x + this->bvElement->axis[0].x * this->bvElement->halfLength[0],
927                 this->bvElement->center->y + this->bvElement->axis[0].y * this->bvElement->halfLength[0],
928                 this->bvElement->center->z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]);
929
930      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
931      glVertex3f(this->bvElement->center->x + this->bvElement->axis[1].x * this->bvElement->halfLength[1],
932                 this->bvElement->center->y + this->bvElement->axis[1].y * this->bvElement->halfLength[1],
933                 this->bvElement->center->z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]);
934
935      glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
936      glVertex3f(this->bvElement->center->x + this->bvElement->axis[2].x * this->bvElement->halfLength[2],
937                 this->bvElement->center->y + this->bvElement->axis[2].y * this->bvElement->halfLength[2],
938                 this->bvElement->center->z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]);
939      glEnd();
940    }
941  }
942
943
944  /* DRAW POLYGONS */
945  if( drawMode & DRAW_BV_POLYGON || drawMode & DRAW_ALL || drawMode & DRAW_BV_BLENDED)
946  {
947    if (top)
948    {
949      glEnable(GL_BLEND);
950      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
951    }
952
953    if(this->nodeLeft == NULL || this->nodeRight == NULL)
954      depth = 0;
955    if( !(drawMode & DRAW_SINGLE && depth != 0))
956    {
957    Vector cen = *this->bvElement->center;
958    Vector* axis = this->bvElement->axis;
959    float* len = this->bvElement->halfLength;
960
961    if( this->bvElement->bCollided)
962    {
963      glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR
964    }
965    else if( drawMode & DRAW_BV_BLENDED)
966    {
967      glColor4f(color.x, color.y, color.z, .5);
968    }
969
970    /* draw bounding box */
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    if( drawMode & DRAW_BV_BLENDED)
990      glBegin(GL_QUADS);
991    else
992      glBegin(GL_LINE_LOOP);
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    if( drawMode & DRAW_BV_BLENDED)
1008      glBegin(GL_QUADS);
1009    else
1010      glBegin(GL_LINE_LOOP);
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    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1021               cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1022               cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1023    glEnd();
1024
1025    if( drawMode & DRAW_BV_BLENDED)
1026      glBegin(GL_QUADS);
1027    else
1028      glBegin(GL_LINE_LOOP);
1029    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1030               cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1031               cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1032    glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1033               cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1034               cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1035    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1036               cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1037               cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1038    glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1039               cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1040               cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1041    glEnd();
1042
1043
1044    if( drawMode & DRAW_BV_BLENDED)
1045    {
1046      glBegin(GL_QUADS);
1047      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1048                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1049                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1050      glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2],
1051                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2],
1052                 cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]);
1053      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
1054                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
1055                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
1056      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2],
1057                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2],
1058                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]);
1059      glEnd();
1060
1061      glBegin(GL_QUADS);
1062      glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1063                 cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1064                 cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1065      glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2],
1066                 cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2],
1067                 cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]);
1068      glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
1069                 cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
1070                 cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
1071      glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2],
1072                 cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2],
1073                 cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]);
1074      glEnd();
1075    }
1076
1077
1078    if( drawMode & DRAW_BV_BLENDED)
1079      glColor3f(color.x, color.y, color.z);
1080    }
1081
1082  }
1083
1084  /* DRAW SEPARATING PLANE */
1085  if( drawMode & DRAW_SEPARATING_PLANE || drawMode & DRAW_ALL)
1086  {
1087    if( !(drawMode & DRAW_SINGLE && depth != 0))
1088    {
1089      if( drawMode & DRAW_BV_BLENDED)
1090        glColor4f(color.x, color.y, color.z, .6);
1091
1092    /* now draw the separation plane */
1093    Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3];
1094    Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3];
1095    Vector c = *this->bvElement->center;
1096    float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
1097    float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
1098    glBegin(GL_QUADS);
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    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);
1102    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);
1103    glEnd();
1104
1105    if( drawMode & DRAW_BV_BLENDED)
1106      glColor4f(color.x, color.y, color.z, 1.0);
1107
1108    }
1109  }
1110
1111
1112
1113  if (depth > 0)
1114  {
1115    if( this->nodeLeft != NULL)
1116      this->nodeLeft->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(15.0,0.0,0.0)), false);
1117    if( this->nodeRight != NULL)
1118      this->nodeRight->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(30.0,0.0,0.0)), false);
1119  }
1120  this->bvElement->bCollided = false;
1121
1122  if (top)
1123    glPopAttrib();
1124}
1125
1126
1127
1128void OBBTreeNode::debug() const
1129{
1130
1131  /*
1132  for(int i = 0; i < length; i++)
1133  {
1134  PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
1135}
1136  */
1137}
Note: See TracBrowser for help on using the repository browser.