Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5705 was 5705, checked in by patrick, 19 years ago

collision_detection: slowly removing old functions and exchanging them with the new interface

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