Changeset 3327 in orxonox.OLD for orxonox/branches
- Timestamp:
- Jan 3, 2005, 6:57:01 PM (20 years ago)
- Location:
- orxonox/branches/parenting/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/parenting/src/curve.cc
r3322 r3327 23 23 24 24 #include "curve.h" 25 #include "matrix.h" 25 26 26 27 #include <math.h> 27 28 #include <stdio.h> 29 28 30 29 31 /** … … 45 47 46 48 49 /////////////////////////////////// 50 /// Bezier Curve ////////////////// 51 /////////////////////////////////// 52 47 53 /** 48 54 \brief Creates a new BezierCurve … … 70 76 It does this by freeing all the space taken over from the nodes 71 77 */ 72 BezierCurve::~BezierCurve 78 BezierCurve::~BezierCurve(void) 73 79 { 74 80 PathNode* tmpNode; … … 197 203 return curvePoint; 198 204 } 205 206 207 208 /////////////////////////////////// 209 //// Uniform Point curve ///////// 210 /////////////////////////////////// 211 /** 212 \brief Creates a new UPointCurve 213 */ 214 UPointCurve::UPointCurve (void) 215 { 216 this->derivation = 0; 217 dirCurve = new UPointCurve(1); 218 this->init(); 219 } 220 221 /** 222 \brief Creates a new UPointCurve-Derivation-Curve of deriavation'th degree 223 */ 224 UPointCurve::UPointCurve (int derivation) 225 { 226 this->derivation = derivation; 227 dirCurve=NULL; 228 this->init(); 229 } 230 231 /** 232 \brief Deletes a UPointCurve. 233 234 It does this by freeing all the space taken over from the nodes 235 */ 236 UPointCurve::~UPointCurve(void) 237 { 238 PathNode* tmpNode; 239 currentNode = firstNode; 240 while (tmpNode != 0) 241 { 242 tmpNode = currentNode; 243 currentNode = currentNode->next; 244 delete tmpNode; 245 } 246 if (dirCurve) 247 delete dirCurve; 248 } 249 250 /** 251 \brief Initializes a UPointCurve 252 */ 253 void UPointCurve::init(void) 254 { 255 nodeCount = 0; 256 firstNode = new PathNode; 257 currentNode = firstNode; 258 259 firstNode->position = Vector (.0, .0, .0); 260 firstNode->number = 0; 261 firstNode->next = 0; // not sure if this really points to NULL!! 262 263 return; 264 } 265 266 /** 267 \brief Rebuilds a UPointCurve 268 269 \todo very bad algorithm 270 */ 271 void UPointCurve::rebuild(void) 272 { 273 // rebuilding the Curve itself 274 PathNode* tmpNode = this->firstNode; 275 int i=0; 276 Matrix xTmpMat = Matrix(this->nodeCount, this->nodeCount); 277 Matrix yTmpMat = Matrix(this->nodeCount, this->nodeCount); 278 Matrix zTmpMat = Matrix(this->nodeCount, this->nodeCount); 279 Matrix xValMat = Matrix(this->nodeCount, 3); 280 Matrix yValMat = Matrix(this->nodeCount, 3); 281 Matrix zValMat = Matrix(this->nodeCount, 3); 282 while(tmpNode) 283 { 284 Vector fac = Vector(1,1,1); 285 for (int j = 0; j < this->nodeCount; j++) 286 { 287 xTmpMat(i,j) = fac.x; fac.x *= (float)i/(float)this->nodeCount;//tmpNode->position.x; 288 yTmpMat(i,j) = fac.y; fac.y *= (float)i/(float)this->nodeCount;//tmpNode->position.y; 289 zTmpMat(i,j) = fac.z; fac.z *= (float)i/(float)this->nodeCount;//tmpNode->position.z; 290 } 291 xValMat(i,0) = tmpNode->position.x; 292 yValMat(i,0) = tmpNode->position.y; 293 zValMat(i,0) = tmpNode->position.z; 294 ++i; 295 tmpNode = tmpNode->next; 296 } 297 tmpNode = this->firstNode; 298 xValMat = xTmpMat.Inv() *= xValMat; 299 yValMat = yTmpMat.Inv() *= yValMat; 300 zValMat = zTmpMat.Inv() *= zValMat; 301 i = 0; 302 while(tmpNode) 303 { 304 tmpNode->vFactor.x = xValMat(i,0); 305 tmpNode->vFactor.y = yValMat(i,0); 306 tmpNode->vFactor.z = zValMat(i,0); 307 308 i++; 309 tmpNode = tmpNode->next; 310 } 311 312 // rebuilding the Derivation curve 313 if(this->derivation == 0) 314 { 315 tmpNode = firstNode; 316 delete dirCurve; 317 dirCurve = new UPointCurve(1); 318 while(tmpNode->next) 319 { 320 Vector tmpVector = (tmpNode->next->position)- (tmpNode->position); 321 tmpVector.x*=(float)nodeCount; 322 tmpVector.y*=(float)nodeCount; 323 tmpVector.z*=(float)nodeCount; 324 tmpVector.normalize(); 325 this->dirCurve->addNode(tmpVector); 326 tmpNode = tmpNode->next; 327 } 328 } 329 } 330 331 /** 332 \brief calculates the Position on the curve 333 \param t The position on the Curve (0<=t<=1) 334 \return the Position on the Path 335 */ 336 Vector UPointCurve::calcPos(float t) 337 { 338 PathNode* tmpNode = firstNode; 339 Vector ret = Vector(0.0,0.0,0.0); 340 float factor = 1.0; 341 while(tmpNode) 342 { 343 ret.x += tmpNode->vFactor.x * factor; 344 ret.y += tmpNode->vFactor.y * factor; 345 ret.z += tmpNode->vFactor.z * factor; 346 factor *= t; 347 348 tmpNode = tmpNode->next; 349 } 350 return ret; 351 } 352 353 /** 354 \brief Calulates the direction of the Curve at time t. 355 \param The time at which to evaluate the curve. 356 \returns The vvaluated Vector. 357 */ 358 Vector UPointCurve::calcDir (float t) 359 { 360 return dirCurve->calcPos(t); 361 } 362 363 /** 364 \brief Calculates the Quaternion needed for our rotations 365 \param t The time at which to evaluate the cuve. 366 \returns The evaluated Quaternion. 367 */ 368 Quaternion UPointCurve::calcQuat (float t) 369 { 370 return Quaternion (calcDir(t), Vector(0,0,1)); 371 } 372 373 374 /** 375 \brief returns the Position of the point calculated on the Curve 376 \return a Vector to the calculated position 377 */ 378 Vector UPointCurve::getPos(void) const 379 { 380 return curvePoint; 381 } -
orxonox/branches/parenting/src/curve.h
r3322 r3327 13 13 14 14 15 //! An abstract class to handle curves. 15 //! An abstract class to handle curves. Needed for the Tracking system in orxonox. 16 16 class Curve 17 17 { … … 28 28 int number; //!< The N-th node of this curve. 29 29 float factor; //!< Curve specific multiplier factor. 30 Vector vFactor; //!< A Vector-factor for multipliing. 30 31 Vector position; //!< Vector Pointung to this curve-point. 31 32 PathNode* next; //!< Pointer to the next Node. … … 46 47 }; 47 48 48 //! Bezier Curve49 //! Class to handle bezier curves in 3-dimesnsional space 49 50 /** 50 Class to handle bezier curves in 3-dimesnsional space 51 52 needed for the Tracking system in OrxOnoX. 51 This Curve is good, for Fast Interaction. If you want to change it during the game, go on. 52 !!be aware!! BezierCurves only flow through their first and last Node. Their Tangents at those Points a directed to the second and second-last Point. 53 53 */ 54 54 class BezierCurve : public Curve … … 81 81 }; 82 82 83 //! Uniform Point Curve-class 84 /** 85 A UPoint Curve is a A Curve, that flows through all the nodes given it. 86 The Algorithm to buid the curve is rather slow, but Painting and tracing along the curve has high speed, so do not change this curve during the Game. 87 88 This Curve is very erattic, so i do not recommend to use it. 89 */ 90 class UPointCurve : public Curve 91 { 92 private: 93 void rebuild(void); 94 public: 95 UPointCurve(void); 96 UPointCurve(int derivation); 97 ~UPointCurve(void); 98 void init(void); 99 100 Vector calcPos(float t); 101 Vector calcDir(float t); 102 Quaternion calcQuat(float t); 103 104 Vector getPos(void) const; 105 }; 83 106 84 107 #endif /* _CURVE_H */ -
orxonox/branches/parenting/src/matrix.cc
r3326 r3327 21 21 #include "matrix.h" 22 22 23 inlineMatrix::Matrix (size_t row, size_t col)23 Matrix::Matrix (size_t row, size_t col) 24 24 { 25 25 _m = new base_mat( row, col, 0); … … 27 27 28 28 // copy constructor 29 inlineMatrix::Matrix (const Matrix& m)29 Matrix::Matrix (const Matrix& m) 30 30 { 31 31 _m = m._m; … … 34 34 35 35 // Internal copy constructor 36 inlinevoid Matrix::clone ()36 void Matrix::clone () 37 37 { 38 38 _m->Refcnt--; … … 41 41 42 42 // destructor 43 inlineMatrix::~Matrix ()43 Matrix::~Matrix () 44 44 { 45 45 if (--_m->Refcnt == 0) delete _m; … … 47 47 48 48 // assignment operator 49 inlineMatrix& Matrix::operator = (const Matrix& m)49 Matrix& Matrix::operator = (const Matrix& m) 50 50 { 51 51 m._m->Refcnt++; … … 56 56 57 57 // reallocation method 58 inlinevoid Matrix::realloc (size_t row, size_t col)58 void Matrix::realloc (size_t row, size_t col) 59 59 { 60 60 if (row == _m->RowSiz && col == _m->ColSiz) … … 80 80 81 81 // public method for resizing Matrix 82 inlinevoid Matrix::SetSize (size_t row, size_t col)82 void Matrix::SetSize (size_t row, size_t col) 83 83 { 84 84 size_t i,j; … … 101 101 102 102 // subscript operator to get/set individual elements 103 inlinefloat& Matrix::operator () (size_t row, size_t col)103 float& Matrix::operator () (size_t row, size_t col) 104 104 { 105 105 if (row >= _m->Row || col >= _m->Col) … … 110 110 111 111 // subscript operator to get/set individual elements 112 inlinefloat Matrix::operator () (size_t row, size_t col) const112 float Matrix::operator () (size_t row, size_t col) const 113 113 { 114 114 if (row >= _m->Row || col >= _m->Col) … … 118 118 119 119 // input stream function 120 i nline istream& operator >> (istream& istrm, Matrix& m)120 istream& operator >> (istream& istrm, Matrix& m) 121 121 { 122 122 for (size_t i=0; i < m.RowNo(); i++) … … 131 131 132 132 // output stream function 133 inlineostream& operator << (ostream& ostrm, const Matrix& m)133 ostream& operator << (ostream& ostrm, const Matrix& m) 134 134 { 135 135 for (size_t i=0; i < m.RowNo(); i++) … … 147 147 148 148 // logical equal-to operator 149 inlinebool operator == (const Matrix& m1, const Matrix& m2)149 bool operator == (const Matrix& m1, const Matrix& m2) 150 150 { 151 151 if (m1.RowNo() != m2.RowNo() || m1.ColNo() != m2.ColNo()) … … 161 161 162 162 // logical no-equal-to operator 163 inlinebool operator != (const Matrix& m1, const Matrix& m2)163 bool operator != (const Matrix& m1, const Matrix& m2) 164 164 { 165 165 return (m1 == m2) ? false : true; … … 167 167 168 168 // combined addition and assignment operator 169 inlineMatrix& Matrix::operator += (const Matrix& m)169 Matrix& Matrix::operator += (const Matrix& m) 170 170 { 171 171 if (_m->Row != m._m->Row || _m->Col != m._m->Col) … … 179 179 180 180 // combined subtraction and assignment operator 181 inlineMatrix& Matrix::operator -= (const Matrix& m)181 Matrix& Matrix::operator -= (const Matrix& m) 182 182 { 183 183 if (_m->Row != m._m->Row || _m->Col != m._m->Col) … … 191 191 192 192 // combined scalar multiplication and assignment operator 193 inlineMatrix&193 Matrix& 194 194 Matrix::operator *= (const float& c) 195 195 { … … 202 202 203 203 // combined Matrix multiplication and assignment operator 204 inlineMatrix&204 Matrix& 205 205 Matrix::operator *= (const Matrix& m) 206 206 { … … 223 223 224 224 // combined scalar division and assignment operator 225 inlineMatrix&225 Matrix& 226 226 Matrix::operator /= (const float& c) 227 227 { … … 235 235 236 236 // combined power and assignment operator 237 inlineMatrix&237 Matrix& 238 238 Matrix::operator ^= (const size_t& pow) 239 239 { … … 247 247 248 248 // unary negation operator 249 inlineMatrix249 Matrix 250 250 Matrix::operator - () 251 251 { … … 260 260 261 261 // binary addition operator 262 inlineMatrix262 Matrix 263 263 operator + (const Matrix& m1, const Matrix& m2) 264 264 { … … 269 269 270 270 // binary subtraction operator 271 inlineMatrix271 Matrix 272 272 operator - (const Matrix& m1, const Matrix& m2) 273 273 { … … 278 278 279 279 // binary scalar multiplication operator 280 inlineMatrix280 Matrix 281 281 operator * (const Matrix& m, const float& no) 282 282 { … … 288 288 289 289 // binary scalar multiplication operator 290 inlineMatrix290 Matrix 291 291 operator * (const float& no, const Matrix& m) 292 292 { … … 295 295 296 296 // binary Matrix multiplication operator 297 inlineMatrix297 Matrix 298 298 operator * (const Matrix& m1, const Matrix& m2) 299 299 { … … 304 304 305 305 // binary scalar division operator 306 inlineMatrix306 Matrix 307 307 operator / (const Matrix& m, const float& no) 308 308 { … … 312 312 313 313 // binary scalar division operator 314 inlineMatrix314 Matrix 315 315 operator / (const float& no, const Matrix& m) 316 316 { … … 319 319 320 320 // binary Matrix division operator 321 inlineMatrix321 Matrix 322 322 operator / (const Matrix& m1, const Matrix& m2) 323 323 { … … 326 326 327 327 // binary power operator 328 inlineMatrix328 Matrix 329 329 operator ^ (const Matrix& m, const size_t& pow) 330 330 { … … 335 335 336 336 // unary transpose operator 337 inlineMatrix337 Matrix 338 338 operator ~ (const Matrix& m) 339 339 { … … 350 350 351 351 // unary inversion operator 352 inlineMatrix352 Matrix 353 353 operator ! (const Matrix m) 354 354 { … … 358 358 359 359 // inversion function 360 inlineMatrix360 Matrix 361 361 Matrix::Inv () 362 362 { … … 405 405 406 406 // solve simultaneous equation 407 inlineMatrix407 Matrix 408 408 Matrix::Solve (const Matrix& v) const 409 409 { … … 451 451 452 452 // set zero to all elements of this Matrix 453 inlinevoid453 void 454 454 Matrix::Null (const size_t& row, const size_t& col) 455 455 { … … 467 467 468 468 // set zero to all elements of this Matrix 469 inlinevoid469 void 470 470 Matrix::Null() 471 471 { … … 478 478 479 479 // set this Matrix to unity 480 inlinevoid480 void 481 481 Matrix::Unit (const size_t& row) 482 482 { … … 494 494 495 495 // set this Matrix to unity 496 inlinevoid496 void 497 497 Matrix::Unit () 498 498 { … … 508 508 509 509 // private partial pivoting method 510 in line int510 int 511 511 Matrix::pivot (size_t row) 512 512 { … … 534 534 535 535 // calculate the determinant of a Matrix 536 inlinefloat536 float 537 537 Matrix::Det () const 538 538 { … … 565 565 566 566 // calculate the norm of a Matrix 567 inlinefloat567 float 568 568 Matrix::Norm () 569 569 { … … 579 579 580 580 // calculate the condition number of a Matrix 581 inlinefloat581 float 582 582 Matrix::Cond () 583 583 { … … 587 587 588 588 // calculate the cofactor of a Matrix for a given element 589 inlinefloat589 float 590 590 Matrix::Cofact (size_t row, size_t col) 591 591 { … … 622 622 623 623 // calculate adjoin of a Matrix 624 inlineMatrix624 Matrix 625 625 Matrix::Adj () 626 626 { … … 637 637 638 638 // Determine if the Matrix is singular 639 inlinebool639 bool 640 640 Matrix::IsSingular () 641 641 { … … 646 646 647 647 // Determine if the Matrix is diagonal 648 inlinebool648 bool 649 649 Matrix::IsDiagonal () 650 650 { … … 659 659 660 660 // Determine if the Matrix is scalar 661 inlinebool661 bool 662 662 Matrix::IsScalar () 663 663 { … … 672 672 673 673 // Determine if the Matrix is a unit Matrix 674 inlinebool674 bool 675 675 Matrix::IsUnit () 676 676 { … … 681 681 682 682 // Determine if this is a null Matrix 683 inlinebool683 bool 684 684 Matrix::IsNull () 685 685 { … … 692 692 693 693 // Determine if the Matrix is symmetric 694 inlinebool694 bool 695 695 Matrix::IsSymmetric () 696 696 { … … 705 705 706 706 // Determine if the Matrix is skew-symmetric 707 inlinebool707 bool 708 708 Matrix::IsSkewSymmetric () 709 709 { … … 718 718 719 719 // Determine if the Matrix is upper triangular 720 inlinebool720 bool 721 721 Matrix::IsUpperTriangular () 722 722 { … … 731 731 732 732 // Determine if the Matrix is lower triangular 733 inlinebool733 bool 734 734 Matrix::IsLowerTriangular () 735 735 { -
orxonox/branches/parenting/src/matrix.h
r3326 r3327 14 14 // Constructors 15 15 Matrix (const Matrix& m); 16 Matrix (size_t row = 6, size_t col = 6);16 Matrix (size_t row, size_t col); 17 17 18 18 // Destructor -
orxonox/branches/parenting/src/world.cc
r3324 r3327 153 153 case DEBUG_WORLD_0: 154 154 { 155 testCurve = new BezierCurve();156 testCurve->addNode(Vector( 0,0,0));157 testCurve->addNode(Vector( 5,7,0));158 testCurve->addNode(Vector( 10,-5,0));159 testCurve->addNode(Vector( 20, 0,10));160 testCurve->addNode(Vector( 50, 7,-5));161 testCurve->addNode(Vector( 60, -20,0));162 testCurve->addNode(Vector(60, 10,0)); 155 testCurve = new UPointCurve(); 156 testCurve->addNode(Vector( 0, 0, 0)); 157 testCurve->addNode(Vector(10, 0, 5)); 158 testCurve->addNode(Vector(20, -5,-5)); 159 testCurve->addNode(Vector(30, 5, 10)); 160 testCurve->addNode(Vector(40, 0,-10)); 161 testCurve->addNode(Vector(50, 0,-10)); 162 163 163 164 164 this->nullParent = NullParent::getInstance (); … … 447 447 448 448 glBegin(GL_LINES); 449 for(float i=0.0; i<1; i+=.0 1)450 { 451 printf("%f %f %f\n",testCurve->calc Dir(i).x,testCurve->calcDir(i).y,testCurve->calcDir(i).z);449 for(float i=0.0; i<1; i+=.001) 450 { 451 printf("%f %f %f\n",testCurve->calcPos(i).x,testCurve->calcPos(i).y,testCurve->calcPos(i).z); 452 452 glVertex3f(testCurve->calcPos(i).x, testCurve->calcPos(i).y, testCurve->calcPos(i).z); 453 glVertex3f(testCurve->calcPos(i).x+testCurve->calcDir(i).x, testCurve->calcPos(i).y+testCurve->calcDir(i).y, testCurve->calcPos(i).z+testCurve->calcDir(i).z);453 // glVertex3f(testCurve->calcPos(i).x+testCurve->calcDir(i).x, testCurve->calcPos(i).y+testCurve->calcDir(i).y, testCurve->calcPos(i).z+testCurve->calcDir(i).z); 454 454 } 455 455 glEnd(); -
orxonox/branches/parenting/src/world.h
r3319 r3327 67 67 68 68 69 BezierCurve* testCurve;69 UPointCurve* testCurve; 70 70 private: 71 71 Uint32 lastFrame; //!> last time of frame
Note: See TracChangeset
for help on using the changeset viewer.