[4570] | 1 | /* |
---|
[3246] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
[5419] | 13 | co-programmer: Benjamin Grauer |
---|
[3246] | 14 | */ |
---|
| 15 | |
---|
[3590] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PNODE |
---|
[3246] | 17 | |
---|
| 18 | #include "p_node.h" |
---|
[4761] | 19 | #include "null_parent.h" |
---|
| 20 | |
---|
| 21 | #include "load_param.h" |
---|
| 22 | #include "class_list.h" |
---|
| 23 | |
---|
[3860] | 24 | #include "compiler.h" |
---|
[3608] | 25 | #include "debug.h" |
---|
| 26 | |
---|
[6054] | 27 | #include "glincl.h" |
---|
[5406] | 28 | #include "color.h" |
---|
[3246] | 29 | |
---|
| 30 | using namespace std; |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | /** |
---|
[6048] | 34 | * @brief standard constructor |
---|
[5420] | 35 | */ |
---|
[4570] | 36 | PNode::PNode () |
---|
[3365] | 37 | { |
---|
[3552] | 38 | init(NULL); |
---|
[3529] | 39 | |
---|
[4436] | 40 | NullParent::getInstance()->addChild(this); |
---|
[3365] | 41 | } |
---|
[3246] | 42 | |
---|
[4448] | 43 | /** |
---|
[4836] | 44 | * @param root the load-Element for the PNode |
---|
[5420] | 45 | */ |
---|
[4436] | 46 | PNode::PNode(const TiXmlElement* root) |
---|
| 47 | { |
---|
| 48 | this->init(NULL); |
---|
[4444] | 49 | this->loadParams(root); |
---|
[4570] | 50 | |
---|
[5372] | 51 | if (this->parent == NULL) |
---|
| 52 | NullParent::getInstance()->addChild(this); |
---|
[4436] | 53 | } |
---|
[3246] | 54 | |
---|
| 55 | /** |
---|
[6048] | 56 | * @brief constructor with coodinates |
---|
[4836] | 57 | * @param absCoordinate the Absolute coordinate of the Object |
---|
| 58 | * @param parent The parent-node of this node. |
---|
[5420] | 59 | */ |
---|
[4993] | 60 | PNode::PNode (const Vector& absCoor, PNode* parent ) |
---|
[3365] | 61 | { |
---|
[3552] | 62 | this->init(parent); |
---|
[3365] | 63 | |
---|
[3860] | 64 | if (likely(parent != NULL)) |
---|
[3800] | 65 | parent->addChild (this); |
---|
[4993] | 66 | |
---|
| 67 | this->setAbsCoor(absCoor); |
---|
[3365] | 68 | } |
---|
| 69 | |
---|
| 70 | /** |
---|
[6048] | 71 | * @brief standard deconstructor |
---|
[5296] | 72 | * |
---|
| 73 | * There are two general ways to delete a PNode |
---|
| 74 | * 1. delete instance; |
---|
| 75 | * -> result |
---|
| 76 | * delete this Node and all its children and children's children... |
---|
| 77 | * (danger if you still need the children's instance somewhere else!!) |
---|
| 78 | * |
---|
| 79 | * 2. instance->remove2D(); delete instance; |
---|
| 80 | * -> result: |
---|
| 81 | * moves its children to the NullParent |
---|
| 82 | * then deletes the Element. |
---|
| 83 | */ |
---|
[4570] | 84 | PNode::~PNode () |
---|
[3365] | 85 | { |
---|
[6054] | 86 | // remove the Node, delete it's children (if required). |
---|
| 87 | std::list<PNode*>::iterator tmp = this->children.begin(); |
---|
| 88 | std::list<PNode*>::iterator deleteNode; |
---|
| 89 | while (tmp != this->children.end()) |
---|
[5214] | 90 | { |
---|
[6054] | 91 | deleteNode = tmp++; |
---|
| 92 | if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT) ) |
---|
| 93 | (*deleteNode)->reparent(); |
---|
| 94 | else |
---|
| 95 | delete (*deleteNode); |
---|
[5214] | 96 | } |
---|
[5296] | 97 | if (this->parent != NULL) |
---|
[5770] | 98 | { |
---|
| 99 | this->parent->children.remove(this); |
---|
| 100 | this->parent = NULL; |
---|
| 101 | } |
---|
[5296] | 102 | |
---|
| 103 | // remove all other allocated memory. |
---|
[5088] | 104 | if (this->toCoordinate != NULL) |
---|
| 105 | delete this->toCoordinate; |
---|
| 106 | if (this->toDirection != NULL) |
---|
| 107 | delete this->toDirection; |
---|
[3365] | 108 | } |
---|
[3246] | 109 | |
---|
[5296] | 110 | |
---|
[4448] | 111 | /** |
---|
[6048] | 112 | * @brief initializes a PNode |
---|
[4836] | 113 | * @param parent the parent for this PNode |
---|
[5420] | 114 | */ |
---|
[3552] | 115 | void PNode::init(PNode* parent) |
---|
| 116 | { |
---|
[4742] | 117 | this->setClassID(CL_PARENT_NODE, "PNode"); |
---|
[5211] | 118 | |
---|
[3552] | 119 | this->bRelCoorChanged = true; |
---|
| 120 | this->bRelDirChanged = true; |
---|
[4570] | 121 | this->parent = parent; |
---|
[5209] | 122 | this->parentMode = PNODE_PARENT_MODE_DEFAULT; |
---|
[6054] | 123 | this->bActive = true; |
---|
[4987] | 124 | |
---|
[6054] | 125 | // smooth-movers |
---|
[4993] | 126 | this->toCoordinate = NULL; |
---|
[4990] | 127 | this->toDirection = NULL; |
---|
[4992] | 128 | this->bias = 1.0; |
---|
[3552] | 129 | } |
---|
[3365] | 130 | |
---|
[4448] | 131 | /** |
---|
[6048] | 132 | * @brief loads parameters of the PNode |
---|
[4836] | 133 | * @param root the XML-element to load the properties of |
---|
[5420] | 134 | */ |
---|
[4436] | 135 | void PNode::loadParams(const TiXmlElement* root) |
---|
| 136 | { |
---|
| 137 | static_cast<BaseObject*>(this)->loadParams(root); |
---|
[4610] | 138 | |
---|
[5671] | 139 | LoadParam(root, "rel-coor", this, PNode, setRelCoor) |
---|
[4771] | 140 | .describe("Sets The relative position of the Node to its parent."); |
---|
| 141 | |
---|
[5671] | 142 | LoadParam(root, "abs-coor", this, PNode, setAbsCoor) |
---|
[4610] | 143 | .describe("Sets The absolute Position of the Node."); |
---|
| 144 | |
---|
[5671] | 145 | LoadParam(root, "rel-dir", this, PNode, setRelDir) |
---|
[4771] | 146 | .describe("Sets The relative rotation of the Node to its parent."); |
---|
[4761] | 147 | |
---|
[5671] | 148 | LoadParam(root, "abs-dir", this, PNode, setAbsDir) |
---|
[4771] | 149 | .describe("Sets The absolute rotation of the Node."); |
---|
| 150 | |
---|
[5671] | 151 | LoadParam(root, "parent", this, PNode, setParent) |
---|
[4761] | 152 | .describe("the Name of the Parent of this PNode"); |
---|
[4765] | 153 | |
---|
[5671] | 154 | LoadParam(root, "parent-mode", this, PNode, setParentMode) |
---|
[4765] | 155 | .describe("the mode to connect this node to its parent ()"); |
---|
| 156 | |
---|
| 157 | // cycling properties |
---|
[4785] | 158 | if (root != NULL) |
---|
[4765] | 159 | { |
---|
[5654] | 160 | LOAD_PARAM_START_CYCLE(root, element); |
---|
[4785] | 161 | { |
---|
[5654] | 162 | LoadParam_CYCLE(element, "parent", this, PNode, addChild) |
---|
[4785] | 163 | .describe("adds a new Child to the current Node."); |
---|
[4765] | 164 | |
---|
[4785] | 165 | } |
---|
[5654] | 166 | LOAD_PARAM_END_CYCLE(element); |
---|
[4765] | 167 | } |
---|
[4436] | 168 | } |
---|
[3365] | 169 | |
---|
| 170 | /** |
---|
[6048] | 171 | * @brief set relative coordinates |
---|
[4836] | 172 | * @param relCoord relative coordinates to its parent |
---|
[5420] | 173 | * |
---|
| 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 | */ |
---|
[3810] | 179 | void PNode::setRelCoor (const Vector& relCoord) |
---|
[3675] | 180 | { |
---|
[5113] | 181 | if (this->toCoordinate!= NULL) |
---|
| 182 | { |
---|
| 183 | delete this->toCoordinate; |
---|
| 184 | this->toCoordinate = NULL; |
---|
| 185 | } |
---|
| 186 | |
---|
[4993] | 187 | this->relCoordinate = relCoord; |
---|
[3675] | 188 | this->bRelCoorChanged = true; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | /** |
---|
[6048] | 192 | * @brief set relative coordinates |
---|
[4836] | 193 | * @param x x-relative coordinates to its parent |
---|
| 194 | * @param y y-relative coordinates to its parent |
---|
| 195 | * @param z z-relative coordinates to its parent |
---|
[4993] | 196 | * @see void PNode::setRelCoor (const Vector& relCoord) |
---|
[5420] | 197 | */ |
---|
[4610] | 198 | void PNode::setRelCoor (float x, float y, float z) |
---|
| 199 | { |
---|
| 200 | this->setRelCoor(Vector(x, y, z)); |
---|
| 201 | } |
---|
| 202 | |
---|
[4992] | 203 | /** |
---|
[6048] | 204 | * @brief sets a new relative position smoothely |
---|
[4992] | 205 | * @param relCoordSoft the new Position to iterate to |
---|
| 206 | * @param bias how fast to iterate to this position |
---|
| 207 | */ |
---|
| 208 | void PNode::setRelCoorSoft(const Vector& relCoordSoft, float bias) |
---|
[4987] | 209 | { |
---|
[4993] | 210 | if (likely(this->toCoordinate == NULL)) |
---|
| 211 | this->toCoordinate = new Vector(); |
---|
[4987] | 212 | |
---|
[4993] | 213 | *this->toCoordinate = relCoordSoft; |
---|
[4992] | 214 | this->bias = bias; |
---|
[4987] | 215 | } |
---|
| 216 | |
---|
[4990] | 217 | |
---|
[4610] | 218 | /** |
---|
[6048] | 219 | * @brief set relative coordinates smoothely |
---|
[4990] | 220 | * @param x x-relative coordinates to its parent |
---|
| 221 | * @param y y-relative coordinates to its parent |
---|
| 222 | * @param z z-relative coordinates to its parent |
---|
[4993] | 223 | * @see void PNode::setRelCoorSoft (const Vector&, float) |
---|
[4990] | 224 | */ |
---|
[4992] | 225 | void PNode::setRelCoorSoft (float x, float y, float z, float bias) |
---|
[4990] | 226 | { |
---|
[4992] | 227 | this->setRelCoorSoft(Vector(x, y, z), bias); |
---|
[4990] | 228 | } |
---|
| 229 | |
---|
[5382] | 230 | |
---|
[4990] | 231 | /** |
---|
[4836] | 232 | * @param absCoord set absolute coordinate |
---|
[5091] | 233 | */ |
---|
[3809] | 234 | void PNode::setAbsCoor (const Vector& absCoord) |
---|
[3675] | 235 | { |
---|
[5113] | 236 | if (this->toCoordinate!= NULL) |
---|
| 237 | { |
---|
| 238 | delete this->toCoordinate; |
---|
| 239 | this->toCoordinate = NULL; |
---|
| 240 | } |
---|
| 241 | |
---|
[4993] | 242 | if( likely(this->parentMode & PNODE_MOVEMENT)) |
---|
| 243 | { |
---|
| 244 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
| 245 | if (likely(this->parent != NULL)) |
---|
| 246 | this->relCoordinate = absCoord - parent->getAbsCoor (); |
---|
| 247 | else |
---|
| 248 | this->relCoordinate = absCoord; |
---|
| 249 | } |
---|
| 250 | if( this->parentMode & PNODE_ROTATE_MOVEMENT) |
---|
| 251 | { |
---|
| 252 | if (likely(this->parent != NULL)) |
---|
| 253 | this->relCoordinate = absCoord - parent->getAbsCoor (); |
---|
| 254 | else |
---|
| 255 | this->relCoordinate = absCoord; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | this->bRelCoorChanged = true; |
---|
| 259 | // this->absCoordinate = absCoord; |
---|
[3675] | 260 | } |
---|
| 261 | |
---|
[5382] | 262 | |
---|
[3675] | 263 | /** |
---|
[4836] | 264 | * @param x x-coordinate. |
---|
| 265 | * @param y y-coordinate. |
---|
| 266 | * @param z z-coordinate. |
---|
[4987] | 267 | * @see void PNode::setAbsCoor (const Vector& absCoord) |
---|
[4610] | 268 | */ |
---|
| 269 | void PNode::setAbsCoor(float x, float y, float z) |
---|
| 270 | { |
---|
| 271 | this->setAbsCoor(Vector(x, y, z)); |
---|
| 272 | } |
---|
| 273 | |
---|
[6054] | 274 | |
---|
[4610] | 275 | /** |
---|
[5406] | 276 | * @param absCoord set absolute coordinate |
---|
| 277 | * @todo check off |
---|
| 278 | */ |
---|
| 279 | void PNode::setAbsCoorSoft (const Vector& absCoordSoft, float bias) |
---|
| 280 | { |
---|
| 281 | if (this->toCoordinate == NULL) |
---|
| 282 | this->toCoordinate = new Vector; |
---|
| 283 | |
---|
| 284 | if( likely(this->parentMode & PNODE_MOVEMENT)) |
---|
| 285 | { |
---|
| 286 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
| 287 | if (likely(this->parent != NULL)) |
---|
| 288 | *this->toCoordinate = absCoordSoft - parent->getAbsCoor (); |
---|
| 289 | else |
---|
| 290 | *this->toCoordinate = absCoordSoft; |
---|
| 291 | } |
---|
| 292 | if( this->parentMode & PNODE_ROTATE_MOVEMENT) |
---|
| 293 | { |
---|
| 294 | if (likely(this->parent != NULL)) |
---|
| 295 | *this->toCoordinate = absCoordSoft - parent->getAbsCoor (); |
---|
| 296 | else |
---|
| 297 | *this->toCoordinate = absCoordSoft; |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | |
---|
| 302 | /** |
---|
[6048] | 303 | * @brief shift coordinate relative |
---|
[4836] | 304 | * @param shift shift vector |
---|
[4987] | 305 | * |
---|
[5420] | 306 | * this function shifts the current coordinates about the vector shift. this is |
---|
| 307 | * usefull because from some place else you can: |
---|
| 308 | * PNode* someNode = ...; |
---|
| 309 | * Vector objectMovement = calculateShift(); |
---|
| 310 | * someNode->shiftCoor(objectMovement); |
---|
| 311 | * |
---|
| 312 | * this is the internal method of: |
---|
| 313 | * PNode* someNode = ...; |
---|
| 314 | * Vector objectMovement = calculateShift(); |
---|
| 315 | * Vector currentCoor = someNode->getRelCoor(); |
---|
| 316 | * Vector newCoor = currentCoor + objectMovement; |
---|
| 317 | * someNode->setRelCoor(newCoor); |
---|
| 318 | * |
---|
[5382] | 319 | */ |
---|
[3809] | 320 | void PNode::shiftCoor (const Vector& shift) |
---|
[3683] | 321 | { |
---|
[4993] | 322 | this->relCoordinate += shift; |
---|
| 323 | this->bRelCoorChanged = true; |
---|
[3683] | 324 | } |
---|
| 325 | |
---|
[6054] | 326 | |
---|
[3683] | 327 | /** |
---|
[6048] | 328 | * @brief set relative direction |
---|
[4836] | 329 | * @param relDir to its parent |
---|
[5091] | 330 | */ |
---|
[3810] | 331 | void PNode::setRelDir (const Quaternion& relDir) |
---|
[3675] | 332 | { |
---|
[5113] | 333 | if (this->toDirection!= NULL) |
---|
| 334 | { |
---|
| 335 | delete this->toDirection; |
---|
| 336 | this->toDirection = NULL; |
---|
| 337 | } |
---|
[4993] | 338 | this->relDirection = relDir; |
---|
[5819] | 339 | |
---|
[3675] | 340 | this->bRelCoorChanged = true; |
---|
| 341 | } |
---|
| 342 | |
---|
[6054] | 343 | |
---|
[3365] | 344 | /** |
---|
[4771] | 345 | * @see void PNode::setRelDir (const Quaternion& relDir) |
---|
| 346 | * @param x the x direction |
---|
| 347 | * @param y the y direction |
---|
| 348 | * @param z the z direction |
---|
| 349 | * |
---|
| 350 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 351 | */ |
---|
| 352 | void PNode::setRelDir (float x, float y, float z) |
---|
| 353 | { |
---|
| 354 | this->setRelDir(Quaternion(Vector(x,y,z), Vector(0,1,0))); |
---|
| 355 | } |
---|
| 356 | |
---|
[4990] | 357 | |
---|
[4771] | 358 | /** |
---|
[6048] | 359 | * @brief sets the Relative Direction of this node to its parent in a Smoothed way |
---|
[4990] | 360 | * @param relDirSoft the direction to iterate to smoothely. |
---|
[4992] | 361 | * @param bias how fast to iterate to the new Direction |
---|
[4990] | 362 | */ |
---|
[4992] | 363 | void PNode::setRelDirSoft(const Quaternion& relDirSoft, float bias) |
---|
[4990] | 364 | { |
---|
| 365 | if (likely(this->toDirection == NULL)) |
---|
| 366 | this->toDirection = new Quaternion(); |
---|
| 367 | |
---|
| 368 | *this->toDirection = relDirSoft; |
---|
[4992] | 369 | this->bias = bias; |
---|
[5819] | 370 | this->bRelDirChanged = true; |
---|
[4990] | 371 | } |
---|
| 372 | |
---|
[6054] | 373 | |
---|
[4990] | 374 | /** |
---|
| 375 | * @see void PNode::setRelDirSoft (const Quaternion& relDir) |
---|
| 376 | * @param x the x direction |
---|
| 377 | * @param y the y direction |
---|
| 378 | * @param z the z direction |
---|
| 379 | * |
---|
| 380 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 381 | */ |
---|
[4992] | 382 | void PNode::setRelDirSoft(float x, float y, float z, float bias) |
---|
[4990] | 383 | { |
---|
[4992] | 384 | this->setRelDirSoft(Quaternion(Vector(x,y,z), Vector(0,1,0)), bias); |
---|
[4990] | 385 | } |
---|
| 386 | |
---|
[6054] | 387 | |
---|
[4990] | 388 | /** |
---|
[6048] | 389 | * @brief sets the absolute direction |
---|
[4836] | 390 | * @param absDir absolute coordinates |
---|
[5091] | 391 | */ |
---|
[3810] | 392 | void PNode::setAbsDir (const Quaternion& absDir) |
---|
[3675] | 393 | { |
---|
[5113] | 394 | if (this->toDirection!= NULL) |
---|
| 395 | { |
---|
| 396 | delete this->toDirection; |
---|
| 397 | this->toDirection = NULL; |
---|
| 398 | } |
---|
| 399 | |
---|
[5001] | 400 | if (likely(this->parent != NULL)) |
---|
| 401 | this->relDirection = absDir / this->parent->getAbsDir(); |
---|
[4996] | 402 | else |
---|
[5001] | 403 | this->relDirection = absDir; |
---|
[4993] | 404 | |
---|
| 405 | this->bRelDirChanged = true; |
---|
[3675] | 406 | } |
---|
| 407 | |
---|
[6054] | 408 | |
---|
[3675] | 409 | /** |
---|
[4771] | 410 | * @see void PNode::setAbsDir (const Quaternion& relDir) |
---|
| 411 | * @param x the x direction |
---|
| 412 | * @param y the y direction |
---|
| 413 | * @param z the z direction |
---|
| 414 | * |
---|
| 415 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 416 | */ |
---|
| 417 | void PNode::setAbsDir (float x, float y, float z) |
---|
| 418 | { |
---|
| 419 | this->setAbsDir(Quaternion(Vector(x,y,z), Vector(0,1,0))); |
---|
| 420 | } |
---|
| 421 | |
---|
[6054] | 422 | |
---|
[4771] | 423 | /** |
---|
[6048] | 424 | * @brief sets the absolute direction |
---|
[5414] | 425 | * @param absDir absolute coordinates |
---|
[6048] | 426 | * @param bias how fast to iterator to the new Position |
---|
[5414] | 427 | */ |
---|
| 428 | void PNode::setAbsDirSoft (const Quaternion& absDirSoft, float bias) |
---|
| 429 | { |
---|
| 430 | if (this->toDirection == NULL) |
---|
| 431 | this->toDirection = new Quaternion(); |
---|
| 432 | |
---|
| 433 | if (likely(this->parent != NULL)) |
---|
| 434 | *this->toDirection = absDirSoft / this->parent->getAbsDir(); |
---|
| 435 | else |
---|
| 436 | *this->toDirection = absDirSoft; |
---|
| 437 | |
---|
| 438 | this->bias = bias; |
---|
[5915] | 439 | this->bRelDirChanged = true; |
---|
[5414] | 440 | } |
---|
| 441 | |
---|
[6054] | 442 | |
---|
[5414] | 443 | /** |
---|
| 444 | * @see void PNode::setAbsDir (const Quaternion& relDir) |
---|
| 445 | * @param x the x direction |
---|
| 446 | * @param y the y direction |
---|
| 447 | * @param z the z direction |
---|
| 448 | * |
---|
| 449 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 450 | */ |
---|
| 451 | void PNode::setAbsDirSoft (float x, float y, float z, float bias) |
---|
| 452 | { |
---|
| 453 | this->setAbsDirSoft(Quaternion(Vector(x,y,z), Vector(0,1,0)), bias); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | |
---|
| 457 | /** |
---|
[6048] | 458 | * @brief shift Direction |
---|
[5091] | 459 | * @param shift the direction around which to shift. |
---|
| 460 | */ |
---|
[3802] | 461 | void PNode::shiftDir (const Quaternion& shift) |
---|
| 462 | { |
---|
[4993] | 463 | this->relDirection = this->relDirection * shift; |
---|
[3802] | 464 | this->bRelDirChanged = true; |
---|
| 465 | } |
---|
[3365] | 466 | |
---|
[6048] | 467 | |
---|
[3683] | 468 | /** |
---|
[6048] | 469 | * @brief adds a child and makes this node to a parent |
---|
[5091] | 470 | * @param child child reference |
---|
[4993] | 471 | * use this to add a child to this node. |
---|
[5420] | 472 | */ |
---|
[5382] | 473 | void PNode::addChild (PNode* child) |
---|
[3365] | 474 | { |
---|
[4993] | 475 | if( likely(child->parent != NULL)) |
---|
[3521] | 476 | { |
---|
[5255] | 477 | PRINTF(5)("PNode::addChild() - reparenting node: removing it and adding it again\n"); |
---|
[5770] | 478 | child->parent->children.remove(child); |
---|
[3521] | 479 | } |
---|
[4993] | 480 | child->parent = this; |
---|
[5397] | 481 | if (unlikely(this != NULL)) |
---|
[5770] | 482 | this->children.push_back(child); |
---|
[4993] | 483 | child->parentCoorChanged(); |
---|
[3365] | 484 | } |
---|
| 485 | |
---|
[6048] | 486 | |
---|
[3365] | 487 | /** |
---|
[5091] | 488 | * @see PNode::addChild(PNode* child); |
---|
[4765] | 489 | * @param childName the name of the child to add to this PNode |
---|
| 490 | */ |
---|
| 491 | void PNode::addChild (const char* childName) |
---|
| 492 | { |
---|
| 493 | PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE)); |
---|
| 494 | if (childNode != NULL) |
---|
| 495 | this->addChild(childNode); |
---|
| 496 | } |
---|
| 497 | |
---|
[6048] | 498 | |
---|
[4765] | 499 | /** |
---|
[6048] | 500 | * @brief removes a child from the node |
---|
[5091] | 501 | * @param child the child to remove from this pNode. |
---|
[4993] | 502 | * |
---|
[6054] | 503 | * Children from pNode will not be lost, they are Reparented by the rules of the ParentMode |
---|
[5420] | 504 | */ |
---|
[4993] | 505 | void PNode::removeChild (PNode* child) |
---|
[3365] | 506 | { |
---|
[5214] | 507 | if (child != NULL) |
---|
| 508 | { |
---|
[5769] | 509 | child->removeNode(); |
---|
[5214] | 510 | // this->children->remove(child); |
---|
| 511 | // child->parent = NULL; |
---|
| 512 | } |
---|
[3365] | 513 | } |
---|
| 514 | |
---|
[6054] | 515 | |
---|
[3365] | 516 | /** |
---|
[6048] | 517 | * @brief remove this pnode from the tree and adds all following to NullParent |
---|
[5420] | 518 | * |
---|
| 519 | * this can be the case, if an entity in the world is being destroyed. |
---|
| 520 | */ |
---|
[5769] | 521 | void PNode::removeNode() |
---|
[3537] | 522 | { |
---|
[6054] | 523 | if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE) |
---|
| 524 | { |
---|
| 525 | list<PNode*>::iterator child = this->children.begin(); |
---|
| 526 | list<PNode*>::iterator reparenter; |
---|
| 527 | while (child != this->children.end()) |
---|
| 528 | { |
---|
| 529 | reparenter = child++; |
---|
| 530 | (*reparenter)->reparent(); |
---|
| 531 | } |
---|
| 532 | } |
---|
[5214] | 533 | if (this->parent != NULL) |
---|
[5770] | 534 | this->parent->children.remove(this); |
---|
[3537] | 535 | } |
---|
| 536 | |
---|
[3365] | 537 | |
---|
[4761] | 538 | /** |
---|
| 539 | * @see PNode::setParent(PNode* parent); |
---|
| 540 | * @param parentName the name of the Parent to set to this PNode |
---|
| 541 | */ |
---|
| 542 | void PNode::setParent (const char* parentName) |
---|
| 543 | { |
---|
| 544 | PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE)); |
---|
| 545 | if (parentNode != NULL) |
---|
| 546 | parentNode->addChild(this); |
---|
| 547 | } |
---|
| 548 | |
---|
[6054] | 549 | |
---|
[4990] | 550 | /** |
---|
[6048] | 551 | * @brief does the reparenting in a very smooth way |
---|
[4990] | 552 | * @param parentNode the new Node to connect this node to. |
---|
[4993] | 553 | * @param bias the speed to iterate to this new Positions |
---|
[4990] | 554 | */ |
---|
[5382] | 555 | void PNode::setParentSoft(PNode* parentNode, float bias) |
---|
[4987] | 556 | { |
---|
[5382] | 557 | // return if the new parent and the old one match |
---|
[4992] | 558 | if (this->parent == parentNode) |
---|
| 559 | return; |
---|
| 560 | |
---|
[5382] | 561 | // store the Valures to iterate to. |
---|
[4993] | 562 | if (likely(this->toCoordinate == NULL)) |
---|
[4989] | 563 | { |
---|
[4993] | 564 | this->toCoordinate = new Vector(); |
---|
| 565 | *this->toCoordinate = this->getRelCoor(); |
---|
[4989] | 566 | } |
---|
[4990] | 567 | if (likely(this->toDirection == NULL)) |
---|
| 568 | { |
---|
| 569 | this->toDirection = new Quaternion(); |
---|
| 570 | *this->toDirection = this->getRelDir(); |
---|
| 571 | } |
---|
[4992] | 572 | this->bias = bias; |
---|
[4987] | 573 | |
---|
| 574 | |
---|
[4990] | 575 | Vector tmpV = this->getAbsCoor(); |
---|
| 576 | Quaternion tmpQ = this->getAbsDir(); |
---|
[4987] | 577 | |
---|
| 578 | parentNode->addChild(this); |
---|
| 579 | |
---|
[5382] | 580 | if (this->parentMode & PNODE_ROTATE_MOVEMENT && this->parent != NULL) |
---|
| 581 | this->relCoordinate = this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()); |
---|
[5000] | 582 | else |
---|
[5382] | 583 | this->relCoordinate = tmpV - parentNode->getAbsCoor(); |
---|
[4991] | 584 | |
---|
[5382] | 585 | this->relDirection = tmpQ / parentNode->getAbsDir(); |
---|
[4987] | 586 | } |
---|
| 587 | |
---|
[6054] | 588 | |
---|
[4993] | 589 | /** |
---|
[6048] | 590 | * @brief does the reparenting in a very smooth way |
---|
[4993] | 591 | * @param parentName the name of the Parent to reconnect to |
---|
| 592 | * @param bias the speed to iterate to this new Positions |
---|
| 593 | */ |
---|
[5382] | 594 | void PNode::setParentSoft(const char* parentName, float bias) |
---|
[4987] | 595 | { |
---|
| 596 | PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE)); |
---|
| 597 | if (parentNode != NULL) |
---|
[5382] | 598 | this->setParentSoft(parentNode, bias); |
---|
[4987] | 599 | } |
---|
| 600 | |
---|
[6054] | 601 | /** |
---|
| 602 | * @param parentMode sets the parentingMode of this Node |
---|
| 603 | */ |
---|
| 604 | void PNode::setParentMode(PARENT_MODE parentMode) |
---|
| 605 | { |
---|
| 606 | this->parentMode &= (0xfff0 | parentMode); |
---|
| 607 | } |
---|
[6048] | 608 | |
---|
[3365] | 609 | /** |
---|
[6048] | 610 | * @brief sets the mode of this parent manually |
---|
[4765] | 611 | * @param parentMode a String representing this parentingMode |
---|
| 612 | */ |
---|
| 613 | void PNode::setParentMode (const char* parentingMode) |
---|
| 614 | { |
---|
[4993] | 615 | this->setParentMode(PNode::charToParentingMode(parentingMode)); |
---|
[4765] | 616 | } |
---|
[3537] | 617 | |
---|
[6054] | 618 | |
---|
[3365] | 619 | /** |
---|
[6054] | 620 | * !!PRIVATE FUNCTION: |
---|
| 621 | * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.) |
---|
| 622 | */ |
---|
| 623 | void PNode::reparent() |
---|
| 624 | { |
---|
| 625 | if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT) |
---|
| 626 | this->setParent(NullParent::getInstance()); |
---|
| 627 | else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL) |
---|
| 628 | this->setParent(this->parent->getParent()); |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | void PNode::addNodeModeFlags(unsigned short nodeFlags) |
---|
| 632 | { |
---|
| 633 | this->parentMode |= nodeFlags; |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | |
---|
| 637 | void PNode::removeNodeModeFlags(unsigned short nodeFlags) |
---|
| 638 | { |
---|
| 639 | this->parentMode &= !nodeFlags; |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | |
---|
| 643 | /** |
---|
[6048] | 644 | * @brief updates the absCoordinate/absDirection |
---|
[4836] | 645 | * @param dt The time passed since the last update |
---|
[5420] | 646 | * |
---|
| 647 | * this is used to go through the parent-tree to update all the absolute coordinates |
---|
| 648 | * and directions. this update should be done by the engine, so you don't have to |
---|
| 649 | * worry, normaly... |
---|
| 650 | */ |
---|
[5769] | 651 | void PNode::updateNode (float dt) |
---|
[3365] | 652 | { |
---|
[4440] | 653 | if( likely(this->parent != NULL)) |
---|
| 654 | { |
---|
[6054] | 655 | if (!(this->parentMode & PNODE_STATIC_NODE)) |
---|
[4987] | 656 | { |
---|
[6054] | 657 | // movement for nodes with smoothMove enabled |
---|
| 658 | if (unlikely(this->toCoordinate != NULL)) |
---|
[4987] | 659 | { |
---|
[6054] | 660 | Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias; |
---|
| 661 | if (likely(moveVect.len() >= PNODE_ITERATION_DELTA)) |
---|
| 662 | { |
---|
| 663 | this->shiftCoor(moveVect); |
---|
| 664 | } |
---|
| 665 | else |
---|
| 666 | { |
---|
| 667 | delete this->toCoordinate; |
---|
| 668 | this->toCoordinate = NULL; |
---|
| 669 | PRINTF(5)("SmoothMove of %s finished\n", this->getName()); |
---|
| 670 | } |
---|
[4987] | 671 | } |
---|
[6054] | 672 | if (unlikely(this->toDirection != NULL)) |
---|
[4987] | 673 | { |
---|
[6054] | 674 | Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias); |
---|
| 675 | if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA) |
---|
| 676 | { |
---|
| 677 | this->relDirection = rotQuat; |
---|
| 678 | this->bRelDirChanged; |
---|
| 679 | } |
---|
| 680 | else |
---|
| 681 | { |
---|
| 682 | delete this->toDirection; |
---|
| 683 | this->toDirection = NULL; |
---|
| 684 | PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); |
---|
| 685 | } |
---|
[4987] | 686 | } |
---|
[4990] | 687 | |
---|
[6054] | 688 | // MAIN UPDATE ///////////////////////////////////// |
---|
| 689 | this->lastAbsCoordinate = this->absCoordinate; |
---|
[4145] | 690 | |
---|
[6054] | 691 | PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); |
---|
[3800] | 692 | |
---|
[4570] | 693 | |
---|
[6054] | 694 | if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged) |
---|
| 695 | { |
---|
| 696 | /* update the current absDirection - remember * means rotation around sth.*/ |
---|
| 697 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 698 | this->absDirection = this->relDirection * parent->getAbsDir();; |
---|
| 699 | } |
---|
[4570] | 700 | |
---|
[6054] | 701 | if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged)) |
---|
| 702 | { |
---|
| 703 | /* update the current absCoordinate */ |
---|
| 704 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 705 | this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; |
---|
| 706 | } |
---|
| 707 | else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged) |
---|
| 708 | { |
---|
| 709 | /* update the current absCoordinate */ |
---|
| 710 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 711 | this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); |
---|
| 712 | } |
---|
| 713 | ///////////////////////////////////////////////// |
---|
[5007] | 714 | } |
---|
[6054] | 715 | } |
---|
| 716 | else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT |
---|
[4440] | 717 | { |
---|
[6054] | 718 | if (!(this->parentMode & PNODE_STATIC_NODE)) |
---|
[5118] | 719 | { |
---|
[6054] | 720 | PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); |
---|
| 721 | if (this->bRelCoorChanged) |
---|
| 722 | { |
---|
| 723 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 724 | this->absCoordinate = this->relCoordinate; |
---|
| 725 | } |
---|
| 726 | if (this->bRelDirChanged) |
---|
| 727 | { |
---|
| 728 | this->prevRelDirection = this->relDirection; |
---|
| 729 | this->absDirection = this->getAbsDir () * this->relDirection; |
---|
| 730 | } |
---|
[5118] | 731 | } |
---|
[4993] | 732 | } |
---|
[3365] | 733 | |
---|
[6054] | 734 | if(!this->children.empty() && (this->bActive || this->parentMode & PNODE_UPDATE_CHILDREN_IF_INACTIVE )) |
---|
[4993] | 735 | { |
---|
[5770] | 736 | list<PNode*>::iterator child; |
---|
| 737 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
[4574] | 738 | { |
---|
| 739 | /* if this node has changed, make sure, that all children are updated also */ |
---|
[4993] | 740 | if( likely(this->bRelCoorChanged)) |
---|
[5770] | 741 | (*child)->parentCoorChanged (); |
---|
[4993] | 742 | if( likely(this->bRelDirChanged)) |
---|
[5770] | 743 | (*child)->parentDirChanged (); |
---|
[4993] | 744 | |
---|
[5770] | 745 | (*child)->updateNode(dt); |
---|
[4993] | 746 | } |
---|
[4440] | 747 | } |
---|
[4993] | 748 | this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; |
---|
| 749 | this->bRelCoorChanged = false; |
---|
| 750 | this->bRelDirChanged = false; |
---|
[3365] | 751 | } |
---|
| 752 | |
---|
[5769] | 753 | |
---|
[6048] | 754 | /** |
---|
| 755 | * @brief counts total amount the children walking through the entire tree. |
---|
| 756 | * @param nodes the counter |
---|
| 757 | */ |
---|
[5769] | 758 | void PNode::countChildNodes(int& nodes) const |
---|
| 759 | { |
---|
| 760 | nodes++; |
---|
[5770] | 761 | list<PNode*>::const_iterator child; |
---|
| 762 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
| 763 | (*child)->countChildNodes(nodes); |
---|
[5769] | 764 | } |
---|
| 765 | |
---|
| 766 | |
---|
[3450] | 767 | /** |
---|
[6048] | 768 | * @brief displays some information about this pNode |
---|
[4836] | 769 | * @param depth The deph into which to debug the children of this PNode to. |
---|
[5383] | 770 | * (0: all children will be debugged, 1: only this PNode, 2: this and direct children, ...) |
---|
| 771 | * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output). |
---|
[5420] | 772 | */ |
---|
[5769] | 773 | void PNode::debugNode(unsigned int depth, unsigned int level) const |
---|
[3365] | 774 | { |
---|
[4574] | 775 | for (unsigned int i = 0; i < level; i++) |
---|
[4575] | 776 | PRINT(0)(" |"); |
---|
[5770] | 777 | if (this->children.size() > 0) |
---|
[4575] | 778 | PRINT(0)(" +"); |
---|
| 779 | else |
---|
| 780 | PRINT(0)(" -"); |
---|
[5769] | 781 | |
---|
| 782 | int childNodeCount = 0; |
---|
| 783 | this->countChildNodes(childNodeCount); |
---|
| 784 | |
---|
| 785 | PRINT(0)("PNode(%s::%s) - absCoord: (%0.2f, %0.2f, %0.2f), relCoord(%0.2f, %0.2f, %0.2f), direction(%0.2f, %0.2f, %0.2f) - %s - %d childs\n", |
---|
[4574] | 786 | this->getClassName(), |
---|
| 787 | this->getName(), |
---|
| 788 | this->absCoordinate.x, |
---|
| 789 | this->absCoordinate.y, |
---|
| 790 | this->absCoordinate.z, |
---|
| 791 | this->relCoordinate.x, |
---|
| 792 | this->relCoordinate.y, |
---|
[4993] | 793 | this->relCoordinate.z, |
---|
[4996] | 794 | this->getAbsDirV().x, |
---|
| 795 | this->getAbsDirV().y, |
---|
| 796 | this->getAbsDirV().z, |
---|
[5769] | 797 | this->parentingModeToChar(parentMode), |
---|
| 798 | childNodeCount); |
---|
[4574] | 799 | if (depth >= 2 || depth == 0) |
---|
| 800 | { |
---|
[5770] | 801 | list<PNode*>::const_iterator child; |
---|
| 802 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
[4574] | 803 | { |
---|
| 804 | if (depth == 0) |
---|
[5770] | 805 | (*child)->debugNode(0, level + 1); |
---|
[4574] | 806 | else |
---|
[5770] | 807 | (*child)->debugNode(depth - 1, level +1); |
---|
[4574] | 808 | } |
---|
| 809 | } |
---|
[3365] | 810 | } |
---|
| 811 | |
---|
[4570] | 812 | /** |
---|
[6048] | 813 | * @brief displays the PNode at its position with its rotation as a cube. |
---|
[5383] | 814 | * @param depth The deph into which to debug the children of this PNode to. |
---|
| 815 | * (0: all children will be displayed, 1: only this PNode, 2: this and direct children, ...) |
---|
| 816 | * @param size the Size of the Box to draw. |
---|
| 817 | * @param color the color of the Box to display. |
---|
| 818 | * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output). |
---|
| 819 | */ |
---|
| 820 | void PNode::debugDraw(unsigned int depth, float size, const Vector& color, unsigned int level) const |
---|
[4570] | 821 | { |
---|
[5432] | 822 | // if this is the first Element we draw |
---|
[5383] | 823 | if (level == 0) |
---|
| 824 | { |
---|
[5432] | 825 | glPushAttrib(GL_ENABLE_BIT); // save the Enable-attributes |
---|
| 826 | glMatrixMode(GL_MODELVIEW); // goto the ModelView Matrix |
---|
[5383] | 827 | |
---|
[5432] | 828 | glDisable(GL_LIGHTING); // disable lighting (we do not need them for just lighting) |
---|
| 829 | glDisable(GL_BLEND); // '' |
---|
| 830 | glDisable(GL_TEXTURE_2D); // '' |
---|
[5438] | 831 | glDisable(GL_DEPTH_TEST); // '' |
---|
[5383] | 832 | } |
---|
| 833 | |
---|
[5432] | 834 | glPushMatrix(); // repush the Matrix-stack |
---|
[4570] | 835 | /* translate */ |
---|
| 836 | glTranslatef (this->getAbsCoor ().x, |
---|
| 837 | this->getAbsCoor ().y, |
---|
| 838 | this->getAbsCoor ().z); |
---|
[4998] | 839 | // this->getAbsDir ().matrix (matrix); |
---|
| 840 | |
---|
[5432] | 841 | /* rotate */ |
---|
[4998] | 842 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
[5432] | 843 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 844 | /* set the new Color */ |
---|
[5008] | 845 | glColor3f(color.x, color.y, color.z); |
---|
[5432] | 846 | { /* draw a cube of size size */ |
---|
[4570] | 847 | glBegin(GL_LINE_STRIP); |
---|
[4995] | 848 | glVertex3f(-.5*size, -.5*size, -.5*size); |
---|
| 849 | glVertex3f(+.5*size, -.5*size, -.5*size); |
---|
| 850 | glVertex3f(+.5*size, -.5*size, +.5*size); |
---|
| 851 | glVertex3f(-.5*size, -.5*size, +.5*size); |
---|
| 852 | glVertex3f(-.5*size, -.5*size, -.5*size); |
---|
[4570] | 853 | glEnd(); |
---|
| 854 | glBegin(GL_LINE_STRIP); |
---|
[4995] | 855 | glVertex3f(-.5*size, +.5*size, -.5*size); |
---|
| 856 | glVertex3f(+.5*size, +.5*size, -.5*size); |
---|
| 857 | glVertex3f(+.5*size, +.5*size, +.5*size); |
---|
| 858 | glVertex3f(-.5*size, +.5*size, +.5*size); |
---|
| 859 | glVertex3f(-.5*size, +.5*size, -.5*size); |
---|
[4570] | 860 | glEnd(); |
---|
[4995] | 861 | |
---|
[4570] | 862 | glBegin(GL_LINES); |
---|
[4995] | 863 | glVertex3f(-.5*size, -.5*size, -.5*size); |
---|
| 864 | glVertex3f(-.5*size, +.5*size, -.5*size); |
---|
| 865 | glVertex3f(+.5*size, -.5*size, -.5*size); |
---|
| 866 | glVertex3f(+.5*size, +.5*size, -.5*size); |
---|
| 867 | glVertex3f(+.5*size, -.5*size, +.5*size); |
---|
| 868 | glVertex3f(+.5*size, +.5*size, +.5*size); |
---|
| 869 | glVertex3f(-.5*size, -.5*size, +.5*size); |
---|
| 870 | glVertex3f(-.5*size, +.5*size, +.5*size); |
---|
[4570] | 871 | glEnd(); |
---|
| 872 | } |
---|
| 873 | |
---|
| 874 | glPopMatrix(); |
---|
[5007] | 875 | if (depth >= 2 || depth == 0) |
---|
| 876 | { |
---|
[5432] | 877 | /* rotate the current color in HSV space around 20 degree */ |
---|
[5115] | 878 | Vector childColor = Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(20,0,.0)); |
---|
[5770] | 879 | list<PNode*>::const_iterator child; |
---|
| 880 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
[5007] | 881 | { |
---|
[5394] | 882 | // drawing the Dependency graph |
---|
[5406] | 883 | if (this != NullParent::getInstance()) |
---|
[5394] | 884 | { |
---|
| 885 | glBegin(GL_LINES); |
---|
| 886 | glColor3f(color.x, color.y, color.z); |
---|
| 887 | glVertex3f(this->getAbsCoor ().x, |
---|
| 888 | this->getAbsCoor ().y, |
---|
| 889 | this->getAbsCoor ().z); |
---|
| 890 | glColor3f(childColor.x, childColor.y, childColor.z); |
---|
[5770] | 891 | glVertex3f((*child)->getAbsCoor ().x, |
---|
| 892 | (*child)->getAbsCoor ().y, |
---|
| 893 | (*child)->getAbsCoor ().z); |
---|
[5394] | 894 | glEnd(); |
---|
| 895 | } |
---|
[5915] | 896 | |
---|
[5432] | 897 | /* if we want to draw the children too */ |
---|
| 898 | if (depth == 0) /* -> all of them */ |
---|
[5770] | 899 | (*child)->debugDraw(0, size, childColor, level+1); |
---|
[5432] | 900 | else /* -> only the Next one */ |
---|
[5770] | 901 | (*child)->debugDraw(depth - 1, size, childColor, level +1); |
---|
[5007] | 902 | } |
---|
| 903 | } |
---|
[5383] | 904 | if (level == 0) |
---|
[5432] | 905 | glPopAttrib(); /* pop the saved attributes back out */ |
---|
[4570] | 906 | } |
---|
[4993] | 907 | |
---|
| 908 | |
---|
| 909 | |
---|
| 910 | ///////////////////// |
---|
| 911 | // HELPER_FUCTIONS // |
---|
| 912 | ///////////////////// |
---|
| 913 | |
---|
| 914 | /** |
---|
[6048] | 915 | * @brief converts a parentingMode into a string that is the name of it |
---|
[4993] | 916 | * @param parentingMode the ParentingMode to convert |
---|
| 917 | * @return the converted string |
---|
| 918 | */ |
---|
| 919 | const char* PNode::parentingModeToChar(int parentingMode) |
---|
| 920 | { |
---|
| 921 | if (parentingMode == PNODE_LOCAL_ROTATE) |
---|
| 922 | return "local-rotate"; |
---|
| 923 | else if (parentingMode == PNODE_ROTATE_MOVEMENT) |
---|
| 924 | return "rotate-movement"; |
---|
| 925 | else if (parentingMode == PNODE_MOVEMENT) |
---|
| 926 | return "movement"; |
---|
| 927 | else if (parentingMode == PNODE_ALL) |
---|
| 928 | return "all"; |
---|
| 929 | else if (parentingMode == PNODE_ROTATE_AND_MOVE) |
---|
| 930 | return "rotate-and-move"; |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | /** |
---|
[6048] | 934 | * @brief converts a parenting-mode-string into a int |
---|
[4993] | 935 | * @param parentingMode the string naming the parentingMode |
---|
| 936 | * @return the int corresponding to the named parentingMode |
---|
| 937 | */ |
---|
| 938 | PARENT_MODE PNode::charToParentingMode(const char* parentingMode) |
---|
| 939 | { |
---|
| 940 | if (!strcmp(parentingMode, "local-rotate")) |
---|
| 941 | return (PNODE_LOCAL_ROTATE); |
---|
| 942 | else if (!strcmp(parentingMode, "rotate-movement")) |
---|
| 943 | return (PNODE_ROTATE_MOVEMENT); |
---|
| 944 | else if (!strcmp(parentingMode, "movement")) |
---|
| 945 | return (PNODE_MOVEMENT); |
---|
| 946 | else if (!strcmp(parentingMode, "all")) |
---|
| 947 | return (PNODE_ALL); |
---|
| 948 | else if (!strcmp(parentingMode, "rotate-and-move")) |
---|
| 949 | return (PNODE_ROTATE_AND_MOVE); |
---|
| 950 | } |
---|