Changeset 4993 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Aug 13, 2005, 11:56:31 AM (19 years ago)
- Location:
- orxonox/trunk/src/lib/coord
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/coord/p_node.cc
r4992 r4993 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 60 58 } 61 59 62 63 60 /** 64 61 * constructor with coodinates … … 66 63 * @param parent The parent-node of this node. 67 64 */ 68 PNode::PNode (const Vector& absCoor dinate, PNode* parent )65 PNode::PNode (const Vector& absCoor, PNode* parent ) 69 66 { 70 67 this->init(parent); 71 68 72 this->absCoordinate = absCoordinate;73 74 69 if (likely(parent != NULL)) 75 {76 this->relCoordinate = this->absCoordinate - parent->getAbsCoor();77 70 parent->addChild (this); 78 } 71 72 this->setAbsCoor(absCoor); 79 73 } 80 74 … … 107 101 this->children = new tList<PNode>(); 108 102 this->bRelCoorChanged = true; 109 this->bAbsCoorChanged = false;110 103 this->bRelDirChanged = true; 111 this->bAbsDirChanged = false;112 104 this->parent = parent; 113 105 114 this->toPosition = NULL; 106 // iterators 107 this->toCoordinate = NULL; 115 108 this->toDirection = NULL; 116 109 this->bias = 1.0; … … 167 160 void PNode::setRelCoor (const Vector& relCoord) 168 161 { 162 this->relCoordinate = relCoord; 169 163 this->bRelCoorChanged = true; 170 this->relCoordinate = relCoord;171 164 } 172 165 … … 176 169 * @param y y-relative coordinates to its parent 177 170 * @param z z-relative coordinates to its parent 178 \see void PNode::setRelCoor (const Vector& relCoord)171 * @see void PNode::setRelCoor (const Vector& relCoord) 179 172 */ 180 173 void PNode::setRelCoor (float x, float y, float z) … … 190 183 void PNode::setRelCoorSoft(const Vector& relCoordSoft, float bias) 191 184 { 192 if (likely(this->to Position== NULL))193 this->to Position= new Vector();194 195 *this->to Position= relCoordSoft;185 if (likely(this->toCoordinate == NULL)) 186 this->toCoordinate = new Vector(); 187 188 *this->toCoordinate = relCoordSoft; 196 189 this->bias = bias; 197 190 } … … 203 196 * @param y y-relative coordinates to its parent 204 197 * @param z z-relative coordinates to its parent 205 \see void PNode::setRelCoorSoft (const Vector&, float)198 * @see void PNode::setRelCoorSoft (const Vector&, float) 206 199 */ 207 200 void PNode::setRelCoorSoft (float x, float y, float z, float bias) … … 219 212 void PNode::setAbsCoor (const Vector& absCoord) 220 213 { 221 this->bAbsCoorChanged = true; 222 this->absCoordinate = absCoord; 214 if( likely(this->parentMode & PNODE_MOVEMENT)) 215 { 216 /* if you have set the absolute coordinates this overrides all other changes */ 217 if (likely(this->parent != NULL)) 218 this->relCoordinate = absCoord - parent->getAbsCoor (); 219 else 220 this->relCoordinate = absCoord; 221 } 222 if( this->parentMode & PNODE_ROTATE_MOVEMENT) 223 { 224 if (likely(this->parent != NULL)) 225 this->relCoordinate = absCoord - parent->getAbsCoor (); 226 else 227 this->relCoordinate = absCoord; 228 } 229 230 this->bRelCoorChanged = true; 231 // this->absCoordinate = absCoord; 223 232 } 224 233 … … 259 268 void PNode::shiftCoor (const Vector& shift) 260 269 { 261 262 if( unlikely(this->bAbsCoorChanged)) 263 { 264 this->absCoordinate += shift; 265 } 266 else 267 { 268 this->relCoordinate += shift; 269 this->bRelCoorChanged = true; 270 } 270 this->relCoordinate += shift; 271 this->bRelCoorChanged = true; 271 272 } 272 273 … … 281 282 void PNode::setRelDir (const Quaternion& relDir) 282 283 { 284 this->relDirection = relDir; 283 285 this->bRelCoorChanged = true; 284 this->relDirection = relDir;285 286 } 286 287 … … 334 335 absDirection. If you don't use this, the PNode won't recognize, that something 335 336 has changed and won't update the children Nodes. 337 * 338 * FIXME ERROR HERE THIS IS IMPLEMENTED FALSELY 339 * @todo FIXME 336 340 */ 337 341 void PNode::setAbsDir (const Quaternion& absDir) 338 342 { 339 this->bAbsDirChanged = true; 340 this->absDirection = absDir; 343 // if (this->parent) 344 this->relDirection = absDir;// - parent->getAbsDir(); 345 // else 346 // this->relDirection = absDir; 347 348 this->bRelDirChanged = true; 349 // this->absDirection = absDir; 341 350 } 342 351 … … 357 366 * shift coordinate (abs and rel) 358 367 * @param shift vector 359 360 this function shifts the current coordinates about the vector shift. this is 361 usefull because from some place else you can: 362 PNode* someNode = ...; 363 Quaternion objectMovement = calculateShift(); 364 someNode->shiftCoor(objectMovement); 365 366 elsewhere you would have to: 367 PNode* someNode = ...; 368 Quaternion objectMovement = calculateShift(); 369 Quaternion currentCoor = someNode->getRelCoor(); 370 Quaternion newCoor = currentCoor + objectMovement; 371 someNode->setRelCoor(newCoor); 372 373 yea right... shorter... 374 375 @todo implement this 368 * @todo implement this 376 369 */ 377 370 void PNode::shiftDir (const Quaternion& shift) 378 371 { 372 this->relDirection = this->relDirection * shift; 379 373 this->bRelDirChanged = true; 380 this->relDirection = this->relDirection * shift;381 374 } 382 375 … … 385 378 * @param pNode child reference 386 379 * @param parentMode on which changes the child should also change ist state 387 388 389 */ 390 void PNode::addChild (PNode* pNode, int parentMode)391 { 392 if( likely( pNode->parent != NULL))380 * 381 * use this to add a child to this node. 382 */ 383 void PNode::addChild (PNode* child, int parentMode) 384 { 385 if( likely(child->parent != NULL)) 393 386 { 394 387 PRINTF(4)("PNode::addChild() - reparenting node: removing it and adding it again\n"); 395 pNode->parent->children->remove(pNode);388 child->parent->children->remove(child); 396 389 } 397 pNode->parentMode = parentMode; 398 pNode->parent = this; 399 this->children->add(pNode); 390 child->parentMode = parentMode; 391 child->parent = this; 392 this->children->add(child); 393 child->parentCoorChanged(); 400 394 } 401 395 … … 411 405 } 412 406 413 414 407 /** 415 408 * removes a child from the node 416 409 * @param pNode the child to remove from this pNode. 417 418 Children from pNode will not be lost, they are referenced to NullPointer 419 */ 420 void PNode::removeChild (PNode* pNode) 421 { 422 pNode->remove(); 423 this->children->remove (pNode); 424 pNode->parent = NULL; 425 } 426 410 * 411 * Children from pNode will not be lost, they are referenced to NullPointer 412 */ 413 void PNode::removeChild (PNode* child) 414 { 415 child->remove(); 416 this->children->remove(child); 417 child->parent = NULL; 418 } 427 419 428 420 /** … … 447 439 } 448 440 449 450 /** 451 * sets the parent of this PNode 441 /** 442 * sets the parent of this PNode 452 443 * @param parent the Parent to set 453 444 */ … … 471 462 * does the reparenting in a very smooth way 472 463 * @param parentNode the new Node to connect this node to. 464 * @param bias the speed to iterate to this new Positions 473 465 */ 474 466 void PNode::softReparent(PNode* parentNode, float bias) … … 477 469 return; 478 470 479 //this->setRelCoorSoft(this->getRelCoor()); 480 if (likely(this->toPosition == NULL)) 471 if (likely(this->toCoordinate == NULL)) 481 472 { 482 this->to Position= new Vector();483 *this->to Position= this->getRelCoor();473 this->toCoordinate = new Vector(); 474 *this->toCoordinate = this->getRelCoor(); 484 475 } 485 476 if (likely(this->toDirection == NULL)) … … 504 495 } 505 496 497 /** 498 * does the reparenting in a very smooth way 499 * @param parentName the name of the Parent to reconnect to 500 * @param bias the speed to iterate to this new Positions 501 */ 506 502 void PNode::softReparent(const char* parentName, float bias) 507 503 { … … 511 507 } 512 508 513 514 /**515 * set the mode of this parent manualy516 * @param parentMode the mode of the bind-type.517 */518 void PNode::setParentMode (PARENT_MODE parentMode)519 {520 this->parentMode = parentMode;521 }522 523 509 /** 524 510 * sets the mode of this parent manually … … 527 513 void PNode::setParentMode (const char* parentingMode) 528 514 { 529 if (!strcmp(parentingMode, "local-rotate")) 530 this->setParentMode(PNODE_LOCAL_ROTATE); 531 else if (!strcmp(parentingMode, "rotate-movement")) 532 this->setParentMode(PNODE_ROTATE_MOVEMENT); 533 else if (!strcmp(parentingMode, "movement")) 534 this->setParentMode(PNODE_MOVEMENT); 535 else if (!strcmp(parentingMode, "all")) 536 this->setParentMode(PNODE_ALL); 537 else if (!strcmp(parentingMode, "rotate-and-move")) 538 this->setParentMode(PNODE_ROTATE_AND_MOVE); 539 } 540 541 542 /** 543 * has to be called, if the parent coordinate has changed 544 545 normaly this will be done by the parent itself automaticaly. If you call this, you 546 will force an update of the coordinated of the node. 547 */ 548 /* 549 void PNode::parentCoorChanged () 550 { 551 this->bRelCoorChanged = true; 552 } 553 */ 515 this->setParentMode(PNode::charToParentingMode(parentingMode)); 516 } 554 517 555 518 /** … … 566 529 { 567 530 // movement for nodes with smoothMove enabled 568 if (unlikely(this->to Position!= NULL))531 if (unlikely(this->toCoordinate != NULL)) 569 532 { 570 Vector moveVect = (*this->to Position- this->getRelCoor()) *dt*bias;533 Vector moveVect = (*this->toCoordinate - this->getRelCoor()) *dt*bias; 571 534 572 535 if (likely(moveVect.len() >= .001)) … … 576 539 else 577 540 { 578 delete this->to Position;579 this->to Position= NULL;541 delete this->toCoordinate; 542 this->toCoordinate = NULL; 580 543 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 581 544 } … … 591 554 /* else 592 555 { 593 delete this->to Position;594 this->to Position= NULL;556 delete this->toCoordinate; 557 this->toCoordinate = NULL; 595 558 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 596 559 }*/ 597 560 } 598 561 562 // MAIN UPDATE ///////////////////////////////////// 599 563 this->lastAbsCoordinate = this->absCoordinate; 600 564 601 565 PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 602 566 603 if( likely(this->parentMode & PNODE_MOVEMENT)) 604 { 605 if( unlikely(this->bAbsCoorChanged)) 606 { 607 /* if you have set the absolute coordinates this overrides all other changes */ 608 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 609 } 610 if( likely(this->bRelCoorChanged)) 611 { 612 /* update the current absCoordinate */ 613 this->absCoordinate = parent->getAbsCoor() + this->relCoordinate; 614 } 615 } 616 617 if( this->parentMode & PNODE_LOCAL_ROTATE) 618 { 619 if( unlikely(this->bAbsDirChanged)) 620 { 621 /* if you have set the absolute coordinates this overrides all other changes */ 622 this->relDirection = this->absDirection - parent->getAbsDir(); 623 } 624 else if( likely(this->bRelDirChanged)) 625 { 626 /* update the current absDirection - remember * means rotation around sth.*/ 627 this->absDirection = parent->getAbsDir() * this->relDirection; 628 } 629 } 567 if(likely(this->parentMode & PNODE_MOVEMENT)) 568 { 569 /* update the current absCoordinate */ 570 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; 571 } 572 573 if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged) 574 { 575 /* update the current absDirection - remember * means rotation around sth.*/ 576 this->absDirection = parent->getAbsDir() * this->relDirection; 577 } 630 578 631 579 if( this->parentMode & PNODE_ROTATE_MOVEMENT) 632 { 633 if( unlikely(this->bAbsCoorChanged)) 634 { 635 /* if you have set the absolute coordinates this overrides all other changes */ 636 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 637 } 638 else if( likely(this->bRelCoorChanged)) 639 { 640 /* update the current absCoordinate */ 641 this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); 642 } 643 } 644 645 646 tIterator<PNode>* iterator = this->children->getIterator(); 647 PNode* pn = iterator->nextElement(); 648 while( pn != NULL) 649 { 650 /* if this node has changed, make sure, that all children are updated also */ 651 if( likely(this->bRelCoorChanged || this->bAbsCoorChanged)) 652 pn->parentCoorChanged (); 653 if( likely(this->bRelDirChanged || this->bAbsDirChanged)) 654 pn->parentDirChanged (); 655 656 pn->update(dt); 657 //pn = this->children->nextElement(); 658 pn = iterator->nextElement(); 659 } 660 delete iterator; 661 662 this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; 663 this->bRelCoorChanged = false; 664 this->bAbsCoorChanged = false; 665 this->bRelDirChanged = false; 666 this->bAbsDirChanged = false; 667 } 580 { 581 /* update the current absCoordinate */ 582 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); 583 } 584 ///////////////////////////////////////////////// 585 } 668 586 else 669 587 { 670 588 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 671 this->absCoordinate = this->relCoordinate; 672 this->absDirection = this->getAbsDir () * this->relDirection; 673 589 if (this->bRelCoorChanged) 590 this->absCoordinate = this->relCoordinate; 591 if (this->bRelDirChanged) 592 this->absDirection = this->getAbsDir () * this->relDirection; 593 } 594 595 if(this->children->getSize() > 0) 596 { 674 597 tIterator<PNode>* iterator = this->children->getIterator(); 675 //PNode* pn = this->children->enumerate ();676 598 PNode* pn = iterator->nextElement(); 677 599 while( pn != NULL) 678 600 { 679 601 /* if this node has changed, make sure, that all children are updated also */ 680 if( this->bRelCoorChanged || this->bAbsCoorChanged) 681 pn->parentCoorChanged (); 682 if( this->bRelDirChanged || this->bAbsDirChanged) 683 pn->parentDirChanged (); 684 pn->update (dt); 685 //pn = this->children->nextElement (); 686 pn = iterator->nextElement(); 687 } 602 if( likely(this->bRelCoorChanged)) 603 pn->parentCoorChanged (); 604 if( likely(this->bRelDirChanged)) 605 pn->parentDirChanged (); 606 607 pn->update(dt); 608 //pn = this->children->nextElement(); 609 pn = iterator->nextElement(); 610 } 688 611 delete iterator; 689 this->bRelCoorChanged = false;690 this->bAbsCoorChanged = false;691 this->bRelDirChanged = false;692 this->bAbsDirChanged = false;693 612 } 613 this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; 614 this->bRelCoorChanged = false; 615 this->bRelDirChanged = false; 694 616 } 695 617 … … 708 630 else 709 631 PRINT(0)(" -"); 710 PRINT(0)("PNode(%s::%s) - absCoord: (%0.2f, %0.2f, %0.2f), relCoord(%0.2f, %0.2f, %0.2f) \n",632 PRINT(0)("PNode(%s::%s) - absCoord: (%0.2f, %0.2f, %0.2f), relCoord(%0.2f, %0.2f, %0.2f) - %s\n", 711 633 this->getClassName(), 712 634 this->getName(), … … 716 638 this->relCoordinate.x, 717 639 this->relCoordinate.y, 718 this->relCoordinate.z ); 640 this->relCoordinate.z, 641 this->parentingModeToChar(parentMode)); 719 642 if (depth >= 2 || depth == 0) 720 643 { … … 777 700 glPopMatrix(); 778 701 } 702 703 704 705 ///////////////////// 706 // HELPER_FUCTIONS // 707 ///////////////////// 708 709 /** 710 * converts a parentingMode into a string that is the name of it 711 * @param parentingMode the ParentingMode to convert 712 * @return the converted string 713 */ 714 const char* PNode::parentingModeToChar(int parentingMode) 715 { 716 if (parentingMode == PNODE_LOCAL_ROTATE) 717 return "local-rotate"; 718 else if (parentingMode == PNODE_ROTATE_MOVEMENT) 719 return "rotate-movement"; 720 else if (parentingMode == PNODE_MOVEMENT) 721 return "movement"; 722 else if (parentingMode == PNODE_ALL) 723 return "all"; 724 else if (parentingMode == PNODE_ROTATE_AND_MOVE) 725 return "rotate-and-move"; 726 } 727 728 /** 729 * converts a parenting-mode-string into a int 730 * @param parentingMode the string naming the parentingMode 731 * @return the int corresponding to the named parentingMode 732 */ 733 PARENT_MODE PNode::charToParentingMode(const char* parentingMode) 734 { 735 if (!strcmp(parentingMode, "local-rotate")) 736 return (PNODE_LOCAL_ROTATE); 737 else if (!strcmp(parentingMode, "rotate-movement")) 738 return (PNODE_ROTATE_MOVEMENT); 739 else if (!strcmp(parentingMode, "movement")) 740 return (PNODE_MOVEMENT); 741 else if (!strcmp(parentingMode, "all")) 742 return (PNODE_ALL); 743 else if (!strcmp(parentingMode, "rotate-and-move")) 744 return (PNODE_ROTATE_AND_MOVE); 745 } -
orxonox/trunk/src/lib/coord/p_node.h
r4992 r4993 1 1 /*! 2 \file p_node.h2 @file p_node.h 3 3 * Definition of a parenting node 4 4 … … 55 55 PNode (); 56 56 PNode(const TiXmlElement* root); 57 PNode (const Vector& absCoor dinate, PNode* pNode);57 PNode (const Vector& absCoor, PNode* pNode); 58 58 virtual ~PNode (); 59 59 … … 89 89 90 90 /** @returns the Speed of the Node */ 91 inline float getSpeed() const { return this->velocity.len();}91 inline float getSpeed() const { return this->velocity.len(); }; 92 92 /** @returns the Velocity of the Node */ 93 inline const Vector& getVelocity() const { return this->velocity;}93 inline const Vector& getVelocity() const { return this->velocity; }; 94 94 95 95 96 void addChild (PNode* pNode, int parentingMode = DEFAULT_MODE);96 void addChild (PNode* child, int parentingMode = DEFAULT_MODE); 97 97 void addChild (const char* childName); 98 void removeChild (PNode* pNode);98 void removeChild (PNode* child); 99 99 void remove(); 100 100 … … 107 107 void softReparent(const char* parentName, float bias = 1.0); 108 108 109 void setParentMode (PARENT_MODE parentMode); 109 /** @param parentMode sets the parentingMode of this Node */ 110 void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; }; 110 111 void setParentMode (const char* parentingMode); 111 112 /** @returns the Parenting mode of this node */ … … 117 118 void debugDraw(float size = 1.0) const; 118 119 120 121 // helper functions // 122 static const char* parentingModeToChar(int parentingMode); 123 static PARENT_MODE charToParentingMode(const char* parentingMode); 119 124 private: 120 125 void init(PNode* parent); … … 124 129 inline void parentDirChanged () { this->bRelDirChanged = true; } 125 130 /** @returns the last calculated coordinate */ 126 inline Vector getLastAbsCoor() { return this->lastAbsCoordinate;}131 inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; } 127 132 128 133 129 134 private: 130 bool bAbsCoorChanged; //!< If Absolute Coordinate has changed since last time we checked131 135 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 132 bool bAbsDirChanged; //!< If Absolute Direction has changed since last time we checked133 136 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 134 137 … … 142 145 143 146 144 Vector* to Position;//!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)147 Vector* toCoordinate; //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft) 145 148 Quaternion* toDirection; //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft) 146 149 float bias; //!< how fast to iterate to the given position (default is 1)
Note: See TracChangeset
for help on using the changeset viewer.