Changeset 4617 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Jun 13, 2005, 9:32:26 AM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
r4616 r4617 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 13 co-programmer: ... … … 44 44 /** 45 45 \brief standard constructor 46 */46 */ 47 47 OBBTreeNode::OBBTreeNode () 48 48 { 49 49 this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); 50 50 51 51 } … … 54 54 /** 55 55 \brief standard deconstructor 56 57 */ 56 */ 58 57 OBBTreeNode::~OBBTreeNode () 59 58 { … … 67 66 \param depth: how much more depth-steps to go: if == 1 don't go any deeper! 68 67 \param verticesList: the list of vertices of the object - each vertices triple is interpreted as a triangle 69 */68 */ 70 69 void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length) 71 70 { 72 71 this->depth = depth; 73 72 73 this->bvElement = this->createBox(); 74 this->calculateBoxAttributes(this->bvElement, verticesList, length); 75 74 76 if( likely( this->depth > 0)) 75 77 { 76 this->bvElement = this->createBox();77 this->calculateBoxAttributes(this->bvElement, verticesList, length);78 78 this->forkBox(this->bvElement); 79 79 } … … 105 105 /* fist compute all the convex hull face/facelets and centroids */ 106 106 for(int i = 0; i < length; i+=3) /* FIX-ME-QUICK: hops of 3, array indiscontinuity*/ 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 107 { 108 p = verticesList[i]; 109 q = verticesList[i +1]; 110 r = verticesList[i + 2]; 111 112 t1 = p - q; t2 = p - r; 113 114 /* finding the facelet surface via cross-product */ 115 facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); 116 /* update the entire convex hull surface */ 117 face += facelet[i]; 118 119 /* calculate the cetroid of the hull triangles */ 120 centroid[i] = (p + q + r) * 1/3; 121 /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ 122 center += centroid[i] * facelet[i]; 123 } 124 124 /* take the average of the centroid sum */ 125 125 center /= face; … … 129 129 /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */ 130 130 for(int j = 0; j < 3; ++j) 131 { 132 for(int k = 0; k < 3; ++k) 131 133 { 132 for(int k = 0; k < 3; ++k) 133 { 134 for(int i = 0; i < length; i+=3) 135 { 136 p = verticesList[i]; 137 q = verticesList[i +1]; 138 r = verticesList[i + 2]; 139 140 covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] + 141 q[j] * q[k] + r[j]*r[k]) - center[j] * center[k]; 142 } 143 } 134 for(int i = 0; i < length; i+=3) 135 { 136 p = verticesList[i]; 137 q = verticesList[i +1]; 138 r = verticesList[i + 2]; 139 140 covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] + 141 q[j] * q[k] + r[j]*r[k]) - center[j] * center[k]; 142 } 144 143 } 145 146 printf("\nVertex Data:\n"); 147 for(int i = 0; i < length; i++) 148 { 149 printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 150 } 144 } 145 146 printf("\nVertex Data:\n"); 147 for(int i = 0; i < length; i++) 148 { 149 printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 150 } 151 151 152 152 printf("\nCovariance Matrix:\n"); 153 153 for(int j = 0; j < 3; ++j) 154 { 155 printf(" |"); 156 for(int k = 0; k < 3; ++k) 154 157 { 155 printf(" |"); 156 for(int k = 0; k < 3; ++k) 157 { 158 printf(" \b%f ", covariance[j][k]); 159 } 160 printf(" |\n"); 158 printf(" \b%f ", covariance[j][k]); 161 159 } 160 printf(" |\n"); 161 } 162 162 printf("center: %f, %f, %f\n\n", center.x, center.y, center.z); 163 163 164 164 165 165 for(int i = 0; i < 3; ++i) 166 167 168 169 170 171 166 { 167 168 box->covarianceMatrix[i][0] = covariance[i][0]; 169 box->covarianceMatrix[i][1] = covariance[i][1]; 170 box->covarianceMatrix[i][3] = covariance[i][2]; 171 } 172 172 *box->center = center; 173 173 174 174 175 175 /* now getting spanning vectors of the sub-space: 176 177 178 179 176 the eigenvectors of a symmertric matrix, such as the 177 covarience matrix are mutually orthogonal. 178 after normalizing them, they can be used as a the basis 179 vectors 180 180 */ 181 181 Matrix V(3,3); //!< for eigenvectors … … 304 304 305 305 /* now definin the separation plane through this specified nearest point and partition 306 306 the points depending on which side they are located 307 307 */ 308 308 Plane separationPlane(*box->axis[axisIndex], box->vertices[vertexIndex]); //!< separation plane … … 379 379 this->nodeRight = node2; 380 380 381 this->nodeLeft->spawnBVTree( this->depth - 1, vertList1, partition1.getSize());382 this->nodeRight->spawnBVTree( this->depth - 1, vertList2, partition2.getSize());381 this->nodeLeft->spawnBVTree(depth - 1, vertList1, partition1.getSize()); 382 this->nodeRight->spawnBVTree(depth - 1, vertList2, partition2.getSize()); 383 383 } 384 384 … … 398 398 // } 399 399 // glEnd(); 400 //this->drawBVPolygon(currentDepth, depth); 400 401 } 401 402 … … 509 510 /* 510 511 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2], 511 512 512 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2], 513 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]); 513 514 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2], 514 515 515 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2], 516 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);*/ 516 517 517 518 … … 531 532 /* 532 533 for(int i = 0; i < length; i++) 533 534 535 534 { 535 printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 536 } 536 537 */ 537 538 } -
orxonox/trunk/src/subprojects/collision_detection/collision_detection.cc
r4615 r4617 31 31 { 32 32 CDEngine::getInstance(); 33 //CDEngine::getInstance()->debug();33 CDEngine::getInstance()->debug(); 34 34 35 model = new MD2Model("models/tris.md2", "models/tris.pcx");36 model->tick(0.1f);37 CDEngine::getInstance()->debugSpawnTree(1, model->data->pVertices, model->data->numVertices);35 //model = new MD2Model("models/tris.md2", "models/tris.pcx"); 36 //model->tick(0.1f); 37 //CDEngine::getInstance()->debugSpawnTree(2, model->data->pVertices, model->data->numVertices); 38 38 39 39 LightManager* lightMan = LightManager::getInstance(); … … 70 70 LightManager::getInstance()->draw(); 71 71 72 model->draw();72 //model->draw(); 73 73 } 74 74 … … 84 84 void Framework::moduleInitGui(int argc, char** argv) 85 85 { 86 Window* guiMainWindow = NULL;87 88 initGUI(0, NULL);89 90 guiMainWindow = new Window("Collision_detection");91 {92 // all the Widgets you need93 }94 Window::mainWindow->showall();95 Window::mainWindow->setSize(300, 500);86 // Window* guiMainWindow = NULL; 87 // 88 // initGUI(0, NULL); 89 // 90 // guiMainWindow = new Window("Collision_detection"); 91 // { 92 // // all the Widgets you need 93 // } 94 // Window::mainWindow->showall(); 95 // Window::mainWindow->setSize(300, 500); 96 96 }
Note: See TracChangeset
for help on using the changeset viewer.