Changeset 3605 in orxonox.OLD for orxonox/branches/levelloader/src/lib/coord
- Timestamp:
- Mar 18, 2005, 11:52:15 AM (20 years ago)
- Location:
- orxonox/branches/levelloader/src/lib/coord
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/levelloader/src/lib/coord/helper_parent.cc
r3499 r3605 39 39 \todo this deconstructor is not jet implemented - do it 40 40 */ 41 HelperParent::~HelperParent () {} 41 HelperParent::~HelperParent () 42 { 42 43 44 } -
orxonox/branches/levelloader/src/lib/coord/helper_parent.h
r3499 r3605 17 17 public: 18 18 HelperParent (); 19 ~HelperParent (); 20 19 virtual ~HelperParent (); 21 20 22 21 }; -
orxonox/branches/levelloader/src/lib/coord/null_parent.cc
r3499 r3605 16 16 */ 17 17 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_NULL_PARENT 18 19 19 20 #include "null_parent.h" … … 26 27 NullParent* NullParent::getInstance () 27 28 { 28 if( singletonRef == NULL)29 if(!singletonRef) 29 30 singletonRef = new NullParent (); 30 31 return singletonRef; … … 36 37 \todo this constructor is not jet implemented - do it 37 38 */ 38 NullParent::NullParent () 39 NullParent::NullParent () : PNode (new Vector(0,0,0), NULL) 39 40 { 41 PRINTF(4)("NullParent::NullParent() - making new NullParent, there can only be one..\n"); 40 42 this->parent = this; 41 this->mode = ALL; 43 this->mode = PNODE_ALL; 44 this->setName("NullParent"); 42 45 } 43 46 44 47 45 NullParent::NullParent (Vector* absCoordinate) 48 NullParent::NullParent (Vector* absCoordinate) : PNode (new Vector(0,0,0), NULL) 46 49 { 50 singletonRef = this; 47 51 this->parent = this; 48 this->mode = ALL;52 this->mode = PNODE_ALL; 49 53 this->absCoordinate = *absCoordinate; 54 this->setName("NullParent"); 50 55 } 51 56 … … 58 63 NullParent::~NullParent () 59 64 { 60 delete singletonRef;65 //delete singletonRef; 61 66 singletonRef = NULL; 62 67 } 63 64 65 66 68 67 69 /** … … 72 74 worry, normaly... 73 75 */ 74 void NullParent::update ( float timeStamp)76 void NullParent::update () 75 77 { 78 79 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 76 80 this->absCoordinate = this->relCoordinate; 77 81 this->absDirection = parent->getAbsDir () * this->relDirection; … … 85 89 if( this->bRelDirChanged || this->bAbsDirChanged) 86 90 pn->parentDirChanged (); 87 pn->update ( timeStamp);91 pn->update (); 88 92 pn = this->children->nextElement (); 89 93 } -
orxonox/branches/levelloader/src/lib/coord/null_parent.h
r3499 r3605 16 16 public: 17 17 static NullParent* getInstance (); 18 ~NullParent (); 19 20 static NullParent* singletonRef; 18 virtual ~NullParent (); 21 19 22 virtual void update (float timeStamp); 20 21 virtual void update (); 23 22 24 23 private: 25 24 NullParent (); 26 25 NullParent (Vector* absCoordinate); 26 static NullParent* singletonRef; 27 27 28 28 }; -
orxonox/branches/levelloader/src/lib/coord/p_node.cc
r3557 r3605 13 13 ### File Specific: 14 14 main-programmer: Patrick Boenzli 15 co-programmer: ... 16 17 \todo Null-Parent => center of the coord system - singleton 15 co-programmer: 16 18 17 \todo Smooth-Parent: delay, speed 19 \todo destroy the stuff again, delete... 20 */ 21 18 */ 19 20 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PNODE 22 21 23 22 #include "p_node.h" 24 23 24 #include "null_parent.h" 25 #include "vector.h" 25 26 26 27 using namespace std; … … 34 35 PNode::PNode () 35 36 { 36 this->children = new tList<PNode>(); 37 this->bRelCoorChanged = true; 38 this->bAbsCoorChanged = false; 39 this->bRelDirChanged = true; 40 this->bAbsDirChanged = false; 41 this->parent = NULL; 37 init(NULL); 38 39 NullParent* np = NullParent::getInstance(); 40 np->addChild(this); 42 41 this->objectName = NULL; 43 42 } … … 51 50 PNode::PNode (Vector* absCoordinate, PNode* parent ) 52 51 { 52 this->init(parent); 53 53 54 this->absCoordinate = *absCoordinate; 54 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 55 56 this->children = new tList<PNode>(); 57 this->bRelCoorChanged = true; 58 this->bAbsCoorChanged = false; 59 this->bRelDirChanged = true; 60 this->bAbsDirChanged = false; 61 this->parent = parent; 62 this->objectName = NULL; 63 64 parent->addChild (this); 65 } 66 55 if (parent != NULL) 56 { 57 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 58 parent->addChild (this); 59 } 60 else 61 this->relCoordinate = Vector(0,0,0); 62 } 67 63 68 64 /** … … 80 76 delete &this->absDirection; 81 77 */ 82 this->parent = NULL;78 //this->parent = NULL; 83 79 if( this->objectName) delete this->objectName; 84 80 /* there is currently a problem with cleaning up - fix*/ 85 } 86 81 82 PNode* pn = this->children->enumerate(); 83 while( pn != NULL) 84 { 85 delete pn; 86 pn = this->children->nextElement(); 87 88 } 89 90 /* this deletes all children in the list */ 91 delete this->children; 92 93 delete []this->objectName; 94 } 95 96 void PNode::init(PNode* parent) 97 { 98 this->children = new tList<PNode>(); 99 this->bRelCoorChanged = true; 100 this->bAbsCoorChanged = false; 101 this->bRelDirChanged = true; 102 this->bAbsDirChanged = false; 103 this->parent = parent; 104 this->objectName = NULL; 105 } 87 106 88 107 /** … … 91 110 cleans up all pnodes 92 111 */ 112 /* 93 113 void PNode::destroy () 94 114 { … … 99 119 pn = this->children->nextElement(); 100 120 } 121 // this deletes all children in the list 101 122 this->children->destroy (); 102 } 103 123 124 static_cast<BaseObject*>(this)->destroy(); 125 } 126 */ 104 127 105 128 /** … … 262 285 {} 263 286 264 265 266 287 /** 267 288 \brief adds a child and makes this node to a parent … … 283 304 use this to add a child to this node. 284 305 */ 285 void PNode::addChild (PNode* pNode, parentingMode mode) 286 { 287 pNode->mode = mode; 306 void PNode::addChild (PNode* pNode, int parentingMode) 307 { 308 if( pNode->parent != NULL ) 309 { 310 PRINTF(2)("PNode::addChild() - reparenting node: removing it and adding it again\n"); 311 pNode->parent->children->remove(pNode); 312 } 313 pNode->mode = parentingMode; 288 314 pNode->parent = this; 289 this->children->add 315 this->children->add(pNode); 290 316 } 291 317 … … 294 320 \brief removes a child from the node 295 321 \param pNode the child to remove from this pNode. 322 323 Children from pNode will not be lost, they are referenced to NullPointer 296 324 */ 297 325 void PNode::removeChild (PNode* pNode) 298 326 { 327 pNode->remove(); 299 328 this->children->remove (pNode); 329 pNode->parent = NULL; 330 } 331 332 333 /** 334 \brief remove this pnode from the tree and adds all following to NullParent 335 336 this can be the case, if an entity in the world is been destroyed. 337 */ 338 void PNode::remove() 339 { 340 NullParent* np = NullParent::getInstance(); 341 PNode* pn = this->children->enumerate(); 342 while( pn != NULL) 343 { 344 this->children->remove(pn); 345 np->addChild(pn, pn->getMode()); 346 pn = this->children->nextElement(); 347 } 300 348 } 301 349 … … 307 355 void PNode::setParent (PNode* parent) 308 356 { 309 this->parent = parent; 310 } 357 parent->addChild(this); 358 } 359 311 360 312 361 /** … … 314 363 \param mode the mode of the bind-type. 315 364 */ 316 void PNode::setMode (parentingMode mode) 317 { 318 this->mode = mode; 365 void PNode::setMode (int parentingMode) 366 { 367 this->mode = parentingMode; 368 } 369 370 371 /** 372 \brief gets the mode of this parent manualy 373 \return the mode of the bind-type. 374 */ 375 int PNode::getMode() 376 { 377 return this->mode; 319 378 } 320 379 … … 351 410 worry, normaly... 352 411 */ 353 void PNode::update (float timeStamp) 354 { 355 printf ("PNode::update - %s - (%f, %f, %f)\n", this->objectName, this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 356 357 if( this->mode == MOVEMENT || this->mode == ALL) 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); 416 if(this->mode & PNODE_MOVEMENT ) 417 { 418 if( this->bAbsCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 358 419 { 359 if( this->bAbsCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 420 /* if you have set the absolute coordinates this overrides all other changes */ 421 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 422 } 423 else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 424 { 425 /*this is bad style... must be deleted later - just for testing*/ 426 if( this->parent == NULL) 360 427 { 361 printf("PNode::update () - this->bAbsCoorChanged = true\n"); 362 /* if you have set the absolute coordinates this overrides all other changes */ 363 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 428 this->absCoordinate = this->relCoordinate; 364 429 } 365 else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 366 { 367 /*this is bad style... must be deleted later - just for testing*/ 368 if( this->parent == NULL) 369 { 370 this->absCoordinate = this->relCoordinate; 371 } 372 else 373 this->absCoordinate = parent->getAbsCoor () + this->relCoordinate; /* update the current absCoordinate */ 374 } 430 else 431 this->absCoordinate = parent->getAbsCoor() + this->relCoordinate; /* update the current absCoordinate */ 375 432 } 376 377 if( this->mode == ROTATION && this->mode == ALL) 433 } 434 435 if( this->mode & PNODE_LOCAL_ROTATE) 436 { 437 if( this->bAbsDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) 378 438 { 379 if( this->bAbsDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) 380 { 381 /* if you have set the absolute coordinates this overrides all other changes */ 382 this->relDirection = this->absDirection - parent->getAbsDir (); 383 } 384 else if( this->bRelDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) 385 { 386 /* update the current absDirection - remember * means rotation around sth.*/ 387 this->absDirection = parent->getAbsDir () * this->relDirection; 388 } 389 } 390 // } 439 /* if you have set the absolute coordinates this overrides all other changes */ 440 this->relDirection = this->absDirection - parent->getAbsDir(); 441 } 442 else if( this->bRelDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) 443 { 444 /* update the current absDirection - remember * means rotation around sth.*/ 445 this->absDirection = parent->getAbsDir() * this->relDirection; 446 } 447 } 448 449 if( this->mode & PNODE_ROTATE_MOVEMENT) 450 { 451 if( this->bAbsCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 452 { 453 /* if you have set the absolute coordinates this overrides all other changes */ 454 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 455 } 456 else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 457 { 458 /*this is bad style... must be deleted later - just for testing*/ 459 if( this->parent == NULL) 460 this->absCoordinate = this->relCoordinate; 461 else 462 this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); /* update the current absCoordinate */ 463 } 464 } 465 466 391 467 PNode* pn = this->children->enumerate(); 392 468 while( pn != NULL) … … 397 473 if( this->bRelDirChanged || this->bAbsDirChanged) 398 474 pn->parentDirChanged (); 399 pn->update( timeStamp);475 pn->update(); 400 476 pn = this->children->nextElement(); 401 477 } … … 415 491 void PNode::processTick (float dt) 416 492 { 417 this->tick (dt);493 //this->tick (dt); 418 494 PNode* pn = this->children->enumerate(); 419 495 while( pn != NULL) … … 424 500 } 425 501 426 /**427 \param dt time to tick428 */429 void PNode::tick (float dt)430 {}431 502 432 503 /** … … 435 506 void PNode::debug() 436 507 { 437 printf("PNode::debug() - absCoord: (%f, %f, %f)\n",508 PRINTF(2)("PNode::debug() - absCoord: (%f, %f, %f)\n", 438 509 this->absCoordinate.x, 439 510 this->absCoordinate.y, … … 451 522 void PNode::setName (const char* newName) 452 523 { 453 int l = strlen( newName); 454 455 if( this->objectName != NULL) delete this->objectName; 456 this->objectName = NULL; 457 458 if( newName != NULL) 459 { 460 this->objectName = new char[l+1]; 461 462 for( int i = 0; i < l+1; i++) 463 this->objectName[i] = newName[i]; 464 } 524 if (this->objectName) 525 delete []this->objectName; 526 this->objectName = new char[strlen(newName)+1]; 527 strcpy(this->objectName,newName); 465 528 } 466 529 … … 473 536 return this->objectName; 474 537 } 538 -
orxonox/branches/levelloader/src/lib/coord/p_node.h
r3557 r3605 22 22 #define _P_NODE_H 23 23 24 #include " stdincl.h"24 #include "base_object.h" 25 25 26 // FORWARD DEFINITION \\ 26 27 class PNode; /* forward decleration, so that parentEntry has access to PNode */ 28 class Quaternion; 29 class Vector; 27 30 28 31 //! enumeration for the different translation-binding-types 29 typedef enum parentingMode {MOVEMENT = 0, ROTATION, ALL}; 32 //typedef enum parentingMode {PNODE_LOCAL_ROTATE, PNODE_ROTATE_MOVEMENT, PNODE_ALL, PNODE_MOVEMENT, PNODE_ROTATE_AND_MOVE}; 33 // linkage modes 34 #define PNODE_LOCAL_ROTATE 1 //!< Rotates all the children around their centers. 35 #define PNODE_ROTATE_MOVEMENT 2 //!< Moves all the children around the center of their parent, without the rotation around their own centers. 36 #define PNODE_MOVEMENT 4 //!< Moves all children along with the parent. 37 // special linkage modes 38 #define PNODE_ALL 3 //!< Moves all children around the center of their parent, and also rotates their centers 39 #define PNODE_ROTATE_AND_MOVE 5 //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent. 40 30 41 //! The default mode of the translation-binding. 31 #define DEFAULT_MODE ALL42 #define DEFAULT_MODE PNODE_ALL 32 43 33 44 //! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent. … … 39 50 virtual ~PNode (); 40 51 41 void destroy ();42 43 52 PNode* parent; //!< a pointer to the parent node 44 53 tList<PNode>* children; //!< list of the children 45 54 46 parentingMode mode; //!< the mode of the binding 55 47 56 48 57 Vector getRelCoor (); … … 62 71 63 72 void addChild (PNode* pNode); 64 void addChild (PNode* pNode, parentingMode mode);73 void addChild (PNode* pNode, int parentingMode); 65 74 void removeChild (PNode* pNode); 75 void remove(); 76 77 66 78 void setParent (PNode* parent); 67 79 void parentCoorChanged (); 68 80 void parentDirChanged (); 69 void setMode (parentingMode mode); 81 void setMode (int parentingMode); 82 int getMode(); 70 83 71 virtual void update ( float timeStamp);84 virtual void update (); 72 85 void processTick (float dt); 73 virtual void tick (float dt);74 86 75 87 void setName (const char* newName); … … 79 91 void debug (); 80 92 93 private: 94 void init(PNode* parent); 95 96 protected: 81 97 float timeStamp; //!< this the timeStamp of when the abs{Coordinat, Direction} has been calculated 82 98 char* objectName; //!< The name of the Object … … 91 107 Quaternion absDirection; //!< absolute direvtion in the world ( from (0,0,1) ) 92 108 109 int mode; //!< the mode of the binding 110 93 111 }; 94 112 95 113 #endif /* _P_NODE_H */ 114
Note: See TracChangeset
for help on using the changeset viewer.