- Timestamp:
- Dec 3, 2008, 1:17:12 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2306 r2313 89 89 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); 90 90 91 this->setCollisionType(None); 91 if (this->physicalBody_) 92 { 93 if (this->physicalBody_->isInWorld()) 94 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 95 delete this->physicalBody_; 96 } 97 // TODO: Delete collisionShapes 92 98 } 93 99 } … … 147 153 else if (object->isKinematic()) 148 154 ThrowException(NotImplemented, "Cannot attach a kinematic object to a static or kinematic one: Not yet implemented."); 149 else if (object->physicalBody_->isInWorld() || this->physicalBody_->isInWorld())150 ThrowException(PhysicsViolation, "Cannot attach a physical object at runtime.");151 155 else 152 156 { 157 if (this->physicalBody_->isInWorld()) 158 removeFromPhysicalWorld(); 159 if (object->physicalBody_->isInWorld()) 160 this->getScene()->removeRigidBody(object->physicalBody_); 161 153 162 // static to static/kinematic/dynamic --> merge shapes 154 163 this->childMass_ += object->getMass(); … … 157 166 // That also implies that cannot add a physics WE to the child afterwards. 158 167 object->setCollisionType(None); 168 169 addToPhysicalWorld(); 159 170 } 160 171 } … … 209 220 // recalculate inertia tensor 210 221 if (this->isDynamic()) 211 {212 222 internalSetMassProps(); 213 }214 223 } 215 224 else … … 228 237 { 229 238 if (this->physicalBody_->isInWorld()) 230 COUT(2) << "Warning: Cannot attach a physical object at runtime."; 231 else 232 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 233 } 239 { 240 COUT(2) << "Warning: Attaching collision shapes at run time causes its physical body to be removed and added again."; 241 removeFromPhysicalWorld(); 242 } 243 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 244 } 245 246 addToPhysicalWorld(); 234 247 } 235 248 … … 257 270 } 258 271 272 void WorldEntity::addToPhysicalWorld() const 273 { 274 if (this->isActive() && this->hasPhysics() && !this->physicalBody_->isInWorld()) 275 this->getScene()->addRigidBody(this->physicalBody_); 276 } 277 278 void WorldEntity::removeFromPhysicalWorld() const 279 { 280 if (this->hasPhysics()) 281 this->getScene()->removeRigidBody(this->physicalBody_); 282 } 283 259 284 void WorldEntity::setScale3D(const Vector3& scale) 260 285 { … … 278 303 if (!this->hasPhysics()) 279 304 COUT(3) << "Warning: Setting the mass of a WorldEntity with no physics has no effect." << std::endl; 280 else if (this->physicalBody_->isInWorld()) 281 COUT(2) << "Warning: Cannot set the physical mass at run time. Storing new mass." << std::endl; 282 else 305 else 306 { 307 if (this->physicalBody_->isInWorld()) 308 { 309 COUT(2) << "Warning: Setting the mass of a WorldEntity at run time causes its physical body to be removed and added again." << std::endl; 310 removeFromPhysicalWorld(); 311 } 283 312 internalSetMassProps(); 313 } 314 315 addToPhysicalWorld(); 284 316 } 285 317 … … 340 372 { 341 373 // Destroy rigid body 342 if (this->physicalBody_->isInWorld())343 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_);374 assert(this->physicalBody_); 375 removeFromPhysicalWorld(); 344 376 delete this->physicalBody_; 345 377 this->physicalBody_ = 0; … … 370 402 // update mass and inertia tensor 371 403 internalSetMassProps(); // type is not None! See case None: in switch 404 405 addToPhysicalWorld(); 372 406 } 373 407
Note: See TracChangeset
for help on using the changeset viewer.