Changeset 2562
- Timestamp:
- Jan 1, 2009, 7:34:44 PM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/OrxonoxPrereqs.h
r2495 r2562 203 203 class CompoundCollisionShape; 204 204 class PlaneCollisionShape; 205 class WorldEntityCollisionShape; 205 206 206 207 // tools -
code/branches/presentation/src/orxonox/objects/collisionshapes/CMakeLists.txt
r2486 r2562 6 6 PlaneCollisionShape.cc 7 7 SphereCollisionShape.cc 8 WorldEntityCollisionShape.cc 8 9 ) 9 10 -
code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.cc
r2527 r2562 37 37 #include "tools/BulletConversions.h" 38 38 39 #include "objects/worldentities/WorldEntity.h" 39 40 #include "CompoundCollisionShape.h" 40 #include " objects/worldentities/WorldEntity.h"41 #include "WorldEntityCollisionShape.h" 41 42 42 43 namespace orxonox … … 85 86 void CollisionShape::parentChanged() 86 87 { 87 CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_)); 88 if (parent) 89 parent->attach(this); 88 Synchronisable* parent = Synchronisable::getSynchronisable(this->parentID_); 89 // Parent can either be a WorldEntity or a CompoundCollisionShape. The reason is that the 90 // internal collision shape (which is compound) of a WE doesn't get synchronised. 91 CompoundCollisionShape* parentCCS = dynamic_cast<CompoundCollisionShape*>(parent); 92 if (parentCCS) 93 parentCCS->attach(this); 94 else 95 { 96 WorldEntity* parentWE = dynamic_cast<WorldEntity*>(parent); 97 if (parentWE) 98 parentWE->attachCollisionShape(this); 99 } 100 } 101 102 bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent) 103 { 104 if (this->parent_) 105 this->parent_->detach(this); 106 107 this->parent_ = newParent; 108 109 WorldEntityCollisionShape* parentWECCS = dynamic_cast<WorldEntityCollisionShape*>(newParent); 110 if (parentWECCS) 111 this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID(); 112 else 113 this->parentID_ = newParent->getObjectID(); 114 115 return true; 116 } 117 118 void CollisionShape::notifyDetached() 119 { 120 this->parent_ = 0; 121 this->parentID_ = OBJECTID_UNKNOWN; 90 122 } 91 123 -
code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.h
r2515 r2562 75 75 bool hasTransform() const; 76 76 77 inline void setParent(CompoundCollisionShape* shape, unsigned int ID)78 { this->parent_ = shape; this->parentID_ = ID; }77 bool notifyBeingAttached(CompoundCollisionShape* newParent); 78 void notifyDetached(); 79 79 80 80 protected: … … 85 85 btCollisionShape* collisionShape_; 86 86 CompoundCollisionShape* parent_; 87 unsigned int parentID_; 87 88 88 89 private: … … 90 91 Quaternion orientation_; 91 92 Vector3 scale_; 92 unsigned int parentID_;93 93 }; 94 94 } -
code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.cc
r2527 r2562 36 36 #include "core/XMLPort.h" 37 37 #include "tools/BulletConversions.h" 38 #include "objects/worldentities/WorldEntity.h"39 38 40 39 namespace orxonox … … 47 46 48 47 this->compoundShape_ = new btCompoundShape(); 49 this->worldEntityParent_ = 0;50 48 } 51 49 … … 59 57 { 60 58 // make sure that the child doesn't want to detach itself --> speedup because of the missing update 61 it->first-> setParent(0, OBJECTID_UNKNOWN);59 it->first->notifyDetached(); 62 60 delete it->first; 63 61 } … … 74 72 } 75 73 76 void CompoundCollisionShape::setWorldEntityParent(WorldEntity* parent)77 {78 // suppress synchronisation79 this->setObjectMode(0x0);80 81 this->worldEntityParent_ = parent;82 }83 84 74 void CompoundCollisionShape::attach(CollisionShape* shape) 85 75 { … … 91 81 return; 92 82 } 83 84 if (!shape->notifyBeingAttached(this)) 85 return; 86 93 87 this->attachedShapes_[shape] = shape->getCollisionShape(); 94 88 … … 101 95 this->updatePublicShape(); 102 96 } 103 104 // network synchro105 if (this->worldEntityParent_)106 {107 // This compound collision shape belongs to a WE and doesn't get synchronised108 // So set our parent to be the WE109 shape->setParent(this, this->worldEntityParent_->getObjectID());110 }111 else112 shape->setParent(this, this->getObjectID());113 97 } 114 98 … … 117 101 if (this->attachedShapes_.find(shape) != this->attachedShapes_.end()) 118 102 { 119 shape->setParent(0, OBJECTID_UNKNOWN);120 103 this->attachedShapes_.erase(shape); 121 104 if (shape->getCollisionShape()) 122 105 this->compoundShape_->removeChildShape(shape->getCollisionShape()); 106 shape->notifyDetached(); 123 107 124 108 this->updatePublicShape(); … … 197 181 } 198 182 199 void CompoundCollisionShape::updateParent()200 {201 if (this->parent_)202 this->parent_->updateAttachedShape(this);203 if (this->worldEntityParent_)204 this->worldEntityParent_->notifyCollisionShapeChanged();205 }206 207 void CompoundCollisionShape::parentChanged()208 {209 if (!this->worldEntityParent_)210 CollisionShape::parentChanged();211 }212 213 183 CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const 214 184 { -
code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.h
r2527 r2562 53 53 void updateAttachedShape(CollisionShape* shape); 54 54 55 void setWorldEntityParent(WorldEntity* parent);56 57 protected:58 virtual void updateParent();59 60 55 private: 61 56 void updatePublicShape(); 62 void parentChanged();63 57 inline virtual btCollisionShape* createNewShape() const 64 58 { assert(false); return 0; } … … 66 60 btCompoundShape* compoundShape_; 67 61 std::map<CollisionShape*, btCollisionShape*> attachedShapes_; 68 WorldEntity* worldEntityParent_;69 62 }; 70 63 } -
code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.cc
r2540 r2562 42 42 43 43 #include "objects/Scene.h" 44 #include "objects/collisionshapes/WorldEntityCollisionShape.h" 44 45 45 46 namespace orxonox … … 57 58 All the default values are being set here. 58 59 */ 59 WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) , collisionShape_(0)60 WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) 60 61 { 61 62 RegisterObject(WorldEntity); … … 74 75 75 76 // Default behaviour does not include physics 76 // Note: CompoundCollisionShape is a Synchronisable, but must not be synchronised.77 // All objects will get attached on the client anyway, so we don't need synchronisation.78 this->collisionShape_.setWorldEntityParent(this);79 77 this->physicalBody_ = 0; 80 78 this->bPhysicsActive_ = false; 81 79 this->bPhysicsActiveSynchronised_ = false; 82 80 this->bPhysicsActiveBeforeAttaching_ = false; 81 this->collisionShape_ = new WorldEntityCollisionShape(this); 83 82 this->collisionType_ = None; 84 83 this->collisionTypeSynchronised_ = None; … … 115 114 delete this->physicalBody_; 116 115 } 116 delete this->collisionShape_; 117 117 118 118 this->node_->detachAllObjects(); … … 291 291 this->children_.insert(object); 292 292 293 this->attachCollisionShape( &object->collisionShape_);293 this->attachCollisionShape(object->collisionShape_); 294 294 // mass 295 295 this->childrenMass_ += object->getMass(); … … 345 345 346 346 // apply transform to collision shape 347 this->collisionShape_ .setPosition(this->getPosition());348 this->collisionShape_ .setOrientation(this->getOrientation());347 this->collisionShape_->setPosition(this->getPosition()); 348 this->collisionShape_->setOrientation(this->getOrientation()); 349 349 // TODO: Scale 350 350 … … 365 365 366 366 // collision shapes 367 this->detachCollisionShape( &object->collisionShape_);367 this->detachCollisionShape(object->collisionShape_); 368 368 369 369 // mass … … 390 390 391 391 // reset orientation of the collisionShape (cannot be set within a WE usually) 392 this->collisionShape_ .setPosition(Vector3::ZERO);393 this->collisionShape_ .setOrientation(Quaternion::IDENTITY);392 this->collisionShape_->setPosition(Vector3::ZERO); 393 this->collisionShape_->setOrientation(Quaternion::IDENTITY); 394 394 // TODO: Scale 395 395 … … 451 451 void WorldEntity::attachCollisionShape(CollisionShape* shape) 452 452 { 453 this->collisionShape_ .attach(shape);453 this->collisionShape_->attach(shape); 454 454 // Note: this->collisionShape_ already notifies us of any changes. 455 455 } … … 458 458 void WorldEntity::detachCollisionShape(CollisionShape* shape) 459 459 { 460 this->collisionShape_.detach(shape); 460 // Note: The collision shapes may not be detached with this function! 461 this->collisionShape_->detach(shape); 461 462 // Note: this->collisionShape_ already notifies us of any changes. 462 463 } … … 465 466 CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index) 466 467 { 467 return this->collisionShape_ .getAttachedShape(index);468 return this->collisionShape_->getAttachedShape(index); 468 469 } 469 470 … … 718 719 */ 719 720 // Create new rigid body 720 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_ .getCollisionShape());721 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_->getCollisionShape()); 721 722 this->physicalBody_ = new btRigidBody(bodyConstructionInfo); 722 723 this->physicalBody_->setUserPointer(this); … … 851 852 { 852 853 this->deactivatePhysics(); 853 this->physicalBody_->setCollisionShape(this->collisionShape_ .getCollisionShape());854 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 854 855 this->activatePhysics(); 855 856 } 856 857 else 857 this->physicalBody_->setCollisionShape(this->collisionShape_ .getCollisionShape());858 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 858 859 } 859 860 recalculateMassProps(); … … 865 866 // Store local inertia for faster access. Evaluates to (0,0,0) if there is no collision shape. 866 867 float totalMass = this->mass_ + this->childrenMass_; 867 this->collisionShape_ .calculateLocalInertia(totalMass, this->localInertia_);868 this->collisionShape_->calculateLocalInertia(totalMass, this->localInertia_); 868 869 if (this->hasPhysics()) 869 870 { … … 878 879 CCOUT(4) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0" << std::endl; 879 880 btVector3 inertia(0, 0, 0); 880 this->collisionShape_ .calculateLocalInertia(1.0f, inertia);881 this->collisionShape_->calculateLocalInertia(1.0f, inertia); 881 882 this->physicalBody_->setMassProps(1.0f, inertia); 882 883 } -
code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.h
r2540 r2562 43 43 #include "core/BaseObject.h" 44 44 #include "network/synchronisable/Synchronisable.h" 45 #include "objects/collisionshapes/CompoundCollisionShape.h"46 45 47 46 namespace orxonox … … 69 68 You can get more information at the corresponding set function. 70 69 71 Collision shapes: These are controlled by the internal CompoundCollisionShape. @see CompoundCollisionShape.70 Collision shapes: These are controlled by the internal WorldEntityCollisionShape. @see WorldEntityCollisionShape. 72 71 */ 73 72 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState … … 399 398 //! When attaching objects hierarchically this variable tells this object (as child) whether physics was activated before attaching (because the deactivate physics while being attached). 400 399 bool bPhysicsActiveBeforeAttaching_; 401 CompoundCollisionShapecollisionShape_; //!< Attached collision shapes go here400 WorldEntityCollisionShape* collisionShape_; //!< Attached collision shapes go here 402 401 btScalar mass_; //!< @see setMass 403 402 btVector3 localInertia_; //!< @see getLocalInertia -
code/branches/presentation/visual_studio/vc8/orxonox.vcproj
r2538 r2562 524 524 > 525 525 </File> 526 <File 527 RelativePath="..\..\src\orxonox\objects\collisionshapes\WorldEntityCollisionShape.cc" 528 > 529 </File> 526 530 </Filter> 527 531 <Filter … … 1294 1298 <File 1295 1299 RelativePath="..\..\src\orxonox\objects\collisionshapes\SphereCollisionShape.h" 1300 > 1301 </File> 1302 <File 1303 RelativePath="..\..\src\orxonox\objects\collisionshapes\WorldEntityCollisionShape.h" 1296 1304 > 1297 1305 </File>
Note: See TracChangeset
for help on using the changeset viewer.