- Timestamp:
- Dec 28, 2008, 7:15:55 PM (16 years ago)
- Location:
- code/branches/presentation/src/orxonox/objects/worldentities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.cc
r2527 r2535 42 42 43 43 #include "objects/Scene.h" 44 #include "objects/collisionshapes/CompoundCollisionShape.h"45 44 46 45 namespace orxonox … … 53 52 const Vector3 WorldEntity::UP = Vector3::UNIT_Y; 54 53 55 WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) 54 WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), collisionShape_(0) 55 56 56 { 57 57 RegisterObject(WorldEntity); … … 68 68 this->node_->setOrientation(Quaternion::IDENTITY); 69 69 70 70 71 // Default behaviour does not include physics 71 this->physicalBody_ = 0;72 this->bPhysicsActive_ = false;73 this->bPhysicsActiveSynchronised_ = false;74 this->bPhysicsActiveBeforeAttaching_ = false;75 this->collisionShape_ = new CompoundCollisionShape(this);76 72 // Note: CompoundCollisionShape is a Synchronisable, but must not be synchronised. 77 73 // All objects will get attached on the client anyway, so we don't need synchronisation. 78 this->collisionShape_->setWorldEntityParent(this); 79 this->collisionType_ = None; 74 this->collisionShape_.setWorldEntityParent(this); 75 this->physicalBody_ = 0; 76 this->bPhysicsActive_ = false; 77 this->bPhysicsActiveSynchronised_ = false; 78 this->bPhysicsActiveBeforeAttaching_ = false; 79 this->collisionType_ = None; 80 80 this->collisionTypeSynchronised_ = None; 81 81 this->mass_ = 0; 82 82 this->childrenMass_ = 0; 83 // Us ebullet default values83 // Using bullet default values 84 84 this->restitution_ = 0; 85 85 this->angularFactor_ = 1; … … 96 96 if (this->isInitialized()) 97 97 { 98 this->node_->detachAllObjects(); 98 if (this->parent_) 99 this->detachFromParent(); 99 100 100 101 for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ) 101 102 delete (*(it++)); 102 103 103 if (this->parent_)104 this->detachFromParent();105 106 this->node_->removeAllChildren();107 108 104 if (this->physicalBody_) 109 105 { … … 111 107 delete this->physicalBody_; 112 108 } 113 delete this->collisionShape_; 114 115 if (this->getScene()->getSceneManager()) 116 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); 109 110 this->node_->detachAllObjects(); 111 this->node_->removeAllChildren(); 112 113 OrxAssert(this->getScene()->getSceneManager(), "No SceneManager defined in a WorldEntity."); 114 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); 117 115 } 118 116 } … … 184 182 } 185 183 184 void WorldEntity::attachToNode(Ogre::SceneNode* node) 185 { 186 Ogre::Node* parent = this->node_->getParent(); 187 if (parent) 188 parent->removeChild(this->node_); 189 node->addChild(this->node_); 190 } 191 192 void WorldEntity::detachFromNode(Ogre::SceneNode* node) 193 { 194 node->removeChild(this->node_); 195 // this->getScene()->getRootSceneNode()->addChild(this->node_); 196 } 197 186 198 void WorldEntity::collisionTypeChanged() 187 199 { … … 223 235 } 224 236 237 void WorldEntity::attach(WorldEntity* object) 238 { 239 if (object == this) 240 { 241 COUT(2) << "Warning: Can't attach a WorldEntity to itself." << std::endl; 242 return; 243 } 244 245 if (!object->notifyBeingAttached(this)) 246 return; 247 248 this->attachNode(object->node_); 249 this->children_.insert(object); 250 251 this->attachCollisionShape(&object->collisionShape_); 252 // mass 253 this->childrenMass_ += object->getMass(); 254 recalculateMassProps(); 255 } 256 257 bool WorldEntity::notifyBeingAttached(WorldEntity* newParent) 258 { 259 // check first whether attaching is even allowed 260 if (this->hasPhysics()) 261 { 262 if (!newParent->hasPhysics()) 263 { 264 COUT(2) << "Warning: Cannot attach a physical object to a non physical one." << std::endl; 265 return false; 266 } 267 else if (this->isDynamic()) 268 { 269 COUT(2) << "Warning: Cannot attach a dynamic object to a WorldEntity." << std::endl; 270 return false; 271 } 272 else if (this->isKinematic() && newParent->isDynamic()) 273 { 274 COUT(2) << "Warning: Cannot attach a kinematic object to a dynamic one." << std::endl; 275 return false; 276 } 277 else if (this->isKinematic()) 278 { 279 COUT(2) << "Warning: Cannot attach a kinematic object to a static or kinematic one: Not yet implemented." << std::endl; 280 return false; 281 } 282 } 283 284 if (this->isPhysicsActive()) 285 this->bPhysicsActiveBeforeAttaching_ = true; 286 this->deactivatePhysics(); 287 288 if (this->parent_) 289 this->detachFromParent(); 290 291 this->parent_ = newParent; 292 this->parentID_ = newParent->getObjectID(); 293 294 // apply transform to collision shape 295 this->collisionShape_.setPosition(this->getPosition()); 296 this->collisionShape_.setOrientation(this->getOrientation()); 297 // TODO: Scale 298 299 return true; 300 } 301 302 void WorldEntity::detach(WorldEntity* object) 303 { 304 if (this->children_.find(object) == this->children_.end()) 305 { 306 CCOUT(2) << "Warning: Cannot detach an object that is not a child." << std::endl; 307 return; 308 } 309 310 // collision shapes 311 this->detachCollisionShape(&object->collisionShape_); 312 313 // mass 314 if (object->getMass() > 0.0f) 315 { 316 this->childrenMass_ -= object->getMass(); 317 recalculateMassProps(); 318 } 319 320 this->detachNode(object->node_); 321 this->children_.erase(object); 322 323 object->notifyDetached(); 324 } 325 326 void WorldEntity::notifyDetached() 327 { 328 this->parent_ = 0; 329 this->parentID_ = OBJECTID_UNKNOWN; 330 331 // reset orientation of the collisionShape (cannot be set within a WE usually) 332 this->collisionShape_.setPosition(Vector3::ZERO); 333 this->collisionShape_.setOrientation(Quaternion::IDENTITY); 334 // TODO: Scale 335 336 if (this->bPhysicsActiveBeforeAttaching_) 337 { 338 this->activatePhysics(); 339 this->bPhysicsActiveBeforeAttaching_ = false; 340 } 341 } 342 343 WorldEntity* WorldEntity::getAttachedObject(unsigned int index) 344 { 345 unsigned int i = 0; 346 for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it) 347 { 348 if (i == index) 349 return (*it); 350 ++i; 351 } 352 return 0; 353 } 354 225 355 void WorldEntity::attachNode(Ogre::SceneNode* node) 226 356 { … … 237 367 } 238 368 239 void WorldEntity::attachToNode(Ogre::SceneNode* node)240 {241 Ogre::Node* parent = this->node_->getParent();242 if (parent)243 parent->removeChild(this->node_);244 node->addChild(this->node_);245 }246 247 void WorldEntity::detachFromNode(Ogre::SceneNode* node)248 {249 node->removeChild(this->node_);250 // this->getScene()->getRootSceneNode()->addChild(this->node_);251 }252 253 void WorldEntity::attach(WorldEntity* object)254 {255 if (object == this)256 {257 COUT(2) << "Warning: Can't attach a WorldEntity to itself." << std::endl;258 return;259 }260 261 if (!object->notifyBeingAttached(this))262 return;263 264 this->attachNode(object->node_);265 this->children_.insert(object);266 267 this->attachCollisionShape(object->getCollisionShape());268 // mass269 this->childrenMass_ += object->getMass();270 recalculateMassProps();271 }272 273 bool WorldEntity::notifyBeingAttached(WorldEntity* newParent)274 {275 // check first whether attaching is even allowed276 if (this->hasPhysics())277 {278 if (!newParent->hasPhysics())279 {280 COUT(2) << "Warning: Cannot attach a physical object to a non physical one." << std::endl;281 return false;282 }283 else if (this->isDynamic())284 {285 COUT(2) << "Warning: Cannot attach a dynamic object to a WorldEntity." << std::endl;286 return false;287 }288 else if (this->isKinematic() && newParent->isDynamic())289 {290 COUT(2) << "Warning: Cannot attach a kinematic object to a dynamic one." << std::endl;291 return false;292 }293 else if (this->isKinematic())294 {295 COUT(2) << "Warning: Cannot attach a kinematic object to a static or kinematic one: Not yet implemented." << std::endl;296 return false;297 }298 }299 300 if (this->isPhysicsActive())301 this->bPhysicsActiveBeforeAttaching_ = true;302 this->deactivatePhysics();303 304 if (this->parent_)305 this->detachFromParent();306 307 this->parent_ = newParent;308 this->parentID_ = newParent->getObjectID();309 310 // apply transform to collision shape311 this->collisionShape_->setPosition(this->getPosition());312 this->collisionShape_->setOrientation(this->getOrientation());313 // TODO: Scale314 315 return true;316 }317 318 void WorldEntity::detach(WorldEntity* object)319 {320 if (this->children_.find(object) == this->children_.end())321 {322 CCOUT(2) << "Warning: Cannot detach an object that is not a child." << std::endl;323 return;324 }325 326 // collision shapes327 this->detachCollisionShape(object->getCollisionShape());328 329 // mass330 if (object->getMass() > 0.0f)331 {332 this->childrenMass_ -= object->getMass();333 recalculateMassProps();334 }335 336 this->detachNode(object->node_);337 this->children_.erase(object);338 339 object->notifyDetached();340 }341 342 void WorldEntity::notifyDetached()343 {344 this->parent_ = 0;345 this->parentID_ = OBJECTID_UNKNOWN;346 347 // reset orientation of the collisionShape (cannot be set within a WE usually)348 this->collisionShape_->setPosition(Vector3::ZERO);349 this->collisionShape_->setOrientation(Quaternion::IDENTITY);350 // TODO: Scale351 352 if (this->bPhysicsActiveBeforeAttaching_)353 {354 this->activatePhysics();355 this->bPhysicsActiveBeforeAttaching_ = false;356 }357 }358 359 WorldEntity* WorldEntity::getAttachedObject(unsigned int index) const360 {361 unsigned int i = 0;362 for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)363 {364 if (i == index)365 return (*it);366 ++i;367 }368 return 0;369 }370 371 369 void WorldEntity::attachOgreObject(Ogre::MovableObject* object) 372 370 { … … 386 384 void WorldEntity::attachCollisionShape(CollisionShape* shape) 387 385 { 388 this->collisionShape_ ->attach(shape);386 this->collisionShape_.attach(shape); 389 387 // Note: this->collisionShape_ already notifies us of any changes. 390 388 } … … 392 390 void WorldEntity::detachCollisionShape(CollisionShape* shape) 393 391 { 394 this->collisionShape_ ->detach(shape);392 this->collisionShape_.detach(shape); 395 393 // Note: this->collisionShape_ already notifies us of any changes. 396 394 } … … 398 396 CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index) const 399 397 { 400 return this->collisionShape_->getAttachedShape(index); 401 } 402 403 void WorldEntity::activatePhysics() 404 { 405 if (this->isActive() && this->hasPhysics() && !this->isPhysicsActive() && !this->parent_) 406 { 407 this->getScene()->addPhysicalObject(this); 408 this->bPhysicsActive_ = true; 409 } 410 } 411 412 void WorldEntity::deactivatePhysics() 413 { 414 if (this->isPhysicsActive()) 415 { 416 this->getScene()->removePhysicalObject(this); 417 this->bPhysicsActive_ = false; 418 } 419 } 420 421 bool WorldEntity::addedToPhysicalWorld() const 422 { 423 return this->physicalBody_ && this->physicalBody_->isInWorld(); 424 } 425 398 return this->collisionShape_.getAttachedShape(index); 399 } 400 401 // Note: These functions are placed in WorldEntity.h as inline functions for the release build. 426 402 #ifndef _NDEBUG 427 403 const Vector3& WorldEntity::getPosition() const … … 451 427 } 452 428 453 void WorldEntity::translate(const Vector3& distance, TransformSpace::Space relativeTo) 429 const Vector3& WorldEntity::getWorldScale3D() const 430 { 431 return this->node_->_getDerivedScale(); 432 } 433 434 float WorldEntity::getWorldScale() const 435 { 436 Vector3 scale = this->getWorldScale3D(); 437 return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; 438 } 439 440 void WorldEntity::setScale3D(const Vector3& scale) 441 { 442 /* 443 HACK HACK HACK 444 if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE) 445 { 446 CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl; 447 return; 448 } 449 HACK HACK HACK 450 */ 451 this->node_->setScale(scale); 452 453 this->changedScale(); 454 } 455 456 void WorldEntity::translate(const Vector3& distance, TransformSpace::Enum relativeTo) 454 457 { 455 458 switch (relativeTo) … … 474 477 475 478 void WorldEntity::rotate(const Quaternion& rotation, TransformSpace::Space relativeTo) 479 void WorldEntity::rotate(const Quaternion& rotation, TransformSpace::Enum relativeTo) 476 480 { 477 481 switch(relativeTo) … … 493 497 494 498 void WorldEntity::lookAt(const Vector3& target, TransformSpace::Space relativeTo, const Vector3& localDirectionVector) 499 void WorldEntity::lookAt(const Vector3& target, TransformSpace::Enum relativeTo, const Vector3& localDirectionVector) 495 500 { 496 501 Vector3 origin; … … 511 516 512 517 void WorldEntity::setDirection(const Vector3& direction, TransformSpace::Space relativeTo, const Vector3& localDirectionVector) 518 void WorldEntity::setDirection(const Vector3& direction, TransformSpace::Enum relativeTo, const Vector3& localDirectionVector) 513 519 { 514 520 Quaternion savedOrientation(this->getOrientation()); … … 529 535 } 530 536 531 void WorldEntity::setScale3D(const Vector3& scale) 532 { 533 /* 534 if (this->hasPhysics() && scale != Vector3::UNIT_SCALE) 535 { 536 CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented." << std::endl; 537 return; 538 } 539 */ 540 this->node_->setScale(scale); 541 542 this->changedScale(); 543 } 544 545 const Vector3& WorldEntity::getWorldScale3D() const 546 { 547 return this->node_->_getDerivedScale(); 548 } 549 550 float WorldEntity::getWorldScale() const 551 { 552 Vector3 scale = this->getWorldScale3D(); 553 return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; 537 void WorldEntity::activatePhysics() 538 { 539 if (this->isActive() && this->hasPhysics() && !this->isPhysicsActive() && !this->parent_) 540 { 541 this->getScene()->addPhysicalObject(this); 542 this->bPhysicsActive_ = true; 543 } 544 } 545 546 void WorldEntity::deactivatePhysics() 547 { 548 if (this->isPhysicsActive()) 549 { 550 this->getScene()->removePhysicalObject(this); 551 this->bPhysicsActive_ = false; 552 } 553 } 554 555 bool WorldEntity::addedToPhysicalWorld() const 556 { 557 return this->physicalBody_ && this->physicalBody_->isInWorld(); 554 558 } 555 559 556 560 void WorldEntity::setCollisionType(CollisionType type) 557 561 { 562 if (this->collisionType_ == type) 563 return; 564 558 565 // If we are already attached to a parent, this would be a bad idea.. 559 566 if (this->parent_) … … 562 569 return; 563 570 } 564 else if (this->addedToPhysicalWorld()) 565 { 566 CCOUT(2) << "Warning: Cannot set the collision type at run time." << std::endl; 567 return; 568 } 569 570 // Check for type legality. Could be StaticEntity or MobileEntity 571 572 // Check for type legality. Could be StaticEntity or MobileEntity. 571 573 if (!this->isCollisionTypeLegal(type)) 572 574 return; … … 576 578 return; 577 579 } 580 581 if (this->isPhysicsActive()) 582 this->deactivatePhysics(); 583 584 bool bReactivatePhysics = true; 585 if (this->hasPhysics() && !this->isPhysicsActive()) 586 bReactivatePhysics = false; 578 587 579 588 // Check whether we have to create or destroy. … … 581 590 { 582 591 /* 592 HACK HACK HACK 583 593 // Check whether there was some scaling applied. 584 594 if (!this->node_->getScale().positionEquals(Vector3(1, 1, 1), 0.001)) … … 587 597 return; 588 598 } 599 HACK HACK HACK 589 600 */ 590 601 // Create new rigid body 591 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_ ->getCollisionShape());602 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_.getCollisionShape()); 592 603 this->physicalBody_ = new btRigidBody(bodyConstructionInfo); 593 604 this->physicalBody_->setUserPointer(this); … … 619 630 break; 620 631 case None: 621 return; // this->collisionType_ was None too 622 } 623 624 // Only sets this->collisionShape_ 632 assert(false); // Doesn't happen 633 return; 634 } 635 636 // Only sets this->collisionType_ 625 637 // However the assertion is to ensure that the internal bullet setting is right 626 638 updateCollisionType(); … … 629 641 // update mass and inertia tensor 630 642 recalculateMassProps(); 631 resetPhysicsProps();643 internalSetPhysicsProps(); 632 644 collisionCallbackActivityChanged(); 633 activatePhysics(); 645 if (bReactivatePhysics) 646 activatePhysics(); 634 647 } 635 648 … … 682 695 } 683 696 684 void WorldEntity::notifyChildMassChanged() // Called by a child WE697 void WorldEntity::notifyChildMassChanged() 685 698 { 686 699 // Note: CollisionShape changes of a child get handled over the internal CompoundCollisionShape already … … 695 708 } 696 709 697 void WorldEntity::notifyCollisionShapeChanged() // called by this->collisionShape_710 void WorldEntity::notifyCollisionShapeChanged() 698 711 { 699 712 if (hasPhysics()) … … 703 716 { 704 717 this->deactivatePhysics(); 705 this->physicalBody_->setCollisionShape(this->collisionShape_ ->getCollisionShape());718 this->physicalBody_->setCollisionShape(this->collisionShape_.getCollisionShape()); 706 719 this->activatePhysics(); 707 720 } 708 721 else 709 this->physicalBody_->setCollisionShape(this->collisionShape_ ->getCollisionShape());722 this->physicalBody_->setCollisionShape(this->collisionShape_.getCollisionShape()); 710 723 } 711 724 recalculateMassProps(); … … 716 729 // Store local inertia for faster access. Evaluates to (0,0,0) if there is no collision shape. 717 730 float totalMass = this->mass_ + this->childrenMass_; 718 this->collisionShape_ ->calculateLocalInertia(totalMass, this->localInertia_);731 this->collisionShape_.calculateLocalInertia(totalMass, this->localInertia_); 719 732 if (this->hasPhysics()) 720 733 { … … 729 742 CCOUT(4) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0." << std::endl; 730 743 btVector3 inertia(0, 0, 0); 731 this->collisionShape_ ->calculateLocalInertia(1.0f, inertia);744 this->collisionShape_.calculateLocalInertia(1.0f, inertia); 732 745 this->physicalBody_->setMassProps(1.0f, inertia); 733 746 } … … 739 752 } 740 753 741 void WorldEntity:: resetPhysicsProps()754 void WorldEntity::internalSetPhysicsProps() 742 755 { 743 756 if (this->hasPhysics()) -
code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.h
r2527 r2535 40 40 #include "LinearMath/btMotionState.h" 41 41 42 #include "util/Math.h" 43 #include "core/BaseObject.h" 42 44 #include "network/synchronisable/Synchronisable.h" 43 #include "core/BaseObject.h" 44 #include "util/Math.h" 45 #include "objects/collisionshapes/CompoundCollisionShape.h" 45 46 46 47 namespace orxonox … … 48 49 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState 49 50 { 51 friend class Scene; 52 50 53 public: 51 54 WorldEntity(BaseObject* creator); … … 71 74 const Vector3& getWorldPosition() const; 72 75 73 void translate(const Vector3& distance, TransformSpace:: SpacerelativeTo = TransformSpace::Parent);74 inline void translate(float x, float y, float z, TransformSpace:: SpacerelativeTo = TransformSpace::Parent)76 void translate(const Vector3& distance, TransformSpace::Enum relativeTo = TransformSpace::Parent); 77 inline void translate(float x, float y, float z, TransformSpace::Enum relativeTo = TransformSpace::Parent) 75 78 { this->translate(Vector3(x, y, z), relativeTo); } 76 79 … … 88 91 const Quaternion& getWorldOrientation() const; 89 92 90 void rotate(const Quaternion& rotation, TransformSpace:: SpacerelativeTo = TransformSpace::Local);91 inline void rotate(const Vector3& axis, const Degree& angle, TransformSpace:: SpacerelativeTo = TransformSpace::Local)93 void rotate(const Quaternion& rotation, TransformSpace::Enum relativeTo = TransformSpace::Local); 94 inline void rotate(const Vector3& axis, const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 92 95 { this->rotate(Quaternion(angle, axis), relativeTo); } 93 96 94 inline void yaw(const Degree& angle, TransformSpace:: SpacerelativeTo = TransformSpace::Local)97 inline void yaw(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 95 98 { this->rotate(Quaternion(angle, Vector3::UNIT_Y), relativeTo); } 96 inline void pitch(const Degree& angle, TransformSpace:: SpacerelativeTo = TransformSpace::Local)99 inline void pitch(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 97 100 { this->rotate(Quaternion(angle, Vector3::UNIT_X), relativeTo); } 98 inline void roll(const Degree& angle, TransformSpace:: SpacerelativeTo = TransformSpace::Local)101 inline void roll(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local) 99 102 { this->rotate(Quaternion(angle, Vector3::UNIT_Z), relativeTo); } 100 103 101 void lookAt(const Vector3& target, TransformSpace:: SpacerelativeTo = TransformSpace::Parent, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);102 void setDirection(const Vector3& direction, TransformSpace:: SpacerelativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);103 inline void setDirection(float x, float y, float z, TransformSpace:: SpacerelativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)104 void lookAt(const Vector3& target, TransformSpace::Enum relativeTo = TransformSpace::Parent, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 105 void setDirection(const Vector3& direction, TransformSpace::Enum relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 106 inline void setDirection(float x, float y, float z, TransformSpace::Enum relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 104 107 { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); } 105 108 … … 127 130 void attach(WorldEntity* object); 128 131 void detach(WorldEntity* object); 129 WorldEntity* getAttachedObject(unsigned int index) const;132 WorldEntity* getAttachedObject(unsigned int index); 130 133 inline const std::set<WorldEntity*>& getAttachedObjects() const 131 134 { return this->children_; } … … 216 219 217 220 inline void setRestitution(float restitution) 218 { this->restitution_ = restitution; resetPhysicsProps(); }221 { this->restitution_ = restitution; internalSetPhysicsProps(); } 219 222 inline float getRestitution() const 220 223 { return this->restitution_; } 221 224 222 225 inline void setAngularFactor(float angularFactor) 223 { this->angularFactor_ = angularFactor; resetPhysicsProps(); }226 { this->angularFactor_ = angularFactor; internalSetPhysicsProps(); } 224 227 inline float getAngularFactor() const 225 228 { return this->angularFactor_; } 226 229 227 230 inline void setLinearDamping(float linearDamping) 228 { this->linearDamping_ = linearDamping; resetPhysicsProps(); }231 { this->linearDamping_ = linearDamping; internalSetPhysicsProps(); } 229 232 inline float getLinearDamping() const 230 233 { return this->linearDamping_; } 231 234 232 235 inline void setAngularDamping(float angularDamping) 233 { this->angularDamping_ = angularDamping; resetPhysicsProps(); }236 { this->angularDamping_ = angularDamping; internalSetPhysicsProps(); } 234 237 inline float getAngularDamping() const 235 238 { return this->angularDamping_; } 236 239 237 240 inline void setFriction(float friction) 238 { this->friction_ = friction; resetPhysicsProps(); }241 { this->friction_ = friction; internalSetPhysicsProps(); } 239 242 inline float getFriction() const 240 243 { return this->friction_; } … … 242 245 void attachCollisionShape(CollisionShape* shape); 243 246 void detachCollisionShape(CollisionShape* shape); 244 CollisionShape* getAttachedCollisionShape(unsigned int index) const; 245 246 inline CompoundCollisionShape* getCollisionShape() const 247 { return this->collisionShape_; } 248 inline btRigidBody* getPhysicalBody() const 249 { return this->physicalBody_; } 247 CollisionShape* getAttachedCollisionShape(unsigned int index); 250 248 251 249 void notifyCollisionShapeChanged(); … … 265 263 virtual bool isCollisionTypeLegal(CollisionType type) const = 0; 266 264 267 btRigidBody* 265 btRigidBody* physicalBody_; 268 266 269 267 private: 270 268 void updateCollisionType(); 271 269 void recalculateMassProps(); 272 void resetPhysicsProps();270 void internalSetPhysicsProps(); 273 271 274 272 bool notifyBeingAttached(WorldEntity* newParent); … … 297 295 bool bPhysicsActiveSynchronised_; 298 296 bool bPhysicsActiveBeforeAttaching_; 299 CompoundCollisionShape *collisionShape_;297 CompoundCollisionShape collisionShape_; 300 298 btScalar mass_; 301 299 btVector3 localInertia_;
Note: See TracChangeset
for help on using the changeset viewer.