Changeset 4557 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Jun 8, 2005, 4:07:28 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/collision_detection
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/collision_detection/bounding_volume.cc
r4511 r4557 27 27 { 28 28 this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume"); 29 this->center = new Vector(); 29 30 30 31 } … … 38 39 { 39 40 // delete what has to be deleted here 41 delete this->center; 40 42 } -
orxonox/trunk/src/lib/collision_detection/bounding_volume.h
r4542 r4557 35 35 Vector* center; //!< Center point of box 36 36 37 tList<sVect3D>* verticesBuffer; //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred 37 sVect3D* vertices; //!< if CD_STORE_VERTICES enabled, this is the place, where the vert. will be sotred 38 int numOfVertices; //!< number of vertices in the vertices buffer 38 39 }; 39 40 -
orxonox/trunk/src/lib/collision_detection/obb.cc
r4542 r4557 18 18 #include "obb.h" 19 19 #include "list.h" 20 #include "vector.h" 20 21 21 22 using namespace std; … … 28 29 { 29 30 this->setClassID(CL_OBB, "OBB"); 31 this->axis = new Vector[3]; 32 this->halfLength = new float[3]; 30 33 } 31 34 … … 38 41 { 39 42 // delete what has to be deleted here 43 delete [] this->axis; 44 delete [] this->halfLength; 40 45 } 41 46 -
orxonox/trunk/src/lib/collision_detection/obb.h
r4542 r4557 32 32 33 33 34 p rivate:34 public: 35 35 Vector* axis; //!< Axes of oriented box [x,y,z] 36 sVect3D* halfLength; //!< Half lengths of the box 36 float* halfLength; //!< Half lengths of the box along the axis 37 float covarianceMatrix[3][3]; //!< the covariance matrix 37 38 38 OBB* leftNode; //!< left node of the tree39 OBB* rightNode; //!< right node of the tree40 39 }; 41 40 -
orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
r4553 r4557 55 55 void OBBTreeNode::spawnBVTree(const int depth, sVec3D *verticesList, const int length) 56 56 { 57 this->bvElement = this->createBox(); 58 this->calculateBoxAttributes(box); 59 this->forkBox(box); 60 } 61 62 63 OBB* OBBTreeNode::createBox() 64 { 65 return new OBB(); 66 } 67 68 69 void OBBTreeNode::calculateBoxAttributes(OBB* box) 70 { 57 71 float facelet[length]; //!< surface area of the i'th triangle of the convex hull 58 72 float face; //!< surface area of the entire convex hull 59 73 Vector centroid[length]; //!< centroid of the i'th convex hull 60 Vector centre; //!< the centre of the entire hull 61 OBB* obb = new OBB(); //!< the new obb to add 74 Vector center; //!< the center of the entire hull 62 75 Vector p, q, r; //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d 63 76 Vector t1, t2; //!< temporary values … … 85 98 centroid[i] = (p + q + r) * 1/3; 86 99 /* now calculate the centroid of the entire convex hull, weighted average of triangle centroids */ 87 cent re+= centroid[i] * facelet[i];100 center += centroid[i] * facelet[i]; 88 101 } 89 102 /* take the average of the centroid sum */ 90 cent re/= face;103 center /= face; 91 104 92 105 /* now calculate the covariance matrix - if not written in three for-loops, it would compute faster: minor */ … … 102 115 103 116 covariance[j][k] = facelet[i] / (12.0f * face) * (9.0f * centroid[i][j] * centroid[i][k] + p[j]* p[k] + 104 q[j] * q[k] + r[j]*r[k]) - cent re[j] * centre[k];117 q[j] * q[k] + r[j]*r[k]) - center[j] * center[k]; 105 118 } 106 119 } 107 120 } 108 121 109 122 printf("Covariance Matrix:\n"); 110 123 for(int j = 0; j < 3; ++j) … … 123 136 printf("vertex %i: %f, %f, %f\n", i, verticesList[i][0], verticesList[i][1], verticesList[i][2]); 124 137 } 138 139 140 141 box->covarianceMatrix = covariance; 142 box->center = center; 143 144 145 /* now getting spanning vectors of the sub-space: 146 the eigenvectors of a symmertric matrix, such as the 147 covarience matrix are mutually orthogonal. 148 after normalizing them, they can be used as a the basis 149 vectors 150 */ 151 152 153 } 154 155 156 void OBBTreeNode::forkBox(OBB* box) 157 { 158 /* get the longest axis of the box */ 159 float aLength = -1.0f; 160 int axisNr = 0; 161 for(int i = 0; i < 3; ++i) 162 { 163 if( aLength < box->axis[i]) 164 { 165 aLength = box->axis[i]; 166 axisNr = i; 167 } 168 } 169 170 /* get the closest vertex near the center */ 125 171 126 172 } … … 145 191 146 192 void OBBTreeNode::drawBVPolygon(int currentDepth, const int depth) const 147 {} 193 { 194 this->bvElement->axis; 195 196 glBegin(GL_TRIANGLE); 197 glVertex3f(this->bvElement->center ); 198 glEnd(); 199 } 148 200 149 201 -
orxonox/trunk/src/lib/collision_detection/obb_tree_node.h
r4553 r4557 14 14 // FORWARD DEFINITION 15 15 class BoundingVolume; 16 class OBB; 16 17 //struct sVec3D; 17 18 … … 35 36 virtual void drawBVBlended(int currentDepth, const int depth) const; 36 37 38 private: 39 OBB* createBox(); 40 void calculateBoxAttributes(OBB* box); 41 void forkBox(OBB* box); 42 43 37 44 38 45 protected:
Note: See TracChangeset
for help on using the changeset viewer.