Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: the damn segfault is nomore, patrick is on killing spree

File size: 20.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 "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->calculateBoxAttributes1(this->bvElement, verticesList, length);
105  PRINTF(0)("Calculated attributes1\n");
106  this->calculateBoxAttributes2(this->bvElement, verticesList, length);
107  PRINTF(0)("Calculated attributes2\n");
108  this->calculateBoxAttributes3(this->bvElement, verticesList, length);
109  PRINTF(0)("Calculated attributes3\n");
110
111  if( likely( this->depth > 0))
112  {
113    this->forkBox(this->bvElement);
114
115    OBBTreeNode*       node1 = new OBBTreeNode();
116    OBBTreeNode*       node2 = new OBBTreeNode();
117
118    this->nodeLeft = node1;
119    this->nodeRight = node2;
120
121    this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
122    this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
123
124  }
125}
126
127
128
129void OBBTreeNode::calculateBoxAttributes1(OBB* box, sVec3D* verticesList, int length)
130{
131  float     facelet[length];                         //!< surface area of the i'th triangle of the convex hull
132  float     face;                                    //!< surface area of the entire convex hull
133  Vector    centroid[length];                        //!< centroid of the i'th convex hull
134  Vector    center;                                  //!< the center of the entire hull
135  Vector    p, q, r;                                 //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d
136  Vector    t1, t2;                                  //!< temporary values
137  float     covariance[3][3];                        //!< the covariance matrix
138
139  this->numOfVertices = length;
140  this->vertices = verticesList;
141  box->vertices = verticesList;
142  box->numOfVertices = length;
143
144
145  /* fist compute all the convex hull face/facelets and centroids */
146  for(int i = 0; i < length; i+=3)          /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/
147  {
148    p = verticesList[i];
149    q = verticesList[i +1];
150    r = verticesList[i + 2];
151
152    t1 = p - q; t2 = p - r;
153
154    /* finding the facelet surface via cross-product */
155    facelet[i] = 0.5f * fabs( t1.cross(t2).len() );
156    /* update the entire convex hull surface */
157    face += facelet[i];
158
159    /* calculate the cetroid of the hull triangles */
160    centroid[i] = (p + q + r) * 1/3;
161    /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */
162    center += centroid[i] * facelet[i];
163  }
164  /* take the average of the centroid sum */
165  center /= face;
166  PRINTF(0)("-- Calculated Center\n");
167
168
169  /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */
170  for(int j = 0; j < 3; ++j)
171  {
172    for(int k = 0; k < 3; ++k)
173    {
174      for(int i = 0; i < length; i+=3)
175      {
176        p = verticesList[i];
177        q = verticesList[i +1];
178        r = verticesList[i + 2];
179
180        covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] +
181            q[j] * q[k] + r[j]*r[k]) - center[j] * center[k];
182      }
183    }
184  }
185  PRINTF(0)("-- Calculated Covariance\n");
186  return;
187
188//   printf("\nVertex Data:\n");
189//   for(int i = 0; i < length; i++)
190//   {
191//     printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
192//   }
193
194//   printf("\nCovariance Matrix:\n");
195//   for(int j = 0; j < 3; ++j)
196//   {
197//     printf(" |");
198//     for(int k = 0; k < 3; ++k)
199//     {
200//       printf(" \b%f ", covariance[j][k]);
201//     }
202//     printf(" |\n");
203//   }
204//   printf("center: %f, %f, %f\n\n", center.x, center.y, center.z);
205
206
207  for(int i = 0; i < 3; ++i)
208  {
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::calculateBoxAttributes2(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//   float**               a = new float*[4];
231//   float**               b = new float*[4];
232//   float                 eigval[3];
233//   int*                  rot = new int;
234
235
236  //coMat[0] = new float[4]; coMat[1] = new float[4]; coMat[2] = new float[4]; coMat[3] = new float[4];
237  //eigvMat[0] = new float[4]; eigvMat[1] = new float[4]; eigvMat[2] = new float[4]; eigvMat[3] = new float[4];
238
239  coMat[1][1] = box->covarianceMatrix[0][0]; coMat[1][2] = box->covarianceMatrix[0][1]; coMat[1][3] = box->covarianceMatrix[0][2];
240  coMat[2][1] = box->covarianceMatrix[1][0]; coMat[2][2] = box->covarianceMatrix[1][1]; coMat[2][3] = box->covarianceMatrix[1][2];
241  coMat[3][1] = box->covarianceMatrix[2][0]; coMat[3][2] = box->covarianceMatrix[2][1]; coMat[3][3] = box->covarianceMatrix[2][2];
242
243  /* new jacobi tests */
244  JacobI(coMat, 3, eigvlMat, eigvMat, rotCount);
245  PRINTF(0)("-- Done Jacobi Decomposition\n");
246
247
248
249//   printf("Jacobi\n");
250//   for(int j = 1; j < 4; ++j)
251//   {
252//     printf(" |");
253//     for(int k = 1; k < 4; ++k)
254//     {
255//       printf(" \b%f ", eigvMat[j][k]);
256//     }
257//     printf(" |\n");
258//   }
259
260  axis[0] = new Vector(eigvMat[1][1], eigvMat[2][1], eigvMat[3][1]);
261  axis[1] = new Vector(eigvMat[1][2], eigvMat[2][2], eigvMat[3][2]);
262  axis[2] = new Vector(eigvMat[1][3], eigvMat[2][3], eigvMat[3][3]);
263  box->axis = axis;
264  PRINTF(0)("-- Got Axis\n");
265
266//   printf("\neigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
267//   printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
268//   printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
269
270
271//   delete [] a[0]; delete [] a[1]; delete [] a[2]; delete [] a[3];
272//   delete [] a;
273//
274//   delete [] b[0]; delete [] b[1]; delete [] b[2]; delete [] b[3];
275//   delete [] b;
276//
277//   delete rot;
278}
279
280void OBBTreeNode::calculateBoxAttributes3(OBB* box, sVec3D* verticesList, int length)
281{
282
283  /* now get the axis length */
284  Line                ax[3];                                 //!< the axis
285  float*              halfLength = new float[3];             //!< half length of the axis
286  float               tmpLength;                             //!< tmp save point for the length
287  Plane               p0(*box->axis[0], *box->center);       //!< the axis planes
288  Plane               p1(*box->axis[1], *box->center);
289  Plane               p2(*box->axis[2], *box->center);
290
291  halfLength[0] = -1.0f;
292  for(int j = 0; j < length; ++j)
293  {
294    tmpLength = fabs(p0.distancePoint(vertices[j]));
295    if( tmpLength > halfLength[0])
296      halfLength[0] = tmpLength;
297  }
298
299  halfLength[1] = -1.0f;
300  for(int j = 0; j < length; ++j)
301  {
302    tmpLength = fabs(p1.distancePoint(vertices[j]));
303    if( tmpLength > halfLength[1])
304      halfLength[1] = tmpLength;
305  }
306
307  halfLength[2] = -1.0f;
308  for(int j = 0; j < length; ++j)
309  {
310    tmpLength = fabs(p2.distancePoint(vertices[j]));
311    if( tmpLength > halfLength[2])
312      halfLength[2] = tmpLength;
313  }
314
315  box->halfLength = halfLength;
316  PRINTF(0)("-- Written Axis to obb\n");
317  PRINTF(0)("-- Finished Calculating Attributes\n");
318
319//   printf("\nwe got length: \n");
320//   for(int i = 0; i < 3; ++i)
321//     printf("length[%i] = %f\n", i, box->halfLength[i]);
322}
323
324
325
326/**
327  \brief this separates an ob-box in the middle
328  \param box: the box to separate
329
330  this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis
331 */
332void OBBTreeNode::forkBox(OBB* box)
333{
334  /* get the longest axis of the box */
335  float               aLength = -1.0f;                     //!< the length of the longest axis
336  int                 axisIndex = 0;                       //!< this is the nr of the longest axis
337
338  for(int i = 0; i < 3; ++i)
339  {
340    if( aLength < box->halfLength[i])
341    {
342      aLength = box->halfLength[i];
343      axisIndex = i;
344    }
345  }
346
347//   printf("\nlongest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);
348
349
350  /* get the closest vertex near the center */
351  float               dist = 999999.0f;                    //!< the smallest distance to each vertex
352  float               tmpDist;                             //!< temporary distance
353  int                 vertexIndex;
354  Plane               middlePlane(*box->axis[axisIndex], *box->center); //!< the middle plane
355
356  for(int i = 0; i < box->numOfVertices; ++i)
357  {
358    tmpDist = fabs(middlePlane.distancePoint(box->vertices[i]));
359    if( tmpDist < dist)
360    {
361      dist = tmpDist;
362      vertexIndex = i;
363    }
364  }
365
366//   printf("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);
367
368
369  /* now definin the separation plane through this specified nearest point and partition
370  the points depending on which side they are located
371  */
372  Plane              separationPlane(*box->axis[axisIndex], box->vertices[vertexIndex]);  //!< separation plane
373  tList<sVec3D>      partition1;                           //!< the vertex partition 1
374  tList<sVec3D>      partition2;                           //!< the vertex partition 2
375
376  for(int i = 0; i < box->numOfVertices; ++i)
377  {
378    if( separationPlane.distancePoint(box->vertices[i]) > 0.0f)
379      partition1.add(&box->vertices[i]);
380    else
381      partition2.add(&box->vertices[i]);
382  }
383  partition1.add(&box->vertices[vertexIndex]);
384
385//   printf("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());
386
387
388  /* now comes the separation into two different sVec3D arrays */
389  tIterator<sVec3D>* iterator;                             //!< the iterator to go through the lists
390  sVec3D*            element;                              //!< the elements
391  int                index;                                //!< index storage place
392  sVec3D*            vertList1;                            //!< the vertex list 1
393  sVec3D*            vertList2;                            //!< the vertex list 2
394
395  vertList1 = new sVec3D[partition1.getSize()];
396  vertList2 = new sVec3D[partition2.getSize()];
397
398  iterator = partition1.getIterator();
399  element = iterator->nextElement();
400  index = 0;
401  while( element != NULL)
402  {
403    vertList1[index][0] = element[0][0];
404    vertList1[index][1] = element[0][1];
405    vertList1[index][2] = element[0][2];
406    ++index;
407    element = iterator->nextElement();
408  }
409
410//   printf("\npartition 1:\n");
411//   for(int i = 0; i < partition1.getSize(); ++i)
412//   {
413//     printf("v[%i][0] = %f\n", i, vertList1[i][0]);
414//     printf("v[%i][1] = %f\n", i, vertList1[i][1]);
415//     printf("v[%i][2] = %f\n", i, vertList1[i][2]);
416//   }
417
418  iterator = partition2.getIterator();
419  element = iterator->nextElement();
420  index = 0;
421  while( element != NULL)
422  {
423    vertList2[index][0] = element[0][0];
424    vertList2[index][1] = element[0][1];
425    vertList2[index][2] = element[0][2];
426    ++index;
427    element = iterator->nextElement();
428  }
429
430  this->tmpVert1 = vertList1;
431  this->tmpVert2 = vertList2;
432  this->tmpLen1 = partition1.getSize();
433  this->tmpLen2 = partition2.getSize();
434
435  //delete iterator;
436//   printf("\npartition 2:\n");
437//   for(int i = 0; i < partition2.getSize(); ++i)
438//   {
439//     printf("v[%i][0] = %f\n", i, vertList2[i][0]);
440//     printf("v[%i][1] = %f\n", i, vertList2[i][1]);
441//     printf("v[%i][2] = %f\n", i, vertList2[i][2]);
442//   }
443}
444
445
446
447
448void OBBTreeNode::collideWith(const BVTree &tree)
449{}
450
451
452
453
454void OBBTreeNode::drawBV(int depth) const
455{
456  glBegin(GL_TRIANGLES);
457  glColor3f(1.0, 1.0, 1.0);
458  for(int i = 0; i < this->bvElement->numOfVertices; ++i)
459    {
460      glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);
461      //printf("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]);
462    }
463  glEnd();
464  //this->drawBVPolygon(depth);
465}
466
467
468void OBBTreeNode::drawBVPolygon(int depth) const
469{
470  //OBBTree::material->select();
471
472  this->obbTree->getMaterial(depth)->select();
473
474  /* draw world axes */
475//   glBegin(GL_LINES);
476//   glColor3f(0.0, 0.4, 0.3);
477//   glVertex3f(0.0, 0.0, 0.0);
478//   glVertex3f(3.0, 0.0, 0.0);
479//
480//   glVertex3f(0.0, 0.0, 0.0);
481//   glVertex3f(0.0, 3.0, 0.0);
482//
483//   glVertex3f(0.0, 0.0, 0.0);
484//   glVertex3f(0.0, 0.0, 3.0);
485//   glEnd();
486
487
488
489  /* draw the obb axes */
490//   glBegin(GL_LINES);
491//   glColor3f(0.0, 0.4, 0.3);
492//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
493//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[0]->x * this->bvElement->halfLength[0],
494//              this->bvElement->center->y + this->bvElement->axis[0]->y * this->bvElement->halfLength[0],
495//              this->bvElement->center->z + this->bvElement->axis[0]->z * this->bvElement->halfLength[0]);
496//
497//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
498//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[1]->x * this->bvElement->halfLength[1],
499//              this->bvElement->center->y + this->bvElement->axis[1]->y * this->bvElement->halfLength[1],
500//              this->bvElement->center->z + this->bvElement->axis[1]->z * this->bvElement->halfLength[1]);
501//
502//   glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z);
503//   glVertex3f(this->bvElement->center->x + this->bvElement->axis[2]->x * this->bvElement->halfLength[2],
504//              this->bvElement->center->y + this->bvElement->axis[2]->y * this->bvElement->halfLength[2],
505//              this->bvElement->center->z + this->bvElement->axis[2]->z * this->bvElement->halfLength[2]);
506//   glEnd();
507
508
509  Vector cen = *this->bvElement->center;
510  Vector** axis = this->bvElement->axis;
511  float* len = this->bvElement->halfLength;
512
513  /* draw bounding box */
514  glBegin(GL_LINE_LOOP);
515  glColor3f(0.3, 0.4, 0.7);
516  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
517             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
518             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
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  glEnd();
529
530  glBegin(GL_LINE_LOOP);
531  glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
532             cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
533             cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
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  glEnd();
544
545  glBegin(GL_LINE_LOOP);
546  glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2],
547             cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2],
548             cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]);
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  glEnd();
559
560  glBegin(GL_LINE_LOOP);
561  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
562             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
563             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
564  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
565             cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
566             cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
567  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
568             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
569             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);
570  glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
571             cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
572             cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
573  glEnd();
574
575/*
576  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2],
577  cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2],
578  cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]);
579  glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2],
580  cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2],
581  cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);*/
582
583
584  glEnd();
585
586  if( this->nodeLeft != NULL && depth != 0 )
587    this->nodeLeft->drawBVPolygon(depth - 1);
588  if( this->nodeRight != NULL && depth != 0)
589    this->nodeRight->drawBVPolygon(depth - 1);
590
591}
592
593
594void OBBTreeNode::drawBVBlended(int depth) const
595{}
596
597
598void OBBTreeNode::debug()
599{
600
601  /*
602  for(int i = 0; i < length; i++)
603  {
604  printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);
605}
606  */
607}
Note: See TracBrowser for help on using the repository browser.