Changeset 6054 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Dec 11, 2005, 6:23:42 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r6048 r6054 22 22 #include "class_list.h" 23 23 24 #include "stdincl.h"25 24 #include "compiler.h" 26 #include "error.h"27 25 #include "debug.h" 28 #include "vector.h" 29 26 27 #include "glincl.h" 30 28 #include "color.h" 31 29 … … 86 84 PNode::~PNode () 87 85 { 88 // remove the Node, delete it's children. 89 PNode* tmp; 90 while (this->children.size() > 0) 91 { 92 tmp = this->children.front(); 93 this->children.pop_front(); 94 delete tmp; 86 // remove the Node, delete it's children (if required). 87 std::list<PNode*>::iterator tmp = this->children.begin(); 88 std::list<PNode*>::iterator deleteNode; 89 while (tmp != this->children.end()) 90 { 91 deleteNode = tmp++; 92 if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT) ) 93 (*deleteNode)->reparent(); 94 else 95 delete (*deleteNode); 95 96 } 96 97 if (this->parent != NULL) … … 120 121 this->parent = parent; 121 122 this->parentMode = PNODE_PARENT_MODE_DEFAULT; 122 123 // iterators 123 this->bActive = true; 124 125 // smooth-movers 124 126 this->toCoordinate = NULL; 125 127 this->toDirection = NULL; … … 269 271 this->setAbsCoor(Vector(x, y, z)); 270 272 } 273 271 274 272 275 /** … … 321 324 } 322 325 326 323 327 /** 324 328 * @brief set relative direction … … 336 340 this->bRelCoorChanged = true; 337 341 } 342 338 343 339 344 /** … … 366 371 } 367 372 373 368 374 /** 369 375 * @see void PNode::setRelDirSoft (const Quaternion& relDir) … … 379 385 } 380 386 387 381 388 /** 382 389 * @brief sets the absolute direction … … 399 406 } 400 407 408 401 409 /** 402 410 * @see void PNode::setAbsDir (const Quaternion& relDir) … … 412 420 } 413 421 422 414 423 /** 415 424 * @brief sets the absolute direction … … 430 439 this->bRelDirChanged = true; 431 440 } 441 432 442 433 443 /** … … 491 501 * @param child the child to remove from this pNode. 492 502 * 493 * Children from pNode will not be lost, they are referenced to NullPointer503 * Children from pNode will not be lost, they are Reparented by the rules of the ParentMode 494 504 */ 495 505 void PNode::removeChild (PNode* child) … … 503 513 } 504 514 515 505 516 /** 506 517 * @brief remove this pnode from the tree and adds all following to NullParent … … 510 521 void PNode::removeNode() 511 522 { 512 list<PNode*>::iterator child; 513 for (child = this->children.begin(); child != this->children.end(); child ++) 514 NullParent::getInstance()->addChild(*child); 515 523 if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE) 524 { 525 list<PNode*>::iterator child = this->children.begin(); 526 list<PNode*>::iterator reparenter; 527 while (child != this->children.end()) 528 { 529 reparenter = child++; 530 (*reparenter)->reparent(); 531 } 532 } 516 533 if (this->parent != NULL) 517 534 this->parent->children.remove(this); … … 529 546 parentNode->addChild(this); 530 547 } 548 531 549 532 550 /** … … 568 586 } 569 587 588 570 589 /** 571 590 * @brief does the reparenting in a very smooth way … … 580 599 } 581 600 601 /** 602 * @param parentMode sets the parentingMode of this Node 603 */ 604 void PNode::setParentMode(PARENT_MODE parentMode) 605 { 606 this->parentMode &= (0xfff0 | parentMode); 607 } 582 608 583 609 /** … … 589 615 this->setParentMode(PNode::charToParentingMode(parentingMode)); 590 616 } 617 618 619 /** 620 * !!PRIVATE FUNCTION: 621 * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.) 622 */ 623 void PNode::reparent() 624 { 625 if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT) 626 this->setParent(NullParent::getInstance()); 627 else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL) 628 this->setParent(this->parent->getParent()); 629 } 630 631 void PNode::addNodeModeFlags(unsigned short nodeFlags) 632 { 633 this->parentMode |= nodeFlags; 634 } 635 636 637 void PNode::removeNodeModeFlags(unsigned short nodeFlags) 638 { 639 this->parentMode &= !nodeFlags; 640 } 641 591 642 592 643 /** … … 602 653 if( likely(this->parent != NULL)) 603 654 { 604 // movement for nodes with smoothMove enabled 605 if (unlikely(this->toCoordinate != NULL)) 655 if (!(this->parentMode & PNODE_STATIC_NODE)) 606 656 { 607 Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias;608 if ( likely(moveVect.len() >= PNODE_ITERATION_DELTA))657 // movement for nodes with smoothMove enabled 658 if (unlikely(this->toCoordinate != NULL)) 609 659 { 610 this->shiftCoor(moveVect); 660 Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias; 661 if (likely(moveVect.len() >= PNODE_ITERATION_DELTA)) 662 { 663 this->shiftCoor(moveVect); 664 } 665 else 666 { 667 delete this->toCoordinate; 668 this->toCoordinate = NULL; 669 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 670 } 611 671 } 612 else672 if (unlikely(this->toDirection != NULL)) 613 673 { 614 delete this->toCoordinate; 615 this->toCoordinate = NULL; 616 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 674 Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias); 675 if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA) 676 { 677 this->relDirection = rotQuat; 678 this->bRelDirChanged; 679 } 680 else 681 { 682 delete this->toDirection; 683 this->toDirection = NULL; 684 PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); 685 } 686 } 687 688 // MAIN UPDATE ///////////////////////////////////// 689 this->lastAbsCoordinate = this->absCoordinate; 690 691 PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 692 693 694 if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged) 695 { 696 /* update the current absDirection - remember * means rotation around sth.*/ 697 this->prevRelCoordinate = this->relCoordinate; 698 this->absDirection = this->relDirection * parent->getAbsDir();; 699 } 700 701 if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged)) 702 { 703 /* update the current absCoordinate */ 704 this->prevRelCoordinate = this->relCoordinate; 705 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; 706 } 707 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged) 708 { 709 /* update the current absCoordinate */ 710 this->prevRelCoordinate = this->relCoordinate; 711 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); 712 } 713 ///////////////////////////////////////////////// 714 } 715 } 716 else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT 717 { 718 if (!(this->parentMode & PNODE_STATIC_NODE)) 719 { 720 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 721 if (this->bRelCoorChanged) 722 { 723 this->prevRelCoordinate = this->relCoordinate; 724 this->absCoordinate = this->relCoordinate; 725 } 726 if (this->bRelDirChanged) 727 { 728 this->prevRelDirection = this->relDirection; 729 this->absDirection = this->getAbsDir () * this->relDirection; 617 730 } 618 731 } 619 if (unlikely(this->toDirection != NULL))620 {621 Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias);622 if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA)623 {624 this->relDirection = rotQuat;625 this->bRelDirChanged;626 }627 else628 {629 delete this->toDirection;630 this->toDirection = NULL;631 PRINTF(5)("SmoothRotate of %s finished\n", this->getName());632 }633 }634 635 // MAIN UPDATE /////////////////////////////////////636 this->lastAbsCoordinate = this->absCoordinate;637 638 PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);639 640 641 if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)642 {643 /* update the current absDirection - remember * means rotation around sth.*/644 this->prevRelCoordinate = this->relCoordinate;645 this->absDirection = this->relDirection * parent->getAbsDir();;646 }647 648 if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))649 {650 /* update the current absCoordinate */651 this->prevRelCoordinate = this->relCoordinate;652 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;653 }654 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)655 {656 /* update the current absCoordinate */657 this->prevRelCoordinate = this->relCoordinate;658 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);659 }660 /////////////////////////////////////////////////661 }662 else663 {664 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);665 if (this->bRelCoorChanged)666 {667 this->prevRelCoordinate = this->relCoordinate;668 this->absCoordinate = this->relCoordinate;669 }670 if (this->bRelDirChanged)671 {672 this->prevRelDirection = this->relDirection;673 this->absDirection = this->getAbsDir () * this->relDirection;674 }675 732 } 676 733 677 if(!this->children.empty() )734 if(!this->children.empty() && (this->bActive || this->parentMode & PNODE_UPDATE_CHILDREN_IF_INACTIVE )) 678 735 { 679 736 list<PNode*>::iterator child; -
trunk/src/lib/coord/p_node.h
r6048 r6054 28 28 29 29 #define PNODE_ITERATION_DELTA .001 30 30 31 //! Parental linkage modes 31 32 typedef enum … … 45 46 PNODE_REPARENT_TO_PARENTS_PARENT = 0x0020, //!< Reparents the Node to the parents (old) parent it the parent gets removed. 46 47 PNODE_REPARENT_DELETE_CHILDREN = 0x0040, //!< Deletes the Children of the node when This Node is Removed. (Use with care). 47 PNODE_REPARENT_KEEP_POSITION = 0x0080, //!< Tries to keep the Position if the Node is reparented. 48 /// FIXME 49 PNODE_REPARENT_KEEP_POSITION = 0x0080, //!< Tries to keep the Position if the Node is reparented. 48 50 49 51 … … 51 53 PNODE_PROHIBIT_CHILD_DELETE = 0x0100, //!< Prohibits the Children from being deleted if this Node gets deleted. 52 54 PNODE_PROHIBIT_DELETE_WITH_PARENT = 0x0200, //!< Prohibits the Node to be deleted if the Parent is. Child will be reparented according to the Repaenting-Rules 53 PNODE_REPARENT_CHILDREN_ON_DELETE = 0x0400, //!< Reparents the Children of the Node to 54 PNODE_REPARANT_CHILDREN_ON_REMOVE = 0x0800, //!< Reparents the Children of the Node if the Node gets Removed. 55 PNODE_REPARENT_CHILDREN_ON_REMOVE = 0x0400, //!< Reparents the Children of the Node if the Node gets Removed. 55 56 56 57 // VISIBILITY/ACTIVITY … … 64 65 //! The default mode of the translation-binding. 65 66 #define PNODE_PARENT_MODE_DEFAULT PNODE_ALL | \ 67 PNODE_REPARENT_CHILDREN_ON_REMOVE | \ 66 68 PNODE_REPARENT_KEEP_POSITION 67 69 … … 77 79 78 80 void loadParams(const TiXmlElement* root); 81 82 inline void activateNode() { this->bActive = true; }; 83 inline void deactivateNode() { this->bActive = false; }; 84 inline bool getNodeActiveState() { return this->bActive; }; 79 85 80 86 void setRelCoor (const Vector& relCoord); … … 132 138 void removeNode(); 133 139 134 /** @param the new parent of this node */140 /** @param parent the new parent of this node */ 135 141 inline void setParent (PNode* parent) { parent->addChild(this); }; 136 142 void setParent (const char* parentName); … … 143 149 void setParentSoft(const char* parentName, float bias = 1.0); 144 150 145 /** @param parentMode sets the parentingMode of this Node */ 146 void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; }; 151 void setParentMode (PARENT_MODE parentMode); 147 152 void setParentMode (const char* parentingMode); 148 153 /** @returns the Parenting mode of this node */ 149 int getParentMode() const { return this->parentMode; }; 154 int getParentMode() const { return 0x000f & this->parentMode; }; 155 156 void addNodeModeFlags(unsigned short nodeFlags); 157 void removeNodeModeFlags(unsigned short nodeFlags); 158 150 159 151 160 void updateNode (float dt); -
trunk/src/lib/event/event_handler.cc
r5978 r6054 258 258 void EventHandler::grabEvents(bool grabEvents) 259 259 { 260 261 262 263 264 SDL_WM_GrabInput(SDL_GRAB_ON);260 this->eventsGrabbed = grabEvents; 261 if(!grabEvents) 262 SDL_WM_GrabInput(SDL_GRAB_OFF); 263 else 264 SDL_WM_GrabInput(SDL_GRAB_ON); 265 265 } 266 266 … … 364 364 { 365 365 printf("Not sending event to the WindowManager\n"); 366 367 EventHandler::getInstance()->grabEvents(false); 366 368 return 0; 367 369 } -
trunk/src/lib/event/event_handler.h
r5978 r6054 44 44 void withUNICODE(bool enableUNICODE); 45 45 void grabEvents(bool grabEvents); 46 bool grabbedEvents() const { return this->eventsGrabbed; }; 46 47 47 48 void process(); … … 52 53 private: 53 54 EventHandler(); 54 55 55 56 56 private:
Note: See TracChangeset
for help on using the changeset viewer.