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