[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 | |
---|
| 20 | #include "load_param.h" |
---|
| 21 | #include "class_list.h" |
---|
| 22 | |
---|
[6078] | 23 | #include <algorithm> |
---|
[3860] | 24 | #include "compiler.h" |
---|
[3608] | 25 | #include "debug.h" |
---|
| 26 | |
---|
[6054] | 27 | #include "glincl.h" |
---|
[5406] | 28 | #include "color.h" |
---|
[3246] | 29 | |
---|
[6341] | 30 | #include "synchronizeable.h" |
---|
| 31 | |
---|
[6424] | 32 | #include "shell_command.h" |
---|
| 33 | SHELL_COMMAND(debugNode, PNode, debugNodeSC); |
---|
| 34 | |
---|
[3246] | 35 | using namespace std; |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | /** |
---|
[6048] | 39 | * @brief standard constructor |
---|
[6078] | 40 | * @param parent the Parent of this Node. __NULL__ if __No Parent__ requested, PNode::getNullParent(), if connected to NullParent directly (default) |
---|
[6299] | 41 | * @param nodeFlags all flags to set. THIS_WILL_OVERWRITE Default_Values. |
---|
[5420] | 42 | */ |
---|
[6078] | 43 | PNode::PNode (PNode* parent, long nodeFlags) |
---|
[7008] | 44 | : Synchronizeable(), BaseObject() |
---|
[3365] | 45 | { |
---|
[6074] | 46 | this->setClassID(CL_PARENT_NODE, "PNode"); |
---|
[3365] | 47 | |
---|
[6074] | 48 | this->bRelCoorChanged = true; |
---|
| 49 | this->bRelDirChanged = true; |
---|
| 50 | this->parent = NULL; |
---|
[6078] | 51 | this->parentMode = nodeFlags; |
---|
[6074] | 52 | this->bActive = true; |
---|
[4993] | 53 | |
---|
[6074] | 54 | // smooth-movers |
---|
| 55 | this->toCoordinate = NULL; |
---|
| 56 | this->toDirection = NULL; |
---|
| 57 | this->bias = 1.0; |
---|
[6078] | 58 | |
---|
| 59 | if (parent != NULL) |
---|
| 60 | parent->addChild(this); |
---|
[3365] | 61 | } |
---|
| 62 | |
---|
[6074] | 63 | // NullParent Reference |
---|
| 64 | PNode* PNode::nullParent = NULL; |
---|
[6073] | 65 | |
---|
[3365] | 66 | /** |
---|
[6048] | 67 | * @brief standard deconstructor |
---|
[5296] | 68 | * |
---|
| 69 | * There are two general ways to delete a PNode |
---|
| 70 | * 1. delete instance; |
---|
| 71 | * -> result |
---|
| 72 | * delete this Node and all its children and children's children... |
---|
| 73 | * (danger if you still need the children's instance somewhere else!!) |
---|
| 74 | * |
---|
[6073] | 75 | * 2. instance->removeNode(); delete instance; |
---|
[5296] | 76 | * -> result: |
---|
| 77 | * moves its children to the NullParent |
---|
| 78 | * then deletes the Element. |
---|
| 79 | */ |
---|
[4570] | 80 | PNode::~PNode () |
---|
[3365] | 81 | { |
---|
[7126] | 82 | PRINTF(4)("delete %s::%s\n", this->getClassName(), this->getName()); |
---|
[6073] | 83 | // remove the Node, delete it's children (if required). |
---|
| 84 | std::list<PNode*>::iterator tmp = this->children.begin(); |
---|
| 85 | std::list<PNode*>::iterator deleteNode; |
---|
[7126] | 86 | unsigned int size; |
---|
[6073] | 87 | while(!this->children.empty()) |
---|
[7126] | 88 | { |
---|
| 89 | tmp = this->children.begin(); |
---|
| 90 | //while (tmp != this->children.end()) |
---|
[6073] | 91 | { |
---|
| 92 | deleteNode = tmp; |
---|
[6142] | 93 | tmp++; |
---|
[7126] | 94 | size = this->children.size(); |
---|
[6073] | 95 | if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || |
---|
| 96 | ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT)) |
---|
| 97 | { |
---|
[6078] | 98 | if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL) |
---|
[7125] | 99 | { |
---|
[7126] | 100 | PRINTF(4)("%s::%s deletes %s::%s\n", |
---|
[7125] | 101 | this->getClassName(), this->getName(), |
---|
| 102 | (*deleteNode)->getClassName(), (*deleteNode)->getName()); |
---|
[6073] | 103 | delete (*deleteNode); |
---|
[7125] | 104 | } |
---|
[6073] | 105 | else |
---|
[7125] | 106 | { |
---|
[7126] | 107 | PRINTF(4)("%s::%s reparents %s::%s\n", |
---|
[7125] | 108 | this->getClassName(), this->getName(), |
---|
| 109 | (*deleteNode)->getClassName(), (*deleteNode)->getName()); |
---|
[6073] | 110 | (*deleteNode)->reparent(); |
---|
[7125] | 111 | } |
---|
[6073] | 112 | } |
---|
| 113 | else |
---|
[7125] | 114 | { |
---|
[7126] | 115 | PRINTF(4)("%s::%s deletes PNode: %s::%s\n", |
---|
[7125] | 116 | this->getClassName(), this->getName(), |
---|
| 117 | (*deleteNode)->getClassName(), (*deleteNode)->getName()); |
---|
[6073] | 118 | delete (*deleteNode); |
---|
[7125] | 119 | } |
---|
[7126] | 120 | //if (size <= this->children.size()) break; |
---|
[6073] | 121 | } |
---|
[7126] | 122 | } |
---|
[6073] | 123 | |
---|
[6071] | 124 | if (this->parent != NULL) |
---|
[7008] | 125 | { |
---|
| 126 | this->parent->eraseChild(this); |
---|
| 127 | this->parent = NULL; |
---|
| 128 | } |
---|
[6071] | 129 | |
---|
[5296] | 130 | // remove all other allocated memory. |
---|
[5088] | 131 | if (this->toCoordinate != NULL) |
---|
| 132 | delete this->toCoordinate; |
---|
| 133 | if (this->toDirection != NULL) |
---|
| 134 | delete this->toDirection; |
---|
[6075] | 135 | |
---|
| 136 | if (this == PNode::nullParent) |
---|
| 137 | PNode::nullParent = NULL; |
---|
[3365] | 138 | } |
---|
[3246] | 139 | |
---|
[5296] | 140 | |
---|
[4448] | 141 | /** |
---|
[6048] | 142 | * @brief loads parameters of the PNode |
---|
[4836] | 143 | * @param root the XML-element to load the properties of |
---|
[5420] | 144 | */ |
---|
[4436] | 145 | void PNode::loadParams(const TiXmlElement* root) |
---|
| 146 | { |
---|
[6512] | 147 | BaseObject::loadParams(root); |
---|
[4610] | 148 | |
---|
[5671] | 149 | LoadParam(root, "rel-coor", this, PNode, setRelCoor) |
---|
[7008] | 150 | .describe("Sets The relative position of the Node to its parent."); |
---|
[4771] | 151 | |
---|
[5671] | 152 | LoadParam(root, "abs-coor", this, PNode, setAbsCoor) |
---|
[7008] | 153 | .describe("Sets The absolute Position of the Node."); |
---|
[4610] | 154 | |
---|
[5671] | 155 | LoadParam(root, "rel-dir", this, PNode, setRelDir) |
---|
[7008] | 156 | .describe("Sets The relative rotation of the Node to its parent."); |
---|
[4761] | 157 | |
---|
[5671] | 158 | LoadParam(root, "abs-dir", this, PNode, setAbsDir) |
---|
[7008] | 159 | .describe("Sets The absolute rotation of the Node."); |
---|
[4771] | 160 | |
---|
[5671] | 161 | LoadParam(root, "parent", this, PNode, setParent) |
---|
[7008] | 162 | .describe("the Name of the Parent to set for this PNode"); |
---|
[4765] | 163 | |
---|
[5671] | 164 | LoadParam(root, "parent-mode", this, PNode, setParentMode) |
---|
[7008] | 165 | .describe("the mode to connect this node to its parent ()"); |
---|
[4765] | 166 | |
---|
| 167 | // cycling properties |
---|
[4785] | 168 | if (root != NULL) |
---|
[4765] | 169 | { |
---|
[5654] | 170 | LOAD_PARAM_START_CYCLE(root, element); |
---|
[4785] | 171 | { |
---|
[6074] | 172 | LoadParam_CYCLE(element, "child", this, PNode, addChild) |
---|
[7008] | 173 | .describe("adds a new Child to the current Node."); |
---|
[4765] | 174 | |
---|
[4785] | 175 | } |
---|
[5654] | 176 | LOAD_PARAM_END_CYCLE(element); |
---|
[4765] | 177 | } |
---|
[4436] | 178 | } |
---|
[3365] | 179 | |
---|
[6424] | 180 | |
---|
[3365] | 181 | /** |
---|
[6424] | 182 | * init the pnode to a well definied state |
---|
| 183 | * |
---|
| 184 | * this function actualy only updates the PNode tree |
---|
| 185 | */ |
---|
| 186 | void PNode::init() |
---|
| 187 | { |
---|
| 188 | /* just update all aboslute positions via timestep 0.001ms */ |
---|
| 189 | this->updateNode(0.001f); |
---|
| 190 | this->updateNode(0.001f); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | /** |
---|
[6048] | 195 | * @brief set relative coordinates |
---|
[4836] | 196 | * @param relCoord relative coordinates to its parent |
---|
[5420] | 197 | * |
---|
| 198 | * |
---|
| 199 | * it is very importand, that you use this function, if you want to update the |
---|
| 200 | * relCoordinates. If you don't use this, the PNode won't recognize, that something |
---|
| 201 | * has changed and won't update the children Nodes. |
---|
| 202 | */ |
---|
[3810] | 203 | void PNode::setRelCoor (const Vector& relCoord) |
---|
[3675] | 204 | { |
---|
[5113] | 205 | if (this->toCoordinate!= NULL) |
---|
| 206 | { |
---|
| 207 | delete this->toCoordinate; |
---|
| 208 | this->toCoordinate = NULL; |
---|
| 209 | } |
---|
| 210 | |
---|
[4993] | 211 | this->relCoordinate = relCoord; |
---|
[3675] | 212 | this->bRelCoorChanged = true; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | /** |
---|
[6048] | 216 | * @brief set relative coordinates |
---|
[4836] | 217 | * @param x x-relative coordinates to its parent |
---|
| 218 | * @param y y-relative coordinates to its parent |
---|
| 219 | * @param z z-relative coordinates to its parent |
---|
[4993] | 220 | * @see void PNode::setRelCoor (const Vector& relCoord) |
---|
[5420] | 221 | */ |
---|
[4610] | 222 | void PNode::setRelCoor (float x, float y, float z) |
---|
| 223 | { |
---|
| 224 | this->setRelCoor(Vector(x, y, z)); |
---|
| 225 | } |
---|
| 226 | |
---|
[4992] | 227 | /** |
---|
[6048] | 228 | * @brief sets a new relative position smoothely |
---|
[4992] | 229 | * @param relCoordSoft the new Position to iterate to |
---|
| 230 | * @param bias how fast to iterate to this position |
---|
| 231 | */ |
---|
| 232 | void PNode::setRelCoorSoft(const Vector& relCoordSoft, float bias) |
---|
[4987] | 233 | { |
---|
[4993] | 234 | if (likely(this->toCoordinate == NULL)) |
---|
| 235 | this->toCoordinate = new Vector(); |
---|
[4987] | 236 | |
---|
[4993] | 237 | *this->toCoordinate = relCoordSoft; |
---|
[4992] | 238 | this->bias = bias; |
---|
[4987] | 239 | } |
---|
| 240 | |
---|
[4990] | 241 | |
---|
[4610] | 242 | /** |
---|
[6048] | 243 | * @brief set relative coordinates smoothely |
---|
[4990] | 244 | * @param x x-relative coordinates to its parent |
---|
| 245 | * @param y y-relative coordinates to its parent |
---|
| 246 | * @param z z-relative coordinates to its parent |
---|
[4993] | 247 | * @see void PNode::setRelCoorSoft (const Vector&, float) |
---|
[4990] | 248 | */ |
---|
[4992] | 249 | void PNode::setRelCoorSoft (float x, float y, float z, float bias) |
---|
[4990] | 250 | { |
---|
[4992] | 251 | this->setRelCoorSoft(Vector(x, y, z), bias); |
---|
[4990] | 252 | } |
---|
| 253 | |
---|
[5382] | 254 | |
---|
[4990] | 255 | /** |
---|
[4836] | 256 | * @param absCoord set absolute coordinate |
---|
[5091] | 257 | */ |
---|
[3809] | 258 | void PNode::setAbsCoor (const Vector& absCoord) |
---|
[3675] | 259 | { |
---|
[5113] | 260 | if (this->toCoordinate!= NULL) |
---|
| 261 | { |
---|
| 262 | delete this->toCoordinate; |
---|
| 263 | this->toCoordinate = NULL; |
---|
| 264 | } |
---|
| 265 | |
---|
[4993] | 266 | if( likely(this->parentMode & PNODE_MOVEMENT)) |
---|
| 267 | { |
---|
[7008] | 268 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
[4993] | 269 | if (likely(this->parent != NULL)) |
---|
| 270 | this->relCoordinate = absCoord - parent->getAbsCoor (); |
---|
| 271 | else |
---|
| 272 | this->relCoordinate = absCoord; |
---|
| 273 | } |
---|
| 274 | if( this->parentMode & PNODE_ROTATE_MOVEMENT) |
---|
| 275 | { |
---|
| 276 | if (likely(this->parent != NULL)) |
---|
| 277 | this->relCoordinate = absCoord - parent->getAbsCoor (); |
---|
| 278 | else |
---|
| 279 | this->relCoordinate = absCoord; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | this->bRelCoorChanged = true; |
---|
[7008] | 283 | // this->absCoordinate = absCoord; |
---|
[3675] | 284 | } |
---|
| 285 | |
---|
[5382] | 286 | |
---|
[3675] | 287 | /** |
---|
[4836] | 288 | * @param x x-coordinate. |
---|
| 289 | * @param y y-coordinate. |
---|
| 290 | * @param z z-coordinate. |
---|
[4987] | 291 | * @see void PNode::setAbsCoor (const Vector& absCoord) |
---|
[4610] | 292 | */ |
---|
| 293 | void PNode::setAbsCoor(float x, float y, float z) |
---|
| 294 | { |
---|
| 295 | this->setAbsCoor(Vector(x, y, z)); |
---|
| 296 | } |
---|
| 297 | |
---|
[6054] | 298 | |
---|
[4610] | 299 | /** |
---|
[5406] | 300 | * @param absCoord set absolute coordinate |
---|
| 301 | * @todo check off |
---|
| 302 | */ |
---|
| 303 | void PNode::setAbsCoorSoft (const Vector& absCoordSoft, float bias) |
---|
| 304 | { |
---|
| 305 | if (this->toCoordinate == NULL) |
---|
| 306 | this->toCoordinate = new Vector; |
---|
| 307 | |
---|
| 308 | if( likely(this->parentMode & PNODE_MOVEMENT)) |
---|
| 309 | { |
---|
[7008] | 310 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
[5406] | 311 | if (likely(this->parent != NULL)) |
---|
| 312 | *this->toCoordinate = absCoordSoft - parent->getAbsCoor (); |
---|
| 313 | else |
---|
| 314 | *this->toCoordinate = absCoordSoft; |
---|
| 315 | } |
---|
| 316 | if( this->parentMode & PNODE_ROTATE_MOVEMENT) |
---|
| 317 | { |
---|
| 318 | if (likely(this->parent != NULL)) |
---|
| 319 | *this->toCoordinate = absCoordSoft - parent->getAbsCoor (); |
---|
| 320 | else |
---|
| 321 | *this->toCoordinate = absCoordSoft; |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | |
---|
| 326 | /** |
---|
[6048] | 327 | * @brief shift coordinate relative |
---|
[4836] | 328 | * @param shift shift vector |
---|
[4987] | 329 | * |
---|
[5420] | 330 | * this function shifts the current coordinates about the vector shift. this is |
---|
| 331 | * usefull because from some place else you can: |
---|
| 332 | * PNode* someNode = ...; |
---|
| 333 | * Vector objectMovement = calculateShift(); |
---|
| 334 | * someNode->shiftCoor(objectMovement); |
---|
| 335 | * |
---|
| 336 | * this is the internal method of: |
---|
| 337 | * PNode* someNode = ...; |
---|
| 338 | * Vector objectMovement = calculateShift(); |
---|
| 339 | * Vector currentCoor = someNode->getRelCoor(); |
---|
| 340 | * Vector newCoor = currentCoor + objectMovement; |
---|
| 341 | * someNode->setRelCoor(newCoor); |
---|
| 342 | * |
---|
[5382] | 343 | */ |
---|
[3809] | 344 | void PNode::shiftCoor (const Vector& shift) |
---|
[3683] | 345 | { |
---|
[4993] | 346 | this->relCoordinate += shift; |
---|
| 347 | this->bRelCoorChanged = true; |
---|
[3683] | 348 | } |
---|
| 349 | |
---|
[6054] | 350 | |
---|
[3683] | 351 | /** |
---|
[6048] | 352 | * @brief set relative direction |
---|
[4836] | 353 | * @param relDir to its parent |
---|
[5091] | 354 | */ |
---|
[3810] | 355 | void PNode::setRelDir (const Quaternion& relDir) |
---|
[3675] | 356 | { |
---|
[5113] | 357 | if (this->toDirection!= NULL) |
---|
| 358 | { |
---|
| 359 | delete this->toDirection; |
---|
| 360 | this->toDirection = NULL; |
---|
| 361 | } |
---|
[4993] | 362 | this->relDirection = relDir; |
---|
[5819] | 363 | |
---|
[3675] | 364 | this->bRelCoorChanged = true; |
---|
| 365 | } |
---|
| 366 | |
---|
[6054] | 367 | |
---|
[3365] | 368 | /** |
---|
[4771] | 369 | * @see void PNode::setRelDir (const Quaternion& relDir) |
---|
| 370 | * @param x the x direction |
---|
| 371 | * @param y the y direction |
---|
| 372 | * @param z the z direction |
---|
| 373 | * |
---|
| 374 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 375 | */ |
---|
[6873] | 376 | void PNode::setRelDir (float angle, float x, float y, float z) |
---|
[4771] | 377 | { |
---|
[6873] | 378 | this->setRelDir(Quaternion(angle, Vector(x,y,z))); |
---|
[4771] | 379 | } |
---|
| 380 | |
---|
[4990] | 381 | |
---|
[4771] | 382 | /** |
---|
[6048] | 383 | * @brief sets the Relative Direction of this node to its parent in a Smoothed way |
---|
[4990] | 384 | * @param relDirSoft the direction to iterate to smoothely. |
---|
[4992] | 385 | * @param bias how fast to iterate to the new Direction |
---|
[4990] | 386 | */ |
---|
[4992] | 387 | void PNode::setRelDirSoft(const Quaternion& relDirSoft, float bias) |
---|
[4990] | 388 | { |
---|
| 389 | if (likely(this->toDirection == NULL)) |
---|
| 390 | this->toDirection = new Quaternion(); |
---|
| 391 | |
---|
| 392 | *this->toDirection = relDirSoft; |
---|
[4992] | 393 | this->bias = bias; |
---|
[5819] | 394 | this->bRelDirChanged = true; |
---|
[4990] | 395 | } |
---|
| 396 | |
---|
[6054] | 397 | |
---|
[4990] | 398 | /** |
---|
| 399 | * @see void PNode::setRelDirSoft (const Quaternion& relDir) |
---|
| 400 | * @param x the x direction |
---|
| 401 | * @param y the y direction |
---|
| 402 | * @param z the z direction |
---|
| 403 | * |
---|
| 404 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 405 | */ |
---|
[6873] | 406 | void PNode::setRelDirSoft(float angle, float x, float y, float z, float bias) |
---|
[4990] | 407 | { |
---|
[6873] | 408 | this->setRelDirSoft(Quaternion(angle, Vector(x,y,z)), bias); |
---|
[4990] | 409 | } |
---|
| 410 | |
---|
[6054] | 411 | |
---|
[4990] | 412 | /** |
---|
[6048] | 413 | * @brief sets the absolute direction |
---|
[4836] | 414 | * @param absDir absolute coordinates |
---|
[5091] | 415 | */ |
---|
[3810] | 416 | void PNode::setAbsDir (const Quaternion& absDir) |
---|
[3675] | 417 | { |
---|
[5113] | 418 | if (this->toDirection!= NULL) |
---|
| 419 | { |
---|
| 420 | delete this->toDirection; |
---|
| 421 | this->toDirection = NULL; |
---|
| 422 | } |
---|
| 423 | |
---|
[5001] | 424 | if (likely(this->parent != NULL)) |
---|
| 425 | this->relDirection = absDir / this->parent->getAbsDir(); |
---|
[4996] | 426 | else |
---|
[7008] | 427 | this->relDirection = absDir; |
---|
[4993] | 428 | |
---|
| 429 | this->bRelDirChanged = true; |
---|
[3675] | 430 | } |
---|
| 431 | |
---|
[6054] | 432 | |
---|
[3675] | 433 | /** |
---|
[4771] | 434 | * @see void PNode::setAbsDir (const Quaternion& relDir) |
---|
| 435 | * @param x the x direction |
---|
| 436 | * @param y the y direction |
---|
| 437 | * @param z the z direction |
---|
| 438 | * |
---|
| 439 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 440 | */ |
---|
[6873] | 441 | void PNode::setAbsDir (float angle, float x, float y, float z) |
---|
[4771] | 442 | { |
---|
[6873] | 443 | this->setAbsDir(Quaternion(angle, Vector(x,y,z))); |
---|
[4771] | 444 | } |
---|
| 445 | |
---|
[6054] | 446 | |
---|
[4771] | 447 | /** |
---|
[6048] | 448 | * @brief sets the absolute direction |
---|
[5414] | 449 | * @param absDir absolute coordinates |
---|
[6048] | 450 | * @param bias how fast to iterator to the new Position |
---|
[5414] | 451 | */ |
---|
| 452 | void PNode::setAbsDirSoft (const Quaternion& absDirSoft, float bias) |
---|
| 453 | { |
---|
| 454 | if (this->toDirection == NULL) |
---|
| 455 | this->toDirection = new Quaternion(); |
---|
| 456 | |
---|
| 457 | if (likely(this->parent != NULL)) |
---|
| 458 | *this->toDirection = absDirSoft / this->parent->getAbsDir(); |
---|
| 459 | else |
---|
[7008] | 460 | *this->toDirection = absDirSoft; |
---|
[5414] | 461 | |
---|
| 462 | this->bias = bias; |
---|
[5915] | 463 | this->bRelDirChanged = true; |
---|
[5414] | 464 | } |
---|
| 465 | |
---|
[6054] | 466 | |
---|
[5414] | 467 | /** |
---|
| 468 | * @see void PNode::setAbsDir (const Quaternion& relDir) |
---|
| 469 | * @param x the x direction |
---|
| 470 | * @param y the y direction |
---|
| 471 | * @param z the z direction |
---|
| 472 | * |
---|
| 473 | * main difference is, that here you give a directional vector, that will be translated into a Quaternion |
---|
| 474 | */ |
---|
[6873] | 475 | void PNode::setAbsDirSoft (float angle, float x, float y, float z, float bias) |
---|
[5414] | 476 | { |
---|
[6873] | 477 | this->setAbsDirSoft(Quaternion(angle, Vector(x,y,z)), bias); |
---|
[5414] | 478 | } |
---|
| 479 | |
---|
| 480 | |
---|
| 481 | /** |
---|
[6048] | 482 | * @brief shift Direction |
---|
[5091] | 483 | * @param shift the direction around which to shift. |
---|
| 484 | */ |
---|
[3802] | 485 | void PNode::shiftDir (const Quaternion& shift) |
---|
| 486 | { |
---|
[4993] | 487 | this->relDirection = this->relDirection * shift; |
---|
[3802] | 488 | this->bRelDirChanged = true; |
---|
| 489 | } |
---|
[3365] | 490 | |
---|
[6048] | 491 | |
---|
[3683] | 492 | /** |
---|
[6048] | 493 | * @brief adds a child and makes this node to a parent |
---|
[5091] | 494 | * @param child child reference |
---|
[4993] | 495 | * use this to add a child to this node. |
---|
[5420] | 496 | */ |
---|
[5382] | 497 | void PNode::addChild (PNode* child) |
---|
[3365] | 498 | { |
---|
[4993] | 499 | if( likely(child->parent != NULL)) |
---|
[7008] | 500 | child->parent->eraseChild(child); |
---|
[6075] | 501 | if (this->checkIntegrity(child)) |
---|
| 502 | { |
---|
| 503 | child->parent = this; |
---|
| 504 | if (unlikely(this != NULL)) |
---|
| 505 | this->children.push_back(child); |
---|
| 506 | child->parentCoorChanged(); |
---|
[6695] | 507 | |
---|
[7008] | 508 | // if(this->getUniqueID() == NET_UID_UNASSIGNED) |
---|
| 509 | // { |
---|
| 510 | // PRINTF(1)("Adding to an UNASSIGNED PNode - looking for next assigned Node\n"); |
---|
| 511 | // PNode* node = this->seekNextAssignedPNode(this); |
---|
| 512 | // if( node == NULL) |
---|
| 513 | // PRINTF(1)(" Got NULL - Is this the NULLParent - uid %i\n", this->getUniqueID()); |
---|
| 514 | // else |
---|
| 515 | // PRINTF(1)(" Found next assigned node: %i\n", node->getUniqueID()); |
---|
| 516 | // } |
---|
[6075] | 517 | } |
---|
| 518 | else |
---|
| 519 | { |
---|
| 520 | PRINTF(1)("Tried to reparent to own child '%s::%s' to '%s::%s'.\n", |
---|
| 521 | this->getClassName(), this->getName(), child->getClassName(), child->getName()); |
---|
| 522 | child->parent = NULL; |
---|
[6142] | 523 | child->parentCoorChanged(); |
---|
[6075] | 524 | } |
---|
[3365] | 525 | } |
---|
| 526 | |
---|
[6048] | 527 | |
---|
[6695] | 528 | PNode* PNode::seekNextAssignedPNode(PNode* node) const |
---|
| 529 | { |
---|
| 530 | PNode* tmpNode = node->parent; |
---|
| 531 | printf("entering seek PNode loop for name: %s, uid: %i\n", node->getName(), node->getUniqueID()); |
---|
| 532 | if(tmpNode) |
---|
| 533 | printf(" @node name: %s, uid: %d\n", tmpNode->getName(), tmpNode->getUniqueID()); |
---|
| 534 | while( tmpNode != NULL && tmpNode->getUniqueID() == NET_UID_UNASSIGNED) |
---|
| 535 | { |
---|
| 536 | printf(" @node name: %s, uid: %d\n", tmpNode->getName(), tmpNode->getUniqueID()); |
---|
| 537 | tmpNode = tmpNode->parent; |
---|
| 538 | } |
---|
| 539 | printf("leaving PNode loop\n\n"); |
---|
| 540 | |
---|
| 541 | return tmpNode; |
---|
| 542 | } |
---|
| 543 | |
---|
| 544 | |
---|
[3365] | 545 | /** |
---|
[5091] | 546 | * @see PNode::addChild(PNode* child); |
---|
[4765] | 547 | * @param childName the name of the child to add to this PNode |
---|
| 548 | */ |
---|
| 549 | void PNode::addChild (const char* childName) |
---|
| 550 | { |
---|
| 551 | PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE)); |
---|
[7008] | 552 | // PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName()); |
---|
| 553 | // assert( childNode != NULL ); |
---|
[4765] | 554 | if (childNode != NULL) |
---|
[6634] | 555 | { |
---|
[4765] | 556 | this->addChild(childNode); |
---|
[6634] | 557 | } |
---|
[4765] | 558 | } |
---|
| 559 | |
---|
[6048] | 560 | |
---|
[4765] | 561 | /** |
---|
[6048] | 562 | * @brief removes a child from the node |
---|
[5091] | 563 | * @param child the child to remove from this pNode. |
---|
[4993] | 564 | * |
---|
[6054] | 565 | * Children from pNode will not be lost, they are Reparented by the rules of the ParentMode |
---|
[5420] | 566 | */ |
---|
[4993] | 567 | void PNode::removeChild (PNode* child) |
---|
[3365] | 568 | { |
---|
[5214] | 569 | if (child != NULL) |
---|
[7008] | 570 | child->removeNode(); |
---|
[3365] | 571 | } |
---|
| 572 | |
---|
[6054] | 573 | |
---|
[3365] | 574 | /** |
---|
[6075] | 575 | * !! PRIVATE FUNCTION |
---|
[6299] | 576 | * @brief reparents a node (happens on Parents Node delete or remove and Flags are set.) |
---|
[6075] | 577 | */ |
---|
| 578 | void PNode::reparent() |
---|
| 579 | { |
---|
[6078] | 580 | if (this->parentMode & PNODE_REPARENT_TO_NULL) |
---|
| 581 | this->setParent((PNode*)NULL); |
---|
[6075] | 582 | else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL) |
---|
| 583 | this->setParent(this->parent->getParent()); |
---|
[6078] | 584 | else |
---|
| 585 | this->setParent(PNode::getNullParent()); |
---|
[6075] | 586 | } |
---|
| 587 | |
---|
[6299] | 588 | /** |
---|
| 589 | * ereases child from the nodes children |
---|
| 590 | * @param chuld the child to remove |
---|
| 591 | */ |
---|
[6078] | 592 | void PNode::eraseChild(PNode* child) |
---|
| 593 | { |
---|
| 594 | std::list<PNode*>::iterator childRemover = std::find(this->children.begin(), this->children.end(), child); |
---|
| 595 | if(childRemover != this->children.end()) |
---|
| 596 | this->children.erase(childRemover); |
---|
| 597 | } |
---|
[6075] | 598 | |
---|
[6078] | 599 | |
---|
[6075] | 600 | /** |
---|
[6048] | 601 | * @brief remove this pnode from the tree and adds all following to NullParent |
---|
[5420] | 602 | * |
---|
| 603 | * this can be the case, if an entity in the world is being destroyed. |
---|
| 604 | */ |
---|
[5769] | 605 | void PNode::removeNode() |
---|
[3537] | 606 | { |
---|
[6078] | 607 | list<PNode*>::iterator child = this->children.begin(); |
---|
| 608 | list<PNode*>::iterator reparenter; |
---|
| 609 | while (child != this->children.end()) |
---|
[6054] | 610 | { |
---|
[6078] | 611 | reparenter = child; |
---|
| 612 | child++; |
---|
| 613 | if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE || |
---|
| 614 | (*reparenter)->parentMode & PNODE_REPARENT_ON_PARENTS_REMOVE) |
---|
[6142] | 615 | { |
---|
| 616 | printf("TEST----------------%s ---- %s\n", this->getClassName(), (*reparenter)->getClassName()); |
---|
[6054] | 617 | (*reparenter)->reparent(); |
---|
[6078] | 618 | printf("REPARENTED TO: %s::%s\n",(*reparenter)->getParent()->getClassName(),(*reparenter)->getParent()->getName()); |
---|
[6054] | 619 | } |
---|
| 620 | } |
---|
[5214] | 621 | if (this->parent != NULL) |
---|
[6142] | 622 | { |
---|
[6078] | 623 | this->parent->eraseChild(this); |
---|
[6142] | 624 | this->parent = NULL; |
---|
| 625 | } |
---|
[3537] | 626 | } |
---|
| 627 | |
---|
[3365] | 628 | |
---|
[4761] | 629 | /** |
---|
| 630 | * @see PNode::setParent(PNode* parent); |
---|
| 631 | * @param parentName the name of the Parent to set to this PNode |
---|
| 632 | */ |
---|
| 633 | void PNode::setParent (const char* parentName) |
---|
| 634 | { |
---|
| 635 | PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE)); |
---|
| 636 | if (parentNode != NULL) |
---|
| 637 | parentNode->addChild(this); |
---|
[6075] | 638 | else |
---|
| 639 | PRINTF(2)("Not Found PNode's (%s::%s) new Parent by Name: %s\n", |
---|
| 640 | this->getClassName(), this->getName(), parentName); |
---|
[4761] | 641 | } |
---|
| 642 | |
---|
[6054] | 643 | |
---|
[4990] | 644 | /** |
---|
[6048] | 645 | * @brief does the reparenting in a very smooth way |
---|
[4990] | 646 | * @param parentNode the new Node to connect this node to. |
---|
[4993] | 647 | * @param bias the speed to iterate to this new Positions |
---|
[4990] | 648 | */ |
---|
[5382] | 649 | void PNode::setParentSoft(PNode* parentNode, float bias) |
---|
[4987] | 650 | { |
---|
[5382] | 651 | // return if the new parent and the old one match |
---|
[6075] | 652 | if (this->parent == parentNode ) |
---|
[4992] | 653 | return; |
---|
[6075] | 654 | if (parentNode == NULL) |
---|
| 655 | parentNode = PNode::getNullParent(); |
---|
[4992] | 656 | |
---|
[5382] | 657 | // store the Valures to iterate to. |
---|
[4993] | 658 | if (likely(this->toCoordinate == NULL)) |
---|
[4989] | 659 | { |
---|
[4993] | 660 | this->toCoordinate = new Vector(); |
---|
| 661 | *this->toCoordinate = this->getRelCoor(); |
---|
[4989] | 662 | } |
---|
[4990] | 663 | if (likely(this->toDirection == NULL)) |
---|
| 664 | { |
---|
| 665 | this->toDirection = new Quaternion(); |
---|
| 666 | *this->toDirection = this->getRelDir(); |
---|
| 667 | } |
---|
[4992] | 668 | this->bias = bias; |
---|
[4987] | 669 | |
---|
[4990] | 670 | Vector tmpV = this->getAbsCoor(); |
---|
| 671 | Quaternion tmpQ = this->getAbsDir(); |
---|
[4987] | 672 | |
---|
| 673 | parentNode->addChild(this); |
---|
| 674 | |
---|
[7008] | 675 | if (this->parentMode & PNODE_ROTATE_MOVEMENT && this->parent != NULL) |
---|
| 676 | this->relCoordinate = this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()); |
---|
| 677 | else |
---|
| 678 | this->relCoordinate = tmpV - parentNode->getAbsCoor(); |
---|
[4991] | 679 | |
---|
[7008] | 680 | this->relDirection = tmpQ / parentNode->getAbsDir(); |
---|
[4987] | 681 | } |
---|
| 682 | |
---|
[6054] | 683 | |
---|
[4993] | 684 | /** |
---|
[6048] | 685 | * @brief does the reparenting in a very smooth way |
---|
[4993] | 686 | * @param parentName the name of the Parent to reconnect to |
---|
| 687 | * @param bias the speed to iterate to this new Positions |
---|
| 688 | */ |
---|
[5382] | 689 | void PNode::setParentSoft(const char* parentName, float bias) |
---|
[4987] | 690 | { |
---|
| 691 | PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE)); |
---|
| 692 | if (parentNode != NULL) |
---|
[5382] | 693 | this->setParentSoft(parentNode, bias); |
---|
[4987] | 694 | } |
---|
| 695 | |
---|
[6054] | 696 | /** |
---|
| 697 | * @param parentMode sets the parentingMode of this Node |
---|
| 698 | */ |
---|
| 699 | void PNode::setParentMode(PARENT_MODE parentMode) |
---|
| 700 | { |
---|
[6307] | 701 | this->parentMode = ((this->parentMode & 0xfff0) | parentMode); |
---|
[6054] | 702 | } |
---|
[6048] | 703 | |
---|
[3365] | 704 | /** |
---|
[6048] | 705 | * @brief sets the mode of this parent manually |
---|
[4765] | 706 | * @param parentMode a String representing this parentingMode |
---|
| 707 | */ |
---|
| 708 | void PNode::setParentMode (const char* parentingMode) |
---|
| 709 | { |
---|
[4993] | 710 | this->setParentMode(PNode::charToParentingMode(parentingMode)); |
---|
[4765] | 711 | } |
---|
[3537] | 712 | |
---|
[3365] | 713 | /** |
---|
[6075] | 714 | * @brief adds special mode Flags to this PNode |
---|
| 715 | * @see PARENT_MODE |
---|
| 716 | * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator. |
---|
[6054] | 717 | */ |
---|
[6078] | 718 | void PNode::addNodeFlags(unsigned short nodeFlags) |
---|
[6054] | 719 | { |
---|
| 720 | this->parentMode |= nodeFlags; |
---|
| 721 | } |
---|
| 722 | |
---|
[6075] | 723 | /** |
---|
| 724 | * @brief removes special mode Flags to this PNode |
---|
| 725 | * @see PARENT_MODE |
---|
| 726 | * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator. |
---|
| 727 | */ |
---|
[6078] | 728 | void PNode::removeNodeFlags(unsigned short nodeFlags) |
---|
[6054] | 729 | { |
---|
| 730 | this->parentMode &= !nodeFlags; |
---|
| 731 | } |
---|
| 732 | |
---|
[6078] | 733 | /** |
---|
| 734 | * @returns the NullParent (and if needed creates it) |
---|
| 735 | */ |
---|
| 736 | PNode* PNode::createNullParent() |
---|
| 737 | { |
---|
| 738 | if (likely(PNode::nullParent == NULL)) |
---|
| 739 | { |
---|
| 740 | PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL); |
---|
[6695] | 741 | PNode::nullParent->setClassID(CL_NULL_PARENT, "NullParent"); |
---|
[6078] | 742 | PNode::nullParent->setName("NullParent"); |
---|
[6695] | 743 | PNode::nullParent->setSynchronized(true); |
---|
[6078] | 744 | } |
---|
| 745 | return PNode::nullParent; |
---|
| 746 | } |
---|
[6054] | 747 | |
---|
[6078] | 748 | |
---|
[6054] | 749 | /** |
---|
[6075] | 750 | * !! PRIVATE FUNCTION |
---|
| 751 | * @brief checks the upward integrity (e.g if PNode is somewhere up the Node tree.) |
---|
| 752 | * @param checkParent the Parent to check. |
---|
| 753 | * @returns true if the integrity-check succeeds, false otherwise. |
---|
| 754 | * |
---|
| 755 | * If there is a second occurence of checkParent before NULL, then a loop could get |
---|
| 756 | * into the Tree, and we do not want this. |
---|
| 757 | */ |
---|
| 758 | bool PNode::checkIntegrity(const PNode* checkParent) const |
---|
| 759 | { |
---|
| 760 | const PNode* parent = this; |
---|
| 761 | while ( (parent = parent->getParent()) != NULL) |
---|
| 762 | if (unlikely(parent == checkParent)) |
---|
| 763 | return false; |
---|
| 764 | return true; |
---|
| 765 | } |
---|
| 766 | |
---|
| 767 | |
---|
| 768 | /** |
---|
[6048] | 769 | * @brief updates the absCoordinate/absDirection |
---|
[4836] | 770 | * @param dt The time passed since the last update |
---|
[5420] | 771 | * |
---|
| 772 | * this is used to go through the parent-tree to update all the absolute coordinates |
---|
| 773 | * and directions. this update should be done by the engine, so you don't have to |
---|
| 774 | * worry, normaly... |
---|
| 775 | */ |
---|
[5769] | 776 | void PNode::updateNode (float dt) |
---|
[3365] | 777 | { |
---|
[6075] | 778 | if (!(this->parentMode & PNODE_STATIC_NODE)) |
---|
| 779 | { |
---|
| 780 | if( likely(this->parent != NULL)) |
---|
[4440] | 781 | { |
---|
[7008] | 782 | // movement for nodes with smoothMove enabled |
---|
| 783 | if (unlikely(this->toCoordinate != NULL)) |
---|
| 784 | { |
---|
| 785 | float shiftLen = fabsf(dt)*bias; |
---|
| 786 | if (shiftLen >= 1.0) |
---|
| 787 | shiftLen = 1.0; |
---|
| 788 | Vector moveVect = (*this->toCoordinate - this->relCoordinate) * shiftLen; |
---|
| 789 | if (likely(moveVect.len() >= PNODE_ITERATION_DELTA)) |
---|
[4987] | 790 | { |
---|
[7008] | 791 | this->shiftCoor(moveVect); |
---|
[4987] | 792 | } |
---|
[7008] | 793 | else |
---|
[4987] | 794 | { |
---|
[7008] | 795 | delete this->toCoordinate; |
---|
| 796 | this->toCoordinate = NULL; |
---|
| 797 | PRINTF(5)("SmoothMove of %s finished\n", this->getName()); |
---|
[4987] | 798 | } |
---|
[7008] | 799 | } |
---|
| 800 | if (unlikely(this->toDirection != NULL)) |
---|
| 801 | { |
---|
| 802 | float shiftLen = fabsf(dt)*bias; |
---|
| 803 | if (shiftLen >= 1.0) |
---|
| 804 | shiftLen = 1.0; |
---|
| 805 | //printf("%s::%s %f\n", this->getClassName(), this->getName(), this->toStep ); |
---|
| 806 | Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, shiftLen); |
---|
| 807 | if (this->relDirection.distance(rotQuat) > PNODE_ITERATION_DELTA) |
---|
| 808 | { |
---|
| 809 | this->relDirection = rotQuat; |
---|
| 810 | this->bRelDirChanged; |
---|
| 811 | } |
---|
| 812 | else |
---|
| 813 | { |
---|
| 814 | delete this->toDirection; |
---|
| 815 | this->toDirection = NULL; |
---|
| 816 | PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); |
---|
| 817 | this->bRelDirChanged; |
---|
| 818 | } |
---|
| 819 | } |
---|
[4990] | 820 | |
---|
[7008] | 821 | // MAIN UPDATE ///////////////////////////////////// |
---|
| 822 | this->lastAbsCoordinate = this->absCoordinate; |
---|
[4145] | 823 | |
---|
[7008] | 824 | PRINTF(5)("PNode::update - '%s::%s' - (%f, %f, %f)\n", this->getClassName(), this->getName(), |
---|
| 825 | this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); |
---|
[3800] | 826 | |
---|
[4570] | 827 | |
---|
[7008] | 828 | if(this->bRelDirChanged && this->parentMode & PNODE_LOCAL_ROTATE ) |
---|
| 829 | { |
---|
| 830 | /* update the current absDirection - remember * means rotation around sth.*/ |
---|
| 831 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 832 | this->absDirection = parent->getAbsDir() * this->relDirection; |
---|
| 833 | } |
---|
[4570] | 834 | |
---|
[7008] | 835 | if(likely(this->bRelCoorChanged && this->parentMode & PNODE_MOVEMENT)) |
---|
| 836 | { |
---|
[6075] | 837 | /* update the current absCoordinate */ |
---|
[7008] | 838 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 839 | this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; |
---|
[5007] | 840 | } |
---|
[7008] | 841 | else if( this->parentMode & PNODE_ROTATE_MOVEMENT && (this->bRelCoorChanged || this->bRelDirChanged)) |
---|
| 842 | { |
---|
| 843 | /* update the current absCoordinate */ |
---|
| 844 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 845 | this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); |
---|
| 846 | } |
---|
| 847 | ///////////////////////////////////////////////// |
---|
| 848 | } |
---|
[6075] | 849 | |
---|
[7008] | 850 | else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT |
---|
[4440] | 851 | { |
---|
[6075] | 852 | PRINTF(4)("update ParentLess Node (%s::%s) - (%f, %f, %f)\n", this->getClassName(), this->getName(), |
---|
| 853 | this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); |
---|
[7008] | 854 | if (this->bRelCoorChanged) |
---|
| 855 | { |
---|
| 856 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 857 | this->absCoordinate = this->relCoordinate; |
---|
[5118] | 858 | } |
---|
[7008] | 859 | if (this->bRelDirChanged) |
---|
| 860 | { |
---|
| 861 | this->prevRelDirection = this->relDirection; |
---|
| 862 | this->absDirection = this->getAbsDir () * this->relDirection; |
---|
| 863 | } |
---|
[4993] | 864 | } |
---|
[7008] | 865 | } |
---|
[3365] | 866 | |
---|
[7008] | 867 | if(!this->children.empty() && (this->bActive || this->parentMode & PNODE_UPDATE_CHILDREN_IF_INACTIVE )) |
---|
| 868 | { |
---|
| 869 | list<PNode*>::iterator child; |
---|
| 870 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
[4993] | 871 | { |
---|
[7008] | 872 | /* if this node has changed, make sure, that all children are updated also */ |
---|
| 873 | if( likely(this->bRelCoorChanged)) |
---|
| 874 | (*child)->parentCoorChanged (); |
---|
| 875 | if( likely(this->bRelDirChanged)) |
---|
| 876 | (*child)->parentDirChanged (); |
---|
[4993] | 877 | |
---|
[7008] | 878 | (*child)->updateNode(dt); |
---|
[4440] | 879 | } |
---|
[7008] | 880 | } |
---|
| 881 | this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; |
---|
| 882 | this->bRelCoorChanged = false; |
---|
| 883 | this->bRelDirChanged = false; |
---|
[3365] | 884 | } |
---|
| 885 | |
---|
[5769] | 886 | |
---|
[6075] | 887 | |
---|
| 888 | |
---|
| 889 | |
---|
| 890 | /************* |
---|
| 891 | * DEBUGGING * |
---|
| 892 | *************/ |
---|
[6048] | 893 | /** |
---|
| 894 | * @brief counts total amount the children walking through the entire tree. |
---|
| 895 | * @param nodes the counter |
---|
| 896 | */ |
---|
[5769] | 897 | void PNode::countChildNodes(int& nodes) const |
---|
| 898 | { |
---|
| 899 | nodes++; |
---|
[5770] | 900 | list<PNode*>::const_iterator child; |
---|
| 901 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
| 902 | (*child)->countChildNodes(nodes); |
---|
[5769] | 903 | } |
---|
| 904 | |
---|
| 905 | |
---|
[3450] | 906 | /** |
---|
[6048] | 907 | * @brief displays some information about this pNode |
---|
[4836] | 908 | * @param depth The deph into which to debug the children of this PNode to. |
---|
[5383] | 909 | * (0: all children will be debugged, 1: only this PNode, 2: this and direct children, ...) |
---|
| 910 | * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output). |
---|
[5420] | 911 | */ |
---|
[5769] | 912 | void PNode::debugNode(unsigned int depth, unsigned int level) const |
---|
[3365] | 913 | { |
---|
[4574] | 914 | for (unsigned int i = 0; i < level; i++) |
---|
[4575] | 915 | PRINT(0)(" |"); |
---|
[5770] | 916 | if (this->children.size() > 0) |
---|
[4575] | 917 | PRINT(0)(" +"); |
---|
| 918 | else |
---|
| 919 | PRINT(0)(" -"); |
---|
[5769] | 920 | |
---|
| 921 | int childNodeCount = 0; |
---|
| 922 | this->countChildNodes(childNodeCount); |
---|
| 923 | |
---|
| 924 | 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] | 925 | this->getClassName(), |
---|
| 926 | this->getName(), |
---|
| 927 | this->absCoordinate.x, |
---|
| 928 | this->absCoordinate.y, |
---|
| 929 | this->absCoordinate.z, |
---|
| 930 | this->relCoordinate.x, |
---|
| 931 | this->relCoordinate.y, |
---|
[4993] | 932 | this->relCoordinate.z, |
---|
[4996] | 933 | this->getAbsDirV().x, |
---|
| 934 | this->getAbsDirV().y, |
---|
| 935 | this->getAbsDirV().z, |
---|
[5769] | 936 | this->parentingModeToChar(parentMode), |
---|
| 937 | childNodeCount); |
---|
[4574] | 938 | if (depth >= 2 || depth == 0) |
---|
| 939 | { |
---|
[5770] | 940 | list<PNode*>::const_iterator child; |
---|
| 941 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
[4574] | 942 | { |
---|
| 943 | if (depth == 0) |
---|
[5770] | 944 | (*child)->debugNode(0, level + 1); |
---|
[4574] | 945 | else |
---|
[5770] | 946 | (*child)->debugNode(depth - 1, level +1); |
---|
[4574] | 947 | } |
---|
| 948 | } |
---|
[3365] | 949 | } |
---|
| 950 | |
---|
[4570] | 951 | /** |
---|
[6048] | 952 | * @brief displays the PNode at its position with its rotation as a cube. |
---|
[5383] | 953 | * @param depth The deph into which to debug the children of this PNode to. |
---|
| 954 | * (0: all children will be displayed, 1: only this PNode, 2: this and direct children, ...) |
---|
| 955 | * @param size the Size of the Box to draw. |
---|
| 956 | * @param color the color of the Box to display. |
---|
| 957 | * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output). |
---|
| 958 | */ |
---|
| 959 | void PNode::debugDraw(unsigned int depth, float size, const Vector& color, unsigned int level) const |
---|
[4570] | 960 | { |
---|
[5432] | 961 | // if this is the first Element we draw |
---|
[5383] | 962 | if (level == 0) |
---|
| 963 | { |
---|
[5432] | 964 | glPushAttrib(GL_ENABLE_BIT); // save the Enable-attributes |
---|
| 965 | glMatrixMode(GL_MODELVIEW); // goto the ModelView Matrix |
---|
[5383] | 966 | |
---|
[5432] | 967 | glDisable(GL_LIGHTING); // disable lighting (we do not need them for just lighting) |
---|
| 968 | glDisable(GL_BLEND); // '' |
---|
| 969 | glDisable(GL_TEXTURE_2D); // '' |
---|
[5438] | 970 | glDisable(GL_DEPTH_TEST); // '' |
---|
[5383] | 971 | } |
---|
| 972 | |
---|
[5432] | 973 | glPushMatrix(); // repush the Matrix-stack |
---|
[4570] | 974 | /* translate */ |
---|
| 975 | glTranslatef (this->getAbsCoor ().x, |
---|
| 976 | this->getAbsCoor ().y, |
---|
| 977 | this->getAbsCoor ().z); |
---|
[7008] | 978 | // this->getAbsDir ().matrix (matrix); |
---|
[4998] | 979 | |
---|
[5432] | 980 | /* rotate */ |
---|
[4998] | 981 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
[5432] | 982 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 983 | /* set the new Color */ |
---|
[5008] | 984 | glColor3f(color.x, color.y, color.z); |
---|
[5432] | 985 | { /* draw a cube of size size */ |
---|
[4570] | 986 | glBegin(GL_LINE_STRIP); |
---|
[4995] | 987 | glVertex3f(-.5*size, -.5*size, -.5*size); |
---|
| 988 | glVertex3f(+.5*size, -.5*size, -.5*size); |
---|
| 989 | glVertex3f(+.5*size, -.5*size, +.5*size); |
---|
| 990 | glVertex3f(-.5*size, -.5*size, +.5*size); |
---|
| 991 | glVertex3f(-.5*size, -.5*size, -.5*size); |
---|
[4570] | 992 | glEnd(); |
---|
| 993 | glBegin(GL_LINE_STRIP); |
---|
[4995] | 994 | glVertex3f(-.5*size, +.5*size, -.5*size); |
---|
| 995 | glVertex3f(+.5*size, +.5*size, -.5*size); |
---|
| 996 | glVertex3f(+.5*size, +.5*size, +.5*size); |
---|
| 997 | glVertex3f(-.5*size, +.5*size, +.5*size); |
---|
| 998 | glVertex3f(-.5*size, +.5*size, -.5*size); |
---|
[4570] | 999 | glEnd(); |
---|
[4995] | 1000 | |
---|
[4570] | 1001 | glBegin(GL_LINES); |
---|
[4995] | 1002 | glVertex3f(-.5*size, -.5*size, -.5*size); |
---|
| 1003 | glVertex3f(-.5*size, +.5*size, -.5*size); |
---|
| 1004 | glVertex3f(+.5*size, -.5*size, -.5*size); |
---|
| 1005 | glVertex3f(+.5*size, +.5*size, -.5*size); |
---|
| 1006 | glVertex3f(+.5*size, -.5*size, +.5*size); |
---|
| 1007 | glVertex3f(+.5*size, +.5*size, +.5*size); |
---|
| 1008 | glVertex3f(-.5*size, -.5*size, +.5*size); |
---|
| 1009 | glVertex3f(-.5*size, +.5*size, +.5*size); |
---|
[4570] | 1010 | glEnd(); |
---|
| 1011 | } |
---|
[6780] | 1012 | glPopMatrix(); |
---|
[4570] | 1013 | |
---|
[5007] | 1014 | if (depth >= 2 || depth == 0) |
---|
| 1015 | { |
---|
[5432] | 1016 | /* rotate the current color in HSV space around 20 degree */ |
---|
[5115] | 1017 | Vector childColor = Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(20,0,.0)); |
---|
[5770] | 1018 | list<PNode*>::const_iterator child; |
---|
| 1019 | for (child = this->children.begin(); child != this->children.end(); child ++) |
---|
[5007] | 1020 | { |
---|
[5394] | 1021 | // drawing the Dependency graph |
---|
[7008] | 1022 | if (this != PNode::getNullParent()) |
---|
[5394] | 1023 | { |
---|
[7008] | 1024 | glBegin(GL_LINES); |
---|
| 1025 | glColor3f(color.x, color.y, color.z); |
---|
| 1026 | glVertex3f(this->getAbsCoor ().x, |
---|
| 1027 | this->getAbsCoor ().y, |
---|
| 1028 | this->getAbsCoor ().z); |
---|
[5394] | 1029 | glColor3f(childColor.x, childColor.y, childColor.z); |
---|
[5770] | 1030 | glVertex3f((*child)->getAbsCoor ().x, |
---|
| 1031 | (*child)->getAbsCoor ().y, |
---|
| 1032 | (*child)->getAbsCoor ().z); |
---|
[5394] | 1033 | glEnd(); |
---|
| 1034 | } |
---|
[5915] | 1035 | |
---|
[5432] | 1036 | /* if we want to draw the children too */ |
---|
| 1037 | if (depth == 0) /* -> all of them */ |
---|
[5770] | 1038 | (*child)->debugDraw(0, size, childColor, level+1); |
---|
[5432] | 1039 | else /* -> only the Next one */ |
---|
[5770] | 1040 | (*child)->debugDraw(depth - 1, size, childColor, level +1); |
---|
[5007] | 1041 | } |
---|
| 1042 | } |
---|
[5383] | 1043 | if (level == 0) |
---|
[5432] | 1044 | glPopAttrib(); /* pop the saved attributes back out */ |
---|
[4570] | 1045 | } |
---|
[4993] | 1046 | |
---|
| 1047 | |
---|
| 1048 | |
---|
| 1049 | ///////////////////// |
---|
| 1050 | // HELPER_FUCTIONS // |
---|
| 1051 | ///////////////////// |
---|
| 1052 | |
---|
| 1053 | /** |
---|
[6048] | 1054 | * @brief converts a parentingMode into a string that is the name of it |
---|
[4993] | 1055 | * @param parentingMode the ParentingMode to convert |
---|
| 1056 | * @return the converted string |
---|
| 1057 | */ |
---|
| 1058 | const char* PNode::parentingModeToChar(int parentingMode) |
---|
| 1059 | { |
---|
| 1060 | if (parentingMode == PNODE_LOCAL_ROTATE) |
---|
| 1061 | return "local-rotate"; |
---|
| 1062 | else if (parentingMode == PNODE_ROTATE_MOVEMENT) |
---|
| 1063 | return "rotate-movement"; |
---|
| 1064 | else if (parentingMode == PNODE_MOVEMENT) |
---|
| 1065 | return "movement"; |
---|
| 1066 | else if (parentingMode == PNODE_ALL) |
---|
| 1067 | return "all"; |
---|
| 1068 | else if (parentingMode == PNODE_ROTATE_AND_MOVE) |
---|
| 1069 | return "rotate-and-move"; |
---|
| 1070 | } |
---|
| 1071 | |
---|
| 1072 | /** |
---|
[6048] | 1073 | * @brief converts a parenting-mode-string into a int |
---|
[4993] | 1074 | * @param parentingMode the string naming the parentingMode |
---|
| 1075 | * @return the int corresponding to the named parentingMode |
---|
| 1076 | */ |
---|
| 1077 | PARENT_MODE PNode::charToParentingMode(const char* parentingMode) |
---|
| 1078 | { |
---|
| 1079 | if (!strcmp(parentingMode, "local-rotate")) |
---|
| 1080 | return (PNODE_LOCAL_ROTATE); |
---|
| 1081 | else if (!strcmp(parentingMode, "rotate-movement")) |
---|
| 1082 | return (PNODE_ROTATE_MOVEMENT); |
---|
| 1083 | else if (!strcmp(parentingMode, "movement")) |
---|
| 1084 | return (PNODE_MOVEMENT); |
---|
| 1085 | else if (!strcmp(parentingMode, "all")) |
---|
| 1086 | return (PNODE_ALL); |
---|
| 1087 | else if (!strcmp(parentingMode, "rotate-and-move")) |
---|
| 1088 | return (PNODE_ROTATE_AND_MOVE); |
---|
| 1089 | } |
---|
[6341] | 1090 | |
---|
| 1091 | /** |
---|
| 1092 | * Writes data from network containing information about the state |
---|
| 1093 | * @param data pointer to data |
---|
| 1094 | * @param length length of data |
---|
| 1095 | * @param sender hostID of sender |
---|
| 1096 | */ |
---|
| 1097 | int PNode::writeState( const byte * data, int length, int sender ) |
---|
| 1098 | { |
---|
| 1099 | SYNCHELP_READ_BEGIN(); |
---|
| 1100 | |
---|
[6815] | 1101 | SYNCHELP_READ_FKT( BaseObject::writeState, NWT_PN_BO_WRITESTATE ); |
---|
[6341] | 1102 | |
---|
[7008] | 1103 | // char * parentName = NULL; |
---|
| 1104 | // SYNCHELP_READ_STRINGM( parentName ); |
---|
| 1105 | // |
---|
| 1106 | // if ( strcmp(parentName, "")==0 ) |
---|
| 1107 | // { |
---|
| 1108 | // setParent( (char*)NULL ); |
---|
| 1109 | // } |
---|
| 1110 | // else |
---|
| 1111 | // { |
---|
| 1112 | // setParent( parentName ); |
---|
| 1113 | // } |
---|
| 1114 | // |
---|
| 1115 | // delete[] parentName; |
---|
[6341] | 1116 | |
---|
| 1117 | int parentMode; |
---|
[6815] | 1118 | SYNCHELP_READ_INT( parentMode, NWT_PN_PARENTMODE ); |
---|
[6341] | 1119 | this->setParentMode((PARENT_MODE)parentMode); |
---|
| 1120 | |
---|
| 1121 | float f1, f2, f3, f4; |
---|
| 1122 | |
---|
[6815] | 1123 | SYNCHELP_READ_FLOAT( f1, NWT_PN_COORX ); |
---|
| 1124 | SYNCHELP_READ_FLOAT( f2, NWT_PN_COORY ); |
---|
| 1125 | SYNCHELP_READ_FLOAT( f3, NWT_PN_COORZ ); |
---|
[6341] | 1126 | this->setRelCoor( f1, f2, f3 ); |
---|
| 1127 | |
---|
| 1128 | |
---|
[6815] | 1129 | SYNCHELP_READ_FLOAT( f1, NWT_PN_ROTV ); |
---|
| 1130 | SYNCHELP_READ_FLOAT( f2, NWT_PN_ROTX ); |
---|
| 1131 | SYNCHELP_READ_FLOAT( f3, NWT_PN_ROTY ); |
---|
| 1132 | SYNCHELP_READ_FLOAT( f4, NWT_PN_ROTZ ); |
---|
[6341] | 1133 | this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) ); |
---|
| 1134 | |
---|
[7008] | 1135 | // int n; |
---|
| 1136 | // char * childName; |
---|
| 1137 | // |
---|
| 1138 | // PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]); |
---|
| 1139 | // SYNCHELP_READ_INT( n ); |
---|
| 1140 | // PRINTF(0)("read %s:n=%d\n", this->getName(), n); |
---|
| 1141 | // |
---|
| 1142 | // for (int i = 0; i<n; i++) |
---|
| 1143 | // { |
---|
| 1144 | // SYNCHELP_READ_STRINGM( childName ); |
---|
| 1145 | // PRINTF(0)("RCVD CHILD = %s\n", childName); |
---|
| 1146 | // addChild( childName ); |
---|
| 1147 | // delete childName; |
---|
| 1148 | // childName = NULL; |
---|
| 1149 | // } |
---|
[6341] | 1150 | |
---|
| 1151 | return SYNCHELP_READ_N; |
---|
| 1152 | } |
---|
| 1153 | |
---|
| 1154 | /** |
---|
| 1155 | * data copied in data will bee sent to another host |
---|
| 1156 | * @param data pointer to data |
---|
| 1157 | * @param maxLength max length of data |
---|
| 1158 | * @return the number of bytes writen |
---|
| 1159 | */ |
---|
| 1160 | int PNode::readState( byte * data, int maxLength ) |
---|
| 1161 | { |
---|
| 1162 | SYNCHELP_WRITE_BEGIN(); |
---|
| 1163 | |
---|
[6815] | 1164 | SYNCHELP_WRITE_FKT( BaseObject::readState, NWT_PN_BO_WRITESTATE ); |
---|
[6341] | 1165 | |
---|
[7008] | 1166 | // if ( this->parent ) |
---|
| 1167 | // { |
---|
| 1168 | // SYNCHELP_WRITE_STRING( parent->getName() ); |
---|
| 1169 | // } |
---|
| 1170 | // else |
---|
| 1171 | // { |
---|
| 1172 | // SYNCHELP_WRITE_STRING( "" ); |
---|
| 1173 | // } |
---|
[6341] | 1174 | |
---|
[6815] | 1175 | SYNCHELP_WRITE_INT( this->parentMode, NWT_PN_PARENTMODE ); |
---|
[6341] | 1176 | |
---|
[6815] | 1177 | SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_COORX ); |
---|
| 1178 | SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_COORY ); |
---|
| 1179 | SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_COORZ ); |
---|
[6341] | 1180 | |
---|
[6815] | 1181 | SYNCHELP_WRITE_FLOAT( this->relDirection.w, NWT_PN_ROTV ); |
---|
| 1182 | SYNCHELP_WRITE_FLOAT( this->relDirection.v.x, NWT_PN_ROTX ); |
---|
| 1183 | SYNCHELP_WRITE_FLOAT( this->relDirection.v.y, NWT_PN_ROTY ); |
---|
| 1184 | SYNCHELP_WRITE_FLOAT( this->relDirection.v.z, NWT_PN_ROTZ ); |
---|
[6341] | 1185 | |
---|
[7008] | 1186 | // int n = children.size(); |
---|
| 1187 | // //check if camera is in children |
---|
| 1188 | // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) |
---|
| 1189 | // { |
---|
| 1190 | // if ( (*it)->isA(CL_CAMERA) ) |
---|
| 1191 | // n--; |
---|
| 1192 | // } |
---|
| 1193 | // PRINTF(0)("write %s:n=%d\n", this->getName(), n); |
---|
| 1194 | // SYNCHELP_WRITE_INT( n ); |
---|
| 1195 | // PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]); |
---|
| 1196 | // |
---|
| 1197 | // |
---|
| 1198 | // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) |
---|
| 1199 | // { |
---|
| 1200 | // //dont add camera because there is only one camera attached to local player |
---|
| 1201 | // if ( !(*it)->isA(CL_CAMERA) ) |
---|
| 1202 | // { |
---|
| 1203 | // PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName()); |
---|
| 1204 | // SYNCHELP_WRITE_STRING( (*it)->getName() ); |
---|
| 1205 | // } |
---|
| 1206 | // } |
---|
[6341] | 1207 | |
---|
| 1208 | return SYNCHELP_WRITE_N; |
---|
| 1209 | } |
---|
[6634] | 1210 | |
---|
| 1211 | #define __FLAG_COOR 1 |
---|
| 1212 | #define __FLAG_ROT 2 |
---|
| 1213 | |
---|
| 1214 | #define __OFFSET_POS 1 |
---|
| 1215 | #define __OFFSET_ROT 0.05 |
---|
| 1216 | |
---|
| 1217 | /** |
---|
| 1218 | * Writes data from network containing information about the state which has changed |
---|
| 1219 | * @param data pointer to data |
---|
| 1220 | * @param length length of data |
---|
| 1221 | * @param sender hostID of sender |
---|
| 1222 | */ |
---|
| 1223 | int PNode::writeSync( const byte * data, int length, int sender ) |
---|
| 1224 | { |
---|
| 1225 | SYNCHELP_READ_BEGIN(); |
---|
| 1226 | |
---|
| 1227 | if ( this->getHostID()==this->getOwner() ) |
---|
| 1228 | { |
---|
| 1229 | return SYNCHELP_READ_N; |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | byte flags = 0; |
---|
[6815] | 1233 | SYNCHELP_READ_BYTE( flags, NWT_PN_FLAGS ); |
---|
[6634] | 1234 | //PRINTF(0)("%s::FLAGS = %d\n", this->getName(), flags); |
---|
| 1235 | |
---|
| 1236 | float f1, f2, f3, f4; |
---|
| 1237 | |
---|
| 1238 | if ( flags & __FLAG_COOR ) |
---|
| 1239 | { |
---|
[6815] | 1240 | SYNCHELP_READ_FLOAT( f1, NWT_PN_SCOORX ); |
---|
| 1241 | SYNCHELP_READ_FLOAT( f2, NWT_PN_SCOORY ); |
---|
| 1242 | SYNCHELP_READ_FLOAT( f3, NWT_PN_SCOORZ ); |
---|
[6634] | 1243 | PRINTF(0)("RCVD COOR: %f %f %f\n", f1, f2, f3); |
---|
| 1244 | this->setRelCoor( f1, f2, f3 ); |
---|
| 1245 | } |
---|
| 1246 | |
---|
| 1247 | if ( flags & __FLAG_ROT ) |
---|
| 1248 | { |
---|
[6815] | 1249 | SYNCHELP_READ_FLOAT( f1, NWT_PN_SROTV ); |
---|
| 1250 | SYNCHELP_READ_FLOAT( f2, NWT_PN_SROTX ); |
---|
| 1251 | SYNCHELP_READ_FLOAT( f3, NWT_PN_SROTY ); |
---|
| 1252 | SYNCHELP_READ_FLOAT( f4, NWT_PN_SROTZ ); |
---|
[6634] | 1253 | PRINTF(0)("RCVD QUAT: %f %f %f %f\n", f1, f2, f3, f4); |
---|
| 1254 | //this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) ); |
---|
| 1255 | Quaternion q; |
---|
| 1256 | q.w = f1; |
---|
| 1257 | q.v.x = f2; |
---|
| 1258 | q.v.y = f3; |
---|
| 1259 | q.v.z = f4; |
---|
| 1260 | this->setAbsDir( q ); |
---|
| 1261 | } |
---|
| 1262 | |
---|
| 1263 | return SYNCHELP_READ_N; |
---|
| 1264 | } |
---|
| 1265 | |
---|
| 1266 | /** |
---|
| 1267 | * data copied in data will bee sent to another host |
---|
| 1268 | * @param data pointer to data |
---|
| 1269 | * @param maxLength max length of data |
---|
| 1270 | * @return the number of bytes writen |
---|
| 1271 | */ |
---|
| 1272 | int PNode::readSync( byte * data, int maxLength ) |
---|
| 1273 | { |
---|
[6815] | 1274 | //WARNING: if you change this file make sure you also change needsReadSync |
---|
[6634] | 1275 | SYNCHELP_WRITE_BEGIN(); |
---|
| 1276 | |
---|
[6959] | 1277 | if ( this->getHostID()!=0 && this->getHostID()!=this->getOwner() ) |
---|
[6634] | 1278 | { |
---|
| 1279 | return SYNCHELP_WRITE_N; |
---|
| 1280 | } |
---|
| 1281 | |
---|
| 1282 | byte flags = 0; |
---|
[6959] | 1283 | if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() || |
---|
| 1284 | fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() || |
---|
| 1285 | fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() ) |
---|
[6634] | 1286 | flags |= __FLAG_COOR; |
---|
| 1287 | |
---|
| 1288 | if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT || |
---|
| 1289 | fabs( rotx - absDirection.v.x ) > __OFFSET_ROT || |
---|
| 1290 | fabs( roty - absDirection.v.y ) > __OFFSET_ROT || |
---|
| 1291 | fabs( rotz - absDirection.v.z ) > __OFFSET_ROT ) |
---|
| 1292 | flags |= __FLAG_ROT; |
---|
| 1293 | |
---|
| 1294 | |
---|
[6815] | 1295 | SYNCHELP_WRITE_BYTE( flags, NWT_PN_FLAGS ); |
---|
[6959] | 1296 | PRINTF(0)("FLAGS = %d\n", flags); |
---|
[6634] | 1297 | |
---|
| 1298 | if ( flags & __FLAG_COOR ) |
---|
| 1299 | { |
---|
| 1300 | |
---|
[6959] | 1301 | PRINTF(0)("SEND COOR: %f %f %f\n", this->relCoordinate.x, this->relCoordinate.y, this->relCoordinate.z); |
---|
[6634] | 1302 | |
---|
[6815] | 1303 | SYNCHELP_WRITE_FLOAT( this->relCoordinate.x, NWT_PN_SCOORX ); |
---|
| 1304 | SYNCHELP_WRITE_FLOAT( this->relCoordinate.y, NWT_PN_SCOORY ); |
---|
| 1305 | SYNCHELP_WRITE_FLOAT( this->relCoordinate.z, NWT_PN_SCOORZ ); |
---|
[6634] | 1306 | |
---|
| 1307 | coorx = relCoordinate.x; |
---|
| 1308 | coory = relCoordinate.y; |
---|
| 1309 | coorz = relCoordinate.z; |
---|
| 1310 | } |
---|
| 1311 | |
---|
| 1312 | if ( flags & __FLAG_ROT ) |
---|
| 1313 | { |
---|
| 1314 | |
---|
[6959] | 1315 | PRINTF(0)("SEND QUAT: %f %f %f %f\n", this->absDirection.w, this->absDirection.v.x, this->absDirection.v.y, this->absDirection.v.z); |
---|
[6634] | 1316 | |
---|
[6815] | 1317 | SYNCHELP_WRITE_FLOAT( this->absDirection.w, NWT_PN_SROTV ); |
---|
| 1318 | SYNCHELP_WRITE_FLOAT( this->absDirection.v.x, NWT_PN_SROTX ); |
---|
| 1319 | SYNCHELP_WRITE_FLOAT( this->absDirection.v.y, NWT_PN_SROTY ); |
---|
| 1320 | SYNCHELP_WRITE_FLOAT( this->absDirection.v.z, NWT_PN_SROTZ ); |
---|
[6634] | 1321 | |
---|
| 1322 | rotw = absDirection.w; |
---|
| 1323 | rotx = absDirection.v.x; |
---|
| 1324 | roty = absDirection.v.y; |
---|
| 1325 | rotz = absDirection.v.z; |
---|
| 1326 | } |
---|
| 1327 | |
---|
| 1328 | return SYNCHELP_WRITE_N; |
---|
| 1329 | } |
---|
[6815] | 1330 | |
---|
| 1331 | bool PNode::needsReadSync( ) |
---|
| 1332 | { |
---|
[6959] | 1333 | if ( fabs( coorx - relCoordinate.x ) > __OFFSET_POS*0.05*this->velocity.len() || |
---|
| 1334 | fabs( coory - relCoordinate.y ) > __OFFSET_POS*0.05*this->velocity.len() || |
---|
| 1335 | fabs( coorz - relCoordinate.z ) > __OFFSET_POS*0.05*this->velocity.len() ) |
---|
[6815] | 1336 | return true; |
---|
| 1337 | |
---|
| 1338 | if ( fabs( rotw - absDirection.w ) > __OFFSET_ROT || |
---|
| 1339 | fabs( rotx - absDirection.v.x ) > __OFFSET_ROT || |
---|
| 1340 | fabs( roty - absDirection.v.y ) > __OFFSET_ROT || |
---|
| 1341 | fabs( rotz - absDirection.v.z ) > __OFFSET_ROT ) |
---|
| 1342 | return true; |
---|
[6873] | 1343 | |
---|
[6815] | 1344 | return false; |
---|
| 1345 | } |
---|