Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: the separation plane is also drawn for debug purposes. vert separation seems to malfunction

File size: 20.7 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 "vector.h"
23#include "abstract_model.h"
24
25#include <math.h>
26
27
28#define WANT_STREAM
29#define WANT_MATH
30#define WANT_FSTREAM
31
32
33#include "include.h"
34#include "newmat.h"
35#include "newmatap.h"
36#include "newmatio.h"
37
38#include "lin_alg.h"
39
40
41
42
43using namespace std;
44
45OBBTree*  OBBTreeNode::obbTree = NULL;
46
47float**  OBBTreeNode::coMat = NULL;
48float**  OBBTreeNode::eigvMat = NULL;
49float*   OBBTreeNode::eigvlMat = NULL;
50int*     OBBTreeNode::rotCount = NULL;
51
52/**
53   \brief standard constructor
54 */
55OBBTreeNode::OBBTreeNode ()
56{
57  this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
58  this->nodeLeft = NULL;
59  this->nodeRight = NULL;
60
61  if(coMat == NULL)
62  {
63    coMat = new float*[4];
64    for(int i = 0; i < 4; i++)
65      coMat[i] = new float[4];
66  }
67  if(eigvMat == NULL)
68  {
69    eigvMat = new float*[4];
70    for(int i = 0; i < 4; i++)
71      eigvMat[i] = new float[4];
72  }
73  if( eigvlMat == NULL)
74  {
75    eigvlMat = new float[4];
76  }
77  if( rotCount == NULL)
78    rotCount = new int;
79}
80
81
82/**
83   \brief standard deconstructor
84 */
85OBBTreeNode::~OBBTreeNode ()
86{
87  // delete what has to be deleted here
88}
89
90
91
92/**
93   \brief creates a new BVTree or BVTree partition
94   \param depth: how much more depth-steps to go: if == 1 don't go any deeper!
95   \param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle
96 */
97void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length)
98{
99  printf("OBB Depth: %i, numVertices: %i\n", depth, length);
100  this->depth = depth;
101
102  this->bvElement = new OBB();
103  PRINTF(0)("Created OBBox\n");
104  this->calculateBoxCovariance(this->bvElement, verticesList, length);
105  PRINTF(0)("Calculated attributes1\n");
106  this->calculateBoxEigenvectors(this->bvElement, verticesList, length);
107  PRINTF(0)("Calculated attributes2\n");
108  this->calculateBoxAxis(this->bvElement, verticesList, length);
109  PRINTF(0)("Calculated attributes3\n");
110
111
112  if( likely( this->depth > 0))
113  {
114    this->forkBox(this->bvElement);
115
116    OBBTreeNode*       node1 = new OBBTreeNode();
117    OBBTreeNode*       node2 = new OBBTreeNode();
118
119    this->nodeLeft = node1;
120    this->nodeRight = node2;
121
122    this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
123    this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
124
125  }
126}
127
128
129
130void OBBTreeNode::calculateBoxCovariance(OBB* box, sVec3D* verticesList, int length)
131{
132  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
133  float     face;                                    //!< surface area of the entire convex hull
134  Vector    centroid[length];                        //!< centroid of the i'th convex hull
135  Vector    center;                                  //!< the center of the entire hull
136  Vector    p, q, r;                                 //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d
137  Vector    t1, t2;                                  //!< temporary values
138  float     covariance[3][3];                        //!< the covariance matrix
139
140  this->numOfVertices = length;
141  this->vertices = verticesList;
142  box->vertices = verticesList;
143  box->numOfVertices = length;
144
145
146  /* fist compute all the convex hull face/facelets and centroids */
147  for(int i = 0; i < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
148  {
149    p = verticesList[i];
150    q = verticesList[i +1];
151    r = verticesList[i + 2];
152
153    t1 = p - q; t2 = p - r;
154
155    /* finding the facelet surface via cross-product */
156    facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
157    /* update the entire convex hull surface */
158    face += facelet[i];
159
160    /* calculate the cetroid of the hull triangles */
161    centroid[i] = (p + q + r) * 1/3;
162    /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
163    center += centroid[i] * facelet[i];
164  }
165  /* take the average of the centroid sum */
166  center /= face;
167  PRINTF(0)("-- Calculated Center\n");
168
169
170  /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
171  for(int j = 0; j < 3; ++j)
172  {
173    for(int k = 0; k < 3; ++k)
174    {
175      for(int i = 0; i < length; i+=3)
176      {
177        p = verticesList[i];
178        q = verticesList[i +1];
179        r = verticesList[i + 2];
180
181        covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
182            q[j] * q[k] + r[j]*r[k]) - center[j] * center[k];
183      }
184    }
185  }
186  PRINTF(0)("-- Calculated Covariance\n");
187  return;
188
189//   printf("\nVertex Data:\n");
190//   for(int i = 0; i < length; i++)
191//   {
192//     printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
193//   }
194
195//   printf("\nCovariance Matrix:\n");
196//   for(int j = 0; j < 3; ++j)
197//   {
198//     printf(" |");
199//     for(int k = 0; k < 3; ++k)
200//     {
201//       printf(" \b%f ", covariance[j][k]);
202//     }
203//     printf(" |\n");
204//   }
205//   printf("center: %f, %f, %f\n\n", center.x, center.y, center.z);
206
207
208  for(int i = 0; i < 3; ++i)
209  {
210
211    box->covarianceMatrix[i][0] = covariance[i][0];
212    box->covarianceMatrix[i][1] = covariance[i][1];
213    box->covarianceMatrix[i][3] = covariance[i][2];
214  }
215  *box->center = center;
216  PRINTF(0)("-- Written Result to obb\n");
217}
218
219
220
221void OBBTreeNode::calculateBoxEigenvectors(OBB* box, sVec3D* verticesList, int length)
222{
223
224  /* now getting spanning vectors of the sub-space:
225  the eigenvectors of a symmertric matrix, such as the
226  covarience matrix are mutually orthogonal.
227  after normalizing them, they can be used as a the basis
228  vectors
229  */
230  Vector**              axis = new Vector*[3];                //!< the references to the obb axis
231
232  coMat[1][1] = box->covarianceMatrix[0][0]; coMat[1][2] = box->covarianceMatrix[0][1]; coMat[1][3] = box->covarianceMatrix[0][2];
233  coMat[2][1] = box->covarianceMatrix[1][0]; coMat[2][2] = box->covarianceMatrix[1][1]; coMat[2][3] = box->covarianceMatrix[1][2];
234  coMat[3][1] = box->covarianceMatrix[2][0]; coMat[3][2] = box->covarianceMatrix[2][1]; coMat[3][3] = box->covarianceMatrix[2][2];
235
236  /* new jacobi tests */
237  JacobI(coMat, 3, eigvlMat, eigvMat, rotCount);
238  PRINTF(0)("-- Done Jacobi Decomposition\n");
239
240
241//   printf("Jacobi\n");
242//   for(int j = 1; j < 4; ++j)
243//   {
244//     printf(" |");
245//     for(int k = 1; k < 4; ++k)
246//     {
247//       printf(" \b%f ", eigvMat[j][k]);
248//     }
249//     printf(" |\n");
250//   }
251
252  axis[0] = new Vector(eigvMat[1][1], eigvMat[2][1], eigvMat[3][1]);
253  axis[1] = new Vector(eigvMat[1][2], eigvMat[2][2], eigvMat[3][2]);
254  axis[2] = new Vector(eigvMat[1][3], eigvMat[2][3], eigvMat[3][3]);
255  box->axis = axis;
256  PRINTF(0)("-- Got Axis\n");
257
258//   printf("\neigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
259//   printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
260//   printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
261}
262
263
264void OBBTreeNode::calculateBoxAxis(OBB* box, sVec3D* verticesList, int length)
265{
266
267  /* now get the axis length */
268  Line                ax[3];                                 //!< the axis
269  float*              halfLength = new float[3];             //!< half length of the axis
270  float               tmpLength;                             //!< tmp save point for the length
271  Plane               p0(*box->axis[0], *box->center);       //!< the axis planes
272  Plane               p1(*box->axis[1], *box->center);
273  Plane               p2(*box->axis[2], *box->center);
274
275  halfLength[0] = -1.0f;
276  for(int j = 0; j < length; ++j)
277  {
278    tmpLength = fabs(p0.distancePoint(vertices[j]));
279    if( tmpLength > halfLength[0])
280      halfLength[0] = tmpLength;
281  }
282
283  halfLength[1] = -1.0f;
284  for(int j = 0; j < length; ++j)
285  {
286    tmpLength = fabs(p1.distancePoint(vertices[j]));
287    if( tmpLength > halfLength[1])
288      halfLength[1] = tmpLength;
289  }
290
291  halfLength[2] = -1.0f;
292  for(int j = 0; j < length; ++j)
293  {
294    tmpLength = fabs(p2.distancePoint(vertices[j]));
295    if( tmpLength > halfLength[2])
296      halfLength[2] = tmpLength;
297  }
298
299  box->halfLength = halfLength;
300  PRINTF(0)("-- Written Axis to obb\n");
301  PRINTF(0)("-- Finished Calculating Attributes\n");
302
303//   printf("\nwe got length: \n");
304//   for(int i = 0; i < 3; ++i)
305//     printf("length[%i] = %f\n", i, box->halfLength[i]);
306}
307
308
309
310/**
311  \brief this separates an ob-box in the middle
312  \param box: the box to separate
313
314  this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
315 */
316void OBBTreeNode::forkBox(OBB* box)
317{
318  /* get the longest axis of the box */
319  float               aLength = -1.0f;                     //!< the length of the longest axis
320  int                 axisIndex = 0;                       //!< this is the nr of the longest axis
321
322  for(int i = 0; i < 3; ++i)
323  {
324    if( aLength < box->halfLength[i])
325    {
326      aLength = box->halfLength[i];
327      axisIndex = i;
328    }
329  }
330
331//   printf("\nlongest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
332
333
334  /* get the closest vertex near the center */
335  float               dist = 999999.0f;                    //!< the smallest distance to each vertex
336  float               tmpDist;                             //!< temporary distance
337  int                 vertexIndex;
338  Plane               middlePlane(*box->axis[axisIndex], *box->center); //!< the middle plane
339
340  for(int i = 0; i < box->numOfVertices; ++i)
341  {
342    tmpDist = fabs(middlePlane.distancePoint(box->vertices[i]));
343    if( tmpDist < dist)
344    {
345      dist = tmpDist;
346      vertexIndex = i;
347    }
348  }
349
350//   printf("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
351
352
353  /* now definin the separation plane through this specified nearest point and partition
354  the points depending on which side they are located
355  */
356  tList<sVec3D>      partition1;                           //!< the vertex partition 1
357  tList<sVec3D>      partition2;                           //!< the vertex partition 2
358
359
360  this->separationPlane = new Plane(*box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
361  this->sepPlaneCenter = &box->vertices[vertexIndex];
362  this->longestAxisIndex = axisIndex;
363
364  for(int i = 0; i < box->numOfVertices; ++i)
365  {
366    if( this->separationPlane->distancePoint(box->vertices[i]) > 0.0f)
367      partition1.add(&box->vertices[i]);
368    else
369      partition2.add(&box->vertices[i]);
370  }
371  partition1.add(&box->vertices[vertexIndex]);
372
373//   printf("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
374
375
376  /* now comes the separation into two different sVec3D arrays */
377  tIterator<sVec3D>* iterator;                             //!< the iterator to go through the lists
378  sVec3D*            element;                              //!< the elements
379  int                index;                                //!< index storage place
380  sVec3D*            vertList1;                            //!< the vertex list 1
381  sVec3D*            vertList2;                            //!< the vertex list 2
382
383  vertList1 = new sVec3D[partition1.getSize()];
384  vertList2 = new sVec3D[partition2.getSize()];
385
386  iterator = partition1.getIterator();
387  element = iterator->nextElement();
388  index = 0;
389  while( element != NULL)
390  {
391    vertList1[index][0] = element[0][0];
392    vertList1[index][1] = element[0][1];
393    vertList1[index][2] = element[0][2];
394    ++index;
395    element = iterator->nextElement();
396  }
397
398//   printf("\npartition 1:\n");
399//   for(int i = 0; i < partition1.getSize(); ++i)
400//   {
401//     printf("v[%i][0] = %f\n", i, vertList1[i][0]);
402//     printf("v[%i][1] = %f\n", i, vertList1[i][1]);
403//     printf("v[%i][2] = %f\n", i, vertList1[i][2]);
404//   }
405
406  iterator = partition2.getIterator();
407  element = iterator->nextElement();
408  index = 0;
409  while( element != NULL)
410  {
411    vertList2[index][0] = element[0][0];
412    vertList2[index][1] = element[0][1];
413    vertList2[index][2] = element[0][2];
414    ++index;
415    element = iterator->nextElement();
416  }
417
418  this->tmpVert1 = vertList1;
419  this->tmpVert2 = vertList2;
420  this->tmpLen1 = partition1.getSize();
421  this->tmpLen2 = partition2.getSize();
422
423  //delete iterator;
424//   printf("\npartition 2:\n");
425//   for(int i = 0; i < partition2.getSize(); ++i)
426//   {
427//     printf("v[%i][0] = %f\n", i, vertList2[i][0]);
428//     printf("v[%i][1] = %f\n", i, vertList2[i][1]);
429//     printf("v[%i][2] = %f\n", i, vertList2[i][2]);
430//   }
431}
432
433
434
435
436void OBBTreeNode::collideWith(const BVTree &tree)
437{}
438
439
440
441
442void OBBTreeNode::drawBV(int depth) const
443{
444  glBegin(GL_TRIANGLES);
445  glColor3f(1.0, 1.0, 1.0);
446  for(int i = 0; i < this->bvElement->numOfVertices; ++i)
447    {
448      glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
449      //printf("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]);
450    }
451  glEnd();
452  //this->drawBVPolygon(depth);
453}
454
455
456void OBBTreeNode::drawBVPolygon(int depth) const
457{
458  //OBBTree::material->select();
459
460  this->obbTree->getMaterial(depth)->select();
461
462  /* draw world axes */
463//   glBegin(GL_LINES);
464//   glColor3f(0.0, 0.4, 0.3);
465//   glVertex3f(0.0, 0.0, 0.0);
466//   glVertex3f(3.0, 0.0, 0.0);
467//
468//   glVertex3f(0.0, 0.0, 0.0);
469//   glVertex3f(0.0, 3.0, 0.0);
470//
471//   glVertex3f(0.0, 0.0, 0.0);
472//   glVertex3f(0.0, 0.0, 3.0);
473//   glEnd();
474
475
476
477  /* draw the obb axes */
478//   glBegin(GL_LINES);
479//   glColor3f(0.0, 0.4, 0.3);
480//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
481//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[0]->x * this->bvElement->halfLength[0],
482//              this->bvElement->center->y + this->bvElement->axis[0]->y * this->bvElement->halfLength[0],
483//              this->bvElement->center->z + this->bvElement->axis[0]->z * this->bvElement->halfLength[0]);
484//
485//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
486//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[1]->x * this->bvElement->halfLength[1],
487//              this->bvElement->center->y + this->bvElement->axis[1]->y * this->bvElement->halfLength[1],
488//              this->bvElement->center->z + this->bvElement->axis[1]->z * this->bvElement->halfLength[1]);
489//
490//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
491//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[2]->x * this->bvElement->halfLength[2],
492//              this->bvElement->center->y + this->bvElement->axis[2]->y * this->bvElement->halfLength[2],
493//              this->bvElement->center->z + this->bvElement->axis[2]->z * this->bvElement->halfLength[2]);
494//   glEnd();
495
496
497  Vector cen = *this->bvElement->center;
498  Vector** axis = this->bvElement->axis;
499  float* len = this->bvElement->halfLength;
500
501  /* draw bounding box */
502  glBegin(GL_LINE_LOOP);
503  glColor3f(0.3, 0.4, 0.7);
504  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
505             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
506             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
507  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
508             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
509             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
510  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
511             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
512             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
513  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
514             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
515             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
516  glEnd();
517
518  glBegin(GL_LINE_LOOP);
519  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
520             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
521             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
522  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
523             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
524             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
525  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
526             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
527             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
528  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
529             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
530             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
531  glEnd();
532
533  glBegin(GL_LINE_LOOP);
534  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
535             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
536             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
537  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
538             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
539             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
540  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
541             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
542             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
543  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
544             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
545             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
546  glEnd();
547
548  glBegin(GL_LINE_LOOP);
549  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
550             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
551             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
552  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
553             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
554             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
555  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
556             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
557             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
558  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
559             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
560             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
561  glEnd();
562
563
564  if( depth != 0)
565  {
566    /* now draw the separation plane */
567    Vector a1 = *this->bvElement->axis[(this->longestAxisIndex + 1)%3];
568    Vector a2 = *this->bvElement->axis[(this->longestAxisIndex + 2)%3];
569    Vector c = *this->bvElement->center;
570    float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
571    float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
572    glBegin(GL_QUADS);
573    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);
574    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);
575    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);
576    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);
577
578    glEnd();
579  }
580
581  if( this->nodeLeft != NULL && depth != 0 )
582    this->nodeLeft->drawBVPolygon(depth - 1);
583  if( this->nodeRight != NULL && depth != 0)
584    this->nodeRight->drawBVPolygon(depth - 1);
585
586}
587
588
589void OBBTreeNode::drawBVBlended(int depth) const
590{}
591
592
593void OBBTreeNode::debug()
594{
595
596  /*
597  for(int i = 0; i < length; i++)
598  {
599  printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
600}
601  */
602}
Note: See TracBrowser for help on using the repository browser.