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