Changeset 3746 in orxonox.OLD for orxonox/branches/levelloader/src/lib/coord
- Timestamp:
- Apr 7, 2005, 3:54:49 PM (20 years ago)
- Location:
- orxonox/branches/levelloader/src/lib/coord
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/lib/coord/helper_parent.h
r3605 r3746 8 8 #define _HELPER_PARENT_H 9 9 10 #include "stdincl.h" 10 11 11 #include "p_node.h" 12 12 -
orxonox/branches/levelloader/src/lib/coord/null_parent.cc
r3605 r3746 19 19 20 20 #include "null_parent.h" 21 #include "stdincl.h" 22 #include "vector.h" 23 #include "list.h" 21 24 22 25 … … 51 54 this->parent = this; 52 55 this->mode = PNODE_ALL; 53 this->absCoordinate = *absCoordinate;56 *this->absCoordinate = *absCoordinate; 54 57 this->setName("NullParent"); 55 58 } … … 74 77 worry, normaly... 75 78 */ 76 void NullParent::update ( )79 void NullParent::update (float dt) 77 80 { 78 81 79 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 80 this->absCoordinate = this->relCoordinate; 81 this->absDirection = parent->getAbsDir () * this->relDirection; 82 83 PNode* pn = this->children->enumerate (); 82 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate->x, this->absCoordinate->y, this->absCoordinate->z); 83 *this->absCoordinate = *this->relCoordinate; 84 *this->absDirection = parent->getAbsDir () * *this->relDirection; 85 86 tIterator<PNode>* iterator = this->children->getIterator(); 87 //PNode* pn = this->children->enumerate (); 88 PNode* pn = iterator->nextElement(); 84 89 while( pn != NULL) 85 90 { … … 89 94 if( this->bRelDirChanged || this->bAbsDirChanged) 90 95 pn->parentDirChanged (); 91 pn->update (); 92 pn = this->children->nextElement (); 96 pn->update (dt); 97 //pn = this->children->nextElement (); 98 pn = iterator->nextElement(); 93 99 } 94 100 -
orxonox/branches/levelloader/src/lib/coord/null_parent.h
r3605 r3746 8 8 #define _NULL_PARENT_H 9 9 10 #include "stdincl.h" 10 11 11 #include "p_node.h" 12 12 … … 19 19 20 20 21 virtual void update ( );22 21 virtual void update (float dt); 22 23 23 private: 24 24 NullParent (); -
orxonox/branches/levelloader/src/lib/coord/p_node.cc
r3605 r3746 21 21 22 22 #include "p_node.h" 23 23 #include "stdincl.h" 24 25 #include "error.h" 26 #include "debug.h" 27 #include "list.h" 28 #include "vector.h" 24 29 #include "null_parent.h" 25 #include "vector.h" 30 31 32 //#include "vector.h" 33 //#include "quaternion.h" 26 34 27 35 using namespace std; … … 52 60 this->init(parent); 53 61 54 this->absCoordinate = *absCoordinate;62 *this->absCoordinate = *absCoordinate; 55 63 if (parent != NULL) 56 64 { 57 this->relCoordinate =this->absCoordinate - parent->getAbsCoor ();65 *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor (); 58 66 parent->addChild (this); 59 67 } 60 68 else 61 this->relCoordinate = Vector(0,0,0);69 this->relCoordinate = new Vector(0,0,0); 62 70 } 63 71 … … 94 102 } 95 103 104 96 105 void PNode::init(PNode* parent) 97 106 { … … 103 112 this->parent = parent; 104 113 this->objectName = NULL; 114 115 this->absCoordinate = new Vector(); 116 this->relCoordinate = new Vector(); 117 this->absDirection = new Quaternion(); 118 this->relDirection = new Quaternion(); 119 this->lastAbsCoordinate = new Vector(); 105 120 } 106 121 … … 129 144 \brief get relative coordinates 130 145 \returns relative coordinates to its parent 131 */ 132 Vector PNode::getRelCoor () 133 { 134 Vector r = this->relCoordinate; /* return a copy, so it can't be modified */ 135 return r; 146 147 the reference that is returned is a pointer to the real relCoor, so don't 148 change it unless you realy know what you are doing. 149 */ 150 Vector* PNode::getRelCoor () 151 { 152 //Vector r = *this->relCoordinate; /* return a copy, so it can't be modified */ 153 return this->relCoordinate; 136 154 } 137 155 … … 148 166 { 149 167 this->bRelCoorChanged = true; 150 this->relCoordinate = *relCoord; 168 *this->relCoordinate = *relCoord; 169 } 170 171 172 /** 173 \brief set relative coordinates 174 \param relCoord relative coordinates to its parent 175 176 it is very importand, that you use this function, if you want to update the 177 relCoordinates. If you don't use this, the PNode won't recognize, that something 178 has changed and won't update the children Nodes. 179 */ 180 void PNode::setRelCoor (Vector relCoord) 181 { 182 this->bRelCoorChanged = true; 183 *this->relCoordinate = relCoord; 151 184 } 152 185 … … 158 191 Vector PNode::getAbsCoor () 159 192 { 160 return this->absCoordinate;193 return *this->absCoordinate; 161 194 } 162 195 … … 172 205 { 173 206 this->bAbsCoorChanged = true; 174 this->absCoordinate = *absCoord; 207 *this->absCoordinate = *absCoord; 208 } 209 210 211 212 /** 213 \param absCoord set absolute coordinate 214 215 it is very importand, that you use this function, if you want to update the 216 absCoordinates. If you don't use this, the PNode won't recognize, that something 217 has changed and won't update the children Nodes. 218 */ 219 void PNode::setAbsCoor (Vector absCoord) 220 { 221 this->bAbsCoorChanged = true; 222 *this->absCoordinate = absCoord; 175 223 } 176 224 … … 200 248 if( this->bAbsCoorChanged) 201 249 { 202 this->absCoordinate =this->absCoordinate + *shift;250 *this->absCoordinate = *this->absCoordinate + *shift; 203 251 } 204 252 else 205 253 { 206 this->relCoordinate = this->relCoordinate + *shift; 254 *this->relCoordinate = *this->relCoordinate + *shift; 255 this->bRelCoorChanged = true; 256 } 257 } 258 259 260 261 /** 262 \brief shift coordinate (abs and rel) 263 \param shift vector 264 265 this function shifts the current coordinates about the vector shift. this is 266 usefull because from some place else you can: 267 PNode* someNode = ...; 268 Vector objectMovement = calculateShift(); 269 someNode->shiftCoor(objectMovement); 270 271 elsewhere you would have to: 272 PNode* someNode = ...; 273 Vector objectMovement = calculateShift(); 274 Vector currentCoor = someNode->getRelCoor(); 275 Vector newCoor = currentCoor + objectMovement; 276 someNode->setRelCoor(newCoor); 277 278 yea right... shorter... 279 280 */ 281 void PNode::shiftCoor (Vector shift) 282 { 283 if( this->bAbsCoorChanged) 284 { 285 *this->absCoordinate = *this->absCoordinate + shift; 286 } 287 else 288 { 289 *this->relCoordinate = *this->relCoordinate + shift; 207 290 this->bRelCoorChanged = true; 208 291 } … … 217 300 Quaternion PNode::getRelDir () 218 301 { 219 return this->relDirection;302 return *this->relDirection; 220 303 } 221 304 … … 232 315 { 233 316 this->bRelCoorChanged = true; 234 this->relDirection = *relDir; 317 *this->relDirection = *relDir; 318 } 319 320 321 void PNode::setRelDir (Quaternion relDir) 322 { 323 this->bRelCoorChanged = true; 324 *this->relDirection = relDir; 235 325 } 236 326 … … 242 332 Quaternion PNode::getAbsDir () 243 333 { 244 return this->absDirection;334 return *this->absDirection; 245 335 } 246 336 … … 257 347 { 258 348 this->bAbsDirChanged = true; 259 this->absDirection = *absDir; 260 } 349 *this->absDirection = *absDir; 350 } 351 352 353 354 /** 355 \brief sets the absolute direction (0,0,1) 356 \param absDir absolute coordinates 357 358 it is very importand, that you use this function, if you want to update the 359 absDirection. If you don't use this, the PNode won't recognize, that something 360 has changed and won't update the children Nodes. 361 */ 362 void PNode::setAbsDir (Quaternion absDir) 363 { 364 this->bAbsDirChanged = true; 365 *this->absDirection = absDir; 366 } 367 261 368 262 369 … … 285 392 {} 286 393 394 395 /** 396 \brief shift coordinate (abs and rel) 397 \param shift vector 398 399 this function shifts the current coordinates about the vector shift. this is 400 usefull because from some place else you can: 401 PNode* someNode = ...; 402 Quaternion objectMovement = calculateShift(); 403 someNode->shiftCoor(objectMovement); 404 405 elsewhere you would have to: 406 PNode* someNode = ...; 407 Quaternion objectMovement = calculateShift(); 408 Quaternion currentCoor = someNode->getRelCoor(); 409 Quaternion newCoor = currentCoor + objectMovement; 410 someNode->setRelCoor(newCoor); 411 412 yea right... shorter... 413 414 \todo implement this 415 */ 416 void PNode::shiftDir (Quaternion shift) 417 {} 418 419 420 /** 421 \brief this calculates the current movement speed of the node 422 */ 423 float PNode::getSpeed() 424 { 425 if(this->time == 0) 426 return 1000; 427 Vector diff; 428 diff = *this->absCoordinate - *this->lastAbsCoordinate; 429 float x = diff.len(); 430 return x / this->time; 431 } 432 433 287 434 /** 288 435 \brief adds a child and makes this node to a parent … … 308 455 if( pNode->parent != NULL ) 309 456 { 310 PRINTF( 2)("PNode::addChild() - reparenting node: removing it and adding it again\n");457 PRINTF(3)("PNode::addChild() - reparenting node: removing it and adding it again\n"); 311 458 pNode->parent->children->remove(pNode); 312 459 } … … 338 485 void PNode::remove() 339 486 { 340 NullParent* np = NullParent::getInstance(); 341 PNode* pn = this->children->enumerate(); 487 NullParent* nullParent = NullParent::getInstance(); 488 489 tIterator<PNode>* iterator = this->children->getIterator(); 490 PNode* pn = iterator->nextElement(); 491 342 492 while( pn != NULL) 343 493 { 344 this->children->remove(pn); 345 np->addChild(pn, pn->getMode()); 346 pn = this->children->nextElement(); 347 } 494 //this->children->remove(pn); 495 nullParent->addChild(pn, pn->getMode()); 496 pn = iterator->nextElement(); 497 } 498 delete iterator; 499 this->parent->children->remove(this); 348 500 } 349 501 … … 410 562 worry, normaly... 411 563 */ 412 void PNode::update () 413 { 414 PRINTF(2)("PNode::update - %s - (%f, %f, %f)\n", this->objectName, this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 415 // printf("%s", this->objectName); 564 void PNode::update (float dt) 565 { 566 *this->lastAbsCoordinate = *this->absCoordinate; 567 this->time = dt; 568 PRINTF(4)("PNode::update - %s - (%f, %f, %f)\n", this->objectName, this->absCoordinate->x, this->absCoordinate->y, this->absCoordinate->z); 416 569 if(this->mode & PNODE_MOVEMENT ) 417 570 { … … 419 572 { 420 573 /* if you have set the absolute coordinates this overrides all other changes */ 421 this->relCoordinate =this->absCoordinate - parent->getAbsCoor ();574 *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor (); 422 575 } 423 576 else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) … … 426 579 if( this->parent == NULL) 427 580 { 428 this->absCoordinate =this->relCoordinate;581 *this->absCoordinate = *this->relCoordinate; 429 582 } 430 583 else 431 this->absCoordinate = parent->getAbsCoor() +this->relCoordinate; /* update the current absCoordinate */584 *this->absCoordinate = parent->getAbsCoor() + *this->relCoordinate; /* update the current absCoordinate */ 432 585 } 433 586 } … … 438 591 { 439 592 /* if you have set the absolute coordinates this overrides all other changes */ 440 this->relDirection =this->absDirection - parent->getAbsDir();593 *this->relDirection = *this->absDirection - parent->getAbsDir(); 441 594 } 442 595 else if( this->bRelDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) 443 596 { 444 597 /* update the current absDirection - remember * means rotation around sth.*/ 445 this->absDirection = parent->getAbsDir() *this->relDirection;598 *this->absDirection = parent->getAbsDir() * *this->relDirection; 446 599 } 447 600 } … … 452 605 { 453 606 /* if you have set the absolute coordinates this overrides all other changes */ 454 this->relCoordinate =this->absCoordinate - parent->getAbsCoor ();607 *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor (); 455 608 } 456 609 else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) … … 458 611 /*this is bad style... must be deleted later - just for testing*/ 459 612 if( this->parent == NULL) 460 this->absCoordinate =this->relCoordinate;613 *this->absCoordinate = *this->relCoordinate; 461 614 else 462 this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); /* update the current absCoordinate */615 *this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(*this->relCoordinate); /* update the current absCoordinate */ 463 616 } 464 617 } 465 618 466 619 467 PNode* pn = this->children->enumerate(); 620 tIterator<PNode>* iterator = this->children->getIterator(); 621 //PNode* pn = this->children->enumerate(); 622 PNode* pn = iterator->nextElement(); 468 623 while( pn != NULL) 469 624 { … … 473 628 if( this->bRelDirChanged || this->bAbsDirChanged) 474 629 pn->parentDirChanged (); 475 pn->update(); 476 pn = this->children->nextElement(); 477 } 630 631 pn->update(dt); 632 //pn = this->children->nextElement(); 633 pn = iterator->nextElement(); 634 } 635 delete iterator; 478 636 479 637 this->timeStamp = timeStamp; … … 507 665 { 508 666 PRINTF(2)("PNode::debug() - absCoord: (%f, %f, %f)\n", 509 this->absCoordinate .x,510 this->absCoordinate .y,511 this->absCoordinate .z);667 this->absCoordinate->x, 668 this->absCoordinate->y, 669 this->absCoordinate->z); 512 670 } 513 671 -
orxonox/branches/levelloader/src/lib/coord/p_node.h
r3605 r3746 23 23 24 24 #include "base_object.h" 25 //#include "vector.h" 25 26 26 27 // FORWARD DEFINITION \\ … … 28 29 class Quaternion; 29 30 class Vector; 31 template<class T> class tList; 30 32 31 33 //! enumeration for the different translation-binding-types … … 55 57 56 58 57 Vector getRelCoor ();59 Vector* getRelCoor (); 58 60 void setRelCoor (Vector* relCoord); 59 //void setRelCoor (Vector relCoord);61 void setRelCoor (Vector relCoord); 60 62 Vector getAbsCoor (); 61 63 void setAbsCoor (Vector* absCoord); 62 //void setAbsCoor (Vector absCoord);64 void setAbsCoor (Vector absCoord); 63 65 void shiftCoor (Vector* shift); 66 void shiftCoor (Vector shift); 64 67 //void shiftCoor (Vector shift); 65 68 66 69 Quaternion getRelDir (); 67 70 void setRelDir (Quaternion* relDir); 71 void setRelDir (Quaternion relDir); 68 72 Quaternion getAbsDir (); 69 73 void setAbsDir (Quaternion* absDir); 74 void setAbsDir (Quaternion absDir); 70 75 void shiftDir (Quaternion* shift); 76 void shiftDir (Quaternion shift); 77 78 float getSpeed(); 71 79 72 80 void addChild (PNode* pNode); … … 82 90 int getMode(); 83 91 84 virtual void update ( );92 virtual void update (float dt); 85 93 void processTick (float dt); 86 94 … … 90 98 91 99 void debug (); 92 93 private:94 void init(PNode* parent);95 100 96 101 protected: … … 102 107 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 103 108 104 Vector relCoordinate; //!< coordinates relative to the parent105 Vector absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) )106 Quaternion relDirection; //!< direction relative to the parent107 Quaternion absDirection; //!< absolute direvtion in the world ( from (0,0,1) )109 Vector* relCoordinate; //!< coordinates relative to the parent 110 Vector* absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) 111 Quaternion* relDirection; //!< direction relative to the parent 112 Quaternion* absDirection; //!< absolute direvtion in the world ( from (0,0,1) ) 108 113 109 114 int mode; //!< the mode of the binding 110 115 116 private: 117 void init(PNode* parent); 118 119 Vector* lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 120 float time; //!< time since last update 111 121 }; 112 122
Note: See TracChangeset
for help on using the changeset viewer.