Changeset 5082 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Aug 19, 2005, 1:29:18 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/null_parent.cc
r4871 r5082 22 22 using namespace std; 23 23 24 NullParent* NullParent::singletonRef = 0;24 NullParent* NullParent::singletonRef = NULL; 25 25 26 26 /** -
trunk/src/lib/coord/p_node.cc
r5050 r5082 209 209 absCoordinates. If you don't use this, the PNode won't recognize, that something 210 210 has changed and won't update the children Nodes. 211 212 @todo check if this does what it should 211 213 */ 212 214 void PNode::setAbsCoor (const Vector& absCoord) -
trunk/src/lib/graphics/render2D/element_2d.cc
r5081 r5082 24 24 #include "tinyxml.h" 25 25 #include "class_list.h" 26 #include "list.h" 26 27 27 28 using namespace std; … … 59 60 this->setAlignment(E2D_ALIGN_NONE); 60 61 this->layer = E2D_TOP; 62 this->setParentMode2D(E2D_PARENT_ALL); 63 64 this->bRelCoorChanged = true; 65 this->bRelDirChanged = true; 61 66 62 67 Render2D::getInstance()->registerElement2D(this); … … 180 185 void Element2D::setRelCoor2D (const Vector& relCoord) 181 186 { 187 this->relCoordinate = relCoord; 188 this->bRelCoorChanged = true; 182 189 } 183 190 … … 185 192 void Element2D::setRelCoor2D (float x, float y, float z) 186 193 { 194 this->setAbsCoor2D(Vector(x,y,z)); 187 195 } 188 196 189 197 void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias) 190 198 { 191 } 192 193 void Element2D::setRelCoorSoft2D(float x, float y, float dontCare, float bias) 194 { 199 if (likely(this->toCoordinate == NULL)) 200 this->toCoordinate = new Vector(); 201 202 *this->toCoordinate = relCoordSoft; 203 this->bias = bias; 204 } 205 206 void Element2D::setRelCoorSoft2D(float x, float y, float depth, float bias) 207 { 208 this->setRelCoorSoft2D(Vector(x, y, depth), bias); 195 209 } 196 210 197 211 void Element2D::setAbsCoor2D (const Vector& absCoord) 198 212 { 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; 199 230 } 200 231 201 232 void Element2D::setAbsCoor2D (float x, float y, float depth) 202 233 { 234 this->setAbsCoor2D(Vector(x, y, depth)); 203 235 } 204 236 205 237 void Element2D::shiftCoor (const Vector& shift) 206 238 { 239 this->relCoordinate += shift; 240 this->bRelCoorChanged = true; 241 207 242 } 208 243 … … 210 245 void Element2D::setRelDir2D (float relDir) 211 246 { 247 this->relDirection = relDir; 248 this->bRelDirChanged = true; 212 249 } 213 250 214 251 void Element2D::setRelDirSoft2D(float relDirSoft, float bias) 215 252 { 253 if (likely(this->toDirection == NULL)) 254 this->toDirection = new float; 255 256 *this->toDirection = relDirSoft; 257 this->bias = bias; 216 258 } 217 259 218 260 void Element2D::setAbsDir2D (float absDir) 219 261 { 262 if (likely(this->parent != NULL)) 263 this->relDirection = absDir - this->parent->getAbsDir2D(); 264 else 265 this->relDirection = absDir; 266 267 this->bRelDirChanged = true; 220 268 } 221 269 222 270 void Element2D::shiftDir (float shiftDir) 223 271 { 272 this->relDirection = this->relDirection + shiftDir; 273 this->bRelDirChanged = true; 224 274 } 225 275 … … 227 277 void Element2D::addChild2D (Element2D* child, int parentingMod) 228 278 { 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(); 229 288 } 230 289 231 290 void Element2D::addChild2D (const char* childName) 232 291 { 292 Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D)); 293 if (childNode != NULL) 294 this->addChild2D(childNode); 233 295 } 234 296 235 297 void Element2D::removeChild2D (Element2D* child) 236 298 { 299 child->remove2D(); 300 this->children->remove(child); 301 child->parent = NULL; 237 302 } 238 303 239 304 void Element2D::remove2D() 240 305 { 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); 241 316 } 242 317 … … 244 319 void Element2D::setParent2D (Element2D* parent) 245 320 { 321 parent->addChild2D(this); 246 322 } 247 323 248 324 void Element2D::setParent2D (const char* parentName) 249 325 { 250 } 251 252 253 void Element2D::softReparent(PNode* parentNode, float bias) 254 { 255 } 256 257 void Element2D::softReparent(const char* parentName, float bias) 258 { 326 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D)); 327 if (parentNode != NULL) 328 parentNode->addChild2D(this); 329 330 } 331 332 333 void Element2D::softReparent2D(Element2D* parentNode, float bias) 334 { 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()); 362 } 363 364 void Element2D::softReparent2D(const char* parentName, float bias) 365 { 366 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D)); 367 if (parentNode != NULL) 368 this->softReparent2D(parentNode, bias); 259 369 } 260 370 … … 262 372 void Element2D::setParentMode2D (const char* parentingMode) 263 373 { 374 this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode)); 264 375 } 265 376 … … 267 378 void Element2D::update2D (float dt) 268 379 { 380 269 381 } 270 382 … … 272 384 void Element2D::debug (unsigned int depth, unsigned int level) const 273 385 { 274 } 386 for (unsigned int i = 0; i < level; i++) 387 PRINT(0)(" |"); 388 if (this->children->getSize() > 0) 389 PRINT(0)(" +"); 390 else 391 PRINT(0)(" -"); 392 PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s\n", 393 this->getClassName(), 394 this->getName(), 395 this->absCoordinate.x, 396 this->absCoordinate.y, 397 this->relCoordinate.x, 398 this->relCoordinate.y, 399 this->getAbsDir2D(), 400 Element2D::parentingModeToChar2D(parentMode)); 401 if (depth >= 2 || depth == 0) 402 { 403 tIterator<Element2D>* iterator = this->children->getIterator(); 404 //PNode* pn = this->children->enumerate (); 405 Element2D* pn = iterator->nextElement(); 406 while( pn != NULL) 407 { 408 if (depth == 0) 409 pn->debug(0, level + 1); 410 else 411 pn->debug(depth - 1, level +1); 412 pn = iterator->nextElement(); 413 } 414 delete iterator; 415 } 416 } 417 418 #include "color.h" 275 419 276 420 void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const 277 421 { 422 278 423 } 279 424 280 425 281 426 // helper functions // 282 const char* Element2D::parentingModeToChar(int parentingMode) 283 { 284 } 285 286 E2D_PARENT_MODE Element2D::charToParentingMode(const char* parentingMode) 287 { 427 const char* Element2D::parentingModeToChar2D(int parentingMode) 428 { 429 if (parentingMode == E2D_PARENT_LOCAL_ROTATE) 430 return "local-rotate"; 431 else if (parentingMode == E2D_PARENT_ROTATE_MOVEMENT) 432 return "rotate-movement"; 433 else if (parentingMode == E2D_PARENT_MOVEMENT) 434 return "movement"; 435 else if (parentingMode == E2D_PARENT_ALL) 436 return "all"; 437 else if (parentingMode == E2D_PARENT_ROTATE_AND_MOVE) 438 return "rotate-and-move"; 439 } 440 441 E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode) 442 { 443 if (!strcmp(parentingMode, "local-rotate")) 444 return (E2D_PARENT_LOCAL_ROTATE); 445 else if (!strcmp(parentingMode, "rotate-movement")) 446 return (E2D_PARENT_ROTATE_MOVEMENT); 447 else if (!strcmp(parentingMode, "movement")) 448 return (E2D_PARENT_MOVEMENT); 449 else if (!strcmp(parentingMode, "all")) 450 return (E2D_PARENT_ALL); 451 else if (!strcmp(parentingMode, "rotate-and-move")) 452 return (E2D_PARENT_ROTATE_AND_MOVE); 288 453 } 289 454 … … 301 466 this->positioning(); 302 467 } 468 469 470 471 472 473 474 475 NullElement2D* NullElement2D::singletonRef = 0; 476 477 /** 478 * creates the one and only NullElement2D 479 * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0)) 480 */ 481 NullElement2D::NullElement2D () 482 { 483 this->setClassID(CL_NULL_PARENT, "NullElement2D"); 484 this->setName("NullElement2D"); 485 486 this->setParentMode2D(E2D_PARENT_ALL); 487 NullElement2D::singletonRef = this; 488 } 489 490 491 /** 492 * standard deconstructor 493 */ 494 NullElement2D::~NullElement2D () 495 { 496 //delete singletonRef; 497 NullElement2D::singletonRef = NULL; 498 } -
trunk/src/lib/graphics/render2D/element_2d.h
r5081 r5082 40 40 typedef enum 41 41 { 42 E2D_ LOCAL_ROTATE= 1, //!< Rotates all the children around their centers.43 E2D_ ROTATE_MOVEMENT= 2, //!< Moves all the children around the center of their parent, without the rotation around their own centers.44 45 E2D_ MOVEMENT= 4, //!< Moves all children along with the parent.42 E2D_PARENT_LOCAL_ROTATE = 1, //!< Rotates all the children around their centers. 43 E2D_PARENT_ROTATE_MOVEMENT = 2, //!< Moves all the children around the center of their parent, without the rotation around their own centers. 44 45 E2D_PARENT_MOVEMENT = 4, //!< Moves all children along with the parent. 46 46 // special linkage modes 47 E2D_ ALL= 3, //!< Moves all children around the center of their parent, and also rotates their centers48 E2D_ ROTATE_AND_MOVE= 5 //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.47 E2D_PARENT_ALL = 3, //!< Moves all children around the center of their parent, and also rotates their centers 48 E2D_PARENT_ROTATE_AND_MOVE = 5 //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent. 49 49 } E2D_PARENT_MODE; 50 #define E2D_DEFAULT_PARENTING_MODE E2D_ ALL50 #define E2D_DEFAULT_PARENTING_MODE E2D_PARENT_ALL 51 51 52 52 //! A Struct defining the Position of an Element in 2D-space … … 137 137 Element2D* getParent () const { return this->parent; }; 138 138 139 void softReparent (PNode* parentNode, float bias = 1.0);140 void softReparent (const char* parentName, float bias = 1.0);139 void softReparent2D(Element2D* parentNode, float bias = 1.0); 140 void softReparent2D(const char* parentName, float bias = 1.0); 141 141 142 142 /** @param parentMode sets the parentingMode of this Node */ … … 152 152 153 153 // helper functions // 154 static const char* parentingModeToChar (int parentingMode);155 static E2D_PARENT_MODE charToParentingMode (const char* parentingMode);154 static const char* parentingModeToChar2D(int parentingMode); 155 static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode); 156 156 157 157 private: … … 213 213 }; 214 214 215 //! The top joint of all Element2D's every Element2D is somehow connected to this one. 216 class NullElement2D : public Element2D { 217 218 public: 219 /** @returns a Pointer to the only object of this Class */ 220 inline static NullElement2D* getInstance() { if (!singletonRef) singletonRef = new NullElement2D(); return singletonRef; }; 221 virtual ~NullElement2D (); 222 223 private: 224 NullElement2D (); 225 virtual void draw() const {}; 226 227 private: 228 static NullElement2D* singletonRef; //!< A reference to the NullElement2D 229 230 }; 215 231 216 232 #endif /* _ELEMENT_2D_H */
Note: See TracChangeset
for help on using the changeset viewer.