[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[4838] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[4839] | 18 | #include "element_2d.h" |
---|
[4840] | 19 | #include "render_2d.h" |
---|
[1853] | 20 | |
---|
[4843] | 21 | #include "graphics_engine.h" |
---|
| 22 | #include "p_node.h" |
---|
[4858] | 23 | #include "load_param.h" |
---|
| 24 | #include "tinyxml.h" |
---|
| 25 | #include "class_list.h" |
---|
[5082] | 26 | #include "list.h" |
---|
[4843] | 27 | |
---|
[1856] | 28 | using namespace std; |
---|
[1853] | 29 | |
---|
[1856] | 30 | |
---|
[3245] | 31 | /** |
---|
[4838] | 32 | * standard constructor |
---|
| 33 | * @todo this constructor is not jet implemented - do it |
---|
[3245] | 34 | */ |
---|
[4838] | 35 | Element2D::Element2D () |
---|
[3365] | 36 | { |
---|
[4847] | 37 | this->init(); |
---|
[3365] | 38 | } |
---|
[1853] | 39 | |
---|
[3245] | 40 | /** |
---|
[4838] | 41 | * standard deconstructor |
---|
[3245] | 42 | */ |
---|
[4838] | 43 | Element2D::~Element2D () |
---|
[3543] | 44 | { |
---|
| 45 | // delete what has to be deleted here |
---|
[4840] | 46 | Render2D::getInstance()->unregisterElement2D(this); |
---|
[3543] | 47 | } |
---|
[4843] | 48 | |
---|
| 49 | |
---|
[4858] | 50 | /** |
---|
| 51 | * initializes a Element2D |
---|
| 52 | */ |
---|
[4847] | 53 | void Element2D::init() |
---|
| 54 | { |
---|
| 55 | this->setClassID(CL_ELEMENT_2D, "Element2D"); |
---|
| 56 | |
---|
[4861] | 57 | this->setVisibility(true); |
---|
[5068] | 58 | this->setActiveness(true); |
---|
[4856] | 59 | this->setPosition2D(0,0); |
---|
[4861] | 60 | this->setAlignment(E2D_ALIGN_NONE); |
---|
[4862] | 61 | this->layer = E2D_TOP; |
---|
[5082] | 62 | this->setParentMode2D(E2D_PARENT_ALL); |
---|
[4856] | 63 | |
---|
[5082] | 64 | this->bRelCoorChanged = true; |
---|
| 65 | this->bRelDirChanged = true; |
---|
| 66 | |
---|
[4847] | 67 | Render2D::getInstance()->registerElement2D(this); |
---|
| 68 | } |
---|
| 69 | |
---|
[4843] | 70 | /** |
---|
[4858] | 71 | * Loads the Parameters of an Element2D from... |
---|
| 72 | * @param root The XML-element to load from |
---|
| 73 | */ |
---|
| 74 | void Element2D::loadParams(const TiXmlElement* root) |
---|
| 75 | { |
---|
| 76 | LoadParam<Element2D>(root, "alignment", this, &Element2D::setAlignment) |
---|
| 77 | .describe("loads the alignment: (either: center, left, right or screen-center)"); |
---|
| 78 | |
---|
| 79 | LoadParam<Element2D>(root, "layer", this, &Element2D::setLayer) |
---|
| 80 | .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)"); |
---|
| 81 | |
---|
| 82 | LoadParam<Element2D>(root, "bind-node", this, &Element2D::setBindNode) |
---|
| 83 | .describe("sets a node, this 2D-Element should be shown upon (name of the node)"); |
---|
| 84 | |
---|
| 85 | LoadParam<Element2D>(root, "2d-position", this, &Element2D::setPosition2D) |
---|
| 86 | .describe("the _relative_ position (away from alignment) this 2d-element shows"); |
---|
| 87 | |
---|
[4860] | 88 | LoadParam<Element2D>(root, "visibility", this, &Element2D::setVisibility) |
---|
| 89 | .describe("if the Element is visible or not"); |
---|
[4858] | 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * sets the alignment of the 2D-element in form of a String |
---|
| 94 | * @param alignment the alignment @see loadParams |
---|
| 95 | */ |
---|
| 96 | void Element2D::setAlignment(const char* alignment) |
---|
| 97 | { |
---|
| 98 | if (!strcmp(alignment, "center")) |
---|
| 99 | this->setAlignment(E2D_ALIGN_CENTER); |
---|
| 100 | else if (!strcmp(alignment, "left")) |
---|
| 101 | this->setAlignment(E2D_ALIGN_LEFT); |
---|
| 102 | else if (!strcmp(alignment, "right")) |
---|
| 103 | this->setAlignment(E2D_ALIGN_RIGHT); |
---|
| 104 | else if (!strcmp(alignment, "screen-center")) |
---|
| 105 | this->setAlignment(E2D_ALIGN_SCREEN_CENTER); |
---|
| 106 | } |
---|
| 107 | |
---|
[4862] | 108 | |
---|
[4858] | 109 | /** |
---|
[4862] | 110 | * moves a Element to another layer |
---|
| 111 | * @param layer the Layer this is drawn on |
---|
| 112 | */ |
---|
| 113 | void Element2D::setLayer(E2D_LAYER layer) |
---|
| 114 | { |
---|
| 115 | Render2D::getInstance()->moveToLayer(this, layer); |
---|
| 116 | this->layer = layer; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
[4858] | 120 | * sets the layer onto which this 2D-element is projected to. |
---|
| 121 | * @param layer the layer @see loadParams |
---|
| 122 | */ |
---|
| 123 | void Element2D::setLayer(const char* layer) |
---|
| 124 | { |
---|
| 125 | if (!strcmp(layer, "top")) |
---|
| 126 | this->setLayer(E2D_TOP); |
---|
| 127 | else if (!strcmp(layer, "medium")) |
---|
| 128 | this->setLayer(E2D_MEDIUM); |
---|
| 129 | else if (!strcmp(layer, "bottom")) |
---|
| 130 | this->setLayer(E2D_BOTTOM); |
---|
| 131 | else if (!strcmp(layer, "below-all")) |
---|
| 132 | this->setLayer(E2D_BELOW_ALL); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | /** |
---|
| 137 | * sets a node, this 2D-Element should be shown upon |
---|
| 138 | * @param bindNode the name of the Node (should be existing) |
---|
| 139 | */ |
---|
| 140 | void Element2D::setBindNode(const char* bindNode) |
---|
| 141 | { |
---|
| 142 | const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE)); |
---|
| 143 | if (tmpBindNode != NULL) |
---|
| 144 | this->bindNode = tmpBindNode; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | /** |
---|
[4843] | 148 | * this sets the position of the Element on the screen. |
---|
[4847] | 149 | * Use this in the your tick function, if you want the element to be automatically positioned. |
---|
[4843] | 150 | */ |
---|
| 151 | void Element2D::positioning() |
---|
| 152 | { |
---|
[4856] | 153 | // setting the Position of this 2D-Element. |
---|
| 154 | if (this->alignment == E2D_ALIGN_SCREEN_CENTER) |
---|
[4843] | 155 | { |
---|
[4856] | 156 | absPos2D.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->relPos2D[0]; |
---|
| 157 | absPos2D.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->relPos2D[1]; |
---|
| 158 | absPos2D.depth = 0; |
---|
| 159 | } |
---|
| 160 | else if (this->bindNode) |
---|
| 161 | { |
---|
[4843] | 162 | GLdouble projectPos[3]; |
---|
[4847] | 163 | gluProject(this->bindNode->getAbsCoor().x, |
---|
| 164 | this->bindNode->getAbsCoor().y, |
---|
| 165 | this->bindNode->getAbsCoor().z, |
---|
| 166 | GraphicsEngine::modMat, |
---|
| 167 | GraphicsEngine::projMat, |
---|
| 168 | GraphicsEngine::viewPort, |
---|
| 169 | projectPos, |
---|
| 170 | projectPos+1, |
---|
| 171 | projectPos+2); |
---|
| 172 | absPos2D.x = projectPos[0] + this->relPos2D[0]; |
---|
| 173 | absPos2D.y = GraphicsEngine::getInstance()->getResolutionY() - projectPos[1] + this->relPos2D[1]; |
---|
| 174 | absPos2D.depth = projectPos[2]; |
---|
[4843] | 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
[4847] | 178 | absPos2D.x = this->relPos2D[0]; |
---|
| 179 | absPos2D.y = this->relPos2D[1]; |
---|
| 180 | absPos2D.depth = 0; |
---|
[4843] | 181 | } |
---|
[4847] | 182 | } |
---|
[4843] | 183 | |
---|
[5081] | 184 | |
---|
| 185 | void Element2D::setRelCoor2D (const Vector& relCoord) |
---|
| 186 | { |
---|
[5082] | 187 | this->relCoordinate = relCoord; |
---|
| 188 | this->bRelCoorChanged = true; |
---|
[5081] | 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | void Element2D::setRelCoor2D (float x, float y, float z) |
---|
| 193 | { |
---|
[5082] | 194 | this->setAbsCoor2D(Vector(x,y,z)); |
---|
[5081] | 195 | } |
---|
| 196 | |
---|
| 197 | void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias) |
---|
| 198 | { |
---|
[5082] | 199 | if (likely(this->toCoordinate == NULL)) |
---|
| 200 | this->toCoordinate = new Vector(); |
---|
| 201 | |
---|
| 202 | *this->toCoordinate = relCoordSoft; |
---|
| 203 | this->bias = bias; |
---|
[5081] | 204 | } |
---|
| 205 | |
---|
[5082] | 206 | void Element2D::setRelCoorSoft2D(float x, float y, float depth, float bias) |
---|
[5081] | 207 | { |
---|
[5082] | 208 | this->setRelCoorSoft2D(Vector(x, y, depth), bias); |
---|
[5081] | 209 | } |
---|
| 210 | |
---|
| 211 | void Element2D::setAbsCoor2D (const Vector& absCoord) |
---|
| 212 | { |
---|
[5082] | 213 | if( likely(this->parentMode & E2D_PARENT_MOVEMENT)) |
---|
| 214 | { |
---|
| 215 | /* if you have set the absolute coordinates this overrides all other changes */ |
---|
| 216 | if (likely(this->parent != NULL)) |
---|
| 217 | this->relCoordinate = absCoord - parent->getAbsCoor2D (); |
---|
| 218 | else |
---|
| 219 | this->relCoordinate = absCoord; |
---|
| 220 | } |
---|
| 221 | if( this->parentMode & E2D_PARENT_ROTATE_MOVEMENT) |
---|
| 222 | { |
---|
| 223 | if (likely(this->parent != NULL)) |
---|
| 224 | this->relCoordinate = absCoord - parent->getAbsCoor2D (); |
---|
| 225 | else |
---|
| 226 | this->relCoordinate = absCoord; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | this->bRelCoorChanged = true; |
---|
[5081] | 230 | } |
---|
| 231 | |
---|
| 232 | void Element2D::setAbsCoor2D (float x, float y, float depth) |
---|
| 233 | { |
---|
[5082] | 234 | this->setAbsCoor2D(Vector(x, y, depth)); |
---|
[5081] | 235 | } |
---|
| 236 | |
---|
[5083] | 237 | void Element2D::shiftCoor2D (const Vector& shift) |
---|
[5081] | 238 | { |
---|
[5082] | 239 | this->relCoordinate += shift; |
---|
| 240 | this->bRelCoorChanged = true; |
---|
| 241 | |
---|
[5081] | 242 | } |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | void Element2D::setRelDir2D (float relDir) |
---|
| 246 | { |
---|
[5082] | 247 | this->relDirection = relDir; |
---|
| 248 | this->bRelDirChanged = true; |
---|
[5081] | 249 | } |
---|
| 250 | |
---|
| 251 | void Element2D::setRelDirSoft2D(float relDirSoft, float bias) |
---|
| 252 | { |
---|
[5082] | 253 | if (likely(this->toDirection == NULL)) |
---|
| 254 | this->toDirection = new float; |
---|
| 255 | |
---|
| 256 | *this->toDirection = relDirSoft; |
---|
| 257 | this->bias = bias; |
---|
[5081] | 258 | } |
---|
| 259 | |
---|
| 260 | void Element2D::setAbsDir2D (float absDir) |
---|
| 261 | { |
---|
[5082] | 262 | if (likely(this->parent != NULL)) |
---|
| 263 | this->relDirection = absDir - this->parent->getAbsDir2D(); |
---|
| 264 | else |
---|
| 265 | this->relDirection = absDir; |
---|
| 266 | |
---|
| 267 | this->bRelDirChanged = true; |
---|
[5081] | 268 | } |
---|
| 269 | |
---|
[5083] | 270 | void Element2D::shiftDir2D (float shiftDir) |
---|
[5081] | 271 | { |
---|
[5082] | 272 | this->relDirection = this->relDirection + shiftDir; |
---|
| 273 | this->bRelDirChanged = true; |
---|
[5081] | 274 | } |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | void Element2D::addChild2D (Element2D* child, int parentingMod) |
---|
| 278 | { |
---|
[5082] | 279 | if( likely(child->parent != NULL)) |
---|
| 280 | { |
---|
| 281 | PRINTF(4)("PNode::addChild() - reparenting node: removing it and adding it again\n"); |
---|
| 282 | child->parent->children->remove(child); |
---|
| 283 | } |
---|
| 284 | child->parentMode = parentMode; |
---|
| 285 | child->parent = this; |
---|
| 286 | this->children->add(child); |
---|
| 287 | child->parentCoorChanged(); |
---|
[5081] | 288 | } |
---|
| 289 | |
---|
| 290 | void Element2D::addChild2D (const char* childName) |
---|
| 291 | { |
---|
[5082] | 292 | Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D)); |
---|
| 293 | if (childNode != NULL) |
---|
| 294 | this->addChild2D(childNode); |
---|
[5081] | 295 | } |
---|
| 296 | |
---|
| 297 | void Element2D::removeChild2D (Element2D* child) |
---|
| 298 | { |
---|
[5082] | 299 | child->remove2D(); |
---|
| 300 | this->children->remove(child); |
---|
| 301 | child->parent = NULL; |
---|
[5081] | 302 | } |
---|
| 303 | |
---|
| 304 | void Element2D::remove2D() |
---|
| 305 | { |
---|
[5082] | 306 | tIterator<Element2D>* iterator = this->children->getIterator(); |
---|
| 307 | Element2D* pn = iterator->nextElement(); |
---|
| 308 | |
---|
| 309 | while( pn != NULL) |
---|
| 310 | { |
---|
| 311 | NullElement2D::getInstance()->addChild2D(pn, pn->getParentMode2D()); |
---|
| 312 | pn = iterator->nextElement(); |
---|
| 313 | } |
---|
| 314 | delete iterator; |
---|
| 315 | this->parent->children->remove(this); |
---|
[5081] | 316 | } |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | void Element2D::setParent2D (Element2D* parent) |
---|
| 320 | { |
---|
[5082] | 321 | parent->addChild2D(this); |
---|
[5081] | 322 | } |
---|
| 323 | |
---|
| 324 | void Element2D::setParent2D (const char* parentName) |
---|
| 325 | { |
---|
[5082] | 326 | Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D)); |
---|
| 327 | if (parentNode != NULL) |
---|
| 328 | parentNode->addChild2D(this); |
---|
| 329 | |
---|
[5081] | 330 | } |
---|
| 331 | |
---|
| 332 | |
---|
[5082] | 333 | void Element2D::softReparent2D(Element2D* parentNode, float bias) |
---|
[5081] | 334 | { |
---|
[5082] | 335 | if (this->parent == parentNode) |
---|
| 336 | return; |
---|
| 337 | |
---|
| 338 | if (likely(this->toCoordinate == NULL)) |
---|
| 339 | { |
---|
| 340 | this->toCoordinate = new Vector(); |
---|
| 341 | *this->toCoordinate = this->getRelCoor2D(); |
---|
| 342 | } |
---|
| 343 | if (likely(this->toDirection == NULL)) |
---|
| 344 | { |
---|
| 345 | this->toDirection = new float; |
---|
| 346 | *this->toDirection = this->getRelDir2D(); |
---|
| 347 | } |
---|
| 348 | this->bias = bias; |
---|
| 349 | |
---|
| 350 | |
---|
| 351 | Vector tmpV = this->getAbsCoor2D(); |
---|
| 352 | float tmpQ = this->getAbsDir2D(); |
---|
| 353 | |
---|
| 354 | parentNode->addChild2D(this); |
---|
| 355 | |
---|
| 356 | if (this->parentMode & PNODE_ROTATE_MOVEMENT) |
---|
| 357 | ;//this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor())); |
---|
| 358 | else |
---|
| 359 | this->setRelCoor2D(tmpV - parentNode->getAbsCoor2D()); |
---|
| 360 | |
---|
| 361 | this->setRelDir2D(tmpQ - parentNode->getAbsDir2D()); |
---|
[5081] | 362 | } |
---|
| 363 | |
---|
[5082] | 364 | void Element2D::softReparent2D(const char* parentName, float bias) |
---|
[5081] | 365 | { |
---|
[5082] | 366 | Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D)); |
---|
| 367 | if (parentNode != NULL) |
---|
| 368 | this->softReparent2D(parentNode, bias); |
---|
[5081] | 369 | } |
---|
| 370 | |
---|
| 371 | |
---|
| 372 | void Element2D::setParentMode2D (const char* parentingMode) |
---|
| 373 | { |
---|
[5082] | 374 | this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode)); |
---|
[5081] | 375 | } |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | void Element2D::update2D (float dt) |
---|
| 379 | { |
---|
[5083] | 380 | if( likely(this->parent != NULL)) |
---|
| 381 | { |
---|
| 382 | // movement for nodes with smoothMove enabled |
---|
| 383 | if (unlikely(this->toCoordinate != NULL)) |
---|
| 384 | { |
---|
| 385 | Vector moveVect = (*this->toCoordinate - this->getRelCoor2D()) *dt*bias; |
---|
[5082] | 386 | |
---|
[5083] | 387 | if (likely(moveVect.len() >= .001))//PNODE_ITERATION_DELTA)) |
---|
| 388 | { |
---|
| 389 | this->shiftCoor2D(moveVect); |
---|
| 390 | } |
---|
| 391 | else |
---|
| 392 | { |
---|
| 393 | delete this->toCoordinate; |
---|
| 394 | this->toCoordinate = NULL; |
---|
| 395 | PRINTF(5)("SmoothMove of %s finished\n", this->getName()); |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | if (unlikely(this->toDirection != NULL)) |
---|
| 399 | { |
---|
| 400 | float rotFlot = (*this->toDirection - this->getRelDir2D()) *dt*bias; |
---|
| 401 | if (likely(rotFlot >= .001))//PNODE_ITERATION_DELTA)) |
---|
| 402 | { |
---|
| 403 | this->shiftDir2D(rotFlot); |
---|
| 404 | } |
---|
| 405 | else |
---|
| 406 | { |
---|
| 407 | delete this->toDirection; |
---|
| 408 | this->toDirection = NULL; |
---|
| 409 | PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | // MAIN UPDATE ///////////////////////////////////// |
---|
| 414 | this->lastAbsCoordinate = this->absCoordinate; |
---|
| 415 | |
---|
| 416 | PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); |
---|
| 417 | |
---|
| 418 | |
---|
| 419 | if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged) |
---|
| 420 | { |
---|
| 421 | /* update the current absDirection - remember * means rotation around sth.*/ |
---|
| 422 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 423 | this->absDirection = this->relDirection + parent->getAbsDir2D();; |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | if(likely(this->parentMode & PNODE_MOVEMENT)) |
---|
| 427 | { |
---|
| 428 | /* update the current absCoordinate */ |
---|
| 429 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 430 | this->absCoordinate = this->parent->getAbsCoor2D() + this->relCoordinate; |
---|
| 431 | } |
---|
| 432 | else if( this->parentMode & PNODE_ROTATE_MOVEMENT) |
---|
| 433 | { |
---|
| 434 | /* update the current absCoordinate */ |
---|
| 435 | this->prevRelCoordinate = this->relCoordinate; |
---|
| 436 | //this->absCoordinate = this->parent->getAbsCoor2D(); |
---|
| 437 | this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D())); |
---|
| 438 | this->absCoordinate.y = this->parent->getAbsCoor2D().y + (this->relCoordinate.x*sin(this->parent->getAbsDir2D()) + this->relCoordinate.y * cos(this->parent->getAbsDir2D())); |
---|
| 439 | |
---|
| 440 | } |
---|
| 441 | ///////////////////////////////////////////////// |
---|
| 442 | } |
---|
| 443 | else |
---|
| 444 | { |
---|
| 445 | PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); |
---|
| 446 | if (this->bRelCoorChanged) |
---|
| 447 | this->absCoordinate = this->relCoordinate; |
---|
| 448 | if (this->bRelDirChanged) |
---|
| 449 | this->absDirection = this->getAbsDir2D() * this->relDirection; |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | if(this->children->getSize() > 0) |
---|
| 453 | { |
---|
| 454 | tIterator<Element2D>* iterator = this->children->getIterator(); |
---|
| 455 | Element2D* pn = iterator->nextElement(); |
---|
| 456 | while( pn != NULL) |
---|
| 457 | { |
---|
| 458 | /* if this node has changed, make sure, that all children are updated also */ |
---|
| 459 | if( likely(this->bRelCoorChanged)) |
---|
| 460 | pn->parentCoorChanged (); |
---|
| 461 | if( likely(this->bRelDirChanged)) |
---|
| 462 | pn->parentDirChanged (); |
---|
| 463 | |
---|
| 464 | pn->update2D(dt); |
---|
| 465 | //pn = this->children->nextElement(); |
---|
| 466 | pn = iterator->nextElement(); |
---|
| 467 | } |
---|
| 468 | delete iterator; |
---|
| 469 | } |
---|
| 470 | this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; |
---|
| 471 | this->bRelCoorChanged = false; |
---|
| 472 | this->bRelDirChanged = false; |
---|
[5081] | 473 | } |
---|
| 474 | |
---|
| 475 | |
---|
| 476 | void Element2D::debug (unsigned int depth, unsigned int level) const |
---|
| 477 | { |
---|
[5082] | 478 | for (unsigned int i = 0; i < level; i++) |
---|
| 479 | PRINT(0)(" |"); |
---|
| 480 | if (this->children->getSize() > 0) |
---|
| 481 | PRINT(0)(" +"); |
---|
| 482 | else |
---|
| 483 | PRINT(0)(" -"); |
---|
| 484 | PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s\n", |
---|
| 485 | this->getClassName(), |
---|
| 486 | this->getName(), |
---|
| 487 | this->absCoordinate.x, |
---|
| 488 | this->absCoordinate.y, |
---|
| 489 | this->relCoordinate.x, |
---|
| 490 | this->relCoordinate.y, |
---|
| 491 | this->getAbsDir2D(), |
---|
| 492 | Element2D::parentingModeToChar2D(parentMode)); |
---|
| 493 | if (depth >= 2 || depth == 0) |
---|
| 494 | { |
---|
| 495 | tIterator<Element2D>* iterator = this->children->getIterator(); |
---|
| 496 | //PNode* pn = this->children->enumerate (); |
---|
| 497 | Element2D* pn = iterator->nextElement(); |
---|
| 498 | while( pn != NULL) |
---|
| 499 | { |
---|
| 500 | if (depth == 0) |
---|
| 501 | pn->debug(0, level + 1); |
---|
| 502 | else |
---|
| 503 | pn->debug(depth - 1, level +1); |
---|
| 504 | pn = iterator->nextElement(); |
---|
| 505 | } |
---|
| 506 | delete iterator; |
---|
| 507 | } |
---|
[5081] | 508 | } |
---|
| 509 | |
---|
[5082] | 510 | #include "color.h" |
---|
| 511 | |
---|
[5081] | 512 | void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const |
---|
| 513 | { |
---|
[5082] | 514 | |
---|
[5081] | 515 | } |
---|
| 516 | |
---|
| 517 | |
---|
| 518 | // helper functions // |
---|
[5082] | 519 | const char* Element2D::parentingModeToChar2D(int parentingMode) |
---|
[5081] | 520 | { |
---|
[5082] | 521 | if (parentingMode == E2D_PARENT_LOCAL_ROTATE) |
---|
| 522 | return "local-rotate"; |
---|
| 523 | else if (parentingMode == E2D_PARENT_ROTATE_MOVEMENT) |
---|
| 524 | return "rotate-movement"; |
---|
| 525 | else if (parentingMode == E2D_PARENT_MOVEMENT) |
---|
| 526 | return "movement"; |
---|
| 527 | else if (parentingMode == E2D_PARENT_ALL) |
---|
| 528 | return "all"; |
---|
| 529 | else if (parentingMode == E2D_PARENT_ROTATE_AND_MOVE) |
---|
| 530 | return "rotate-and-move"; |
---|
[5081] | 531 | } |
---|
| 532 | |
---|
[5082] | 533 | E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode) |
---|
[5081] | 534 | { |
---|
[5082] | 535 | if (!strcmp(parentingMode, "local-rotate")) |
---|
| 536 | return (E2D_PARENT_LOCAL_ROTATE); |
---|
| 537 | else if (!strcmp(parentingMode, "rotate-movement")) |
---|
| 538 | return (E2D_PARENT_ROTATE_MOVEMENT); |
---|
| 539 | else if (!strcmp(parentingMode, "movement")) |
---|
| 540 | return (E2D_PARENT_MOVEMENT); |
---|
| 541 | else if (!strcmp(parentingMode, "all")) |
---|
| 542 | return (E2D_PARENT_ALL); |
---|
| 543 | else if (!strcmp(parentingMode, "rotate-and-move")) |
---|
| 544 | return (E2D_PARENT_ROTATE_AND_MOVE); |
---|
[5081] | 545 | } |
---|
| 546 | |
---|
| 547 | |
---|
| 548 | |
---|
| 549 | |
---|
| 550 | |
---|
| 551 | |
---|
[4847] | 552 | /** |
---|
| 553 | * ticks the 2d-Element |
---|
| 554 | * @param dt the time elapsed since the last tick |
---|
| 555 | */ |
---|
| 556 | void Element2D::tick(float dt) |
---|
| 557 | { |
---|
| 558 | this->positioning(); |
---|
[4843] | 559 | } |
---|
[5082] | 560 | |
---|
| 561 | |
---|
| 562 | |
---|
| 563 | |
---|
| 564 | |
---|
| 565 | |
---|
| 566 | |
---|
| 567 | NullElement2D* NullElement2D::singletonRef = 0; |
---|
| 568 | |
---|
| 569 | /** |
---|
| 570 | * creates the one and only NullElement2D |
---|
| 571 | * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0)) |
---|
| 572 | */ |
---|
| 573 | NullElement2D::NullElement2D () |
---|
| 574 | { |
---|
| 575 | this->setClassID(CL_NULL_PARENT, "NullElement2D"); |
---|
| 576 | this->setName("NullElement2D"); |
---|
| 577 | |
---|
| 578 | this->setParentMode2D(E2D_PARENT_ALL); |
---|
| 579 | NullElement2D::singletonRef = this; |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | |
---|
| 583 | /** |
---|
| 584 | * standard deconstructor |
---|
| 585 | */ |
---|
| 586 | NullElement2D::~NullElement2D () |
---|
| 587 | { |
---|
| 588 | //delete singletonRef; |
---|
| 589 | NullElement2D::singletonRef = NULL; |
---|
| 590 | } |
---|