Changeset 2527 for code/branches/presentation/src/orxonox
- Timestamp:
- Dec 22, 2008, 10:23:29 PM (16 years ago)
- Location:
- code/branches/presentation/src/orxonox/objects
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.cc
r2515 r2527 62 62 // Detach from parent 63 63 if (this->isInitialized() && this->parent_) 64 this->parent_-> removeChildShape(this);64 this->parent_->detach(this); 65 65 } 66 66 … … 87 87 CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_)); 88 88 if (parent) 89 parent->a ddChildShape(this);89 parent->attach(this); 90 90 } 91 91 … … 93 93 { 94 94 if (this->parent_) 95 this->parent_->update ChildShape(this);95 this->parent_->updateAttachedShape(this); 96 96 } 97 97 -
code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.cc
r2514 r2527 55 55 { 56 56 // Delete all children 57 for (std::map<CollisionShape*, btCollisionShape*>::iterator it = this-> childShapes_.begin();58 it != this-> childShapes_.end(); ++it)57 for (std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin(); 58 it != this->attachedShapes_.end(); ++it) 59 59 { 60 60 // make sure that the child doesn't want to detach itself --> speedup because of the missing update … … 71 71 SUPER(CompoundCollisionShape, XMLPort, xmlelement, mode); 72 72 // Attached collision shapes 73 XMLPortObject(CompoundCollisionShape, CollisionShape, "", a ddChildShape, getChildShape, xmlelement, mode);73 XMLPortObject(CompoundCollisionShape, CollisionShape, "", attach, detach, xmlelement, mode); 74 74 } 75 75 … … 82 82 } 83 83 84 void CompoundCollisionShape::a ddChildShape(CollisionShape* shape)84 void CompoundCollisionShape::attach(CollisionShape* shape) 85 85 { 86 86 if (!shape || static_cast<CollisionShape*>(this) == shape) 87 87 return; 88 if (this-> childShapes_.find(shape) != this->childShapes_.end())88 if (this->attachedShapes_.find(shape) != this->attachedShapes_.end()) 89 89 { 90 90 CCOUT(2) << "Warning: Attaching a CollisionShape twice is not yet supported." << std::endl; 91 91 return; 92 92 } 93 this-> childShapes_[shape] = shape->getCollisionShape();93 this->attachedShapes_[shape] = shape->getCollisionShape(); 94 94 95 95 if (shape->getCollisionShape()) … … 113 113 } 114 114 115 void CompoundCollisionShape:: removeChildShape(CollisionShape* shape)116 { 117 if (this-> childShapes_.find(shape) != this->childShapes_.end())115 void CompoundCollisionShape::detach(CollisionShape* shape) 116 { 117 if (this->attachedShapes_.find(shape) != this->attachedShapes_.end()) 118 118 { 119 119 shape->setParent(0, OBJECTID_UNKNOWN); 120 this-> childShapes_.erase(shape);120 this->attachedShapes_.erase(shape); 121 121 if (shape->getCollisionShape()) 122 122 this->compoundShape_->removeChildShape(shape->getCollisionShape()); … … 124 124 this->updatePublicShape(); 125 125 } 126 } 127 128 void CompoundCollisionShape::removeAllChildShapes() 129 { 130 while (this->childShapes_.size() > 0) 131 this->removeChildShape(this->childShapes_.begin()->first); 132 } 133 134 void CompoundCollisionShape::updateChildShape(CollisionShape* shape) 126 else 127 CCOUT(2) << "Warning: Cannot detach non child collision shape" << std::endl; 128 } 129 130 void CompoundCollisionShape::detachAll() 131 { 132 while (this->attachedShapes_.size() > 0) 133 this->detach(this->attachedShapes_.begin()->first); 134 } 135 136 void CompoundCollisionShape::updateAttachedShape(CollisionShape* shape) 135 137 { 136 138 if (!shape) 137 139 return; 138 std::map<CollisionShape*, btCollisionShape*>::iterator it = this-> childShapes_.find(shape);139 if (it == this-> childShapes_.end())140 std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.find(shape); 141 if (it == this->attachedShapes_.end()) 140 142 { 141 143 CCOUT(2) << "Warning: Cannot update child shape: Instance not a child." << std::endl; … … 162 164 bool bPrimitive = true; 163 165 bool bEmpty = true; 164 for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this-> childShapes_.begin(); it != this->childShapes_.end(); ++it)166 for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it) 165 167 { 166 168 if (it->second) … … 198 200 { 199 201 if (this->parent_) 200 this->parent_->update ChildShape(this);202 this->parent_->updateAttachedShape(this); 201 203 if (this->worldEntityParent_) 202 204 this->worldEntityParent_->notifyCollisionShapeChanged(); … … 209 211 } 210 212 211 CollisionShape* CompoundCollisionShape::get ChildShape(unsigned int index) const213 CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const 212 214 { 213 215 unsigned int i = 0; 214 for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this-> childShapes_.begin(); it != this->childShapes_.end(); ++it)216 for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it) 215 217 { 216 218 if (i == index) -
code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.h
r2514 r2527 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 47 48 void a ddChildShape(CollisionShape* shape);49 void removeChildShape(CollisionShape* shape);50 void removeAllChildShapes();51 CollisionShape* get ChildShape(unsigned int index) const;48 void attach(CollisionShape* shape); 49 void detach(CollisionShape* shape); 50 void detachAll(); 51 CollisionShape* getAttachedShape(unsigned int index) const; 52 52 53 void update ChildShape(CollisionShape* shape);53 void updateAttachedShape(CollisionShape* shape); 54 54 55 55 void setWorldEntityParent(WorldEntity* parent); … … 65 65 66 66 btCompoundShape* compoundShape_; 67 std::map<CollisionShape*, btCollisionShape*> childShapes_;67 std::map<CollisionShape*, btCollisionShape*> attachedShapes_; 68 68 WorldEntity* worldEntityParent_; 69 69 }; -
code/branches/presentation/src/orxonox/objects/worldentities/Camera.cc
r2500 r2527 109 109 float coeff = min(1.0f, 15.0f * dt); 110 110 111 Vector3 offset = this->get Node()->getWorldPosition() - this->cameraNode_->getWorldPosition();111 Vector3 offset = this->getWorldPosition() - this->cameraNode_->getWorldPosition(); 112 112 this->cameraNode_->translate(coeff * offset); 113 113 -
code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.cc
r2501 r2527 71 71 this->physicalBody_ = 0; 72 72 this->bPhysicsActive_ = false; 73 this->bPhysicsActiveSynchronised_ = false; 74 this->bPhysicsActiveBeforeAttaching_ = false; 73 75 this->collisionShape_ = new CompoundCollisionShape(this); 74 76 // Note: CompoundCollisionShape is a Synchronisable, but must not be synchronised. … … 251 253 void WorldEntity::attach(WorldEntity* object) 252 254 { 253 // check first whether attaching is even allowed254 if (object->hasPhysics())255 {256 if (!this->hasPhysics())257 {258 COUT(2) << "Warning: Cannot attach a physical object to a non physical one." << std::endl;259 return;260 }261 else if (object->isDynamic())262 {263 COUT(2) << "Warning: Cannot attach a dynamic object to a WorldEntity." << std::endl;264 return;265 }266 else if (object->isKinematic() && this->isDynamic())267 {268 COUT(2) << "Warning: Cannot attach a kinematic object to a dynamic one." << std::endl;269 return;270 }271 else if (object->isKinematic())272 {273 COUT(2) << "Warning: Cannot attach a kinematic object to a static or kinematic one: Not yet implemented." << std::endl;274 return;275 }276 else277 {278 object->deactivatePhysics();279 }280 }281 282 255 if (object == this) 283 256 { … … 286 259 } 287 260 288 if ( object->getParent())289 object->detachFromParent();261 if (!object->notifyBeingAttached(this)) 262 return; 290 263 291 264 this->attachNode(object->node_); 292 293 265 this->children_.insert(object); 294 object->parent_ = this; 295 object->parentID_ = this->getObjectID(); 296 297 // collision shapes 266 298 267 this->attachCollisionShape(object->getCollisionShape()); 299 268 // mass … … 302 271 } 303 272 273 bool WorldEntity::notifyBeingAttached(WorldEntity* newParent) 274 { 275 // check first whether attaching is even allowed 276 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 shape 311 this->collisionShape_->setPosition(this->getPosition()); 312 this->collisionShape_->setOrientation(this->getOrientation()); 313 // TODO: Scale 314 315 return true; 316 } 317 304 318 void WorldEntity::detach(WorldEntity* object) 305 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 306 326 // collision shapes 307 327 this->detachCollisionShape(object->getCollisionShape()); 328 308 329 // mass 309 330 if (object->getMass() > 0.0f) … … 315 336 this->detachNode(object->node_); 316 337 this->children_.erase(object); 317 object->parent_ = 0; 318 object->parentID_ = OBJECTID_UNKNOWN; 319 320 // Note: It is possible that the object has physics but was disabled when attaching 321 object->activatePhysics(); 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: Scale 351 352 if (this->bPhysicsActiveBeforeAttaching_) 353 { 354 this->activatePhysics(); 355 this->bPhysicsActiveBeforeAttaching_ = false; 356 } 322 357 } 323 358 … … 351 386 void WorldEntity::attachCollisionShape(CollisionShape* shape) 352 387 { 353 this->collisionShape_->a ddChildShape(shape);388 this->collisionShape_->attach(shape); 354 389 // Note: this->collisionShape_ already notifies us of any changes. 355 390 } … … 357 392 void WorldEntity::detachCollisionShape(CollisionShape* shape) 358 393 { 359 this->collisionShape_-> removeChildShape(shape);394 this->collisionShape_->detach(shape); 360 395 // Note: this->collisionShape_ already notifies us of any changes. 361 396 } … … 363 398 CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index) const 364 399 { 365 return this->collisionShape_->get ChildShape(index);400 return this->collisionShape_->getAttachedShape(index); 366 401 } 367 402 -
code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.h
r2485 r2527 244 244 CollisionShape* getAttachedCollisionShape(unsigned int index) const; 245 245 246 inline CompoundCollisionShape* getCollisionShape() 246 inline CompoundCollisionShape* getCollisionShape() const 247 247 { return this->collisionShape_; } 248 inline btRigidBody* getPhysicalBody() 248 inline btRigidBody* getPhysicalBody() const 249 249 { return this->physicalBody_; } 250 250 … … 259 259 inline void disableCollisionCallback() 260 260 { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); } 261 inline bool isCollisionCallbackActive() 261 inline bool isCollisionCallbackActive() const 262 262 { return this->bCollisionCallbackActive_; } 263 263 … … 271 271 void recalculateMassProps(); 272 272 void resetPhysicsProps(); 273 274 bool notifyBeingAttached(WorldEntity* newParent); 275 void notifyDetached(); 273 276 274 277 // network callbacks … … 293 296 bool bPhysicsActive_; 294 297 bool bPhysicsActiveSynchronised_; 298 bool bPhysicsActiveBeforeAttaching_; 295 299 CompoundCollisionShape* collisionShape_; 296 300 btScalar mass_;
Note: See TracChangeset
for help on using the changeset viewer.