[3246] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
[3551] | 15 | co-programmer: |
---|
[3365] | 16 | |
---|
| 17 | \todo Smooth-Parent: delay, speed |
---|
[3246] | 18 | */ |
---|
| 19 | |
---|
[3590] | 20 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PNODE |
---|
[3246] | 21 | |
---|
| 22 | #include "p_node.h" |
---|
[3607] | 23 | #include "stdincl.h" |
---|
[3543] | 24 | |
---|
[3608] | 25 | #include "error.h" |
---|
| 26 | #include "debug.h" |
---|
| 27 | #include "list.h" |
---|
| 28 | #include "vector.h" |
---|
[3521] | 29 | #include "null_parent.h" |
---|
[3608] | 30 | |
---|
[3607] | 31 | //#include "vector.h" |
---|
| 32 | //#include "quaternion.h" |
---|
[3246] | 33 | |
---|
| 34 | using namespace std; |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | \brief standard constructor |
---|
| 39 | |
---|
| 40 | \todo this constructor is not jet implemented - do it |
---|
| 41 | */ |
---|
[3365] | 42 | PNode::PNode () |
---|
| 43 | { |
---|
[3552] | 44 | init(NULL); |
---|
[3529] | 45 | |
---|
| 46 | NullParent* np = NullParent::getInstance(); |
---|
| 47 | np->addChild(this); |
---|
[3365] | 48 | } |
---|
[3246] | 49 | |
---|
| 50 | |
---|
[3799] | 51 | |
---|
[3246] | 52 | /** |
---|
[3365] | 53 | \brief constructor with coodinates |
---|
[3450] | 54 | \param absCoordinate the Absolute coordinate of the Object |
---|
| 55 | \param parent The parent-node of this node. |
---|
[3365] | 56 | */ |
---|
[3809] | 57 | PNode::PNode (const Vector& absCoordinate, PNode* parent ) |
---|
[3365] | 58 | { |
---|
[3552] | 59 | this->init(parent); |
---|
[3365] | 60 | |
---|
[3809] | 61 | *this->absCoordinate = absCoordinate; |
---|
[3800] | 62 | |
---|
| 63 | __LIKELY_IF(parent != NULL) |
---|
| 64 | { |
---|
| 65 | *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor (); |
---|
| 66 | parent->addChild (this); |
---|
| 67 | } |
---|
[3554] | 68 | else |
---|
[3607] | 69 | this->relCoordinate = new Vector(0,0,0); |
---|
[3365] | 70 | } |
---|
| 71 | |
---|
| 72 | /** |
---|
[3246] | 73 | \brief standard deconstructor |
---|
| 74 | */ |
---|
[3365] | 75 | PNode::~PNode () |
---|
| 76 | { |
---|
[3804] | 77 | tIterator<PNode>* iterator = this->children->getIterator(); |
---|
| 78 | PNode* pn = iterator->nextElement(); |
---|
[3544] | 79 | while( pn != NULL) |
---|
| 80 | { |
---|
[3560] | 81 | delete pn; |
---|
[3804] | 82 | pn = iterator->nextElement(); |
---|
[3551] | 83 | } |
---|
[3804] | 84 | delete iterator; |
---|
[3544] | 85 | /* this deletes all children in the list */ |
---|
| 86 | delete this->children; |
---|
[3804] | 87 | this->parent = NULL; |
---|
| 88 | delete []this->objectName; |
---|
[3544] | 89 | |
---|
[3804] | 90 | delete this->relCoordinate; |
---|
| 91 | delete this->absCoordinate; |
---|
| 92 | delete this->relDirection; |
---|
| 93 | delete this->absDirection; |
---|
| 94 | delete this->lastAbsCoordinate; |
---|
| 95 | delete this->diffCoordinate; |
---|
[3365] | 96 | } |
---|
[3246] | 97 | |
---|
[3607] | 98 | |
---|
[3552] | 99 | void PNode::init(PNode* parent) |
---|
| 100 | { |
---|
| 101 | this->children = new tList<PNode>(); |
---|
| 102 | this->bRelCoorChanged = true; |
---|
| 103 | this->bAbsCoorChanged = false; |
---|
| 104 | this->bRelDirChanged = true; |
---|
| 105 | this->bAbsDirChanged = false; |
---|
| 106 | this->parent = parent; |
---|
| 107 | this->objectName = NULL; |
---|
[3607] | 108 | |
---|
| 109 | this->absCoordinate = new Vector(); |
---|
| 110 | this->relCoordinate = new Vector(); |
---|
| 111 | this->absDirection = new Quaternion(); |
---|
| 112 | this->relDirection = new Quaternion(); |
---|
[3644] | 113 | this->lastAbsCoordinate = new Vector(); |
---|
[3802] | 114 | this->diffCoordinate = new Vector(); |
---|
[3552] | 115 | } |
---|
[3365] | 116 | |
---|
| 117 | |
---|
[3531] | 118 | |
---|
[3365] | 119 | /** |
---|
| 120 | \brief get relative coordinates |
---|
| 121 | \returns relative coordinates to its parent |
---|
[3675] | 122 | |
---|
| 123 | the reference that is returned is a pointer to the real relCoor, so don't |
---|
| 124 | change it unless you realy know what you are doing. |
---|
[3365] | 125 | */ |
---|
[3804] | 126 | //Vector* PNode::getRelCoor () const |
---|
[3365] | 127 | |
---|
| 128 | |
---|
[3804] | 129 | |
---|
[3365] | 130 | /** |
---|
| 131 | \brief set relative coordinates |
---|
[3450] | 132 | \param relCoord relative coordinates to its parent |
---|
[3365] | 133 | |
---|
| 134 | it is very importand, that you use this function, if you want to update the |
---|
| 135 | relCoordinates. If you don't use this, the PNode won't recognize, that something |
---|
| 136 | has changed and won't update the children Nodes. |
---|
| 137 | */ |
---|
[3810] | 138 | /* |
---|
[3365] | 139 | void PNode::setRelCoor (Vector* relCoord) |
---|
| 140 | { |
---|
| 141 | this->bRelCoorChanged = true; |
---|
[3607] | 142 | *this->relCoordinate = *relCoord; |
---|
[3365] | 143 | } |
---|
[3810] | 144 | */ |
---|
[3365] | 145 | |
---|
| 146 | |
---|
| 147 | /** |
---|
[3675] | 148 | \brief set relative coordinates |
---|
| 149 | \param relCoord relative coordinates to its parent |
---|
| 150 | |
---|
| 151 | it is very importand, that you use this function, if you want to update the |
---|
| 152 | relCoordinates. If you don't use this, the PNode won't recognize, that something |
---|
| 153 | has changed and won't update the children Nodes. |
---|
| 154 | */ |
---|
[3810] | 155 | void PNode::setRelCoor (const Vector& relCoord) |
---|
[3675] | 156 | { |
---|
| 157 | this->bRelCoorChanged = true; |
---|
| 158 | *this->relCoordinate = relCoord; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | /** |
---|
[3365] | 163 | \brief get absolute coordinates |
---|
| 164 | \returns absolute coordinates from (0,0,0) |
---|
| 165 | */ |
---|
[3804] | 166 | //Vector PNode::getAbsCoor () const |
---|
[3365] | 167 | |
---|
| 168 | |
---|
| 169 | /** |
---|
[3450] | 170 | \param absCoord set absolute coordinate |
---|
[3365] | 171 | |
---|
| 172 | it is very importand, that you use this function, if you want to update the |
---|
| 173 | absCoordinates. If you don't use this, the PNode won't recognize, that something |
---|
| 174 | has changed and won't update the children Nodes. |
---|
| 175 | */ |
---|
[3809] | 176 | /* |
---|
[3365] | 177 | void PNode::setAbsCoor (Vector* absCoord) |
---|
| 178 | { |
---|
| 179 | this->bAbsCoorChanged = true; |
---|
[3607] | 180 | *this->absCoordinate = *absCoord; |
---|
[3365] | 181 | } |
---|
[3809] | 182 | */ |
---|
[3365] | 183 | |
---|
| 184 | |
---|
| 185 | /** |
---|
[3675] | 186 | \param absCoord set absolute coordinate |
---|
| 187 | |
---|
| 188 | it is very importand, that you use this function, if you want to update the |
---|
| 189 | absCoordinates. If you don't use this, the PNode won't recognize, that something |
---|
| 190 | has changed and won't update the children Nodes. |
---|
| 191 | */ |
---|
[3809] | 192 | void PNode::setAbsCoor (const Vector& absCoord) |
---|
[3675] | 193 | { |
---|
| 194 | this->bAbsCoorChanged = true; |
---|
| 195 | *this->absCoordinate = absCoord; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | /** |
---|
[3365] | 200 | \brief shift coordinate (abs and rel) |
---|
| 201 | \param shift vector |
---|
| 202 | |
---|
| 203 | this function shifts the current coordinates about the vector shift. this is |
---|
| 204 | usefull because from some place else you can: |
---|
| 205 | PNode* someNode = ...; |
---|
| 206 | Vector objectMovement = calculateShift(); |
---|
| 207 | someNode->shiftCoor(objectMovement); |
---|
| 208 | |
---|
| 209 | elsewhere you would have to: |
---|
| 210 | PNode* someNode = ...; |
---|
| 211 | Vector objectMovement = calculateShift(); |
---|
| 212 | Vector currentCoor = someNode->getRelCoor(); |
---|
| 213 | Vector newCoor = currentCoor + objectMovement; |
---|
| 214 | someNode->setRelCoor(newCoor); |
---|
| 215 | |
---|
| 216 | yea right... shorter... |
---|
| 217 | |
---|
| 218 | */ |
---|
| 219 | void PNode::shiftCoor (Vector* shift) |
---|
| 220 | { |
---|
[3800] | 221 | |
---|
| 222 | __UNLIKELY_IF( this->bAbsCoorChanged) |
---|
[3365] | 223 | { |
---|
[3607] | 224 | *this->absCoordinate = *this->absCoordinate + *shift; |
---|
[3365] | 225 | } |
---|
| 226 | else |
---|
| 227 | { |
---|
[3607] | 228 | *this->relCoordinate = *this->relCoordinate + *shift; |
---|
[3365] | 229 | this->bRelCoorChanged = true; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | /** |
---|
[3683] | 236 | \brief shift coordinate (abs and rel) |
---|
| 237 | \param shift vector |
---|
| 238 | |
---|
| 239 | this function shifts the current coordinates about the vector shift. this is |
---|
| 240 | usefull because from some place else you can: |
---|
| 241 | PNode* someNode = ...; |
---|
| 242 | Vector objectMovement = calculateShift(); |
---|
| 243 | someNode->shiftCoor(objectMovement); |
---|
| 244 | |
---|
| 245 | elsewhere you would have to: |
---|
| 246 | PNode* someNode = ...; |
---|
| 247 | Vector objectMovement = calculateShift(); |
---|
| 248 | Vector currentCoor = someNode->getRelCoor(); |
---|
| 249 | Vector newCoor = currentCoor + objectMovement; |
---|
| 250 | someNode->setRelCoor(newCoor); |
---|
| 251 | |
---|
| 252 | yea right... shorter... |
---|
| 253 | |
---|
| 254 | */ |
---|
[3809] | 255 | void PNode::shiftCoor (const Vector& shift) |
---|
[3683] | 256 | { |
---|
[3800] | 257 | |
---|
| 258 | __UNLIKELY_IF( this->bAbsCoorChanged) |
---|
[3683] | 259 | { |
---|
| 260 | *this->absCoordinate = *this->absCoordinate + shift; |
---|
| 261 | } |
---|
| 262 | else |
---|
| 263 | { |
---|
| 264 | *this->relCoordinate = *this->relCoordinate + shift; |
---|
| 265 | this->bRelCoorChanged = true; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | /** |
---|
[3365] | 272 | \brief get relative direction |
---|
| 273 | \returns relative direction to its parent |
---|
| 274 | */ |
---|
[3804] | 275 | //Quaternion* PNode::getRelDir () const |
---|
[3365] | 276 | |
---|
| 277 | |
---|
[3804] | 278 | |
---|
[3365] | 279 | /** |
---|
| 280 | \brief set relative direction |
---|
[3450] | 281 | \param relDir to its parent |
---|
[3365] | 282 | |
---|
| 283 | it is very importand, that you use this function, if you want to update the |
---|
| 284 | relDirection. If you don't use this, the PNode won't recognize, that something |
---|
| 285 | has changed and won't update the children Nodes. |
---|
| 286 | */ |
---|
[3810] | 287 | /* |
---|
[3365] | 288 | void PNode::setRelDir (Quaternion* relDir) |
---|
| 289 | { |
---|
| 290 | this->bRelCoorChanged = true; |
---|
[3607] | 291 | *this->relDirection = *relDir; |
---|
[3365] | 292 | } |
---|
[3810] | 293 | */ |
---|
[3365] | 294 | |
---|
| 295 | |
---|
[3810] | 296 | void PNode::setRelDir (const Quaternion& relDir) |
---|
[3675] | 297 | { |
---|
| 298 | this->bRelCoorChanged = true; |
---|
| 299 | *this->relDirection = relDir; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | |
---|
[3365] | 303 | /** |
---|
| 304 | \brief gets the absolute direction (0,0,1) |
---|
| 305 | \returns absolute coordinates |
---|
| 306 | */ |
---|
[3804] | 307 | //Quaternion PNode::getAbsDir () const |
---|
[3365] | 308 | |
---|
| 309 | |
---|
[3804] | 310 | |
---|
[3365] | 311 | /** |
---|
| 312 | \brief sets the absolute direction (0,0,1) |
---|
[3450] | 313 | \param absDir absolute coordinates |
---|
[3365] | 314 | |
---|
| 315 | it is very importand, that you use this function, if you want to update the |
---|
| 316 | absDirection. If you don't use this, the PNode won't recognize, that something |
---|
| 317 | has changed and won't update the children Nodes. |
---|
| 318 | */ |
---|
[3810] | 319 | /* |
---|
[3365] | 320 | void PNode::setAbsDir (Quaternion* absDir) |
---|
[3370] | 321 | { |
---|
| 322 | this->bAbsDirChanged = true; |
---|
[3607] | 323 | *this->absDirection = *absDir; |
---|
[3370] | 324 | } |
---|
[3810] | 325 | */ |
---|
[3365] | 326 | |
---|
| 327 | |
---|
[3675] | 328 | |
---|
[3365] | 329 | /** |
---|
[3675] | 330 | \brief sets the absolute direction (0,0,1) |
---|
| 331 | \param absDir absolute coordinates |
---|
| 332 | |
---|
| 333 | it is very importand, that you use this function, if you want to update the |
---|
| 334 | absDirection. If you don't use this, the PNode won't recognize, that something |
---|
| 335 | has changed and won't update the children Nodes. |
---|
| 336 | */ |
---|
[3810] | 337 | void PNode::setAbsDir (const Quaternion& absDir) |
---|
[3675] | 338 | { |
---|
| 339 | this->bAbsDirChanged = true; |
---|
| 340 | *this->absDirection = absDir; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | |
---|
| 344 | |
---|
| 345 | /** |
---|
[3365] | 346 | \brief shift coordinate (abs and rel) |
---|
| 347 | \param shift vector |
---|
| 348 | |
---|
| 349 | this function shifts the current coordinates about the vector shift. this is |
---|
| 350 | usefull because from some place else you can: |
---|
| 351 | PNode* someNode = ...; |
---|
| 352 | Quaternion objectMovement = calculateShift(); |
---|
| 353 | someNode->shiftCoor(objectMovement); |
---|
| 354 | |
---|
| 355 | elsewhere you would have to: |
---|
| 356 | PNode* someNode = ...; |
---|
| 357 | Quaternion objectMovement = calculateShift(); |
---|
| 358 | Quaternion currentCoor = someNode->getRelCoor(); |
---|
| 359 | Quaternion newCoor = currentCoor + objectMovement; |
---|
| 360 | someNode->setRelCoor(newCoor); |
---|
| 361 | |
---|
| 362 | yea right... shorter... |
---|
| 363 | |
---|
[3450] | 364 | \todo implement this |
---|
[3365] | 365 | */ |
---|
[3802] | 366 | void PNode::shiftDir (const Quaternion& shift) |
---|
| 367 | { |
---|
| 368 | this->bRelDirChanged = true; |
---|
| 369 | *this->relDirection = *this->relDirection * shift; |
---|
| 370 | } |
---|
[3365] | 371 | |
---|
[3644] | 372 | |
---|
[3365] | 373 | /** |
---|
[3683] | 374 | \brief shift coordinate (abs and rel) |
---|
| 375 | \param shift vector |
---|
| 376 | |
---|
| 377 | this function shifts the current coordinates about the vector shift. this is |
---|
| 378 | usefull because from some place else you can: |
---|
| 379 | PNode* someNode = ...; |
---|
| 380 | Quaternion objectMovement = calculateShift(); |
---|
| 381 | someNode->shiftCoor(objectMovement); |
---|
| 382 | |
---|
| 383 | elsewhere you would have to: |
---|
| 384 | PNode* someNode = ...; |
---|
| 385 | Quaternion objectMovement = calculateShift(); |
---|
| 386 | Quaternion currentCoor = someNode->getRelCoor(); |
---|
| 387 | Quaternion newCoor = currentCoor + objectMovement; |
---|
| 388 | someNode->setRelCoor(newCoor); |
---|
| 389 | |
---|
| 390 | yea right... shorter... |
---|
| 391 | |
---|
| 392 | \todo implement this |
---|
| 393 | */ |
---|
[3810] | 394 | /* |
---|
| 395 | void PNode::shiftDir (Quaternion* shift) |
---|
[3683] | 396 | {} |
---|
[3810] | 397 | */ |
---|
[3683] | 398 | |
---|
| 399 | |
---|
| 400 | /** |
---|
[3644] | 401 | \brief this calculates the current movement speed of the node |
---|
| 402 | */ |
---|
[3802] | 403 | float PNode::getSpeed() const |
---|
[3644] | 404 | { |
---|
[3800] | 405 | __UNLIKELY_IF( this->time == 0) |
---|
[3686] | 406 | return 1000; |
---|
[3802] | 407 | *this->diffCoordinate = *this->absCoordinate - *this->lastAbsCoordinate; |
---|
| 408 | return this->diffCoordinate->len() / this->time; |
---|
[3644] | 409 | } |
---|
| 410 | |
---|
| 411 | |
---|
| 412 | /** |
---|
[3365] | 413 | \brief adds a child and makes this node to a parent |
---|
[3450] | 414 | \param pNode child reference |
---|
| 415 | \param mode on which changes the child should also change ist state |
---|
[3365] | 416 | |
---|
| 417 | use this to add a child to this node. |
---|
| 418 | */ |
---|
[3565] | 419 | void PNode::addChild (PNode* pNode, int parentingMode) |
---|
[3365] | 420 | { |
---|
[3800] | 421 | |
---|
| 422 | __UNLIKELY_IF( pNode->parent != NULL) |
---|
[3521] | 423 | { |
---|
[3668] | 424 | PRINTF(3)("PNode::addChild() - reparenting node: removing it and adding it again\n"); |
---|
[3547] | 425 | pNode->parent->children->remove(pNode); |
---|
[3521] | 426 | } |
---|
[3565] | 427 | pNode->mode = parentingMode; |
---|
[3529] | 428 | pNode->parent = this; |
---|
| 429 | this->children->add(pNode); |
---|
[3365] | 430 | } |
---|
| 431 | |
---|
| 432 | |
---|
| 433 | /** |
---|
[3450] | 434 | \brief removes a child from the node |
---|
| 435 | \param pNode the child to remove from this pNode. |
---|
[3547] | 436 | |
---|
| 437 | Children from pNode will not be lost, they are referenced to NullPointer |
---|
[3365] | 438 | */ |
---|
| 439 | void PNode::removeChild (PNode* pNode) |
---|
| 440 | { |
---|
[3547] | 441 | pNode->remove(); |
---|
[3669] | 442 | this->children->remove (pNode); |
---|
[3521] | 443 | pNode->parent = NULL; |
---|
[3365] | 444 | } |
---|
| 445 | |
---|
| 446 | |
---|
| 447 | /** |
---|
[3537] | 448 | \brief remove this pnode from the tree and adds all following to NullParent |
---|
| 449 | |
---|
| 450 | this can be the case, if an entity in the world is been destroyed. |
---|
| 451 | */ |
---|
| 452 | void PNode::remove() |
---|
| 453 | { |
---|
[3662] | 454 | NullParent* nullParent = NullParent::getInstance(); |
---|
| 455 | |
---|
[3668] | 456 | tIterator<PNode>* iterator = this->children->getIterator(); |
---|
| 457 | PNode* pn = iterator->nextElement(); |
---|
| 458 | |
---|
[3537] | 459 | while( pn != NULL) |
---|
| 460 | { |
---|
[3662] | 461 | //this->children->remove(pn); |
---|
| 462 | nullParent->addChild(pn, pn->getMode()); |
---|
[3668] | 463 | pn = iterator->nextElement(); |
---|
[3537] | 464 | } |
---|
[3668] | 465 | delete iterator; |
---|
[3669] | 466 | this->parent->children->remove(this); |
---|
[3537] | 467 | } |
---|
| 468 | |
---|
| 469 | |
---|
| 470 | /** |
---|
[3365] | 471 | \brief sets the parent of this PNode |
---|
[3450] | 472 | \param parent the Parent to set |
---|
[3365] | 473 | */ |
---|
| 474 | void PNode::setParent (PNode* parent) |
---|
| 475 | { |
---|
[3511] | 476 | parent->addChild(this); |
---|
[3365] | 477 | } |
---|
| 478 | |
---|
[3535] | 479 | |
---|
[3365] | 480 | /** |
---|
| 481 | \brief set the mode of this parent manualy |
---|
[3450] | 482 | \param mode the mode of the bind-type. |
---|
[3365] | 483 | */ |
---|
[3565] | 484 | void PNode::setMode (int parentingMode) |
---|
[3365] | 485 | { |
---|
[3565] | 486 | this->mode = parentingMode; |
---|
[3365] | 487 | } |
---|
| 488 | |
---|
[3537] | 489 | |
---|
[3365] | 490 | /** |
---|
[3537] | 491 | \brief gets the mode of this parent manualy |
---|
| 492 | \return the mode of the bind-type. |
---|
| 493 | */ |
---|
[3565] | 494 | int PNode::getMode() |
---|
[3537] | 495 | { |
---|
| 496 | return this->mode; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | /** |
---|
[3365] | 500 | \brief has to be called, if the parent coordinate has changed |
---|
| 501 | |
---|
| 502 | normaly this will be done by the parent itself automaticaly. If you call this, you |
---|
| 503 | will force an update of the coordinated of the node. |
---|
| 504 | */ |
---|
| 505 | void PNode::parentCoorChanged () |
---|
| 506 | { |
---|
| 507 | this->bRelCoorChanged = true; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | |
---|
| 511 | /** |
---|
| 512 | \brief has to be called, if the parent direction has changed |
---|
| 513 | |
---|
| 514 | normaly this will be done by the parent itself automaticaly. If you call this, you |
---|
| 515 | will force an update of the direction of the node. |
---|
| 516 | */ |
---|
| 517 | void PNode::parentDirChanged () |
---|
| 518 | { |
---|
| 519 | this->bRelDirChanged = true; |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | |
---|
| 523 | /** |
---|
| 524 | \brief updates the absCoordinate/absDirection |
---|
[3450] | 525 | \param timeStamp The timestanp used for to look if calculations should be done |
---|
[3365] | 526 | |
---|
| 527 | this is used to go through the parent-tree to update all the absolute coordinates |
---|
| 528 | and directions. this update should be done by the engine, so you don't have to |
---|
| 529 | worry, normaly... |
---|
| 530 | */ |
---|
[3644] | 531 | void PNode::update (float dt) |
---|
[3365] | 532 | { |
---|
[3687] | 533 | *this->lastAbsCoordinate = *this->absCoordinate; |
---|
[3644] | 534 | this->time = dt; |
---|
[3617] | 535 | PRINTF(4)("PNode::update - %s - (%f, %f, %f)\n", this->objectName, this->absCoordinate->x, this->absCoordinate->y, this->absCoordinate->z); |
---|
[3800] | 536 | |
---|
| 537 | |
---|
| 538 | __LIKELY_IF( this->mode & PNODE_MOVEMENT) |
---|
[3565] | 539 | { |
---|
[3800] | 540 | __UNLIKELY_IF(this->bAbsCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) |
---|
[3365] | 541 | { |
---|
[3565] | 542 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
[3607] | 543 | *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor (); |
---|
[3365] | 544 | } |
---|
[3800] | 545 | __LIKELY_IF(this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) |
---|
| 546 | |
---|
[3365] | 547 | { |
---|
[3565] | 548 | /*this is bad style... must be deleted later - just for testing*/ |
---|
[3800] | 549 | |
---|
| 550 | /* |
---|
| 551 | __UNLIKELY_IF( this->parent == NULL) |
---|
[3365] | 552 | { |
---|
[3607] | 553 | *this->absCoordinate = *this->relCoordinate; |
---|
[3365] | 554 | } |
---|
[3800] | 555 | else */ |
---|
| 556 | *this->absCoordinate = parent->getAbsCoor() + *this->relCoordinate; /* update the current absCoordinate */ |
---|
[3534] | 557 | } |
---|
[3565] | 558 | } |
---|
| 559 | |
---|
| 560 | if( this->mode & PNODE_LOCAL_ROTATE) |
---|
| 561 | { |
---|
[3800] | 562 | __UNLIKELY_IF( this->bAbsDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) |
---|
[3534] | 563 | { |
---|
[3565] | 564 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
[3607] | 565 | *this->relDirection = *this->absDirection - parent->getAbsDir(); |
---|
[3534] | 566 | } |
---|
[3800] | 567 | else __LIKELY_IF( this->bRelDirChanged /*&& this->timeStamp != DataTank::timeStamp*/) |
---|
[3565] | 568 | { |
---|
| 569 | /* update the current absDirection - remember * means rotation around sth.*/ |
---|
[3607] | 570 | *this->absDirection = parent->getAbsDir() * *this->relDirection; |
---|
[3565] | 571 | } |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | if( this->mode & PNODE_ROTATE_MOVEMENT) |
---|
| 575 | { |
---|
[3800] | 576 | __UNLIKELY_IF( this->bAbsCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) |
---|
[3565] | 577 | { |
---|
| 578 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
[3607] | 579 | *this->relCoordinate = *this->absCoordinate - parent->getAbsCoor (); |
---|
[3565] | 580 | } |
---|
[3800] | 581 | else __LIKELY_IF( this->bRelCoorChanged /*&& this->timeStamp != DataTank::timeStamp*/) |
---|
[3565] | 582 | { |
---|
| 583 | /*this is bad style... must be deleted later - just for testing*/ |
---|
[3800] | 584 | /*if( this->parent == NULL) |
---|
[3607] | 585 | *this->absCoordinate = *this->relCoordinate; |
---|
[3800] | 586 | else*/ |
---|
| 587 | *this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(*this->relCoordinate); /* update the current absCoordinate */ |
---|
[3565] | 588 | } |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | |
---|
[3669] | 592 | tIterator<PNode>* iterator = this->children->getIterator(); |
---|
| 593 | //PNode* pn = this->children->enumerate(); |
---|
| 594 | PNode* pn = iterator->nextElement(); |
---|
[3365] | 595 | while( pn != NULL) |
---|
| 596 | { |
---|
| 597 | /* if this node has changed, make sure, that all children are updated also */ |
---|
[3800] | 598 | __LIKELY_IF( this->bRelCoorChanged || this->bAbsCoorChanged) |
---|
[3365] | 599 | pn->parentCoorChanged (); |
---|
[3800] | 600 | __LIKELY_IF( this->bRelDirChanged || this->bAbsDirChanged) |
---|
[3365] | 601 | pn->parentDirChanged (); |
---|
[3608] | 602 | |
---|
[3644] | 603 | pn->update(dt); |
---|
[3669] | 604 | //pn = this->children->nextElement(); |
---|
| 605 | pn = iterator->nextElement(); |
---|
[3365] | 606 | } |
---|
[3669] | 607 | delete iterator; |
---|
[3365] | 608 | |
---|
| 609 | this->timeStamp = timeStamp; |
---|
| 610 | this->bRelCoorChanged = false; |
---|
| 611 | this->bAbsCoorChanged = false; |
---|
| 612 | this->bRelDirChanged = false; |
---|
| 613 | this->bAbsDirChanged = false; |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | |
---|
[3450] | 617 | /** |
---|
[3365] | 618 | \brief tick |
---|
[3450] | 619 | \param dt time to tick |
---|
[3365] | 620 | */ |
---|
| 621 | void PNode::processTick (float dt) |
---|
| 622 | { |
---|
[3551] | 623 | //this->tick (dt); |
---|
[3365] | 624 | PNode* pn = this->children->enumerate(); |
---|
| 625 | while( pn != NULL) |
---|
| 626 | { |
---|
| 627 | pn->processTick (dt); |
---|
| 628 | pn = this->children->nextElement(); |
---|
| 629 | } |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | |
---|
[3450] | 633 | /** |
---|
| 634 | \brief displays some information about this pNode |
---|
| 635 | */ |
---|
[3365] | 636 | void PNode::debug() |
---|
| 637 | { |
---|
[3546] | 638 | PRINTF(2)("PNode::debug() - absCoord: (%f, %f, %f)\n", |
---|
[3607] | 639 | this->absCoordinate->x, |
---|
| 640 | this->absCoordinate->y, |
---|
| 641 | this->absCoordinate->z); |
---|
[3365] | 642 | } |
---|
| 643 | |
---|
| 644 | |
---|
[3450] | 645 | /** |
---|
[3365] | 646 | \brief set the name of the node |
---|
| 647 | |
---|
| 648 | for debug purposes realy usefull, not used to work properly |
---|
| 649 | */ |
---|
| 650 | void PNode::setName (char* newName) |
---|
| 651 | { |
---|
[3552] | 652 | this->objectName = new char[strlen(newName)+1]; |
---|
| 653 | strcpy(this->objectName,newName); |
---|
[3365] | 654 | } |
---|
| 655 | |
---|
| 656 | |
---|
[3450] | 657 | /** |
---|
[3365] | 658 | \brief gets the name of the node |
---|
| 659 | */ |
---|
| 660 | char* PNode::getName () |
---|
| 661 | { |
---|
| 662 | return this->objectName; |
---|
| 663 | } |
---|
[3521] | 664 | |
---|