Changeset 4588 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Jun 10, 2005, 11:23:01 AM (19 years ago)
- Location:
- orxonox/trunk/src/lib/collision_detection
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/collision_detection/bounding_volume.h
r4560 r4588 1 /*! 1 /*! 2 2 \file bounding_volume.h 3 3 \brief Definition of a bounding volume for collision detection algorithms … … 9 9 10 10 #include "base_object.h" 11 #include "abstract_model.h" 11 12 12 class sVect3D;13 13 class Vector; 14 14 template<class T> class tList; … … 24 24 inline const Vector* getCenter() const { return this->center; } 25 25 26 virtual sVect3D* getVertices() const = NULL;26 sVec3D* getVertices() const { return this->vertices; } 27 27 virtual void mergeWith(const BoundingVolume &bv) = NULL; 28 28 … … 35 35 Vector* center; //!< Center point of box 36 36 37 sVec t3D*vertices; //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred37 sVec3D* vertices; //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred 38 38 int numOfVertices; //!< number of vertices in the vertices buffer 39 39 }; -
orxonox/trunk/src/lib/collision_detection/obb.h
r4576 r4588 24 24 inline const float* getHalfLength() const { return this->halfLength; } 25 25 26 virtual sVect3D* getVertices() const { return this->vertices; }27 26 virtual void mergeWith(const BoundingVolume &bv); 28 27 -
orxonox/trunk/src/lib/collision_detection/obb_tree.cc
r4587 r4588 97 97 /* generate some test vertices */ 98 98 sVec3D* vertList = new sVec3D[4]; 99 sVec3D data[] = {{0.0, 0.0, 0.0},{ 10.0, -5.0, 5.0},{10.0, 5.0, 0.0}, {5.0, 4.0, 1.0}};99 sVec3D data[] = {{0.0, 0.0, 0.0},{2.0, -8.0, 5.0},{10.0, 5.0, 0.0}, {5.0, 4.0, 1.0}}; 100 100 101 for(int i = 0; i < 3; ++i)101 for(int i = 0; i < 4; ++i) 102 102 { 103 103 vertList[i][0] = data[i][0]; -
orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
r4587 r4588 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 44 44 \brief standard constructor 45 45 */ 46 OBBTreeNode::OBBTreeNode () 47 { 48 this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); 46 OBBTreeNode::OBBTreeNode () 47 { 48 this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode"); 49 49 50 50 } … … 55 55 56 56 */ 57 OBBTreeNode::~OBBTreeNode () 57 OBBTreeNode::~OBBTreeNode () 58 58 { 59 59 // delete what has to be deleted here … … 85 85 float facelet[length]; //!< surface area of the i'th triangle of the convex hull 86 86 float face; //!< surface area of the entire convex hull 87 Vector centroid[length]; //!< centroid of the i'th convex hull 87 Vector centroid[length]; //!< centroid of the i'th convex hull 88 88 Vector center; //!< the center of the entire hull 89 89 Vector p, q, r; //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d 90 90 Vector t1, t2; //!< temporary values 91 91 float covariance[3][3]; //!< the covariance matrix 92 92 93 93 this->numOfVertices = length; 94 94 this->vertices = verticesList; 95 box->vertices = verticesList; 96 box->numOfVertices = length; 95 97 96 98 … … 101 103 q = verticesList[i +1]; 102 104 r = verticesList[i + 2]; 103 105 104 106 t1 = p - q; t2 = p - r; 105 107 106 108 /* finding the facelet surface via cross-product */ 107 109 facelet[i] = 0.5f * fabs( t1.cross(t2).len() ); … … 118 120 119 121 120 122 121 123 /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */ 122 124 for(int j = 0; j < 3; ++j) 123 125 { 124 126 for(int k = 0; k < 3; ++k) 125 126 127 128 129 130 131 132 133 134 135 127 { 128 for(int i = 0; i < length; i+=3) 129 { 130 p = verticesList[i]; 131 q = verticesList[i +1]; 132 r = verticesList[i + 2]; 133 134 covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] + 135 q[j] * q[k] + r[j]*r[k]) - center[j] * center[k]; 136 } 137 } 136 138 } 137 139 … … 141 143 printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 142 144 } 143 145 144 146 printf("\nCovariance Matrix:\n"); 145 147 for(int j = 0; j < 3; ++j) … … 147 149 printf(" |"); 148 150 for(int k = 0; k < 3; ++k) 149 150 151 151 { 152 printf(" \b%f ", covariance[j][k]); 153 } 152 154 printf(" |\n"); 153 155 } 154 156 printf("center: %f, %f, %f\n\n", center.x, center.y, center.z); 155 157 156 158 157 159 for(int i = 0; i < 3; ++i) 158 160 { 159 161 160 162 box->covarianceMatrix[i][0] = covariance[i][0]; 161 163 box->covarianceMatrix[i][1] = covariance[i][1]; … … 168 170 the eigenvectors of a symmertric matrix, such as the 169 171 covarience matrix are mutually orthogonal. 170 after normalizing them, they can be used as a the basis 172 after normalizing them, they can be used as a the basis 171 173 vectors 172 174 */ 173 175 Matrix V(3,3); //!< for eigenvectors 174 DiagonalMatrix D(3); //!< for eigenvalues 176 DiagonalMatrix D(3); //!< for eigenvalues 175 177 SymmetricMatrix C(3); //!< for the covariance symmetrical matrix 176 178 Vector** axis = new Vector*[3]; //!< the references to the obb axis 177 179 178 180 C(1,1) = covariance[0][0]; 179 181 C(1,2) = covariance[0][1]; 180 182 C(1,3) = covariance[0][2]; 181 C(2,1) = covariance[1][0]; 183 C(2,1) = covariance[1][0]; 182 184 C(2,2) = covariance[1][1]; 183 C(2,3) = covariance[1][2]; 185 C(2,3) = covariance[1][2]; 184 186 C(3,1) = covariance[2][0]; 185 187 C(3,2) = covariance[2][1]; … … 204 206 axis[2] = new Vector(V(1, 3), V(2, 3), V(3, 3)); 205 207 box->axis = axis; 206 208 207 209 printf("eigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z); 208 210 printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z); 209 211 printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z); 210 212 211 213 212 214 /* now get the axis length */ 213 215 Line ax[3]; //!< the axis 214 216 float* halfLength = new float[3]; //!< half length of the axis 215 217 float tmpLength; //!< tmp save point for the length 216 218 217 219 ax[0].r = *box->center; ax[0].a = *box->axis[0]; 218 220 ax[1].r = *box->center; ax[1].a = *box->axis[1]; … … 222 224 Plane p1(*box->axis[1], *box->center); 223 225 Plane p2(*box->axis[2], *box->center); 224 226 225 227 226 228 … … 252 254 box->halfLength = halfLength; 253 255 254 255 256 257 256 258 printf("we got length: \n"); 257 259 for(int i = 0; i < 3; ++i) … … 268 270 { 269 271 if( aLength < box->axis[i]->len()) 270 271 272 273 274 } 275 272 { 273 aLength = box->axis[i]->len(); 274 axisNr = i; 275 } 276 } 277 276 278 /* get the closest vertex near the center */ 277 279 278 280 } 279 281 … … 287 289 glBegin(GL_LINE_LOOP); 288 290 glColor3f(1.0, 1.0, 1.0); 289 for(int i = 0; i < this-> numOfVertices; ++i)290 { 291 glVertex3f(this-> vertices[i][0], this->vertices[i][1], this->vertices[i][2]);291 for(int i = 0; i < this->bvElement->numOfVertices; ++i) 292 { 293 glVertex3f(this->bvElement->vertices[i][0], this->bvElement->vertices[i][1], this->bvElement->vertices[i][2]); 292 294 //printf("v(%f, %f, %f)\n", this->vertices[i][0], this->vertices[i][1], this->vertices[i][2]); 293 295 } … … 298 300 void OBBTreeNode::drawBVPolygon(int currentDepth, const int depth) const 299 301 { 302 303 /* draw the obb axes */ 300 304 glBegin(GL_LINES); 301 305 glColor3f(0.0, 0.4, 0.3); … … 304 308 this->bvElement->center->y + this->bvElement->axis[0]->y * this->bvElement->halfLength[0], 305 309 this->bvElement->center->z + this->bvElement->axis[0]->z * this->bvElement->halfLength[0]); 306 310 307 311 glVertex3f(this->bvElement->center->x, this->bvElement->center->y, this->bvElement->center->z); 308 312 glVertex3f(this->bvElement->center->x + this->bvElement->axis[1]->x * this->bvElement->halfLength[1], … … 315 319 this->bvElement->center->z + this->bvElement->axis[2]->z * this->bvElement->halfLength[2]); 316 320 glEnd(); 321 322 323 Vector cen = *this->bvElement->center; 324 Vector** axis = this->bvElement->axis; 325 float* len = this->bvElement->halfLength; 326 327 /* draw bounding box */ 328 glBegin(GL_LINE_LOOP); 329 glColor3f(0.3, 0.4, 0.7); 330 glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2], 331 cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2], 332 cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]); 333 glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2], 334 cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2], 335 cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]); 336 glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2], 337 cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2], 338 cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]); 339 glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2], 340 cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2], 341 cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]); 342 glEnd(); 343 344 glBegin(GL_LINE_LOOP); 345 glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2], 346 cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2], 347 cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]); 348 glVertex3f(cen.x + axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2], 349 cen.y + axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2], 350 cen.z + axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]); 351 glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2], 352 cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2], 353 cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]); 354 glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2], 355 cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2], 356 cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]); 357 glEnd(); 358 359 glBegin(GL_LINE_LOOP); 360 glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] + axis[2]->x * len[2], 361 cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] + axis[2]->y * len[2], 362 cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] + axis[2]->z * len[2]); 363 glVertex3f(cen.x - axis[0]->x * len[0] - axis[1]->x * len[1] - axis[2]->x * len[2], 364 cen.y - axis[0]->y * len[0] - axis[1]->y * len[1] - axis[2]->y * len[2], 365 cen.z - axis[0]->z * len[0] - axis[1]->z * len[1] - axis[2]->z * len[2]); 366 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2], 367 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2], 368 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]); 369 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2], 370 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2], 371 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]); 372 glEnd(); 373 374 glBegin(GL_LINE_LOOP); 375 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2], 376 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2], 377 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]); 378 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2], 379 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2], 380 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]); 381 glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2], 382 cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2], 383 cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]); 384 glVertex3f(cen.x + axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2], 385 cen.y + axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2], 386 cen.z + axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]); 387 glEnd(); 388 389 /* 390 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] - axis[2]->x * len[2], 391 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] - axis[2]->y * len[2], 392 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] - axis[2]->z * len[2]); 393 glVertex3f(cen.x - axis[0]->x * len[0] + axis[1]->x * len[1] + axis[2]->x * len[2], 394 cen.y - axis[0]->y * len[0] + axis[1]->y * len[1] + axis[2]->y * len[2], 395 cen.z - axis[0]->z * len[0] + axis[1]->z * len[1] + axis[2]->z * len[2]);*/ 396 397 398 glEnd(); 399 400 317 401 } 318 402
Note: See TracChangeset
for help on using the changeset viewer.