Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: me be tha bug-killa :) tree spawning seems to work perfectly :)

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
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(0)("center: %f, %f, %f\n", center.x, center.y, center.z);
206
207
208//   for(int i = 0; i < 3; ++i)
209//   {
210//     box->covarianceMatrix[i][0] = covariance[i][0];
211//     box->covarianceMatrix[i][1] = covariance[i][1];
212//     box->covarianceMatrix[i][3] = covariance[i][2];
213//   }
214  *box->center = center;
215  PRINTF(0)("-- Written Result to obb\n");
216}
217
218
219
220void OBBTreeNode::calculateBoxEigenvectors(OBB* box, sVec3D* verticesList, int length)
221{
222
223  /* now getting spanning vectors of the sub-space:
224  the eigenvectors of a symmertric matrix, such as the
225  covarience matrix are mutually orthogonal.
226  after normalizing them, they can be used as a the basis
227  vectors
228  */
229  Vector**              axis = new Vector*[3];                //!< the references to the obb axis
230
231  coMat[1][1] = box->covarianceMatrix[0][0]; coMat[1][2] = box->covarianceMatrix[0][1]; coMat[1][3] = box->covarianceMatrix[0][2];
232  coMat[2][1] = box->covarianceMatrix[1][0]; coMat[2][2] = box->covarianceMatrix[1][1]; coMat[2][3] = box->covarianceMatrix[1][2];
233  coMat[3][1] = box->covarianceMatrix[2][0]; coMat[3][2] = box->covarianceMatrix[2][1]; coMat[3][3] = box->covarianceMatrix[2][2];
234
235  /* new jacobi tests */
236  JacobI(coMat, 3, eigvlMat, eigvMat, rotCount);
237  PRINTF(0)("-- Done Jacobi Decomposition\n");
238
239
240//   printf("Jacobi\n");
241//   for(int j = 1; j < 4; ++j)
242//   {
243//     printf(" |");
244//     for(int k = 1; k < 4; ++k)
245//     {
246//       printf(" \b%f ", eigvMat[j][k]);
247//     }
248//     printf(" |\n");
249//   }
250
251  axis[0] = new Vector(eigvMat[1][1], eigvMat[2][1], eigvMat[3][1]);
252  axis[1] = new Vector(eigvMat[1][2], eigvMat[2][2], eigvMat[3][2]);
253  axis[2] = new Vector(eigvMat[1][3], eigvMat[2][3], eigvMat[3][3]);
254  box->axis = axis;
255  PRINTF(0)("-- Got Axis\n");
256
257//   printf("\neigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
258//   printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
259//   printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
260}
261
262
263void OBBTreeNode::calculateBoxAxis(OBB* box, sVec3D* verticesList, int length)
264{
265
266  /* now get the axis length */
267  Line                ax[3];                                 //!< the axis
268  float*              halfLength = new float[3];             //!< half length of the axis
269  float               tmpLength;                             //!< tmp save point for the length
270  Plane               p0(*box->axis[0], *box->center);       //!< the axis planes
271  Plane               p1(*box->axis[1], *box->center);
272  Plane               p2(*box->axis[2], *box->center);
273
274  halfLength[0] = -1.0f;
275  for(int j = 0; j < length; ++j)
276  {
277    tmpLength = fabs(p0.distancePoint(vertices[j]));
278    if( tmpLength > halfLength[0])
279      halfLength[0] = tmpLength;
280  }
281
282  halfLength[1] = -1.0f;
283  for(int j = 0; j < length; ++j)
284  {
285    tmpLength = fabs(p1.distancePoint(vertices[j]));
286    if( tmpLength > halfLength[1])
287      halfLength[1] = tmpLength;
288  }
289
290  halfLength[2] = -1.0f;
291  for(int j = 0; j < length; ++j)
292  {
293    tmpLength = fabs(p2.distancePoint(vertices[j]));
294    if( tmpLength > halfLength[2])
295      halfLength[2] = tmpLength;
296  }
297
298  box->halfLength = halfLength;
299  PRINTF(0)("-- Written Axis to obb\n");
300  PRINTF(0)("-- Finished Calculating Attributes\n");
301
302//   printf("\nwe got length: \n");
303//   for(int i = 0; i < 3; ++i)
304//     printf("length[%i] = %f\n", i, box->halfLength[i]);
305}
306
307
308
309/**
310  \brief this separates an ob-box in the middle
311  \param box: the box to separate
312
313  this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
314 */
315void OBBTreeNode::forkBox(OBB* box)
316{
317  /* get the longest axis of the box */
318  float               aLength = -1.0f;                     //!< the length of the longest axis
319  int                 axisIndex = 0;                       //!< this is the nr of the longest axis
320
321  for(int i = 0; i < 3; ++i)
322  {
323    if( aLength < box->halfLength[i])
324    {
325      aLength = box->halfLength[i];
326      axisIndex = i;
327    }
328  }
329
330//   printf("\nlongest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
331
332
333  /* get the closest vertex near the center */
334  float               dist = 999999.0f;                    //!< the smallest distance to each vertex
335  float               tmpDist;                             //!< temporary distance
336  int                 vertexIndex;
337  Plane               middlePlane(*box->axis[axisIndex], *box->center); //!< the middle plane
338
339  for(int i = 0; i < box->numOfVertices; ++i)
340  {
341    tmpDist = fabs(middlePlane.distancePoint(box->vertices[i]));
342    if( tmpDist < dist)
343    {
344      dist = tmpDist;
345      vertexIndex = i;
346    }
347  }
348
349//   printf("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
350
351
352  /* now definin the separation plane through this specified nearest point and partition
353  the points depending on which side they are located
354  */
355  tList<sVec3D>      partition1;                           //!< the vertex partition 1
356  tList<sVec3D>      partition2;                           //!< the vertex partition 2
357
358
359  this->separationPlane = new Plane(*box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
360  this->sepPlaneCenter = &box->vertices[vertexIndex];
361  this->longestAxisIndex = axisIndex;
362
363  for(int i = 0; i < box->numOfVertices; ++i)
364  {
365    if( this->separationPlane->distancePoint(box->vertices[i]) > 0.0f)
366      partition1.add(&box->vertices[i]);
367    else
368      partition2.add(&box->vertices[i]);
369  }
370  partition1.add(&box->vertices[vertexIndex]);
371
372//   printf("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
373
374
375  /* now comes the separation into two different sVec3D arrays */
376  tIterator<sVec3D>* iterator;                             //!< the iterator to go through the lists
377  sVec3D*            element;                              //!< the elements
378  int                index;                                //!< index storage place
379  sVec3D*            vertList1;                            //!< the vertex list 1
380  sVec3D*            vertList2;                            //!< the vertex list 2
381
382  vertList1 = new sVec3D[partition1.getSize()];
383  vertList2 = new sVec3D[partition2.getSize()];
384
385  iterator = partition1.getIterator();
386  element = iterator->nextElement();
387  index = 0;
388  while( element != NULL)
389  {
390    vertList1[index][0] = element[0][0];
391    vertList1[index][1] = element[0][1];
392    vertList1[index][2] = element[0][2];
393    ++index;
394    element = iterator->nextElement();
395  }
396
397//   printf("\npartition 1:\n");
398//   for(int i = 0; i < partition1.getSize(); ++i)
399//   {
400//     printf("v[%i][0] = %f\n", i, vertList1[i][0]);
401//     printf("v[%i][1] = %f\n", i, vertList1[i][1]);
402//     printf("v[%i][2] = %f\n", i, vertList1[i][2]);
403//   }
404
405  iterator = partition2.getIterator();
406  element = iterator->nextElement();
407  index = 0;
408  while( element != NULL)
409  {
410    vertList2[index][0] = element[0][0];
411    vertList2[index][1] = element[0][1];
412    vertList2[index][2] = element[0][2];
413    ++index;
414    element = iterator->nextElement();
415  }
416
417  this->tmpVert1 = vertList1;
418  this->tmpVert2 = vertList2;
419  this->tmpLen1 = partition1.getSize();
420  this->tmpLen2 = partition2.getSize();
421
422  //delete iterator;
423//   printf("\npartition 2:\n");
424//   for(int i = 0; i < partition2.getSize(); ++i)
425//   {
426//     printf("v[%i][0] = %f\n", i, vertList2[i][0]);
427//     printf("v[%i][1] = %f\n", i, vertList2[i][1]);
428//     printf("v[%i][2] = %f\n", i, vertList2[i][2]);
429//   }
430}
431
432
433
434
435void OBBTreeNode::collideWith(const BVTree &tree)
436{}
437
438
439
440
441void OBBTreeNode::drawBV(int depth) const
442{
443  glBegin(GL_TRIANGLES);
444  glColor3f(1.0, 1.0, 1.0);
445  for(int i = 0; i < this->bvElement->numOfVertices; ++i)
446    {
447      glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
448      //printf("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]);
449    }
450  glEnd();
451  //this->drawBVPolygon(depth);
452}
453
454
455void OBBTreeNode::drawBVPolygon(int depth) const
456{
457  //OBBTree::material->select();
458
459  this->obbTree->getMaterial(depth)->select();
460
461  /* draw world axes */
462//   glBegin(GL_LINES);
463//   glColor3f(0.0, 0.4, 0.3);
464//   glVertex3f(0.0, 0.0, 0.0);
465//   glVertex3f(3.0, 0.0, 0.0);
466//
467//   glVertex3f(0.0, 0.0, 0.0);
468//   glVertex3f(0.0, 3.0, 0.0);
469//
470//   glVertex3f(0.0, 0.0, 0.0);
471//   glVertex3f(0.0, 0.0, 3.0);
472//   glEnd();
473
474
475
476  /* draw the obb axes */
477//   glBegin(GL_LINES);
478//   glColor3f(0.0, 0.4, 0.3);
479//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
480//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[0]->x * this->bvElement->halfLength[0],
481//              this->bvElement->center->y + this->bvElement->axis[0]->y * this->bvElement->halfLength[0],
482//              this->bvElement->center->z + this->bvElement->axis[0]->z * this->bvElement->halfLength[0]);
483//
484//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
485//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[1]->x * this->bvElement->halfLength[1],
486//              this->bvElement->center->y + this->bvElement->axis[1]->y * this->bvElement->halfLength[1],
487//              this->bvElement->center->z + this->bvElement->axis[1]->z * this->bvElement->halfLength[1]);
488//
489//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
490//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[2]->x * this->bvElement->halfLength[2],
491//              this->bvElement->center->y + this->bvElement->axis[2]->y * this->bvElement->halfLength[2],
492//              this->bvElement->center->z + this->bvElement->axis[2]->z * this->bvElement->halfLength[2]);
493//   glEnd();
494
495
496  Vector cen = *this->bvElement->center;
497  Vector** axis = this->bvElement->axis;
498  float* len = this->bvElement->halfLength;
499
500  /* draw bounding box */
501  glBegin(GL_LINE_LOOP);
502  glColor3f(0.3, 0.4, 0.7);
503  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
504             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
505             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
506  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
507             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
508             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
509  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
510             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
511             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
512  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
513             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
514             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
515  glEnd();
516
517  glBegin(GL_LINE_LOOP);
518  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
519             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
520             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
521  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
522             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
523             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
524  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
525             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
526             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
527  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
528             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
529             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
530  glEnd();
531
532  glBegin(GL_LINE_LOOP);
533  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
534             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
535             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
536  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2],
537             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2],
538             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]);
539  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
540             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
541             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
542  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
543             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
544             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
545  glEnd();
546
547  glBegin(GL_LINE_LOOP);
548  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
549             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
550             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
551  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
552             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
553             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
554  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
555             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
556             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
557  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
558             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
559             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
560  glEnd();
561
562
563  if( true)//depth != 0)
564  {
565    /* now draw the separation plane */
566    Vector a1 = *this->bvElement->axis[(this->longestAxisIndex + 1)%3];
567    Vector a2 = *this->bvElement->axis[(this->longestAxisIndex + 2)%3];
568    Vector c = *this->bvElement->center;
569    float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3];
570    float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3];
571    glBegin(GL_QUADS);
572    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);
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    glEnd();
577  }
578
579  if( this->nodeLeft != NULL && depth != 0 )
580    this->nodeLeft->drawBVPolygon(depth - 1);
581  if( this->nodeRight != NULL && depth != 0)
582    this->nodeRight->drawBVPolygon(depth - 1);
583
584}
585
586
587void OBBTreeNode::drawBVBlended(int depth) const
588{}
589
590
591void OBBTreeNode::debug()
592{
593
594  /*
595  for(int i = 0; i < length; i++)
596  {
597  printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
598}
599  */
600}
Note: See TracBrowser for help on using the repository browser.