Changeset 5712 in orxonox.OLD
- Timestamp:
- Nov 22, 2005, 5:49:30 PM (19 years ago)
- Location:
- branches/collision_detection/src/lib/collision_detection
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc
r5711 r5712 125 125 126 126 /* create the boxes in three steps */ 127 this->calculateBoxCovariance( this->bvElement, modelInf, triangleIndexes, length);128 this->calculateBoxEigenvectors( this->bvElement, modelInf, triangleIndexes, length);129 this->calculateBoxAxis( this->bvElement, modelInf, triangleIndexes, length);127 this->calculateBoxCovariance(*this->bvElement, modelInf, triangleIndexes, length); 128 this->calculateBoxEigenvectors(*this->bvElement, modelInf, triangleIndexes, length); 129 this->calculateBoxAxis(*this->bvElement, modelInf, triangleIndexes, length); 130 130 131 131 /* do we need to descent further in the obb tree?*/ 132 132 if( likely( this->depth > 0)) 133 133 { 134 this->forkBox( this->bvElement);134 this->forkBox(*this->bvElement); 135 135 136 136 … … 218 218 219 219 220 void OBBTreeNode::calculateBoxCovariance(OBB *box, const modelInfo& modelInf,220 void OBBTreeNode::calculateBoxCovariance(OBB& box, const modelInfo& modelInf, 221 221 const int* triangleIndexes, unsigned int length) 222 222 { … … 284 284 PRINTF(3)("\nVertex Data:\n"); 285 285 for(int i = 0; i < length; i++) 286 PRINTF(3)(" Vertex[%i]: %f, %f, %f\n", i, box ->vertices[i][0], box->vertices[i][1], box->vertices[i][2]);286 PRINTF(3)(" Vertex[%i]: %f, %f, %f\n", i, box.vertices[i][0], box.vertices[i][1], box.vertices[i][2]); 287 287 PRINTF(3)("\nOBB Covariance Matrix:\n"); 288 288 for(int j = 0; j < 3; ++j) { PRINT(3)(" |"); for(int k = 0; k < 3; ++k) { PRINT(3)(" \b%f ", covariance[j][k]); } PRINT(3)(" |\n"); } … … 292 292 for(int i = 0; i < 3; ++i) 293 293 { 294 box ->covarianceMatrix[i][0] = covariance[i][0];295 box ->covarianceMatrix[i][1] = covariance[i][1];296 box ->covarianceMatrix[i][2] = covariance[i][2];297 } 298 box ->center = center;294 box.covarianceMatrix[i][0] = covariance[i][0]; 295 box.covarianceMatrix[i][1] = covariance[i][1]; 296 box.covarianceMatrix[i][2] = covariance[i][2]; 297 } 298 box.center = center; 299 299 300 300 PRINTF(3)("-- Written Result to OBB\n"); … … 302 302 303 303 304 void OBBTreeNode::calculateBoxEigenvectors(OBB *box, const modelInfo& modInfo,304 void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const modelInfo& modInfo, 305 305 const int* triangleIndexes, unsigned int length) 306 306 {} 307 307 308 void OBBTreeNode::calculateBoxEigenvectors(OBB *box, const sVec3D* verticesList, unsigned int length)308 void OBBTreeNode::calculateBoxEigenvectors(OBB& box, const sVec3D* verticesList, unsigned int length) 309 309 { 310 310 PRINTF(3)("Calculated attributes1\n"); … … 317 317 Vector axis[3]; //!< the references to the obb axis 318 318 319 Matrix covMat( box ->covarianceMatrix );319 Matrix covMat( box.covarianceMatrix ); 320 320 covMat.getEigenVectors(axis[0], axis[1], axis[2] ); 321 321 … … 343 343 axis[1].normalize(); 344 344 axis[2].normalize();*/ 345 box ->axis[0] = axis[0];346 box ->axis[1] = axis[1];347 box ->axis[2] = axis[2];345 box.axis[0] = axis[0]; 346 box.axis[1] = axis[1]; 347 box.axis[2] = axis[2]; 348 348 349 349 // PRINTF(0)("-- Got Axis\n"); 350 350 // 351 // PRINTF(0)("eigenvector: %f, %f, %f\n", box ->axis[0].x, box->axis[0].y, box->axis[0].z);352 // PRINTF(0)("eigenvector: %f, %f, %f\n", box ->axis[1].x, box->axis[1].y, box->axis[1].z);353 // PRINTF(0)("eigenvector: %f, %f, %f\n", box ->axis[2].x, box->axis[2].y, box->axis[2].z);354 } 355 356 357 void OBBTreeNode::calculateBoxAxis(OBB *box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length)351 // PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z); 352 // PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z); 353 // PRINTF(0)("eigenvector: %f, %f, %f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z); 354 } 355 356 357 void OBBTreeNode::calculateBoxAxis(OBB& box, const modelInfo& modInfo, const int* triangleIndexes, unsigned int length) 358 358 { 359 359 this->calculateBoxAxis(box, (const sVec3D*)modInfo.pVertices, modInfo.numVertices); … … 362 362 363 363 364 void OBBTreeNode::calculateBoxAxis(OBB *box, const sVec3D* verticesList, unsigned int length)364 void OBBTreeNode::calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length) 365 365 { 366 366 PRINTF(3)("Calculated attributes3\n"); … … 369 369 float halfLength[3]; //!< half length of the axis 370 370 float tmpLength; //!< tmp save point for the length 371 Plane p0(box ->axis[0], box->center); //!< the axis planes372 Plane p1(box ->axis[1], box->center);373 Plane p2(box ->axis[2], box->center);371 Plane p0(box.axis[0], box.center); //!< the axis planes 372 Plane p1(box.axis[1], box.center); 373 Plane p2(box.axis[2], box.center); 374 374 float maxLength[3]; 375 375 float minLength[3]; … … 446 446 centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f; // min length is negatie 447 447 newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative 448 box ->center += (box->axis[i] * centerOffset[i]); // update the new center vector448 box.center += (box.axis[i] * centerOffset[i]); // update the new center vector 449 449 halfLength[i] = newHalfLength[i]; 450 450 } … … 452 452 453 453 454 box ->halfLength[0] = halfLength[0];455 box ->halfLength[1] = halfLength[1];456 box ->halfLength[2] = halfLength[2];454 box.halfLength[0] = halfLength[0]; 455 box.halfLength[1] = halfLength[1]; 456 box.halfLength[2] = halfLength[2]; 457 457 PRINTF(3)("-- Written Axis to obb\n"); 458 458 PRINTF(3)("-- Finished Calculating Attributes\n"); … … 467 467 this will separate the box into to smaller boxes. the separation is done along the middle of the longest axis 468 468 */ 469 void OBBTreeNode::forkBox(OBB *box)469 void OBBTreeNode::forkBox(OBB& box) 470 470 { 471 471 /* get the longest axis of the box */ … … 475 475 for(int i = 0; i < 3; ++i) 476 476 { 477 if( aLength < box ->halfLength[i])478 { 479 aLength = box ->halfLength[i];477 if( aLength < box.halfLength[i]) 478 { 479 aLength = box.halfLength[i]; 480 480 axisIndex = i; 481 481 } … … 489 489 float tmpDist; //!< temporary distance 490 490 int vertexIndex; 491 Plane middlePlane(box ->axis[axisIndex], box->center); //!< the middle plane491 Plane middlePlane(box.axis[axisIndex], box.center); //!< the middle plane 492 492 493 493 vertexIndex = 0; 494 for(int i = 0; i < box ->numOfVertices; ++i)495 { 496 tmpDist = fabs(middlePlane.distancePoint(box ->vertices[i]));494 for(int i = 0; i < box.numOfVertices; ++i) 495 { 496 tmpDist = fabs(middlePlane.distancePoint(box.vertices[i])); 497 497 if( tmpDist < dist) 498 498 { … … 512 512 513 513 514 PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box ->numOfVertices);515 this->separationPlane = Plane(box ->axis[axisIndex], box->vertices[vertexIndex]); //!< separation plane516 this->sepPlaneCenter = &box ->vertices[vertexIndex];514 PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box.numOfVertices); 515 this->separationPlane = Plane(box.axis[axisIndex], box.vertices[vertexIndex]); //!< separation plane 516 this->sepPlaneCenter = &box.vertices[vertexIndex]; 517 517 this->longestAxisIndex = axisIndex; 518 518 519 for(int i = 0; i < box ->numOfVertices; ++i)519 for(int i = 0; i < box.numOfVertices; ++i) 520 520 { 521 521 if( i == vertexIndex) continue; 522 tmpDist = this->separationPlane.distancePoint(box ->vertices[i]);522 tmpDist = this->separationPlane.distancePoint(box.vertices[i]); 523 523 if( tmpDist > 0.0) 524 partition1.add(&box ->vertices[i]); /* positive numbers plus zero */524 partition1.add(&box.vertices[i]); /* positive numbers plus zero */ 525 525 else 526 partition2.add(&box ->vertices[i]); /* negatice numbers */527 } 528 partition1.add(&box ->vertices[vertexIndex]);529 partition2.add(&box ->vertices[vertexIndex]);526 partition2.add(&box.vertices[i]); /* negatice numbers */ 527 } 528 partition1.add(&box.vertices[vertexIndex]); 529 partition2.add(&box.vertices[vertexIndex]); 530 530 531 531 PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize()); -
branches/collision_detection/src/lib/collision_detection/obb_tree_node.h
r5705 r5712 31 31 /* this function returns the bounding volume of this tree node @return: returns the BV */ 32 32 virtual inline const BoundingVolume* getBV() const { return (BoundingVolume*)this->bvElement; } 33 34 33 34 35 35 virtual void spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length); 36 virtual void spawnBVTree(const int depth, const modelInfo& modelInf, 36 virtual void spawnBVTree(const int depth, const modelInfo& modelInf, 37 37 const int* triangleIndexes, unsigned int length); 38 38 … … 41 41 void debug() const; 42 42 43 43 44 44 private: 45 void calculateBoxEigenvectors(OBB *box, const sVec3D* verticesList, unsigned int length);46 void calculateBoxAxis(OBB *box, const sVec3D* verticesList, unsigned int length);45 void calculateBoxEigenvectors(OBB& box, const sVec3D* verticesList, unsigned int length); 46 void calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length); 47 47 48 void calculateBoxCovariance(OBB *box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);49 void calculateBoxEigenvectors(OBB *box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);50 void calculateBoxAxis(OBB *box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length);48 void calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); 49 void calculateBoxEigenvectors(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); 50 void calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); 51 51 52 void forkBox(OBB *box);52 void forkBox(OBB& box); 53 53 54 54 bool overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB); 55 55 56 56 57 57 protected: 58 58 OBB* bvElement; //!< the obb element … … 65 65 int depth; //!< the depth of the node in the tree 66 66 const OBBTree* obbTree; //!< reference to the obb tree 67 67 68 68 const sVec3D* vertices; //!< pointer to the vertices data 69 69 int numOfVertices; //!< number of vertices in vertices data … … 82 82 static float* eigvlMat; 83 83 static int* rotCount; 84 84 85 85 }; 86 86
Note: See TracChangeset
for help on using the changeset viewer.