Changeset 5882 in orxonox.OLD for branches/collision_detection/src/lib
- Timestamp:
- Dec 3, 2005, 1:31:23 AM (19 years ago)
- Location:
- branches/collision_detection/src/lib/collision_detection
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/collision_detection/src/lib/collision_detection/bounding_sphere.cc
r4836 r5882 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 17 18 18 #include "bounding_sphere.h" … … 24 24 * standard constructor 25 25 */ 26 BoundingSphere::BoundingSphere () 26 BoundingSphere::BoundingSphere () 27 27 { 28 this->setClassID(CL_BOUNDING_SPHERE, "BoundingSphere"); 28 this->setClassID(CL_BOUNDING_SPHERE, "BoundingSphere"); 29 29 } 30 30 … … 34 34 35 35 */ 36 BoundingSphere::~BoundingSphere () 36 BoundingSphere::~BoundingSphere () 37 37 { 38 38 // delete what has to be deleted here -
branches/collision_detection/src/lib/collision_detection/bounding_volume.cc
r5706 r5882 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 17 18 18 #include "bounding_volume.h" … … 27 27 { 28 28 this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume"); 29 this->vertices = NULL; 29 this->modelInf = NULL; 30 this->triangleIndexes = NULL; 31 this->triangleIndexesLength = 0; 30 32 } 31 33 -
branches/collision_detection/src/lib/collision_detection/bv_tree.cc
r5693 r5882 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 17 18 18 #include "bv_tree.h" … … 25 25 * standard constructor 26 26 */ 27 BVTree::BVTree () 27 BVTree::BVTree () 28 28 { 29 this->setClassID(CL_BV_TREE, "BVTree"); 29 this->setClassID(CL_BV_TREE, "BVTree"); 30 30 31 31 } … … 36 36 37 37 */ 38 BVTree::~BVTree () 38 BVTree::~BVTree () 39 39 { 40 40 // delete what has to be deleted here -
branches/collision_detection/src/lib/collision_detection/bv_tree.h
r5718 r5882 18 18 class WorldEntity; 19 19 20 //! draw mode for the bounding volume 20 21 typedef enum DrawMode 21 22 { … … 33 34 34 35 //! A class that represents a bounding volume tree 35 class BVTree : public BaseObject { 36 class BVTree : public BaseObject 37 { 36 38 37 public:38 BVTree();39 virtual ~BVTree();39 public: 40 BVTree(); 41 virtual ~BVTree(); 40 42 41 virtual void spawnBVTree(sVec3D *verticesList, const int length) = 0; 42 virtual void spawnBVTree(const modelInfo& modelInf) = 0; 43 virtual void flushTree() = 0; 43 virtual void spawnBVTree(const modelInfo& modelInf) = 0; 44 virtual void flushTree() = 0; 44 45 45 virtual void collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const = 0;46 virtual void collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const = 0; 46 47 47 /** @param depth: depth, @param drawMode: how to draw the Model */ 48 virtual void drawBV(int depth, int drawMode) const = 0; 49 50 51 protected: 52 int numberOfVertices; 53 54 private: 55 56 48 virtual void drawBV(int depth, int drawMode) const = 0; 57 49 }; 58 50 -
branches/collision_detection/src/lib/collision_detection/bv_tree_node.cc
r4836 r5882 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 17 18 18 #include "bv_tree_node.h" -
branches/collision_detection/src/lib/collision_detection/bv_tree_node.h
r5718 r5882 8 8 #define _BV_TREE_NODE_H 9 9 10 10 11 #include "base_object.h" 11 12 #include "abstract_model.h" 12 13 #include "vector.h" 13 14 14 // FORWARD DECLARATION 15 16 // forward declarations 15 17 class BoundingVolume; 16 18 class BVTree; … … 29 31 30 32 virtual const BoundingVolume* getBV() const = 0; 33 /** returns the index of this bounding volume tree node @returns index of this index */ 31 34 inline const int getIndex() const { return this->treeIndex; } 32 35 33 virtual void spawnBVTree(const sVec3D *verticesList, unsigned int length ) = 0;34 36 virtual void spawnBVTree(const modelInfo& modInfo, const int* triangleIndexes, unsigned int length) = 0; 35 36 37 virtual void collideWith(const BVTreeNode& treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const = 0; 37 38 38 virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const = 0; 39 39 -
branches/collision_detection/src/lib/collision_detection/cd_engine.cc
r5718 r5882 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 17 18 18 #include "cd_engine.h" … … 168 168 void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices) 169 169 { 170 if ( this->rootTree == NULL)171 this->rootTree = new OBBTree(depth, vertices, numVertices);170 // if ( this->rootTree == NULL) 171 // this->rootTree = new OBBTree(depth, vertices, numVertices); 172 172 } 173 173 -
branches/collision_detection/src/lib/collision_detection/collision.cc
r4836 r5882 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 17 18 18 #include "collision.h" … … 24 24 * standard constructor 25 25 */ 26 Collision::Collision () 26 Collision::Collision () 27 27 { 28 this->setClassID(CL_COLLISION, "Collision"); 28 this->setClassID(CL_COLLISION, "Collision"); 29 29 30 30 } … … 35 35 36 36 */ 37 Collision::~Collision () 37 Collision::~Collision () 38 38 { 39 39 // delete what has to be deleted here -
branches/collision_detection/src/lib/collision_detection/obb.cc
r5699 r5882 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_DETECTION 17 17 18 18 #include "obb.h" -
branches/collision_detection/src/lib/collision_detection/obb_tree.cc
r5718 r5882 31 31 * standard constructor 32 32 */ 33 OBBTree::OBBTree(int depth, sVec3D *verticesList, const int length)34 : BVTree()35 {36 this->depth = depth;37 this->init();38 this->spawnBVTree(verticesList, length);39 }40 41 42 33 OBBTree::OBBTree(int depth, const modelInfo& modelInf) 43 34 : BVTree() … … 66 57 } 67 58 68 69 void OBBTree::spawnBVTree(sVec3D *verticesList, const int length)70 {71 if( unlikely(this->rootNode != NULL))72 {73 PRINTF(2)("The BVTree has already been spawned, flushing and respawning again...\n");74 this->flushTree();75 }76 OBBTreeNode* node = new OBBTreeNode(*this, depth);77 this->rootNode = node;78 this->rootNode->spawnBVTree(verticesList, length);79 }80 59 81 60 … … 150 129 } 151 130 152 this->spawnBVTree(vertList, length);131 // this->spawnBVTree(vertList, length); 153 132 154 133 PRINT(0)("= Spawning Tree: Finished\n"); -
branches/collision_detection/src/lib/collision_detection/obb_tree.h
r5718 r5882 17 17 18 18 //! A class for representing an obb tree 19 class OBBTree : public BVTree { 19 class OBBTree : public BVTree 20 { 20 21 21 22 public: 22 OBBTree(int depth, sVec3D *verticesList, const int length);23 23 OBBTree(int depth, const modelInfo& modInfo); 24 24 virtual ~OBBTree(); 25 25 void init(); 26 26 27 virtual void spawnBVTree(sVec3D *verticesList, const int length);28 27 virtual void spawnBVTree(const modelInfo& modelInf); 29 28 virtual void flushTree(); 30 29 31 30 virtual void collideWith(const WorldEntity& entity1, const WorldEntity& entity2) const; 32 33 31 virtual void drawBV(int depth, int drawMode) const; 34 32 33 /** returns the next if for the obb tree node @return integer id number of the next node */ 35 34 const int getID() { return ++this->id;} 35 /** returns the root node of the bounding volume tree @return reference to the root node */ 36 36 inline const OBBTreeNode* getRootNode() const { return this->rootNode; } 37 37 -
branches/collision_detection/src/lib/collision_detection/obb_tree_node.cc
r5870 r5882 17 17 18 18 #include "obb_tree_node.h" 19 #include "list.h" 20 #include <list> 19 #include "obb_tree.h" 21 20 #include "obb.h" 22 #include "obb_tree.h" 21 23 22 #include "matrix.h" 24 23 #include "abstract_model.h" … … 26 25 27 26 #include "color.h" 28 27 #include "glincl.h" 28 29 #include <list> 29 30 #include "debug.h" 30 #include "glincl.h"31 31 32 32 … … 34 34 using namespace std; 35 35 36 float** OBBTreeNode::coMat = NULL; 37 float** OBBTreeNode::eigvMat = NULL; 38 float* OBBTreeNode::eigvlMat = NULL; 39 int* OBBTreeNode::rotCount = NULL; 36 40 37 GLUquadricObj* OBBTreeNode_sphereObj = NULL; 38 41 39 42 40 /** 43 41 * standard constructor 42 * @param tree: reference to the obb tree 43 * @param depth: the depth of the obb tree to generate 44 44 */ 45 45 OBBTreeNode::OBBTreeNode (const OBBTree& tree, unsigned int depth) … … 55 55 this->bvElement = NULL; 56 56 57 this->tmpVert1 = NULL; 58 this->tmpVert2 = NULL; 59 60 if( OBBTreeNode::coMat == NULL) 61 { 62 OBBTreeNode::coMat = new float*[4]; 63 for(int i = 0; i < 4; i++) 64 OBBTreeNode::coMat[i] = new float[4]; 65 } 66 if( OBBTreeNode::eigvMat == NULL) 67 { 68 OBBTreeNode::eigvMat = new float*[4]; 69 for( int i = 0; i < 4; i++) 70 OBBTreeNode::eigvMat[i] = new float[4]; 71 } 72 if( OBBTreeNode::eigvlMat == NULL) 73 { 74 OBBTreeNode::eigvlMat = new float[4]; 75 } 76 if( OBBTreeNode::rotCount == NULL) 77 OBBTreeNode::rotCount = new int; 57 this->triangleIndexList1 = NULL; 58 this->triangleIndexList2 = NULL; 59 60 this->modelInf = NULL; 61 this->triangleIndexes = NULL; 78 62 79 63 if( OBBTreeNode_sphereObj == NULL) … … 88 72 { 89 73 if( this->nodeLeft) 90 {91 74 delete this->nodeLeft; 92 this->nodeLeft = NULL;93 }94 75 if( this->nodeRight) 95 {96 76 delete this->nodeRight; 97 this->nodeRight = NULL; 98 } 77 99 78 if( this->bvElement) 100 79 delete this->bvElement; 101 this->bvElement = NULL; 102 103 if (this->tmpVert1 != NULL) 104 delete this->tmpVert1; 105 if (this->tmpVert2 != NULL) 106 delete this->tmpVert2; 80 81 if( this->triangleIndexList1 != NULL) 82 delete [] this->triangleIndexList1; 83 if( this->triangleIndexList2 != NULL) 84 delete [] this->triangleIndexList2; 107 85 } 108 86 … … 118 96 void OBBTreeNode::spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, unsigned int length) 119 97 { 120 sVec3D* verticesList; 121 122 PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length); 123 printf("OBBTreeNode::spawnBVTree()\n"); 98 PRINTF(3)("\n==============================Creating OBB Tree Node==================\n"); 99 PRINT(3)(" OBB Tree Infos: \n"); 100 PRINT(3)("\tDepth: %i \n\tTree Index: %i \n\tNumber of Vertices: %i\n", depth, treeIndex, length); 124 101 this->depth = depth; 125 102 … … 137 114 if( likely( this->depth > 0)) 138 115 { 139 //this->forkBox(*this->bvElement); 140 141 142 // if(this->tmpLen1 > 2) 143 // { 144 // OBBTreeNode* node1 = new OBBTreeNode(); 145 // this->nodeLeft = node1; 146 // this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); 147 // } 148 // else 149 // { 150 // PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n"); 151 // } 152 // 153 // if( this->tmpLen2 > 2) 154 // { 155 // OBBTreeNode* node2 = new OBBTreeNode(); 156 // this->nodeRight = node2; 157 // this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); 158 // } 159 // else 160 // { 161 // PRINTF(3)("Abording tree walk: less than 3 vertices left\n"); 162 // } 163 164 } 165 } 116 this->forkBox(*this->bvElement); 117 118 if( this->triangleIndexLength1 >= 3) 119 { 120 this->nodeLeft = new OBBTreeNode(*this->obbTree, depth - 1); 121 this->nodeLeft->spawnBVTree(modelInf, this->triangleIndexList1, this->triangleIndexLength1); 122 } 123 if( this->triangleIndexLength2 >= 3) 124 { 125 this->nodeRight = new OBBTreeNode(*this->obbTree, depth - 1); 126 this->nodeRight->spawnBVTree(modelInf, this->triangleIndexList2, this->triangleIndexLength2); 127 } 128 } 129 } 130 166 131 167 132 168 133 /** 169 * c reates a new BVTree or BVTree partition170 * @param depth: how much more depth-steps to go: if == 1 don't go any deeper!171 * @param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle172 * 173 * this function creates an Bounding Volume tree from a vertices soup (no triangle data)134 * calculate the box covariance matrix 135 * @param box: reference to the box 136 * @param modelInf: the model info structure of the model 137 * @param tirangleIndexes: an array with the indexes of the triangles inside this 138 * @param length: the length of the indexes array 174 139 */ 175 void OBBTreeNode::spawnBVTree(const sVec3D *verticesList, unsigned int length)176 {177 // PRINTF(3)("\n");178 // PRINTF(3)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length);179 // this->depth = depth;180 //181 //182 // this->bvElement = new OBB();183 // this->bvElement->vertices = verticesList;184 // this->bvElement->numOfVertices = length;185 // PRINTF(3)("Created OBBox\n");186 // this->calculateBoxCovariance(this->bvElement, verticesList, length);187 // PRINTF(3)("Calculated attributes1\n");188 // this->calculateBoxEigenvectors(this->bvElement, verticesList, length);189 // PRINTF(3)("Calculated attributes2\n");190 // this->calculateBoxAxis(this->bvElement, verticesList, length);191 // PRINTF(3)("Calculated attributes3\n");192 //193 //194 //195 // if( likely( this->depth > 0))196 // {197 // this->forkBox(this->bvElement);198 //199 //200 // if(this->tmpLen1 > 2)201 // {202 // OBBTreeNode* node1 = new OBBTreeNode(this->obbTree);203 // this->nodeLeft = node1;204 // this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);205 // }206 // else207 // {208 // PRINTF(3)("Aboarding tree walk: less than 3 vertices left\n");209 // }210 //211 // if( this->tmpLen2 > 2)212 // {213 // OBBTreeNode* node2 = new OBBTreeNode(this->obbTree);214 // this->nodeRight = node2;215 // this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);216 // }217 // else218 // {219 // PRINTF(3)("Abording tree walk: less than 3 vertices left\n");220 // }221 // }222 }223 224 225 140 void OBBTreeNode::calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length) 226 141 { 227 228 PRINTF(3)("Created OBBox\n");229 230 142 float facelet[length]; //!< surface area of the i'th triangle of the convex hull 231 143 float face = 0.0f; //!< surface area of the entire convex hull … … 288 200 for(int j = 0; j < 3; ++j) 289 201 { 290 PRINT F(3)(" |");202 PRINT(3)("\t\t"); 291 203 for(int k = 0; k < 3; ++k) 292 204 { 293 PRINT F(3)(" \b%f", covariance[j][k]);294 } 295 PRINT F(3)(" |\n");296 } 297 PRINTF(3)(" OBB Center: %f, %f, %f\n", center.x, center.y, center.z);205 PRINT(3)("%11.2f\t", covariance[j][k]); 206 } 207 PRINT(3)("\n"); 208 } 209 PRINTF(3)("\nOBB Center:\n\t\t%11.2f\t %11.2f\t %11.2f\n", center.x, center.y, center.z); 298 210 299 211 /* write back the covariance matrix data to the object oriented bouning box */ … … 320 232 { 321 233 322 PRINTF(3)("Calculate the Box Eigenvectors\n");323 324 234 Vector axis[3]; //!< the references to the obb axis 325 235 Matrix covMat( box.covarianceMatrix ); //!< covariance matrix (in the matrix dataform) … … 339 249 box.axis[2] = axis[2]; 340 250 341 PRINTF( 0)("-- Got Axis\n");342 PRINT F(0)("Eigenvector: %f, %f, %f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z);343 PRINT F(0)("Eigenvector: %f, %f, %f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z);344 PRINT F(0)("Eigenvector: %f, %f, %f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z);251 PRINTF(3)("Eigenvectors:\n"); 252 PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[0].x, box.axis[0].y, box.axis[0].z); 253 PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[1].x, box.axis[1].y, box.axis[1].z); 254 PRINT(3)("\t\t%11.2f \t%11.2f \t%11.2f\n", box.axis[2].x, box.axis[2].y, box.axis[2].z); 345 255 } 346 256 … … 361 271 362 272 363 PRINTF(3)("Calculate d attributes3\n");273 PRINTF(3)("Calculate Box Axis\n"); 364 274 /* now get the axis length */ 365 275 Line ax[3]; //!< the axis 366 276 float halfLength[3]; //!< half length of the axis 367 277 float tmpLength; //!< tmp save point for the length 368 Plane p0(box.axis[0], box.center); //!< the axis planes369 Plane p1(box.axis[1], box.center); 370 Plane p2(box.axis[2], box.center); 371 float maxLength[3]; 372 float minLength[3]; 373 const sVec3D* tmpVec; 278 Plane p0(box.axis[0], box.center); //!< the axis planes 279 Plane p1(box.axis[1], box.center); //!< the axis planes 280 Plane p2(box.axis[2], box.center); //!< the axis planes 281 float maxLength[3]; //!< maximal lenth of the axis 282 float minLength[3]; //!< minimal length of the axis 283 const sVec3D* tmpVec; //!< variable taking tmp vectors 374 284 375 285 /* … … 476 386 for(int i = 0; i < 3; ++i) 477 387 { 478 PRINTF(3)("max: %f, min: %f \n", maxLength[i], minLength[i]);479 388 centerOffset[i] = (maxLength[i] + minLength[i]) / 2.0f; // min length is negatie 480 389 newHalfLength[i] = (maxLength[i] - minLength[i]) / 2.0f; // min length is negative 481 box.center += (box.axis[i] * centerOffset[i]); // update the new center vector390 box.center += (box.axis[i] * centerOffset[i]); // update the new center vector 482 391 halfLength[i] = newHalfLength[i]; 483 392 } 484 393 PRINTF(3)("\n"); 394 PRINT(3)("\tmax: %11.2f, \tmin: %11.2f\n", maxLength[0], minLength[0]); 395 PRINT(3)("\tmax: %11.2f, \tmin: %11.2f\n", maxLength[1], minLength[1]); 396 PRINT(3)("\tmax: %11.2f, \tmin: %11.2f\n", maxLength[2], minLength[2]); 485 397 486 398 … … 488 400 box.halfLength[1] = halfLength[1]; 489 401 box.halfLength[2] = halfLength[2]; 490 PRINTF(3)("-- Written Axis to obb\n");491 PRINTF(3)("-- Finished Calculating Attributes\n");492 402 } 493 403 … … 503 413 { 504 414 415 PRINTF(3)("Fork Box\n"); 416 PRINTF(4)("Calculating the longest Axis\n"); 505 417 /* get the longest axis of the box */ 506 float aLength = -1.0f; //!< the length of the longest axis 507 int axisIndex = 0; //!< this is the nr of the longest axis 508 509 for(int i = 0; i < 3; ++i) 510 { 511 if( aLength < box.halfLength[i]) 512 { 513 aLength = box.halfLength[i]; 514 axisIndex = i; 515 } 516 } 517 518 PRINTF(3)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength); 519 520 418 float longestAxis = -1.0f; //!< the length of the longest axis 419 int longestAxisIndex = 0; //!< this is the nr of the longest axis 420 421 422 /* now get the longest axis of the three exiting */ 423 for( int i = 0; i < 3; ++i) 424 { 425 if( longestAxis < box.halfLength[i]) 426 { 427 longestAxis = box.halfLength[i]; 428 longestAxisIndex = i; 429 } 430 } 431 PRINTF(3)("\nLongest Axis is: Nr %i with a half-length of:%11.2f\n", longestAxisIndex, longestAxis); 432 433 434 PRINTF(4)("Separating along the longest axis\n"); 521 435 /* get the closest vertex near the center */ 522 436 float dist = 999999.0f; //!< the smallest distance to each vertex 523 float tmpDist; //!< temporary distance 524 int vertexIndex; 525 Plane middlePlane(box.axis[axisIndex], box.center); //!< the middle plane 526 527 vertexIndex = 0; 528 for(int i = 0; i < box.numOfVertices; ++i) 529 { 530 tmpDist = fabs(middlePlane.distancePoint(box.vertices[i])); 531 if( tmpDist < dist) 532 { 533 dist = tmpDist; 534 vertexIndex = i; 535 } 536 } 537 538 PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist); 437 float tmpDist; //!< variable to save diverse distances temporarily 438 int vertexIndex; //!< index of the vertex near the center 439 Plane middlePlane(box.axis[longestAxisIndex], box.center); //!< the middle plane 440 const sVec3D* tmpVec; //!< temp simple 3D vector 539 441 540 442 … … 542 444 the points depending on which side they are located 543 445 */ 544 std::list<const sVec3D*> partition1; //!< the vertex partition 1 545 std::list<const sVec3D*> partition2; //!< the vertex partition 2 546 547 548 //nameList.push_back("Pumba"); 549 //nameList.push_back("Mogli"); 550 //nameList.push_back("Timon"); 551 552 // std::list<char*>::iterator element; 553 // for (element = nameList.begin(); element != nameList.end(); element++) 554 // { 555 // PRINTF(3)("found name: %s in list\n", (*name)); 556 // } 557 558 559 560 PRINTF(3)("vertex index: %i, of %i\n", vertexIndex, box.numOfVertices); 561 this->separationPlane = Plane(box.axis[axisIndex], box.vertices[vertexIndex]); //!< separation plane 562 this->sepPlaneCenter = &box.vertices[vertexIndex]; 563 this->longestAxisIndex = axisIndex; 564 565 for(int i = 0; i < box.numOfVertices; ++i) 566 { 567 if( i == vertexIndex) 568 continue; 569 tmpDist = this->separationPlane.distancePoint(box.vertices[i]); 570 if( tmpDist > 0.0) 571 partition1.push_back(&box.vertices[i]); /* positive numbers plus zero */ 446 std::list<int> partition1; //!< the vertex partition 1 447 std::list<int> partition2; //!< the vertex partition 2 448 float* triangleCenter; //!< the center of the triangle 449 const float* a; //!< triangle edge a 450 const float* b; //!< triangle edge b 451 const float* c; //!< triangle edge c 452 453 this->separationPlane = Plane(box.axis[longestAxisIndex], box.center); 454 this->sepPlaneCenter[0] = box.center.x; 455 this->sepPlaneCenter[1] = box.center.y; 456 this->sepPlaneCenter[2] = box.center.z; 457 this->longestAxisIndex = longestAxisIndex; 458 459 for( int i = 0; i < box.triangleIndexesLength; ++i) 460 { 461 /* first calculate the middle of the triangle */ 462 a = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[0]]; 463 b = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[1]]; 464 c = &box.modelInf->pVertices[box.modelInf->pTriangles[box.triangleIndexes[i]].indexToVertices[2]]; 465 466 triangleCenter[0] = (a[0] + b[0] + c[0])/3.0f; 467 triangleCenter[1] = (a[1] + b[1] + c[1])/3.0f; 468 triangleCenter[2] = (a[2] + b[2] + c[2])/3.0f; 469 470 tmpDist = this->separationPlane.distancePoint(*((sVec3D*)triangleCenter)); 471 if( tmpDist > 0.0f) 472 partition1.push_back(i); /* positive numbers plus zero */ 572 473 else 573 partition2.push_back(&box.vertices[i]); /* negatice numbers */ 574 } 575 partition1.push_back(&box.vertices[vertexIndex]); 576 partition2.push_back(&box.vertices[vertexIndex]); 577 578 PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.size(), partition2.size()); 474 partition2.push_back(i); /* negatice numbers */ 475 } 476 PRINTF(3)("\nPartition1: got \t%i Vertices \nPartition2: got \t%i Vertices\n", partition1.size(), partition2.size()); 579 477 580 478 581 479 /* now comes the separation into two different sVec3D arrays */ 582 tIterator<const sVec3D>* iterator; //!< the iterator to go through the lists583 480 int index; //!< index storage place 584 sVec3D* vertList1; //!< the vertex list 1 585 sVec3D* vertList2; //!< the vertex list 2 586 std::list<const sVec3D*>::iterator element; //!< the list iterator 587 588 vertList1 = new sVec3D[partition1.size()]; 589 vertList2 = new sVec3D[partition2.size()]; 590 591 592 for(element = partition1.begin(), index = 0; element != partition1.end(); element++, index++) 593 { 594 vertList1[index][0] = (*element)[0][0]; 595 vertList1[index][1] = (*element)[0][1]; 596 vertList1[index][2] = (*element)[0][2]; 597 ++index; 598 } 599 600 // PRINTF(0)("\npartition 1:\n"); 601 // for(int i = 0; i < partition1.getSize(); ++i) 602 // { 603 // 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]); 604 // } 605 606 607 608 for(element = partition2.begin(), index = 0; element != partition2.end(); element++, index++) 609 { 610 vertList2[index][0] = (*element)[0][0]; 611 vertList2[index][1] = (*element)[0][1]; 612 vertList2[index][2] = (*element)[0][2]; 613 } 614 615 if (this->tmpVert1 != NULL) 616 delete[] this->tmpVert1; 617 this->tmpVert1 = vertList1; 618 if (this->tmpVert2 != NULL) 619 delete[] this->tmpVert2; 620 this->tmpVert2 = vertList2; 621 this->tmpLen1 = partition1.size(); 622 this->tmpLen2 = partition2.size(); 623 624 625 // PRINTF(0)("\npartition 2:\n"); 626 // for(int i = 0; i < partition2.getSize(); ++i) 627 // { 628 // 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]); 629 // } 481 int* triangleIndexList1; //!< the vertex list 1 482 int* triangleIndexList2; //!< the vertex list 2 483 std::list<int>::iterator element; //!< the list iterator 484 485 triangleIndexList1 = new int[partition1.size()]; 486 triangleIndexList2 = new int[partition2.size()]; 487 488 for( element = partition1.begin(), index = 0; element != partition1.end(); element++, index++) 489 triangleIndexList1[index] = (*element); 490 491 for( element = partition2.begin(), index = 0; element != partition2.end(); element++, index++) 492 triangleIndexList2[index] = (*element); 493 494 if( this->triangleIndexList1!= NULL) 495 delete[] this->triangleIndexList1; 496 this->triangleIndexList1 = triangleIndexList1; 497 this->triangleIndexLength1 = partition1.size(); 498 499 if( this->triangleIndexList2 != NULL) 500 delete[] this->triangleIndexList2; 501 this->triangleIndexList2 = triangleIndexList2; 502 this->triangleIndexLength2 = partition2.size(); 630 503 } 631 504 … … 814 687 if( drawMode & DRAW_POINTS) 815 688 glBegin(GL_POINTS); 816 for( int i = 0; i < this->bvElement->numOfVertices; ++i)689 for( int i = 0; i < this->bvElement->modelInf->numVertices; i+=3) 817 690 { 818 691 if( drawMode & DRAW_POINTS) 819 glVertex3f(this->bvElement-> vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);692 glVertex3f(this->bvElement->modelInf->pVertices[i], this->bvElement->modelInf->pVertices[i+1], this->bvElement->modelInf->pVertices[i+2]); 820 693 else 821 694 { 822 695 glPushMatrix(); 823 gl Translatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]);696 glVertex3f(this->bvElement->modelInf->pVertices[i], this->bvElement->modelInf->pVertices[i+1], this->bvElement->modelInf->pVertices[i+2]); 824 697 gluSphere(OBBTreeNode_sphereObj, 0.1, 10, 10); 825 698 glPopMatrix(); -
branches/collision_detection/src/lib/collision_detection/obb_tree_node.h
r5825 r5882 11 11 12 12 13 14 // FORWARD DECLARATION 13 // forward declarations 15 14 class BoundingVolume; 16 15 class OBB; … … 18 17 class Plane; 19 18 class PNode; 20 //struct sVec3D; 19 21 20 22 21 //! A class that represents a bounding volume tree … … 29 28 virtual ~OBBTreeNode(); 30 29 31 /* this function returns the bounding volume of this tree node @return: returns the BV */ 32 virtual inline const BoundingVolume* getBV() const 33 { 34 return (BoundingVolume*)this->bvElement; 35 } 30 /** this function returns the bounding volume of this tree node @return: returns the BV */ 31 virtual inline const BoundingVolume* getBV() const { return (BoundingVolume*)this->bvElement; } 36 32 37 virtual void spawnBVTree(const sVec3D *verticesList, unsigned int length);38 33 virtual void spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); 39 34 … … 68 63 const int* triangleIndexes; //!< indexes to the used model triangles 69 64 70 const sVec3D* vertices; //!< pointer to the vertices data71 int numOfVertices; //!< number of vertices in vertices data72 65 Plane separationPlane; //!< the separation plane of the obb 73 const sVec3D*sepPlaneCenter; //!< only needed to draw plane66 sVec3D sepPlaneCenter; //!< only needed to draw plane 74 67 int longestAxisIndex; //!< only needed to draw plane 75 68 76 69 /* tmp saving place for obb variables */ 77 sVec3D* tmpVert1; //!< pointer to the vert data of obbox1 78 sVec3D* tmpVert2; //!< pointer to the vert data of obbox1 79 int tmpLen1; //!< len vert data obbox1 80 int tmpLen2; //!< len vert data obbox2 81 82 static float** coMat; 83 static float** eigvMat; 84 static float* eigvlMat; 85 static int* rotCount; 86 70 int* triangleIndexList1; //!< pointer to the vert data of obbox1 71 int* triangleIndexList2; //!< pointer to the vert data of obbox1 72 int triangleIndexLength1; //!< len vert data obbox1 73 int triangleIndexLength2; //!< len vert data obbox2 87 74 }; 88 75
Note: See TracChangeset
for help on using the changeset viewer.