Changeset 3605 in orxonox.OLD for orxonox/branches/levelloader/src/lib/coord/p_node.cc
- Timestamp:
- Mar 18, 2005, 11:52:15 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.