Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

collision_detection: cleanup and recode of some small parts.

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