Changeset 3265 in orxonox.OLD for orxonox/branches/parenting/src/p_node.cc
- Timestamp:
- Dec 24, 2004, 1:45:15 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/parenting/src/p_node.cc
r3249 r3265 14 14 main-programmer: Patrick Boenzli 15 15 co-programmer: ... 16 17 \todo Null-Parent => center of the coord system - singleton 18 \todo Smooth-Parent: delay, speed 16 19 */ 17 20 … … 31 34 { 32 35 this->children = new tList<PNode>(); 33 this->bCoorChanged = true; 34 this->bDirChanged = true; 36 this->bRelCoorChanged = true; 37 this->bAbsCoorChanged = false; 38 this->bRelDirChanged = true; 39 this->bAbsDirChanged = false; 40 this->parent = NULL; 41 } 42 43 44 /** 45 \brief constructor with coodinates 46 */ 47 PNode::PNode (Vector* absCoordinate, PNode* parent ) 48 { 49 this->absCoordinate = *absCoordinate; 50 this->relCoordinate = this->absCoordinate - this->parent->getAbsCoor (); 51 52 53 this->children = new tList<PNode>(); 54 this->bRelCoorChanged = false; 55 this->bAbsCoorChanged = true; 56 this->bRelDirChanged = true; 57 this->bAbsDirChanged = false; 58 this->parent = parent; 59 60 parent->addChild (this); 35 61 } 36 62 … … 68 94 */ 69 95 void PNode::setRelCoor (Vector relCoord) 70 {} 96 { 97 this->bRelCoorChanged = true; 98 this->relCoordinate = relCoord; 99 } 71 100 72 101 … … 76 105 */ 77 106 Vector PNode::getAbsCoor () 78 {} 107 { 108 return this->absCoordinate; 109 } 79 110 80 111 … … 88 119 */ 89 120 void PNode::setAbsCoor (Vector absCoord) 90 {} 121 { 122 this->bAbsCoorChanged = true; 123 this->absCoordinate = absCoord; 124 } 91 125 92 126 … … 111 145 112 146 */ 113 void PNode::shiftCoor (Vector shift) 114 {} 147 void PNode::shiftCoor (Vector* shift) 148 { 149 if( this->bAbsCoorChanged) 150 { 151 this->absCoordinate = this->absCoordinate + *shift; 152 } 153 else 154 { 155 this->relCoordinate = this->relCoordinate + *shift; 156 this->bRelCoorChanged = true; 157 } 158 159 printf("PNode::shiftCoor() - relCoord: (%f, %f, %f)\n", 160 this->relCoordinate.x, 161 this->relCoordinate.y, 162 this->relCoordinate.z); 163 } 115 164 116 165 … … 121 170 */ 122 171 Quaternion PNode::getRelDir () 123 {} 172 { 173 return this->relDirection; 174 } 124 175 125 176 … … 133 184 */ 134 185 void PNode::setRelDir (Quaternion relDir) 135 {} 186 { 187 this->bRelCoorChanged = true; 188 this->relDirection = relDir; 189 } 136 190 137 191 … … 176 230 177 231 */ 178 void PNode::shiftDir (Quaternion shift)232 void PNode::shiftDir (Quaternion* shift) 179 233 {} 180 234 … … 203 257 { 204 258 pNode->mode = mode; 259 pNode->parent = this; 205 260 this->children->add (pNode); 206 261 } … … 222 277 { 223 278 this->parent = parent; 279 } 280 281 /** 282 \brief set the mode of this parent manualy 283 */ 284 void PNode::setMode (parentingMode mode) 285 { 286 this->mode = mode; 287 } 288 289 /** 290 \brief has to be called, if the parent coordinate has changed 291 292 normaly this will be done by the parent itself automaticaly. If you call this, you 293 will force an update of the coordinated of the node. 294 */ 295 void PNode::parentCoorChanged () 296 { 297 this->bRelCoorChanged = true; 298 } 299 300 301 /** 302 \brief has to be called, if the parent direction has changed 303 304 normaly this will be done by the parent itself automaticaly. If you call this, you 305 will force an update of the direction of the node. 306 */ 307 void PNode::parentDirChanged () 308 { 309 this->bRelDirChanged = true; 224 310 } 225 311 … … 232 318 worry, normaly... 233 319 */ 234 void PNode::update(long timeStamp) 235 { 236 if(this->parent == NULL) 237 printf("PNode::upate(long timeStamp) - parent is NULL..."); 238 if( this->bCoorChanged && this->timeStamp != DataTank::timeStamp) 239 { 240 /* update the current absCoordinate */ 241 this->absCoordinate = parent->getAbsCoor () + this->relCoordinate; 242 } 243 if( this->bDirChanged && this->timeStamp != DataTank::timeStamp) 244 { 245 /* update the current absDirection - remember * means rotation around sth.*/ 246 this->absDirection = parent->getAbsDir () * this->relDirection; 247 } 248 320 void PNode::update (long timeStamp) 321 { 322 printf("PNode::update() \n"); 323 //if( this->parent != NULL) 324 // { 325 326 if( this->mode == MOVEMENT || this->mode == ALL) 327 { 328 if( this->bAbsCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 329 { 330 /* if you have set the absolute coordinates this overrides all other changes */ 331 this->relCoordinate = this->absCoordinate - parent->getAbsCoor (); 332 } 333 else if( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) 334 { 335 printf("PNode::update() - inside: before: absCoord: (%f, %f, %f)\n", 336 this->absCoordinate.x, 337 this->absCoordinate.y, 338 this->absCoordinate.z); 339 printf("PNode::update() - inside: before: relCoord: (%f, %f, %f)\n", 340 this->relCoordinate.x, 341 this->relCoordinate.y, 342 this->relCoordinate.z); 343 /*this is bad style... must be deleted later - just for testing*/ 344 if( this->parent == NULL) 345 { 346 this->absCoordinate = this->relCoordinate; 347 printf("PNode::update() - insinde: NULL NULL NULL\n"); 348 } 349 else 350 this->absCoordinate = parent->getAbsCoor () + this->relCoordinate; /* update the current absCoordinate */ 351 printf("PNode::update() - inside after: absCoord: (%f, %f, %f)\n", 352 this->absCoordinate.x, 353 this->absCoordinate.y, 354 this->absCoordinate.z); 355 printf("PNode::update() - inside after: relCoord: (%f, %f, %f)\n", 356 this->relCoordinate.x, 357 this->relCoordinate.y, 358 this->relCoordinate.z); 359 } 360 } 361 362 if( this->mode == ROTATION && this->mode == ALL) 363 { 364 if( this->bAbsDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) 365 { 366 /* if you have set the absolute coordinates this overrides all other changes */ 367 this->relDirection = this->absDirection - parent->getAbsDir (); 368 } 369 else if( this->bRelDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) 370 { 371 /* update the current absDirection - remember * means rotation around sth.*/ 372 this->absDirection = parent->getAbsDir () * this->relDirection; 373 } 374 } 375 // } 249 376 PNode* pn = this->children->enumerate(); 250 377 while( pn != NULL) 251 378 { 379 /* if this node has changed, make sure, that all children are updated also */ 380 if( this->bRelCoorChanged || this->bAbsCoorChanged) 381 pn->parentCoorChanged (); 382 if( this->bRelDirChanged || this->bAbsDirChanged) 383 pn->parentDirChanged (); 252 384 pn->update(timeStamp); 253 385 pn = this->children->nextElement(); … … 255 387 256 388 this->timeStamp = timeStamp; 257 this->bCoorChanged = false; 258 this->bDirChanged = false; 259 260 } 261 389 this->bRelCoorChanged = false; 390 this->bAbsCoorChanged = false; 391 this->bRelDirChanged = false; 392 this->bAbsDirChanged = false; 393 } 394 395 396 void PNode::debug() 397 { 398 printf("PNode::debug() - absCoord: (%f, %f, %f)\n", 399 this->absCoordinate.x, 400 this->absCoordinate.y, 401 this->absCoordinate.z); 402 }
Note: See TracChangeset
for help on using the changeset viewer.