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