[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" |
---|
[5674] | 22 | #include "matrix.h" |
---|
[4550] | 23 | #include "abstract_model.h" |
---|
[5028] | 24 | #include "world_entity.h" |
---|
[4541] | 25 | |
---|
[5481] | 26 | #include "color.h" |
---|
[4543] | 27 | |
---|
[5511] | 28 | #include "debug.h" |
---|
[5431] | 29 | #include "glincl.h" |
---|
[4572] | 30 | |
---|
| 31 | |
---|
| 32 | |
---|
[4541] | 33 | using namespace std; |
---|
| 34 | |
---|
[4622] | 35 | OBBTree* OBBTreeNode::obbTree = NULL; |
---|
[4541] | 36 | |
---|
[5431] | 37 | float** OBBTreeNode::coMat = NULL; |
---|
| 38 | float** OBBTreeNode::eigvMat = NULL; |
---|
| 39 | float* OBBTreeNode::eigvlMat = NULL; |
---|
| 40 | int* OBBTreeNode::rotCount = NULL; |
---|
[5430] | 41 | GLUquadricObj* OBBTreeNode_sphereObj = NULL; |
---|
[4630] | 42 | |
---|
[4541] | 43 | /** |
---|
[4836] | 44 | * standard constructor |
---|
[4617] | 45 | */ |
---|
[4588] | 46 | OBBTreeNode::OBBTreeNode () |
---|
[4541] | 47 | { |
---|
[4617] | 48 | this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); |
---|
[4618] | 49 | this->nodeLeft = NULL; |
---|
| 50 | this->nodeRight = NULL; |
---|
[4814] | 51 | this->bvElement = NULL; |
---|
[4630] | 52 | |
---|
[5431] | 53 | if(OBBTreeNode::coMat == NULL) |
---|
[4630] | 54 | { |
---|
[5431] | 55 | OBBTreeNode::coMat = new float*[4]; |
---|
[4630] | 56 | for(int i = 0; i < 4; i++) |
---|
[5431] | 57 | OBBTreeNode::coMat[i] = new float[4]; |
---|
[4630] | 58 | } |
---|
[5431] | 59 | if(OBBTreeNode::eigvMat == NULL) |
---|
[4630] | 60 | { |
---|
[5431] | 61 | OBBTreeNode::eigvMat = new float*[4]; |
---|
[4630] | 62 | for(int i = 0; i < 4; i++) |
---|
[5431] | 63 | OBBTreeNode::eigvMat[i] = new float[4]; |
---|
[4630] | 64 | } |
---|
[5431] | 65 | if( OBBTreeNode::eigvlMat == NULL) |
---|
[4630] | 66 | { |
---|
[5431] | 67 | OBBTreeNode::eigvlMat = new float[4]; |
---|
[4630] | 68 | } |
---|
[5431] | 69 | if( OBBTreeNode::rotCount == NULL) |
---|
| 70 | OBBTreeNode::rotCount = new int; |
---|
[4638] | 71 | |
---|
[5430] | 72 | if (OBBTreeNode_sphereObj == NULL) |
---|
| 73 | OBBTreeNode_sphereObj = gluNewQuadric(); |
---|
[4541] | 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | /** |
---|
[4836] | 78 | * standard deconstructor |
---|
[4617] | 79 | */ |
---|
[4588] | 80 | OBBTreeNode::~OBBTreeNode () |
---|
[4541] | 81 | { |
---|
[4814] | 82 | if( this->nodeLeft) |
---|
| 83 | { |
---|
| 84 | delete this->nodeLeft; |
---|
| 85 | this->nodeLeft = NULL; |
---|
| 86 | } |
---|
| 87 | if( this->nodeRight) |
---|
| 88 | { |
---|
| 89 | delete this->nodeRight; |
---|
| 90 | this->nodeRight = NULL; |
---|
| 91 | } |
---|
| 92 | if( this->bvElement) |
---|
| 93 | delete this->bvElement; |
---|
| 94 | this->bvElement = NULL; |
---|
[4541] | 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
[5684] | 98 | /** |
---|
| 99 | * creates a new BVTree or BVTree partition |
---|
| 100 | * @param depth: how much more depth-steps to go: if == 1 don't go any deeper! |
---|
| 101 | * @param modInfo: model informations from the abstrac model |
---|
| 102 | * |
---|
| 103 | * this function creates the Bounding Volume tree from a modelInfo struct and bases its calculations |
---|
| 104 | * on the triangle informations (triangle soup not polygon soup) |
---|
| 105 | */ |
---|
| 106 | void OBBTreeNode::spawnBVTree(const int depth, const modelInfo& modInfo) |
---|
| 107 | { |
---|
| 108 | int length = 0; |
---|
| 109 | sVec3D* verticesList; |
---|
| 110 | |
---|
| 111 | PRINT(3)("\n"); |
---|
| 112 | this->treeIndex = this->obbTree->getID(); |
---|
| 113 | PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length); |
---|
| 114 | this->depth = depth; |
---|
[4542] | 115 | |
---|
[5684] | 116 | |
---|
| 117 | this->bvElement = new OBB(); |
---|
| 118 | this->bvElement->vertices = verticesList; |
---|
| 119 | this->bvElement->numOfVertices = length; |
---|
| 120 | PRINTF(3)("Created OBBox\n"); |
---|
| 121 | this->calculateBoxCovariance(this->bvElement, modInfo); |
---|
| 122 | PRINTF(3)("Calculated attributes1\n"); |
---|
| 123 | this->calculateBoxEigenvectors(this->bvElement, modInfo); |
---|
| 124 | PRINTF(3)("Calculated attributes2\n"); |
---|
| 125 | this->calculateBoxAxis(this->bvElement,modInfo); |
---|
| 126 | PRINTF(3)("Calculated attributes3\n"); |
---|
| 127 | |
---|
| 128 | /* if this is the first node, the vertices data are the original ones of the model itself, so dont delete them in cleanup */ |
---|
| 129 | if( this->treeIndex == 1) |
---|
| 130 | this->bvElement->bOrigVertices = true; |
---|
| 131 | |
---|
| 132 | if( likely( this->depth > 0)) |
---|
| 133 | { |
---|
| 134 | this->forkBox(this->bvElement); |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | // if(this->tmpLen1 > 2) |
---|
| 138 | // { |
---|
| 139 | // OBBTreeNode* node1 = new OBBTreeNode(); |
---|
| 140 | // this->nodeLeft = node1; |
---|
| 141 | // this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); |
---|
| 142 | // } |
---|
| 143 | // else |
---|
| 144 | // { |
---|
| 145 | // PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n"); |
---|
| 146 | // } |
---|
| 147 | // |
---|
| 148 | // if( this->tmpLen2 > 2) |
---|
| 149 | // { |
---|
| 150 | // OBBTreeNode* node2 = new OBBTreeNode(); |
---|
| 151 | // this->nodeRight = node2; |
---|
| 152 | // this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); |
---|
| 153 | // } |
---|
| 154 | // else |
---|
| 155 | // { |
---|
| 156 | // PRINTF(3)("Abording tree walk: less than 3 vertices left\n"); |
---|
| 157 | // } |
---|
| 158 | |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
[4542] | 163 | /** |
---|
[4836] | 164 | * creates a new BVTree or BVTree partition |
---|
| 165 | * @param depth: how much more depth-steps to go: if == 1 don't go any deeper! |
---|
| 166 | * @param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle |
---|
[5684] | 167 | * |
---|
| 168 | * this function creates an Bounding Volume tree from a vertices soup (no triangle data) |
---|
[4617] | 169 | */ |
---|
[4544] | 170 | void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length) |
---|
[4542] | 171 | { |
---|
[4717] | 172 | PRINT(3)("\n"); |
---|
[4638] | 173 | this->treeIndex = this->obbTree->getID(); |
---|
[4717] | 174 | PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length); |
---|
[4614] | 175 | this->depth = depth; |
---|
| 176 | |
---|
[4638] | 177 | |
---|
[4630] | 178 | this->bvElement = new OBB(); |
---|
[4638] | 179 | this->bvElement->vertices = verticesList; |
---|
| 180 | this->bvElement->numOfVertices = length; |
---|
| 181 | PRINTF(3)("Created OBBox\n"); |
---|
[4632] | 182 | this->calculateBoxCovariance(this->bvElement, verticesList, length); |
---|
[4638] | 183 | PRINTF(3)("Calculated attributes1\n"); |
---|
[4632] | 184 | this->calculateBoxEigenvectors(this->bvElement, verticesList, length); |
---|
[4638] | 185 | PRINTF(3)("Calculated attributes2\n"); |
---|
[4632] | 186 | this->calculateBoxAxis(this->bvElement, verticesList, length); |
---|
[4638] | 187 | PRINTF(3)("Calculated attributes3\n"); |
---|
[4617] | 188 | |
---|
[4814] | 189 | /* if this is the first node, the vertices data are the original ones of the model itself, so dont delete them in cleanup */ |
---|
| 190 | if( this->treeIndex == 1) |
---|
| 191 | this->bvElement->bOrigVertices = true; |
---|
[4632] | 192 | |
---|
[4614] | 193 | if( likely( this->depth > 0)) |
---|
| 194 | { |
---|
| 195 | this->forkBox(this->bvElement); |
---|
[4626] | 196 | |
---|
[4630] | 197 | |
---|
[4710] | 198 | if(this->tmpLen1 > 2) |
---|
[4638] | 199 | { |
---|
| 200 | OBBTreeNode* node1 = new OBBTreeNode(); |
---|
| 201 | this->nodeLeft = node1; |
---|
| 202 | this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); |
---|
| 203 | } |
---|
| 204 | else |
---|
| 205 | { |
---|
[4717] | 206 | PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n"); |
---|
[4638] | 207 | } |
---|
[4630] | 208 | |
---|
[4710] | 209 | if( this->tmpLen2 > 2) |
---|
[4638] | 210 | { |
---|
| 211 | OBBTreeNode* node2 = new OBBTreeNode(); |
---|
| 212 | this->nodeRight = node2; |
---|
| 213 | this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); |
---|
| 214 | } |
---|
| 215 | else |
---|
| 216 | { |
---|
[4717] | 217 | PRINTF(3)("Abording tree walk: less than 3 vertices left\n"); |
---|
[4638] | 218 | } |
---|
[4614] | 219 | } |
---|
[4557] | 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
[5684] | 223 | void OBBTreeNode::calculateBoxCovariance(OBB* box, const modelInfo& modInfo) |
---|
| 224 | {} |
---|
[4557] | 225 | |
---|
[5684] | 226 | |
---|
[4632] | 227 | void OBBTreeNode::calculateBoxCovariance(OBB* box, sVec3D* verticesList, int length) |
---|
[4557] | 228 | { |
---|
[4543] | 229 | float facelet[length]; //!< surface area of the i'th triangle of the convex hull |
---|
[5428] | 230 | float face = 0.0f; //!< surface area of the entire convex hull |
---|
[4588] | 231 | Vector centroid[length]; //!< centroid of the i'th convex hull |
---|
[4557] | 232 | Vector center; //!< the center of the entire hull |
---|
[4544] | 233 | Vector p, q, r; //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d |
---|
[4545] | 234 | Vector t1, t2; //!< temporary values |
---|
[4628] | 235 | float covariance[3][3]; //!< the covariance matrix |
---|
[4674] | 236 | int mode = 0; //!< mode = 0: vertex soup, no connections, mode = 1: 3 following verteces build a triangle |
---|
[4588] | 237 | |
---|
[4553] | 238 | this->numOfVertices = length; |
---|
| 239 | this->vertices = verticesList; |
---|
| 240 | |
---|
[4562] | 241 | |
---|
[4648] | 242 | if( likely(mode == 0)) |
---|
| 243 | { |
---|
| 244 | /* fist compute all the convex hull face/facelets and centroids */ |
---|
[5428] | 245 | for( int i = 0; i+3 < length ; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ |
---|
[4648] | 246 | { |
---|
| 247 | p = verticesList[i]; |
---|
| 248 | q = verticesList[i + 1]; |
---|
| 249 | r = verticesList[i + 2]; |
---|
[4638] | 250 | |
---|
[4648] | 251 | t1 = p - q; t2 = p - r; |
---|
[4638] | 252 | |
---|
[4648] | 253 | /* finding the facelet surface via cross-product */ |
---|
| 254 | facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); |
---|
| 255 | /* update the entire convex hull surface */ |
---|
| 256 | face += facelet[i]; |
---|
| 257 | |
---|
| 258 | /* calculate the cetroid of the hull triangles */ |
---|
| 259 | centroid[i] = (p + q + r) * 1/3; |
---|
| 260 | /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ |
---|
| 261 | center += centroid[i] * facelet[i]; |
---|
| 262 | } |
---|
| 263 | /* take the average of the centroid sum */ |
---|
| 264 | center /= face; |
---|
| 265 | PRINTF(3)("-- Calculated Center\n"); |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */ |
---|
[5428] | 269 | for( int j = 0; j < 3; ++j) |
---|
[4648] | 270 | { |
---|
[5428] | 271 | for( int k = 0; k < 3; ++k) |
---|
[4648] | 272 | { |
---|
[5428] | 273 | for( int i = 0; i + 3 < length; i+=3) |
---|
[4648] | 274 | { |
---|
| 275 | p = verticesList[i]; |
---|
| 276 | q = verticesList[i + 1]; |
---|
| 277 | r = verticesList[i + 2]; |
---|
| 278 | |
---|
| 279 | covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j] * p[k] + |
---|
| 280 | q[j] * q[k] + r[j] * r[k]) - center[j] * center[k]; |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | PRINTF(3)("-- Calculated Covariance\n"); |
---|
| 285 | } |
---|
| 286 | else if( mode == 1) |
---|
[4617] | 287 | { |
---|
[5428] | 288 | for( int i = 0; i + 3 < length; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ |
---|
[4648] | 289 | { |
---|
| 290 | p = verticesList[i]; |
---|
| 291 | q = verticesList[i + 1]; |
---|
| 292 | r = verticesList[i + 2]; |
---|
[4588] | 293 | |
---|
[4648] | 294 | centroid[i] = (p + q + r) / 3.0f; |
---|
| 295 | center += centroid[i]; |
---|
| 296 | } |
---|
| 297 | center /= length; |
---|
[4588] | 298 | |
---|
[4648] | 299 | for( int j = 0; j < 3; ++j) |
---|
| 300 | { |
---|
| 301 | for( int k = 0; k < 3; ++k) |
---|
| 302 | { |
---|
[5428] | 303 | for( int i = 0; i + 3 < length; i+=3) |
---|
[4648] | 304 | { |
---|
| 305 | p = verticesList[i]; |
---|
| 306 | q = verticesList[i +1]; |
---|
| 307 | r = verticesList[i + 2]; |
---|
[4545] | 308 | |
---|
[4648] | 309 | covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k]; |
---|
| 310 | } |
---|
| 311 | covariance[j][k] /= (3.0f * length); |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | PRINTF(3)("-- Calculated Covariance\n"); |
---|
[4617] | 315 | } |
---|
[4648] | 316 | else if( mode == 2) |
---|
| 317 | { |
---|
| 318 | /* fist compute all the convex hull face/facelets and centroids */ |
---|
[5428] | 319 | for(int i = 0; i + 3 < length; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ |
---|
[4648] | 320 | { |
---|
| 321 | p = verticesList[i]; |
---|
| 322 | q = verticesList[i + 1]; |
---|
| 323 | r = verticesList[i + 2]; |
---|
[4562] | 324 | |
---|
[4648] | 325 | t1 = p - q; t2 = p - r; |
---|
[4562] | 326 | |
---|
[4648] | 327 | /* finding the facelet surface via cross-product */ |
---|
| 328 | facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); |
---|
| 329 | /* update the entire convex hull surface */ |
---|
| 330 | face += facelet[i]; |
---|
| 331 | |
---|
| 332 | /* calculate the cetroid of the hull triangles */ |
---|
| 333 | centroid[i] = (p + q + r) * 1/3; |
---|
| 334 | /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ |
---|
| 335 | center += centroid[i] * facelet[i]; |
---|
| 336 | } |
---|
| 337 | /* take the average of the centroid sum */ |
---|
| 338 | center /= face; |
---|
| 339 | PRINTF(3)("-- Calculated Center\n"); |
---|
| 340 | |
---|
| 341 | for( int j = 0; j < 3; ++j) |
---|
| 342 | { |
---|
| 343 | for( int k = 0; k < 3; ++k) |
---|
| 344 | { |
---|
[5428] | 345 | for( int i = 0; i + 3 < length; i+=3) |
---|
[4648] | 346 | { |
---|
| 347 | p = verticesList[i]; |
---|
| 348 | q = verticesList[i +1]; |
---|
| 349 | r = verticesList[i + 2]; |
---|
| 350 | |
---|
| 351 | covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k]; |
---|
| 352 | } |
---|
| 353 | covariance[j][k] /= (3.0f * length); |
---|
| 354 | } |
---|
| 355 | } |
---|
| 356 | PRINTF(3)("-- Calculated Covariance\n"); |
---|
| 357 | } |
---|
| 358 | else |
---|
[4617] | 359 | { |
---|
[4648] | 360 | for( int i = 0; i < length; ++i) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ |
---|
[4545] | 361 | { |
---|
[4648] | 362 | center += verticesList[i]; |
---|
| 363 | } |
---|
| 364 | center /= length; |
---|
| 365 | |
---|
| 366 | for( int j = 0; j < 3; ++j) |
---|
| 367 | { |
---|
| 368 | for( int k = 0; k < 3; ++k) |
---|
[4617] | 369 | { |
---|
[5428] | 370 | for( int i = 0; i + 3 < length; i+=3) |
---|
[4648] | 371 | { |
---|
| 372 | p = verticesList[i]; |
---|
| 373 | q = verticesList[i +1]; |
---|
| 374 | r = verticesList[i + 2]; |
---|
[4544] | 375 | |
---|
[4648] | 376 | covariance[j][k] = p[j] * p[k] + q[j] * q[k] + r[j] + r[k]; |
---|
| 377 | } |
---|
| 378 | covariance[j][k] /= (3.0f * length); |
---|
[4617] | 379 | } |
---|
[4545] | 380 | } |
---|
[4648] | 381 | PRINTF(3)("-- Calculated Covariance\n"); |
---|
[4617] | 382 | } |
---|
[4562] | 383 | |
---|
[4648] | 384 | PRINTF(3)("\nVertex Data:\n"); |
---|
[4638] | 385 | for(int i = 0; i < length; i++) |
---|
| 386 | { |
---|
[4648] | 387 | PRINTF(3)("vertex %i: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]); |
---|
[4638] | 388 | } |
---|
[4588] | 389 | |
---|
[4648] | 390 | |
---|
[4675] | 391 | PRINTF(3)("\nCovariance Matrix:\n"); |
---|
[4674] | 392 | for(int j = 0; j < 3; ++j) |
---|
| 393 | { |
---|
[4675] | 394 | PRINT(3)(" |"); |
---|
[4674] | 395 | for(int k = 0; k < 3; ++k) |
---|
| 396 | { |
---|
[4675] | 397 | PRINT(3)(" \b%f ", covariance[j][k]); |
---|
[4674] | 398 | } |
---|
[4675] | 399 | PRINT(3)(" |\n"); |
---|
[4674] | 400 | } |
---|
| 401 | |
---|
[4638] | 402 | PRINTF(3)("center: %f, %f, %f\n", center.x, center.y, center.z); |
---|
[4553] | 403 | |
---|
[4588] | 404 | |
---|
[4674] | 405 | for(int i = 0; i < 3; ++i) |
---|
| 406 | { |
---|
| 407 | box->covarianceMatrix[i][0] = covariance[i][0]; |
---|
| 408 | box->covarianceMatrix[i][1] = covariance[i][1]; |
---|
| 409 | box->covarianceMatrix[i][2] = covariance[i][2]; |
---|
| 410 | } |
---|
[4560] | 411 | *box->center = center; |
---|
[4638] | 412 | PRINTF(3)("-- Written Result to obb\n"); |
---|
[4631] | 413 | } |
---|
[4557] | 414 | |
---|
[4631] | 415 | |
---|
[5684] | 416 | void OBBTreeNode::calculateBoxEigenvectors(OBB* box, const modelInfo& modInfo) |
---|
| 417 | {} |
---|
[4631] | 418 | |
---|
[4632] | 419 | void OBBTreeNode::calculateBoxEigenvectors(OBB* box, sVec3D* verticesList, int length) |
---|
[4631] | 420 | { |
---|
| 421 | |
---|
[4557] | 422 | /* now getting spanning vectors of the sub-space: |
---|
[4617] | 423 | the eigenvectors of a symmertric matrix, such as the |
---|
| 424 | covarience matrix are mutually orthogonal. |
---|
| 425 | after normalizing them, they can be used as a the basis |
---|
| 426 | vectors |
---|
[4557] | 427 | */ |
---|
[4660] | 428 | Vector* axis = new Vector[3]; //!< the references to the obb axis |
---|
[4588] | 429 | |
---|
[5674] | 430 | Matrix covMat( box->covarianceMatrix[0][0], box->covarianceMatrix[0][1], box->covarianceMatrix[0][2], |
---|
| 431 | box->covarianceMatrix[1][0], box->covarianceMatrix[1][1], box->covarianceMatrix[1][2], |
---|
| 432 | box->covarianceMatrix[2][0], box->covarianceMatrix[2][1], box->covarianceMatrix[2][2] ); |
---|
| 433 | covMat.getEigenVectors(axis[0], axis[1], axis[2] ); |
---|
[4627] | 434 | |
---|
[5449] | 435 | |
---|
[4630] | 436 | /* new jacobi tests */ |
---|
[5674] | 437 | // JacobI(OBBTreeNode::coMat, OBBTreeNode::eigvlMat, OBBTreeNode::eigvMat, OBBTreeNode::rotCount); |
---|
| 438 | // PRINTF(3)("-- Done Jacobi Decomposition\n"); |
---|
[4628] | 439 | |
---|
[4627] | 440 | |
---|
[5491] | 441 | // PRINTF(0)("Jacobi\n"); |
---|
| 442 | // for(int j = 0; j < 3; ++j) |
---|
[4629] | 443 | // { |
---|
[5491] | 444 | // printf(" |"); |
---|
| 445 | // for(int k = 0; k < 3; ++k) |
---|
[4629] | 446 | // { |
---|
[5491] | 447 | // printf(" \t%f ", OBBTreeNode::OBBTreeNode::eigvMat[j][k]); |
---|
[4629] | 448 | // } |
---|
[5491] | 449 | // printf(" |\n"); |
---|
[4629] | 450 | // } |
---|
| 451 | |
---|
[5674] | 452 | /* axis[0].x = OBBTreeNode::eigvMat[0][0]; axis[0].y = OBBTreeNode::eigvMat[1][0]; axis[0].z = OBBTreeNode::eigvMat[2][0]; |
---|
[5449] | 453 | axis[1].x = OBBTreeNode::eigvMat[0][1]; axis[1].y = OBBTreeNode::eigvMat[1][1]; axis[1].z = OBBTreeNode::eigvMat[2][1]; |
---|
| 454 | axis[2].x = OBBTreeNode::eigvMat[0][2]; axis[2].y = OBBTreeNode::eigvMat[1][2]; axis[2].z = OBBTreeNode::eigvMat[2][2]; |
---|
[4705] | 455 | axis[0].normalize(); |
---|
| 456 | axis[1].normalize(); |
---|
[5674] | 457 | axis[2].normalize();*/ |
---|
[4576] | 458 | box->axis = axis; |
---|
[4660] | 459 | |
---|
[5492] | 460 | // PRINTF(0)("-- Got Axis\n"); |
---|
| 461 | // |
---|
| 462 | // PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0].x, box->axis[0].y, box->axis[0].z); |
---|
| 463 | // PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1].x, box->axis[1].y, box->axis[1].z); |
---|
| 464 | // PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2].x, box->axis[2].y, box->axis[2].z); |
---|
[4632] | 465 | } |
---|
[4588] | 466 | |
---|
[4626] | 467 | |
---|
[5684] | 468 | void OBBTreeNode::calculateBoxAxis(OBB* box, const modelInfo& modInfo) |
---|
| 469 | {} |
---|
| 470 | |
---|
| 471 | |
---|
[4632] | 472 | void OBBTreeNode::calculateBoxAxis(OBB* box, sVec3D* verticesList, int length) |
---|
[4631] | 473 | { |
---|
[4630] | 474 | |
---|
[4576] | 475 | /* now get the axis length */ |
---|
[4578] | 476 | Line ax[3]; //!< the axis |
---|
| 477 | float* halfLength = new float[3]; //!< half length of the axis |
---|
| 478 | float tmpLength; //!< tmp save point for the length |
---|
[4660] | 479 | Plane p0(box->axis[0], *box->center); //!< the axis planes |
---|
| 480 | Plane p1(box->axis[1], *box->center); |
---|
| 481 | Plane p2(box->axis[2], *box->center); |
---|
[4658] | 482 | float maxLength[3]; |
---|
| 483 | float minLength[3]; |
---|
[4588] | 484 | |
---|
[4658] | 485 | |
---|
| 486 | /* get a bad bounding box */ |
---|
[4589] | 487 | halfLength[0] = -1.0f; |
---|
[4585] | 488 | for(int j = 0; j < length; ++j) |
---|
[4658] | 489 | { |
---|
[4661] | 490 | tmpLength = fabs(p0.distancePoint(vertices[j])); |
---|
[4658] | 491 | if( tmpLength > halfLength[0]) |
---|
[4659] | 492 | halfLength[0] = tmpLength; |
---|
[4658] | 493 | } |
---|
| 494 | |
---|
| 495 | halfLength[1] = -1.0f; |
---|
| 496 | for(int j = 0; j < length; ++j) |
---|
| 497 | { |
---|
| 498 | tmpLength = fabs(p1.distancePoint(vertices[j])); |
---|
| 499 | if( tmpLength > halfLength[1]) |
---|
[4659] | 500 | halfLength[1] = tmpLength; |
---|
[4658] | 501 | } |
---|
| 502 | |
---|
| 503 | halfLength[2] = -1.0f; |
---|
| 504 | for(int j = 0; j < length; ++j) |
---|
| 505 | { |
---|
[4661] | 506 | tmpLength = fabs(p2.distancePoint(vertices[j])); |
---|
[4658] | 507 | if( tmpLength > halfLength[2]) |
---|
[4659] | 508 | halfLength[2] = tmpLength; |
---|
[4658] | 509 | } |
---|
| 510 | |
---|
| 511 | |
---|
| 512 | |
---|
| 513 | /* get the maximal dimensions of the body in all directions */ |
---|
[4710] | 514 | maxLength[0] = p0.distancePoint(vertices[0]); |
---|
| 515 | minLength[0] = p0.distancePoint(vertices[0]); |
---|
[4660] | 516 | for(int j = 0; j < length; ++j) |
---|
| 517 | { |
---|
| 518 | tmpLength = p0.distancePoint(vertices[j]); |
---|
| 519 | if( tmpLength > maxLength[0]) |
---|
| 520 | maxLength[0] = tmpLength; |
---|
| 521 | else if( tmpLength < minLength[0]) |
---|
| 522 | minLength[0] = tmpLength; |
---|
| 523 | } |
---|
[4578] | 524 | |
---|
[4710] | 525 | maxLength[1] = p1.distancePoint(vertices[0]); |
---|
| 526 | minLength[1] = p1.distancePoint(vertices[0]); |
---|
[4660] | 527 | for(int j = 0; j < length; ++j) |
---|
| 528 | { |
---|
[4661] | 529 | tmpLength = p1.distancePoint(vertices[j]); |
---|
[4660] | 530 | if( tmpLength > maxLength[1]) |
---|
| 531 | maxLength[1] = tmpLength; |
---|
| 532 | else if( tmpLength < minLength[1]) |
---|
| 533 | minLength[1] = tmpLength; |
---|
| 534 | } |
---|
[4585] | 535 | |
---|
[4710] | 536 | maxLength[2] = p2.distancePoint(vertices[0]); |
---|
| 537 | minLength[2] = p2.distancePoint(vertices[0]); |
---|
[4660] | 538 | for(int j = 0; j < length; ++j) |
---|
| 539 | { |
---|
[4661] | 540 | tmpLength = p2.distancePoint(vertices[j]); |
---|
[4660] | 541 | if( tmpLength > maxLength[2]) |
---|
| 542 | maxLength[2] = tmpLength; |
---|
| 543 | else if( tmpLength < minLength[2]) |
---|
| 544 | minLength[2] = tmpLength; |
---|
| 545 | } |
---|
[4585] | 546 | |
---|
[4660] | 547 | |
---|
| 548 | /* calculate the real centre of the body by using the axis length */ |
---|
[4668] | 549 | float centerOffset[3]; |
---|
| 550 | float newHalfLength[3]; |
---|
[4660] | 551 | for(int i = 0; i < 3; ++i) |
---|
| 552 | { |
---|
[4674] | 553 | PRINTF(3)("max: %f, min: %f \n", maxLength[i], minLength[i]); |
---|
[4710] | 554 | centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f; // min length is negatie |
---|
| 555 | newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative |
---|
[4668] | 556 | *box->center += (box->axis[i] * centerOffset[i]); // update the new center vector |
---|
| 557 | halfLength[i] = newHalfLength[i]; |
---|
[4660] | 558 | } |
---|
| 559 | |
---|
| 560 | |
---|
| 561 | |
---|
[4586] | 562 | box->halfLength = halfLength; |
---|
[4638] | 563 | PRINTF(3)("-- Written Axis to obb\n"); |
---|
| 564 | PRINTF(3)("-- Finished Calculating Attributes\n"); |
---|
[4585] | 565 | |
---|
[4542] | 566 | } |
---|
| 567 | |
---|
| 568 | |
---|
[4609] | 569 | |
---|
| 570 | /** |
---|
| 571 | \brief this separates an ob-box in the middle |
---|
[4836] | 572 | * @param box: the box to separate |
---|
[4609] | 573 | |
---|
| 574 | this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis |
---|
| 575 | */ |
---|
[4557] | 576 | void OBBTreeNode::forkBox(OBB* box) |
---|
| 577 | { |
---|
| 578 | /* get the longest axis of the box */ |
---|
[4609] | 579 | float aLength = -1.0f; //!< the length of the longest axis |
---|
| 580 | int axisIndex = 0; //!< this is the nr of the longest axis |
---|
| 581 | |
---|
[4557] | 582 | for(int i = 0; i < 3; ++i) |
---|
[4609] | 583 | { |
---|
| 584 | if( aLength < box->halfLength[i]) |
---|
[4557] | 585 | { |
---|
[4609] | 586 | aLength = box->halfLength[i]; |
---|
| 587 | axisIndex = i; |
---|
[4557] | 588 | } |
---|
[4609] | 589 | } |
---|
[4588] | 590 | |
---|
[4688] | 591 | PRINTF(3)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength); |
---|
[4609] | 592 | |
---|
| 593 | |
---|
[4557] | 594 | /* get the closest vertex near the center */ |
---|
[4611] | 595 | float dist = 999999.0f; //!< the smallest distance to each vertex |
---|
[4609] | 596 | float tmpDist; //!< temporary distance |
---|
| 597 | int vertexIndex; |
---|
[4660] | 598 | Plane middlePlane(box->axis[axisIndex], *box->center); //!< the middle plane |
---|
[4588] | 599 | |
---|
[4660] | 600 | vertexIndex = 0; |
---|
[4609] | 601 | for(int i = 0; i < box->numOfVertices; ++i) |
---|
| 602 | { |
---|
[4611] | 603 | tmpDist = fabs(middlePlane.distancePoint(box->vertices[i])); |
---|
| 604 | if( tmpDist < dist) |
---|
| 605 | { |
---|
[4609] | 606 | dist = tmpDist; |
---|
[4611] | 607 | vertexIndex = i; |
---|
| 608 | } |
---|
[4609] | 609 | } |
---|
| 610 | |
---|
[4710] | 611 | PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist); |
---|
[4609] | 612 | |
---|
| 613 | |
---|
[4611] | 614 | /* now definin the separation plane through this specified nearest point and partition |
---|
[4617] | 615 | the points depending on which side they are located |
---|
[4611] | 616 | */ |
---|
| 617 | tList<sVec3D> partition1; //!< the vertex partition 1 |
---|
| 618 | tList<sVec3D> partition2; //!< the vertex partition 2 |
---|
| 619 | |
---|
[4710] | 620 | |
---|
[4695] | 621 | PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box->numOfVertices); |
---|
[4660] | 622 | this->separationPlane = new Plane(box->axis[axisIndex], box->vertices[vertexIndex]); //!< separation plane |
---|
[4632] | 623 | this->sepPlaneCenter = &box->vertices[vertexIndex]; |
---|
| 624 | this->longestAxisIndex = axisIndex; |
---|
| 625 | |
---|
[4612] | 626 | for(int i = 0; i < box->numOfVertices; ++i) |
---|
| 627 | { |
---|
[4710] | 628 | if( i == vertexIndex) continue; |
---|
| 629 | tmpDist = this->separationPlane->distancePoint(box->vertices[i]); |
---|
| 630 | if( tmpDist > 0.0) |
---|
| 631 | partition1.add(&box->vertices[i]); /* positive numbers plus zero */ |
---|
[4612] | 632 | else |
---|
[4710] | 633 | partition2.add(&box->vertices[i]); /* negatice numbers */ |
---|
[4612] | 634 | } |
---|
[4613] | 635 | partition1.add(&box->vertices[vertexIndex]); |
---|
[4710] | 636 | partition2.add(&box->vertices[vertexIndex]); |
---|
[4611] | 637 | |
---|
[4710] | 638 | PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize()); |
---|
[4612] | 639 | |
---|
[4613] | 640 | |
---|
| 641 | /* now comes the separation into two different sVec3D arrays */ |
---|
| 642 | tIterator<sVec3D>* iterator; //!< the iterator to go through the lists |
---|
| 643 | sVec3D* element; //!< the elements |
---|
| 644 | int index; //!< index storage place |
---|
| 645 | sVec3D* vertList1; //!< the vertex list 1 |
---|
| 646 | sVec3D* vertList2; //!< the vertex list 2 |
---|
| 647 | |
---|
| 648 | vertList1 = new sVec3D[partition1.getSize()]; |
---|
| 649 | vertList2 = new sVec3D[partition2.getSize()]; |
---|
| 650 | |
---|
| 651 | iterator = partition1.getIterator(); |
---|
[5115] | 652 | element = iterator->firstElement(); |
---|
[4613] | 653 | index = 0; |
---|
| 654 | while( element != NULL) |
---|
| 655 | { |
---|
| 656 | vertList1[index][0] = element[0][0]; |
---|
| 657 | vertList1[index][1] = element[0][1]; |
---|
| 658 | vertList1[index][2] = element[0][2]; |
---|
| 659 | ++index; |
---|
| 660 | element = iterator->nextElement(); |
---|
| 661 | } |
---|
| 662 | |
---|
[4638] | 663 | // PRINTF(0)("\npartition 1:\n"); |
---|
[4626] | 664 | // for(int i = 0; i < partition1.getSize(); ++i) |
---|
| 665 | // { |
---|
[4638] | 666 | // PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList1[i][0], i, vertList1[i][1], i, vertList1[i][2]); |
---|
[4626] | 667 | // } |
---|
[4613] | 668 | |
---|
| 669 | iterator = partition2.getIterator(); |
---|
[5115] | 670 | element = iterator->firstElement(); |
---|
[4613] | 671 | index = 0; |
---|
| 672 | while( element != NULL) |
---|
| 673 | { |
---|
| 674 | vertList2[index][0] = element[0][0]; |
---|
| 675 | vertList2[index][1] = element[0][1]; |
---|
| 676 | vertList2[index][2] = element[0][2]; |
---|
| 677 | ++index; |
---|
| 678 | element = iterator->nextElement(); |
---|
| 679 | } |
---|
| 680 | |
---|
[4630] | 681 | this->tmpVert1 = vertList1; |
---|
| 682 | this->tmpVert2 = vertList2; |
---|
| 683 | this->tmpLen1 = partition1.getSize(); |
---|
| 684 | this->tmpLen2 = partition2.getSize(); |
---|
| 685 | |
---|
[4638] | 686 | delete iterator; |
---|
| 687 | |
---|
| 688 | // PRINTF(0)("\npartition 2:\n"); |
---|
[4626] | 689 | // for(int i = 0; i < partition2.getSize(); ++i) |
---|
| 690 | // { |
---|
[4638] | 691 | // PRINTF(0)("v[%i][0] = %f,\tv[%i][1] = %f,\tv[%i][1] = %f\n", i, vertList2[i][0], i, vertList2[i][1], i, vertList2[i][2]); |
---|
[4626] | 692 | // } |
---|
[4557] | 693 | } |
---|
| 694 | |
---|
| 695 | |
---|
[4626] | 696 | |
---|
| 697 | |
---|
[5028] | 698 | void OBBTreeNode::collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB) |
---|
[4695] | 699 | { |
---|
[4705] | 700 | PRINTF(3)("collideWith\n"); |
---|
[4695] | 701 | /* if the obb overlap, make subtests: check which node is realy overlaping */ |
---|
[4705] | 702 | PRINT(3)("Checking OBB %i vs %i: ", this->getIndex(), treeNode->getIndex()); |
---|
[4718] | 703 | if( unlikely(treeNode == NULL)) return; |
---|
[5042] | 704 | |
---|
[4700] | 705 | if( this->overlapTest(this->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) |
---|
[4695] | 706 | { |
---|
[5044] | 707 | PRINTF(3)("collision @ lvl %i, object %s vs. %s, (%p, %p)\n", this->depth, nodeA->getClassName(), nodeB->getClassName(), this->nodeLeft, this->nodeRight); |
---|
[5038] | 708 | |
---|
[4695] | 709 | /* check if left node overlaps */ |
---|
[4704] | 710 | if( likely( this->nodeLeft != NULL)) |
---|
| 711 | { |
---|
[4705] | 712 | PRINT(3)("Checking OBB %i vs %i: ", this->nodeLeft->getIndex(), treeNode->getIndex()); |
---|
[4700] | 713 | if( this->overlapTest(this->nodeLeft->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) |
---|
[4704] | 714 | { |
---|
[4700] | 715 | this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB); |
---|
[4704] | 716 | this->nodeLeft->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB); |
---|
| 717 | } |
---|
| 718 | } |
---|
[4695] | 719 | /* check if right node overlaps */ |
---|
[4704] | 720 | if( likely( this->nodeRight != NULL)) |
---|
| 721 | { |
---|
[4705] | 722 | PRINT(3)("Checking OBB %i vs %i: ", this->nodeRight->getIndex(), treeNode->getIndex()); |
---|
[4700] | 723 | if(this->overlapTest(this->nodeRight->bvElement, ((OBBTreeNode*)treeNode)->bvElement, nodeA, nodeB)) |
---|
[4704] | 724 | { |
---|
| 725 | this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeLeft, nodeA, nodeB); |
---|
| 726 | this->nodeRight->collideWith(((OBBTreeNode*)treeNode)->nodeRight, nodeA, nodeB); |
---|
| 727 | } |
---|
[5044] | 728 | } |
---|
[5028] | 729 | |
---|
[5044] | 730 | /* so there is a collision and this is the last box in the tree (i.e. leaf) */ |
---|
| 731 | if( unlikely(this->nodeRight == NULL && this->nodeLeft == NULL)) |
---|
| 732 | { |
---|
[5046] | 733 | nodeA->collidesWith(nodeB, *((OBBTreeNode*)treeNode)->bvElement->center); |
---|
| 734 | |
---|
| 735 | nodeB->collidesWith(nodeA, *this->bvElement->center); |
---|
[4704] | 736 | } |
---|
[5044] | 737 | |
---|
[4695] | 738 | } |
---|
| 739 | } |
---|
[4542] | 740 | |
---|
| 741 | |
---|
[4626] | 742 | |
---|
[5028] | 743 | bool OBBTreeNode::overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB) |
---|
[4695] | 744 | { |
---|
[4696] | 745 | /* first check all axis */ |
---|
[4708] | 746 | Vector t; |
---|
[4700] | 747 | float rA = 0.0f; |
---|
| 748 | float rB = 0.0f; |
---|
| 749 | Vector l; |
---|
[4708] | 750 | Vector rotAxisA[3]; |
---|
| 751 | Vector rotAxisB[3]; |
---|
[4626] | 752 | |
---|
[4708] | 753 | rotAxisA[0] = nodeA->getAbsDir().apply(boxA->axis[0]); |
---|
| 754 | rotAxisA[1] = nodeA->getAbsDir().apply(boxA->axis[1]); |
---|
| 755 | rotAxisA[2] = nodeA->getAbsDir().apply(boxA->axis[2]); |
---|
| 756 | |
---|
| 757 | rotAxisB[0] = nodeB->getAbsDir().apply(boxB->axis[0]); |
---|
| 758 | rotAxisB[1] = nodeB->getAbsDir().apply(boxB->axis[1]); |
---|
| 759 | rotAxisB[2] = nodeB->getAbsDir().apply(boxB->axis[2]); |
---|
| 760 | |
---|
| 761 | t = nodeA->getAbsCoor() + nodeA->getAbsDir().apply(*boxA->center) - ( nodeB->getAbsCoor() + nodeB->getAbsDir().apply(*boxB->center)); |
---|
| 762 | |
---|
| 763 | // printf("\n"); |
---|
| 764 | // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[0].x, boxA->axis[0].y, boxA->axis[0].z, rotAxisA[0].x, rotAxisA[0].y, rotAxisA[0].z); |
---|
| 765 | // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[1].x, boxA->axis[1].y, boxA->axis[1].z, rotAxisA[1].x, rotAxisA[1].y, rotAxisA[1].z); |
---|
| 766 | // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxA->axis[2].x, boxA->axis[2].y, boxA->axis[2].z, rotAxisA[2].x, rotAxisA[2].y, rotAxisA[2].z); |
---|
| 767 | // |
---|
| 768 | // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[0].x, boxB->axis[0].y, boxB->axis[0].z, rotAxisB[0].x, rotAxisB[0].y, rotAxisB[0].z); |
---|
| 769 | // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[1].x, boxB->axis[1].y, boxB->axis[1].z, rotAxisB[1].x, rotAxisB[1].y, rotAxisB[1].z); |
---|
| 770 | // printf("(%f, %f, %f) -> (%f, %f, %f)\n", boxB->axis[2].x, boxB->axis[2].y, boxB->axis[2].z, rotAxisB[2].x, rotAxisB[2].y, rotAxisB[2].z); |
---|
| 771 | |
---|
| 772 | |
---|
[4703] | 773 | /* All 3 axis of the object A */ |
---|
[4701] | 774 | for( int j = 0; j < 3; ++j) |
---|
[4705] | 775 | { |
---|
| 776 | rA = 0.0f; |
---|
| 777 | rB = 0.0f; |
---|
[4708] | 778 | l = rotAxisA[j]; |
---|
[4705] | 779 | |
---|
[4708] | 780 | rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); |
---|
| 781 | rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); |
---|
| 782 | rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); |
---|
[4705] | 783 | |
---|
[4708] | 784 | rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); |
---|
| 785 | rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); |
---|
| 786 | rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); |
---|
[4705] | 787 | |
---|
| 788 | PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); |
---|
| 789 | |
---|
| 790 | if( (rA + rB) < fabs(t.dot(l))) |
---|
[4700] | 791 | { |
---|
[4705] | 792 | PRINT(3)("keine Kollision\n"); |
---|
| 793 | return false; |
---|
| 794 | } |
---|
| 795 | } |
---|
[4700] | 796 | |
---|
[4705] | 797 | /* All 3 axis of the object B */ |
---|
| 798 | for( int j = 0; j < 3; ++j) |
---|
| 799 | { |
---|
| 800 | rA = 0.0f; |
---|
| 801 | rB = 0.0f; |
---|
[4708] | 802 | l = rotAxisB[j]; |
---|
[4701] | 803 | |
---|
[4708] | 804 | rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); |
---|
| 805 | rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); |
---|
| 806 | rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); |
---|
[4700] | 807 | |
---|
[4708] | 808 | rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); |
---|
| 809 | rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); |
---|
| 810 | rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); |
---|
[4703] | 811 | |
---|
[4705] | 812 | PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); |
---|
| 813 | |
---|
| 814 | if( (rA + rB) < fabs(t.dot(l))) |
---|
| 815 | { |
---|
| 816 | PRINT(3)("keine Kollision\n"); |
---|
| 817 | return false; |
---|
[4701] | 818 | } |
---|
[4705] | 819 | } |
---|
[4700] | 820 | |
---|
[4705] | 821 | |
---|
| 822 | /* Now check for all face cross products */ |
---|
| 823 | |
---|
| 824 | for( int j = 0; j < 3; ++j) |
---|
| 825 | { |
---|
| 826 | for(int k = 0; k < 3; ++k ) |
---|
[4701] | 827 | { |
---|
| 828 | rA = 0.0f; |
---|
| 829 | rB = 0.0f; |
---|
[4708] | 830 | l = rotAxisA[j].cross(rotAxisB[k]); |
---|
[4701] | 831 | |
---|
[4708] | 832 | rA += fabs(boxA->halfLength[0] * rotAxisA[0].dot(l)); |
---|
| 833 | rA += fabs(boxA->halfLength[1] * rotAxisA[1].dot(l)); |
---|
| 834 | rA += fabs(boxA->halfLength[2] * rotAxisA[2].dot(l)); |
---|
[4701] | 835 | |
---|
[4708] | 836 | rB += fabs(boxB->halfLength[0] * rotAxisB[0].dot(l)); |
---|
| 837 | rB += fabs(boxB->halfLength[1] * rotAxisB[1].dot(l)); |
---|
| 838 | rB += fabs(boxB->halfLength[2] * rotAxisB[2].dot(l)); |
---|
[4701] | 839 | |
---|
[4703] | 840 | PRINTF(3)("s = %f, rA+rB = %f\n", fabs(t.dot(l)), rA+rB); |
---|
| 841 | |
---|
[4701] | 842 | if( (rA + rB) < fabs(t.dot(l))) |
---|
| 843 | { |
---|
[4705] | 844 | PRINT(3)("keine Kollision\n"); |
---|
[4701] | 845 | return false; |
---|
| 846 | } |
---|
[4703] | 847 | } |
---|
[4705] | 848 | } |
---|
[4701] | 849 | |
---|
| 850 | |
---|
[4705] | 851 | boxA->bCollided = true; /* use this ONLY(!!!!) for drawing operations */ |
---|
| 852 | boxB->bCollided = true; |
---|
| 853 | PRINT(3)("Kollision!\n"); |
---|
| 854 | return true; |
---|
[4695] | 855 | } |
---|
| 856 | |
---|
| 857 | |
---|
[4696] | 858 | |
---|
[4708] | 859 | |
---|
| 860 | |
---|
[5481] | 861 | void OBBTreeNode::drawBV(int depth, int drawMode, const Vector& color, bool top) const |
---|
[4553] | 862 | { |
---|
[4635] | 863 | |
---|
| 864 | /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */ |
---|
| 865 | if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL) |
---|
| 866 | { |
---|
[4638] | 867 | if( !(drawMode & DRAW_SINGLE && depth != 0)) |
---|
[4622] | 868 | { |
---|
[4712] | 869 | if( drawMode & DRAW_POINTS) |
---|
| 870 | glBegin(GL_POINTS); |
---|
[4638] | 871 | for(int i = 0; i < this->bvElement->numOfVertices; ++i) |
---|
| 872 | { |
---|
[4712] | 873 | if( drawMode & DRAW_POINTS) |
---|
| 874 | glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); |
---|
| 875 | else |
---|
| 876 | { |
---|
| 877 | glPushMatrix(); |
---|
| 878 | glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); |
---|
[5430] | 879 | gluSphere(OBBTreeNode_sphereObj, 0.1, 10, 10); |
---|
[4712] | 880 | glPopMatrix(); |
---|
| 881 | } |
---|
[4638] | 882 | } |
---|
[4712] | 883 | if( drawMode & DRAW_POINTS) |
---|
| 884 | glEnd(); |
---|
[4622] | 885 | } |
---|
[4635] | 886 | } |
---|
[4542] | 887 | |
---|
[5481] | 888 | if (top) |
---|
| 889 | { |
---|
| 890 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 891 | glDisable(GL_LIGHTING); |
---|
| 892 | glDisable(GL_TEXTURE_2D); |
---|
| 893 | } |
---|
| 894 | glColor3f(color.x, color.y, color.z); |
---|
[4542] | 895 | |
---|
[5481] | 896 | |
---|
[4589] | 897 | /* draw world axes */ |
---|
[4676] | 898 | if( drawMode & DRAW_BV_AXIS) |
---|
| 899 | { |
---|
| 900 | glBegin(GL_LINES); |
---|
[5481] | 901 | glColor3f(1.0, 0.0, 0.0); |
---|
[4676] | 902 | glVertex3f(0.0, 0.0, 0.0); |
---|
| 903 | glVertex3f(3.0, 0.0, 0.0); |
---|
[4589] | 904 | |
---|
[5481] | 905 | glColor3f(0.0, 1.0, 0.0); |
---|
[4676] | 906 | glVertex3f(0.0, 0.0, 0.0); |
---|
| 907 | glVertex3f(0.0, 3.0, 0.0); |
---|
[4589] | 908 | |
---|
[5481] | 909 | glColor3f(0.0, 0.0, 1.0); |
---|
[4676] | 910 | glVertex3f(0.0, 0.0, 0.0); |
---|
| 911 | glVertex3f(0.0, 0.0, 3.0); |
---|
| 912 | glEnd(); |
---|
| 913 | } |
---|
[4674] | 914 | |
---|
[4688] | 915 | |
---|
[4635] | 916 | if( drawMode & DRAW_BV_AXIS || drawMode & DRAW_ALL) |
---|
| 917 | { |
---|
[4636] | 918 | if( !(drawMode & DRAW_SINGLE && depth != 0)) |
---|
[4635] | 919 | { |
---|
| 920 | /* draw the obb axes */ |
---|
| 921 | glBegin(GL_LINES); |
---|
| 922 | glColor3f(0.0, 0.4, 0.3); |
---|
| 923 | glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z); |
---|
[4660] | 924 | glVertex3f(this->bvElement->center->x + this->bvElement->axis[0].x * this->bvElement->halfLength[0], |
---|
| 925 | this->bvElement->center->y + this->bvElement->axis[0].y * this->bvElement->halfLength[0], |
---|
| 926 | this->bvElement->center->z + this->bvElement->axis[0].z * this->bvElement->halfLength[0]); |
---|
[4589] | 927 | |
---|
[4635] | 928 | glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z); |
---|
[4660] | 929 | glVertex3f(this->bvElement->center->x + this->bvElement->axis[1].x * this->bvElement->halfLength[1], |
---|
| 930 | this->bvElement->center->y + this->bvElement->axis[1].y * this->bvElement->halfLength[1], |
---|
| 931 | this->bvElement->center->z + this->bvElement->axis[1].z * this->bvElement->halfLength[1]); |
---|
[4588] | 932 | |
---|
[4635] | 933 | glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z); |
---|
[4660] | 934 | glVertex3f(this->bvElement->center->x + this->bvElement->axis[2].x * this->bvElement->halfLength[2], |
---|
| 935 | this->bvElement->center->y + this->bvElement->axis[2].y * this->bvElement->halfLength[2], |
---|
| 936 | this->bvElement->center->z + this->bvElement->axis[2].z * this->bvElement->halfLength[2]); |
---|
[4635] | 937 | glEnd(); |
---|
| 938 | } |
---|
| 939 | } |
---|
[4581] | 940 | |
---|
[4588] | 941 | |
---|
[4674] | 942 | /* DRAW POLYGONS */ |
---|
[4673] | 943 | if( drawMode & DRAW_BV_POLYGON || drawMode & DRAW_ALL || drawMode & DRAW_BV_BLENDED) |
---|
[4635] | 944 | { |
---|
[5487] | 945 | if (top) |
---|
| 946 | { |
---|
| 947 | glEnable(GL_BLEND); |
---|
| 948 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
---|
| 949 | } |
---|
| 950 | |
---|
[4711] | 951 | if(this->nodeLeft == NULL || this->nodeRight == NULL) |
---|
[4710] | 952 | depth = 0; |
---|
[4636] | 953 | if( !(drawMode & DRAW_SINGLE && depth != 0)) |
---|
[4635] | 954 | { |
---|
[4636] | 955 | Vector cen = *this->bvElement->center; |
---|
[4660] | 956 | Vector* axis = this->bvElement->axis; |
---|
[4636] | 957 | float* len = this->bvElement->halfLength; |
---|
[4588] | 958 | |
---|
[4702] | 959 | if( this->bvElement->bCollided) |
---|
[5481] | 960 | { |
---|
[5487] | 961 | glColor4f(1.0, 1.0, 1.0, .5); // COLLISION COLOR |
---|
[5481] | 962 | } |
---|
[4702] | 963 | else if( drawMode & DRAW_BV_BLENDED) |
---|
[5481] | 964 | { |
---|
| 965 | glColor4f(color.x, color.y, color.z, .5); |
---|
| 966 | } |
---|
[4670] | 967 | |
---|
[4636] | 968 | /* draw bounding box */ |
---|
[4670] | 969 | if( drawMode & DRAW_BV_BLENDED) |
---|
| 970 | glBegin(GL_QUADS); |
---|
| 971 | else |
---|
| 972 | glBegin(GL_LINE_LOOP); |
---|
[4660] | 973 | glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 974 | cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 975 | cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 976 | glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 977 | cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 978 | cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 979 | glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 980 | cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 981 | cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 982 | glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 983 | cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 984 | cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); |
---|
[4636] | 985 | glEnd(); |
---|
[4588] | 986 | |
---|
[4670] | 987 | if( drawMode & DRAW_BV_BLENDED) |
---|
| 988 | glBegin(GL_QUADS); |
---|
| 989 | else |
---|
| 990 | glBegin(GL_LINE_LOOP); |
---|
[4660] | 991 | glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 992 | cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 993 | cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 994 | glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 995 | cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 996 | cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 997 | glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 998 | cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 999 | cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1000 | glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1001 | cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1002 | cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); |
---|
[4636] | 1003 | glEnd(); |
---|
[4588] | 1004 | |
---|
[4670] | 1005 | if( drawMode & DRAW_BV_BLENDED) |
---|
| 1006 | glBegin(GL_QUADS); |
---|
| 1007 | else |
---|
| 1008 | glBegin(GL_LINE_LOOP); |
---|
[4660] | 1009 | glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1010 | cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1011 | cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 1012 | glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1013 | cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1014 | cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1015 | glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1016 | cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1017 | cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1018 | glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1019 | cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1020 | cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); |
---|
[4636] | 1021 | glEnd(); |
---|
[4588] | 1022 | |
---|
[4670] | 1023 | if( drawMode & DRAW_BV_BLENDED) |
---|
| 1024 | glBegin(GL_QUADS); |
---|
| 1025 | else |
---|
| 1026 | glBegin(GL_LINE_LOOP); |
---|
[4660] | 1027 | glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1028 | cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1029 | cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1030 | glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1031 | cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1032 | cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 1033 | glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1034 | cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1035 | cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 1036 | glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1037 | cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1038 | cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); |
---|
[4636] | 1039 | glEnd(); |
---|
[4670] | 1040 | |
---|
[4671] | 1041 | |
---|
[4670] | 1042 | if( drawMode & DRAW_BV_BLENDED) |
---|
[4671] | 1043 | { |
---|
| 1044 | glBegin(GL_QUADS); |
---|
| 1045 | glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1046 | cen.y - axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1047 | cen.z - axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1048 | glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1049 | cen.y + axis[0].y * len[0] + axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1050 | cen.z + axis[0].z * len[0] + axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1051 | glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1052 | cen.y + axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1053 | cen.z + axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1054 | glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] - axis[2].x * len[2], |
---|
| 1055 | cen.y - axis[0].y * len[0] - axis[1].y * len[1] - axis[2].y * len[2], |
---|
| 1056 | cen.z - axis[0].z * len[0] - axis[1].z * len[1] - axis[2].z * len[2]); |
---|
| 1057 | glEnd(); |
---|
| 1058 | |
---|
| 1059 | glBegin(GL_QUADS); |
---|
| 1060 | glVertex3f(cen.x - axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1061 | cen.y - axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1062 | cen.z - axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 1063 | glVertex3f(cen.x + axis[0].x * len[0] + axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1064 | cen.y + axis[0].y * len[0] + axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1065 | cen.z + axis[0].z * len[0] + axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 1066 | glVertex3f(cen.x + axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1067 | cen.y + axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1068 | cen.z + axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 1069 | glVertex3f(cen.x - axis[0].x * len[0] - axis[1].x * len[1] + axis[2].x * len[2], |
---|
| 1070 | cen.y - axis[0].y * len[0] - axis[1].y * len[1] + axis[2].y * len[2], |
---|
| 1071 | cen.z - axis[0].z * len[0] - axis[1].z * len[1] + axis[2].z * len[2]); |
---|
| 1072 | glEnd(); |
---|
| 1073 | } |
---|
| 1074 | |
---|
| 1075 | |
---|
| 1076 | if( drawMode & DRAW_BV_BLENDED) |
---|
[5481] | 1077 | glColor3f(color.x, color.y, color.z); |
---|
[4635] | 1078 | } |
---|
[4636] | 1079 | |
---|
[4635] | 1080 | } |
---|
[4588] | 1081 | |
---|
[4674] | 1082 | /* DRAW SEPARATING PLANE */ |
---|
[4635] | 1083 | if( drawMode & DRAW_SEPARATING_PLANE || drawMode & DRAW_ALL) |
---|
[4632] | 1084 | { |
---|
[4636] | 1085 | if( !(drawMode & DRAW_SINGLE && depth != 0)) |
---|
[4635] | 1086 | { |
---|
[4671] | 1087 | if( drawMode & DRAW_BV_BLENDED) |
---|
[5481] | 1088 | glColor4f(color.x, color.y, color.z, .6); |
---|
[4671] | 1089 | |
---|
[4636] | 1090 | /* now draw the separation plane */ |
---|
[4660] | 1091 | Vector a1 = this->bvElement->axis[(this->longestAxisIndex + 1)%3]; |
---|
| 1092 | Vector a2 = this->bvElement->axis[(this->longestAxisIndex + 2)%3]; |
---|
[4636] | 1093 | Vector c = *this->bvElement->center; |
---|
| 1094 | float l1 = this->bvElement->halfLength[(this->longestAxisIndex + 1)%3]; |
---|
| 1095 | float l2 = this->bvElement->halfLength[(this->longestAxisIndex + 2)%3]; |
---|
| 1096 | glBegin(GL_QUADS); |
---|
| 1097 | 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); |
---|
| 1098 | 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); |
---|
| 1099 | 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); |
---|
| 1100 | 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); |
---|
| 1101 | glEnd(); |
---|
[4671] | 1102 | |
---|
| 1103 | if( drawMode & DRAW_BV_BLENDED) |
---|
[5481] | 1104 | glColor4f(color.x, color.y, color.z, 1.0); |
---|
[4671] | 1105 | |
---|
[4635] | 1106 | } |
---|
[4632] | 1107 | } |
---|
[4588] | 1108 | |
---|
[4702] | 1109 | |
---|
| 1110 | |
---|
[5481] | 1111 | if (depth > 0) |
---|
| 1112 | { |
---|
| 1113 | if( this->nodeLeft != NULL) |
---|
[5494] | 1114 | this->nodeLeft->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(15.0,0.0,0.0)), false); |
---|
[5481] | 1115 | if( this->nodeRight != NULL) |
---|
[5494] | 1116 | this->nodeRight->drawBV(depth - 1, drawMode, Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(30.0,0.0,0.0)), false); |
---|
[5481] | 1117 | } |
---|
| 1118 | this->bvElement->bCollided = false; |
---|
[4588] | 1119 | |
---|
[5481] | 1120 | if (top) |
---|
| 1121 | glPopAttrib(); |
---|
[4557] | 1122 | } |
---|
[4542] | 1123 | |
---|
| 1124 | |
---|
[4568] | 1125 | |
---|
[4746] | 1126 | void OBBTreeNode::debug() const |
---|
[4568] | 1127 | { |
---|
| 1128 | |
---|
| 1129 | /* |
---|
| 1130 | for(int i = 0; i < length; i++) |
---|
[4617] | 1131 | { |
---|
[4638] | 1132 | PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); |
---|
[4617] | 1133 | } |
---|
[4568] | 1134 | */ |
---|
| 1135 | } |
---|