- Timestamp:
- May 23, 2011, 11:40:58 PM (13 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
- Property svn:mergeinfo changed
/code/branches/pickup (added) merged: 8255,8375,8381,8422,8433,8486,8489,8502,8534-8536,8543,8554-8555
- Property svn:mergeinfo changed
-
code/branches/presentation/src/orxonox/collisionshapes/CompoundCollisionShape.cc
r5929 r8556 27 27 */ 28 28 29 /** 30 @file CompoundCollisionShape.cc 31 @brief Implementation of the CompoundCollisionShape class. 32 */ 33 29 34 #include "CompoundCollisionShape.h" 30 35 … … 39 44 CreateFactory(CompoundCollisionShape); 40 45 46 /** 47 @brief 48 Constructor. Registers and initializes the object. 49 */ 41 50 CompoundCollisionShape::CompoundCollisionShape(BaseObject* creator) : CollisionShape(creator) 42 51 { … … 46 55 } 47 56 57 /** 58 @brief 59 Destructor. 60 Deletes all its children. 61 */ 48 62 CompoundCollisionShape::~CompoundCollisionShape() 49 63 { … … 70 84 } 71 85 86 /** 87 @brief 88 Attach the input CollisionShape to the CompoundCollisionShape. 89 @param shape 90 A pointer to the CollisionShape that is to be attached. 91 */ 72 92 void CompoundCollisionShape::attach(CollisionShape* shape) 73 93 { 94 // If either the input shape is NULL or we try to attach the CollisionShape to itself. 74 95 if (!shape || static_cast<CollisionShape*>(this) == shape) 75 96 return; 97 76 98 if (this->attachedShapes_.find(shape) != this->attachedShapes_.end()) 77 99 { … … 80 102 } 81 103 104 // Notify the CollisionShape that it is being attached to the CompoundCollisionShape. 82 105 if (!shape->notifyBeingAttached(this)) 83 106 return; 84 107 108 // Attach it. 85 109 this->attachedShapes_[shape] = shape->getCollisionShape(); 86 110 111 // Only actually attach if we didn't pick a CompoundCollisionShape with no content. 87 112 if (shape->getCollisionShape()) 88 113 { 89 // Only actually attach if we didn't pick a CompoundCollisionShape with no content90 114 btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition())); 115 // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape. 91 116 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); 92 117 … … 95 120 } 96 121 122 /** 123 @brief 124 Detach the input CollisionShape form the CompoundCollisionShape. 125 @param shape 126 A pointer to the CollisionShape to be detached. 127 */ 97 128 void CompoundCollisionShape::detach(CollisionShape* shape) 98 129 { 130 // If the input CollisionShape is actually attached. 99 131 if (this->attachedShapes_.find(shape) != this->attachedShapes_.end()) 100 132 { 101 133 this->attachedShapes_.erase(shape); 102 134 if (shape->getCollisionShape()) 103 this->compoundShape_->removeChildShape(shape->getCollisionShape()); 135 this->compoundShape_->removeChildShape(shape->getCollisionShape()); // TODO: Apparently this is broken? 104 136 shape->notifyDetached(); 105 137 … … 110 142 } 111 143 144 /** 145 @brief 146 Detach all attached CollisionShapes. 147 */ 112 148 void CompoundCollisionShape::detachAll() 113 149 { … … 116 152 } 117 153 154 /** 155 @brief 156 Update the input CollisionShape that is attached to the CompoundCollisionShape. 157 This is called when the input shape's internal collision shape (a btCollisionShape) has changed. 158 @param shape 159 A pointer to the CollisionShape to be updated. 160 */ 118 161 void CompoundCollisionShape::updateAttachedShape(CollisionShape* shape) 119 162 { 120 163 if (!shape) 121 164 return; 165 122 166 std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.find(shape); 167 // Check whether the input shape belongs to this CompoundCollisionShape. 123 168 if (it == this->attachedShapes_.end()) 124 169 { … … 129 174 // Remove old btCollisionShape, stored in the children map 130 175 if (it->second) 131 this->compoundShape_->removeChildShape(it->second); 176 this->compoundShape_->removeChildShape(it->second); // TODO: Apparently this is broken? 177 178 // Only actually attach if we didn't pick a CompoundCollisionShape with no content 132 179 if (shape->getCollisionShape()) 133 180 { 134 // Only actually attach if we didn't pick a CompoundCollisionShape with no content135 181 btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition())); 136 182 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); … … 141 187 } 142 188 189 /** 190 @brief 191 Updates the public shape, the collision shape this CompoundCollisionShape has to the outside. 192 */ 143 193 void CompoundCollisionShape::updatePublicShape() 144 194 { 145 btCollisionShape* primitive = 0; 146 bool bPrimitive = true; 147 bool bEmpty = true; 195 btCollisionShape* primitive = 0; // The primitive shape, if there is one. 196 bool bPrimitive = true; // Whether the CompoundCollisionShape has just one non-empty CollisionShape. And that shape also has no transformation. 197 bool bEmpty = true; // Whether the CompoundCollisionShape is empty. 198 // Iterate over all CollisionShapes that belong to this CompoundCollisionShape. 148 199 for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it) 149 200 { 201 // TODO: Make sure this is correct. 150 202 if (it->second) 151 203 { 152 204 bEmpty = false; 153 if (!it->first->hasTransform() && !bPrimitive)205 if (!it->first->hasTransform() && bPrimitive) 154 206 primitive = it->second; 155 207 else 208 { 156 209 bPrimitive = false; 210 break; 211 } 157 212 } 158 213 } 214 215 // If there is no non-empty CollisionShape. 159 216 if (bEmpty) 160 217 { 218 // If there was none all along, nothing needs to be changed. 161 219 if (this->collisionShape_ == 0) 162 {163 this->collisionShape_ = 0;164 220 return; 165 }166 221 this->collisionShape_ = 0; 167 222 } 223 // If the CompoundCollisionShape is just a primitive. 224 // Only one shape to be added, no transform; return it directly. 168 225 else if (bPrimitive) 169 {170 // --> Only one shape to be added, no transform; return it directly171 226 this->collisionShape_ = primitive; 172 }227 // Make sure we use the compound shape when returning a btCollisionShape. 173 228 else 174 {175 // Make sure we use the compound shape when returning a btCollisionShape176 229 this->collisionShape_ = this->compoundShape_; 177 } 230 178 231 this->updateParent(); 179 232 } 180 233 234 /** 235 @brief 236 Get the attached CollisionShape at the given index. 237 @param index 238 The index of the desired CollisionShape. 239 @return 240 Returns a pointer to the attached CollisionShape at the given index. 241 */ 181 242 CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const 182 243 { … … 190 251 return 0; 191 252 } 253 254 /** 255 @brief 256 Is called when the scale of the CompoundCollisionShape has changed. 257 Iterates over all attached CollisionShapes and scales them, then recomputes their compound shape. 258 */ 259 void CompoundCollisionShape::changedScale() 260 { 261 CollisionShape::changedScale(); 262 263 std::vector<CollisionShape*> shapes; 264 // Iterate through all attached CollisionShapes and add them to the list of shapes. 265 for(std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++) 266 shapes.push_back(it->first); 267 268 // Delete the compound shape and create a new one. 269 delete this->compoundShape_; 270 this->compoundShape_ = new btCompoundShape(); 271 272 // Re-attach all CollisionShapes. 273 for(std::vector<CollisionShape*>::iterator it = shapes.begin(); it != shapes.end(); it++) 274 { 275 CollisionShape* shape = *it; 276 shape->setScale3D(this->getScale3D()); 277 // Only actually attach if we didn't pick a CompoundCollisionShape with no content. 278 if (shape->getCollisionShape()) 279 { 280 btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition())); 281 // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape. 282 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); 283 } 284 } 285 286 this->updatePublicShape(); 287 288 /* 289 // Iterate through all attached CollisionShapes 290 for(std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++) 291 { 292 // Rescale the CollisionShape. 293 it->first->setScale3D(this->getScale3D()); 294 this->updateAttachedShape(it->first); 295 } 296 297 this->updatePublicShape();*/ 298 } 192 299 }
Note: See TracChangeset
for help on using the changeset viewer.