Changeset 4638 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Jun 16, 2005, 1:42:14 AM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/collision_detection/obb_tree.cc
r4635 r4638 33 33 this->setClassID(CL_OBB_TREE, "OBBTree"); 34 34 35 material = new Material*[ 3];36 for(int i = 0; i < 3; ++i)35 material = new Material*[5]; 36 for(int i = 0; i < 5; ++i) 37 37 { 38 38 material[i] = new Material(); 39 material[i]->setIllum( 0);39 material[i]->setIllum(3); 40 40 } 41 41 material[0]->setAmbient(0.0, 0.3, 0.0); 42 material[1]->setAmbient(0. 0, 0.0, 0.2);42 material[1]->setAmbient(0.4, 0.0, 0.2); 43 43 material[2]->setAmbient(1.0, 0.0, 0.0); 44 material[3]->setAmbient(5.0, 3.0, 1.0); 45 material[4]->setAmbient(1.0, 0.0, 7.0); 46 47 this->id = 0; 44 48 } 45 49 … … 93 97 94 98 /* generate some test vertices */ 95 int const length = 6;99 int const length = 9; 96 100 sVec3D* vertList = new sVec3D[length]; 97 sVec3D data[length] = {{5.0, 0.0, 0.0},{2.0, 0.0, 5.0},{14.0, 0.0, 0.0}, {5.0, 0.0, 1.0}, {12.0, 0.0, 8.0}, {3.0, 5.0, 4.9}}; 101 sVec3D data[length] = {{0.0, 0.0, 0.0},{1.0, 2.0, 5.0},{0.0, 6.0, 9.0}, 102 {1.0, 4.0, 12.0}, {1.0, 2.0, 16.0}, {0.0, 0.0, 19.0}, 103 {0.0, 3.0, 23.0}, {1.0, 5.0, 30.0}, {0.0, 10.0, 35.0}}; 98 104 99 105 for(int i = 0; i < length; ++i) … … 104 110 } 105 111 106 this->spawnBVTree( 2, vertList, length);112 this->spawnBVTree(3, vertList, length); 107 113 108 114 PRINT(0)("= Spawning Tree: Finished\n"); -
orxonox/trunk/src/lib/collision_detection/obb_tree.h
r4635 r4638 29 29 virtual void drawBV(int depth, int drawMode) const; 30 30 31 Material* getMaterial(unsigned int depth) { return material[depth%3]; } 31 Material* getMaterial(unsigned int depth) { return material[depth%5]; } 32 int getID() { return ++this->id;} 33 32 34 33 35 void debug(); … … 40 42 OBBTreeNode* rootNode; //!< reference to the root node of the tree 41 43 Material** material; 42 44 int id; 43 45 }; 44 46 -
orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
r4636 r4638 30 30 #define WANT_FSTREAM 31 31 32 #include "stdincl.h" 32 33 33 34 #include "include.h" … … 77 78 if( rotCount == NULL) 78 79 rotCount = new int; 80 81 this->sphereObj = gluNewQuadric(); 79 82 } 80 83 … … 97 100 void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length) 98 101 { 99 printf("OBB Depth: %i, numVertices: %i\n", depth, length); 102 PRINT(0)("\n"); 103 this->treeIndex = this->obbTree->getID(); 104 PRINTF(0)("OBB Depth: %i, tree index: %i, numVertices: %i\n", depth, treeIndex, length); 100 105 this->depth = depth; 101 106 107 102 108 this->bvElement = new OBB(); 103 PRINTF(0)("Created OBBox\n"); 109 this->bvElement->vertices = verticesList; 110 this->bvElement->numOfVertices = length; 111 PRINTF(3)("Created OBBox\n"); 104 112 this->calculateBoxCovariance(this->bvElement, verticesList, length); 105 PRINTF( 0)("Calculated attributes1\n");113 PRINTF(3)("Calculated attributes1\n"); 106 114 this->calculateBoxEigenvectors(this->bvElement, verticesList, length); 107 PRINTF( 0)("Calculated attributes2\n");115 PRINTF(3)("Calculated attributes2\n"); 108 116 this->calculateBoxAxis(this->bvElement, verticesList, length); 109 PRINTF( 0)("Calculated attributes3\n");117 PRINTF(3)("Calculated attributes3\n"); 110 118 111 119 … … 114 122 this->forkBox(this->bvElement); 115 123 116 OBBTreeNode* node1 = new OBBTreeNode(); 117 OBBTreeNode* node2 = new OBBTreeNode(); 118 119 this->nodeLeft = node1; 120 this->nodeRight = node2; 121 122 this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); 123 this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); 124 125 if(this->tmpLen1 > 2) 126 { 127 OBBTreeNode* node1 = new OBBTreeNode(); 128 this->nodeLeft = node1; 129 this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1); 130 } 131 else 132 { 133 PRINTF(0)("Aboarding tree walk: less than 3 vertices left\n"); 134 } 135 136 if( this->tmpLen2 > 2) 137 { 138 OBBTreeNode* node2 = new OBBTreeNode(); 139 this->nodeRight = node2; 140 this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2); 141 } 142 else 143 { 144 PRINTF(0)("Aboarding tree walk: less than 3 vertices left\n"); 145 } 124 146 125 147 } … … 140 162 this->numOfVertices = length; 141 163 this->vertices = verticesList; 142 box->vertices = verticesList; 143 box->numOfVertices = length; 164 165 144 166 145 167 … … 165 187 /* take the average of the centroid sum */ 166 188 center /= face; 167 PRINTF( 0)("-- Calculated Center\n");189 PRINTF(3)("-- Calculated Center\n"); 168 190 169 191 … … 184 206 } 185 207 } 186 PRINTF(0)("-- Calculated Covariance\n"); 187 188 189 // printf("\nVertex Data:\n"); 190 // for(int i = 0; i < length; i++) 191 // { 192 // printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 193 // } 194 195 // printf("\nCovariance Matrix:\n"); 208 PRINTF(3)("-- Calculated Covariance\n"); 209 210 211 PRINTF(0)("\nVertex Data:\n"); 212 for(int i = 0; i < length; i++) 213 { 214 //PRINTF(0)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 215 PRINTF(0)("vertex %i: %f, %f, %f\n", i, box->vertices[i][0], box->vertices[i][1], box->vertices[i][2]); 216 } 217 218 // PRINTF(3)("\nCovariance Matrix:\n"); 196 219 // for(int j = 0; j < 3; ++j) 197 220 // { 198 // printf(" |");221 // PRINTF(3)(" |"); 199 222 // for(int k = 0; k < 3; ++k) 200 223 // { 201 // printf(" \b%f ", covariance[j][k]);224 // PRINTF(3)(" \b%f ", covariance[j][k]); 202 225 // } 203 // printf(" |\n");226 // PRINTF(3)(" |\n"); 204 227 // } 205 PRINTF( 0)("center: %f, %f, %f\n", center.x, center.y, center.z);228 PRINTF(3)("center: %f, %f, %f\n", center.x, center.y, center.z); 206 229 207 230 … … 213 236 // } 214 237 *box->center = center; 215 PRINTF( 0)("-- Written Result to obb\n");238 PRINTF(3)("-- Written Result to obb\n"); 216 239 } 217 240 … … 235 258 /* new jacobi tests */ 236 259 JacobI(coMat, 3, eigvlMat, eigvMat, rotCount); 237 PRINTF( 0)("-- Done Jacobi Decomposition\n");238 239 240 // printf("Jacobi\n");260 PRINTF(3)("-- Done Jacobi Decomposition\n"); 261 262 263 // PRINTF(3)("Jacobi\n"); 241 264 // for(int j = 1; j < 4; ++j) 242 265 // { 243 // printf(" |");266 // PRINTF(3)(" |"); 244 267 // for(int k = 1; k < 4; ++k) 245 268 // { 246 // printf(" \b%f ", eigvMat[j][k]);269 // PRINTF(3)(" \b%f ", eigvMat[j][k]); 247 270 // } 248 // printf(" |\n");271 // PRINTF(3)(" |\n"); 249 272 // } 250 273 … … 253 276 axis[2] = new Vector(eigvMat[1][3], eigvMat[2][3], eigvMat[3][3]); 254 277 box->axis = axis; 255 PRINTF( 0)("-- Got Axis\n");256 257 // printf("\neigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);258 // printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);259 // printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);278 PRINTF(3)("-- Got Axis\n"); 279 280 PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z); 281 PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z); 282 PRINTF(0)("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z); 260 283 } 261 284 … … 297 320 298 321 box->halfLength = halfLength; 299 PRINTF(0)("-- Written Axis to obb\n"); 300 PRINTF(0)("-- Finished Calculating Attributes\n"); 301 302 // printf("\nwe got length: \n"); 303 // for(int i = 0; i < 3; ++i) 304 // printf("length[%i] = %f\n", i, box->halfLength[i]); 322 PRINTF(3)("-- Written Axis to obb\n"); 323 PRINTF(3)("-- Finished Calculating Attributes\n"); 324 325 326 327 // PRINTF(3)("\nwe got length: \n"); 328 for(int i = 0; i < 3; ++i) 329 { 330 //if( box->halfLength[i] == 0.0) 331 PRINTF(0)("length[%i] = %f\n", i, box->halfLength[i]); 332 } 305 333 } 306 334 … … 328 356 } 329 357 330 // printf("\nlongest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength);358 PRINTF(0)("longest axis is: nr %i with a half-length of: %f\n", axisIndex, aLength); 331 359 332 360 … … 347 375 } 348 376 349 // printf("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist);377 // PRINTF(3)("\nthe clostest vertex is nr: %i, with a dist of: %f\n", vertexIndex ,dist); 350 378 351 379 … … 370 398 partition1.add(&box->vertices[vertexIndex]); 371 399 372 // printf("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize());400 // PRINTF(3)("\npartition1: got %i vertices/ partition 2: got %i vertices\n", partition1.getSize(), partition2.getSize()); 373 401 374 402 … … 395 423 } 396 424 397 // printf("\npartition 1:\n");425 // PRINTF(0)("\npartition 1:\n"); 398 426 // for(int i = 0; i < partition1.getSize(); ++i) 399 427 // { 400 // printf("v[%i][0] = %f\n", i, vertList1[i][0]); 401 // printf("v[%i][1] = %f\n", i, vertList1[i][1]); 402 // printf("v[%i][2] = %f\n", i, vertList1[i][2]); 428 // 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]); 403 429 // } 404 430 … … 420 446 this->tmpLen2 = partition2.getSize(); 421 447 422 //delete iterator; 423 // printf("\npartition 2:\n"); 448 delete iterator; 449 450 // PRINTF(0)("\npartition 2:\n"); 424 451 // for(int i = 0; i < partition2.getSize(); ++i) 425 452 // { 426 // printf("v[%i][0] = %f\n", i, vertList2[i][0]); 427 // printf("v[%i][1] = %f\n", i, vertList2[i][1]); 428 // printf("v[%i][2] = %f\n", i, vertList2[i][2]); 453 // 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]); 429 454 // } 430 455 } … … 441 466 void OBBTreeNode::drawBV(int depth, int drawMode) const 442 467 { 443 //OBBTree::material->select(); 444 445 this->obbTree->getMaterial(depth)->select(); 468 this->obbTree->getMaterial(treeIndex)->select(); 446 469 447 470 /* draw the model itself, there is some problem concerning this: the vertices are drawn multiple times */ 448 471 if( drawMode & DRAW_MODEL || drawMode & DRAW_ALL) 449 472 { 450 glBegin(GL_TRIANGLES); 451 glColor3f(1.0, 1.0, 1.0); 452 for(int i = 0; i < this->bvElement->numOfVertices; ++i) 453 { 454 glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); 455 //printf("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]); 456 } 457 glEnd(); 473 if( !(drawMode & DRAW_SINGLE && depth != 0)) 474 { 475 glBegin(GL_LINE_STRIP); 476 for(int i = 0; i < this->bvElement->numOfVertices; ++i) 477 { 478 glPushMatrix(); 479 glMatrixMode(GL_MODELVIEW); 480 //glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); 481 glTranslatef(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); 482 gluSphere(this->sphereObj, 1, 10, 10); 483 //PRINTF(0)("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]); 484 glPopMatrix(); 485 } 486 glEnd(); 487 } 458 488 } 459 489 … … 509 539 /* draw bounding box */ 510 540 glBegin(GL_LINE_LOOP); 511 glColor3f(0.3, 0.4, 0.7);512 541 glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2], 513 542 cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2], … … 606 635 for(int i = 0; i < length; i++) 607 636 { 608 printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]);637 PRINTF(3)("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 609 638 } 610 639 */ -
orxonox/trunk/src/lib/collision_detection/obb_tree_node.h
r4635 r4638 72 72 static float* eigvlMat; //!< temp eigenvalue vector save place 73 73 static int* rotCount; //!< temp rotations count save place: how many givens-rotations where needed to transform the matrix :) 74 75 GLUquadricObj* sphereObj; 74 76 }; 75 77 -
orxonox/trunk/src/subprojects/collision_detection/collision_detection.cc
r4636 r4638 37 37 { 38 38 CDEngine::getInstance(); 39 //CDEngine::getInstance()->debug();40 41 model = new MD2Model("models/tris.md2", "models/tris.pcx");42 model->tick(0.1f);39 CDEngine::getInstance()->debug(); 40 41 //model = new MD2Model("models/tris.md2", "models/tris.pcx"); 42 //model->tick(0.1f); 43 43 44 44 // int const length = 6; … … 53 53 // } 54 54 55 CDEngine::getInstance()->debugSpawnTree(7, model->data->pVertices, model->data->numVertices);55 //CDEngine::getInstance()->debugSpawnTree(3, model->data->pVertices, model->data->numVertices); 56 56 57 57 … … 59 59 lightMan->setAmbientColor(.1,.1,.1); 60 60 lightMan->addLight(); 61 lightMan->setPosition(30, 30, 30); 61 62 lightMan->addLight(); 62 lightMan->setPosition( 10, 20, 100);63 lightMan->setPosition(-30, -30, -30); 63 64 64 65 drawMode = DRAW_MODEL; … … 71 72 printf(" -| Displaying Separation Plane\t s\n"); 72 73 printf("\n"); 74 printf(" -| Tree Depth 0\t\t 0\n"); 73 75 printf(" -| Tree Depth 1\t\t 1\n"); 74 76 printf(" -| Tree Depth 2\t\t 2\n"); … … 90 92 drawMode |= DRAW_ALL; 91 93 break; 94 case SDLK_0: 95 { 96 printf("Setting tree depth = 0\n"); 97 depth = 0; 98 int temp = drawMode & DRAW_ALL; 99 drawMode ^= temp; 100 drawMode |= DRAW_SINGLE; 101 break; 102 } 92 103 case SDLK_1: 93 104 {
Note: See TracChangeset
for help on using the changeset viewer.