- Timestamp:
- Jan 17, 2016, 10:29:21 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.cc
r10624 r11071 65 65 { 66 66 // Delete all children 67 for (std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin(); 68 it != this->attachedShapes_.end(); ++it) 67 for (const auto& mapEntry : this->attachedShapes_) 69 68 { 70 69 // make sure that the child doesn't want to detach itself --> speedup because of the missing update 71 it->first->notifyDetached();72 it->first->destroy();73 if (this->collisionShape_ == it->second)74 this->collisionShape_ = NULL; // don't destroy it twice70 mapEntry.first->notifyDetached(); 71 mapEntry.first->destroy(); 72 if (this->collisionShape_ == mapEntry.second) 73 this->collisionShape_ = nullptr; // don't destroy it twice 75 74 } 76 75 77 76 delete this->compoundShape_; 78 77 if (this->collisionShape_ == this->compoundShape_) 79 this->collisionShape_ = NULL; // don't destroy it twice78 this->collisionShape_ = nullptr; // don't destroy it twice 80 79 } 81 80 } … … 96 95 void CompoundCollisionShape::attach(CollisionShape* shape) 97 96 { 98 // If either the input shape is NULLor we try to attach the CollisionShape to itself.97 // If either the input shape is nullptr or we try to attach the CollisionShape to itself. 99 98 if (!shape || static_cast<CollisionShape*>(this) == shape) 100 99 return; … … 197 196 void CompoundCollisionShape::updatePublicShape() 198 197 { 199 btCollisionShape* primitive = 0; // The primitive shape, if there is one.198 btCollisionShape* primitive = nullptr; // The primitive shape, if there is one. 200 199 bool bPrimitive = true; // Whether the CompoundCollisionShape has just one non-empty CollisionShape. And that shape also has no transformation. 201 200 bool bEmpty = true; // Whether the CompoundCollisionShape is empty. 202 201 // Iterate over all CollisionShapes that belong to this CompoundCollisionShape. 203 for ( std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it)202 for (const auto& mapEntry : this->attachedShapes_) 204 203 { 205 204 // TODO: Make sure this is correct. 206 if ( it->second)205 if (mapEntry.second) 207 206 { 208 207 bEmpty = false; 209 if (! it->first->hasTransform() && bPrimitive)210 primitive = it->second;208 if (!mapEntry.first->hasTransform() && bPrimitive) 209 primitive = mapEntry.second; 211 210 else 212 211 { … … 221 220 { 222 221 // If there was none all along, nothing needs to be changed. 223 if (this->collisionShape_ == 0)222 if (this->collisionShape_ == nullptr) 224 223 return; 225 this->collisionShape_ = 0;224 this->collisionShape_ = nullptr; 226 225 } 227 226 // If the CompoundCollisionShape is just a primitive. … … 247 246 { 248 247 unsigned int i = 0; 249 for ( std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it)248 for (const auto& mapEntry : this->attachedShapes_) 250 249 { 251 250 if (i == index) 252 return it->first;251 return mapEntry.first; 253 252 ++i; 254 253 } 255 return 0;254 return nullptr; 256 255 } 257 256 … … 267 266 std::vector<CollisionShape*> shapes; 268 267 // Iterate through all attached CollisionShapes and add them to the list of shapes. 269 for( std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++)270 shapes.push_back( it->first);268 for(const auto& mapEntry : this->attachedShapes_) 269 shapes.push_back(mapEntry.first); 271 270 272 271 // Delete the compound shape and create a new one. … … 275 274 276 275 // Re-attach all CollisionShapes. 277 for(std::vector<CollisionShape*>::iterator it = shapes.begin(); it != shapes.end(); it++) 278 { 279 CollisionShape* shape = *it; 276 for(CollisionShape* shape : shapes) 277 { 280 278 shape->setScale3D(this->getScale3D()); 281 279 // Only actually attach if we didn't pick a CompoundCollisionShape with no content.
Note: See TracChangeset
for help on using the changeset viewer.