Changeset 8556
- Timestamp:
- May 23, 2011, 11:40:58 PM (14 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 20 edited
- 2 copied
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/data/levels/includes/pickups.oxi
r7163 r8556 202 202 <PickupRepresentation 203 203 pickupName = "Drone Pickup" 204 pickupDescription = "Adds a Drone to the Player s Spaceship"204 pickupDescription = "Adds a Drone to the Player's Spaceship" 205 205 spawnerTemplate = "dronepickupRepresentation" 206 206 > … … 210 210 </PickupRepresentation> 211 211 212 <!-- Shrink Pickup --> 213 214 <PickupRepresentation 215 pickupName = "Small Shrink" 216 pickupDescription = "Shrinks the Ship by a bit" 217 spawnerTemplate = "smallshrinkpickupRepresentation" 218 > 219 <pickup> 220 <ShrinkPickup template=smallshrinkpickup /> 221 </pickup> 222 </PickupRepresentation> 223 224 <PickupRepresentation 225 pickupName = "Medium Shrink" 226 pickupDescription = "Shrinks the Ship" 227 spawnerTemplate = "mediumshrinkpickupRepresentation" 228 > 229 <pickup> 230 <ShrinkPickup template=mediumshrinkpickup /> 231 </pickup> 232 </PickupRepresentation> 233 234 <PickupRepresentation 235 pickupName = "Huge Shrink" 236 pickupDescription = "Shrinks the Ship considerably" 237 spawnerTemplate = "hugeshrinkpickupRepresentation" 238 > 239 <pickup> 240 <ShrinkPickup template=hugeshrinkpickup /> 241 </pickup> 242 </PickupRepresentation> 243 -
code/branches/presentation/data/levels/pickups.oxw
r7679 r8556 190 190 </PickupSpawner> 191 191 192 <PickupSpawner position="-25,-50,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5"> 193 <pickup> 194 <ShrinkPickup template ="smallshrinkpickup"/> 195 </pickup> 196 </PickupSpawner> 197 198 <PickupSpawner position="0,-50,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5"> 199 <pickup> 200 <ShrinkPickup template ="mediumshrinkpickup"/> 201 </pickup> 202 </PickupSpawner> 203 204 <PickupSpawner position="25,-50,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5"> 205 <pickup> 206 <ShrinkPickup template ="hugeshrinkpickup"/> 207 </pickup> 208 </PickupSpawner> 209 210 <!--StaticEntity position="0,-200,0" direction="0,-1,0" collisionType=static mass=500 friction=0.01 > 211 <attached> 212 <Model position="0,0,0" mesh="cube.mesh" scale3D="10,10,10" /> 213 </attached> 214 <collisionShapes> 215 <BoxCollisionShape position="0,0,0" halfExtents="10,10,10" /> 216 </collisionShapes> 217 </StaticEntity--> 218 192 219 </Scene> 193 220 </Level> -
code/branches/presentation/data/levels/templates/pickupRepresentationTemplates.oxt
r7679 r8556 391 391 <InvisiblePickup 392 392 duration = 20.0 393 activaionType = "immediate" 394 durationType = "continuous" 395 /> 396 </Template> 397 398 <Template name=smallshrinkpickupRepresentation> 399 <PickupRepresentation> 400 <spawner-representation> 401 <StaticEntity> 402 <attached> 403 <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Sphere2" scale=0.1> 404 <attached> 405 <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Shrink" scale=0.4 /> 406 </attached> 407 </Billboard> 408 </attached> 409 </StaticEntity> 410 </spawner-representation> 411 </PickupRepresentation> 412 </Template> 413 414 <Template name=smallshrinkpickup> 415 <InvisiblePickup 416 duration = 10.0 417 shrinkFactor = 2.5 418 activaionType = "immediate" 419 durationType = "continuous" 420 /> 421 </Template> 422 423 <Template name=mediumshrinkpickupRepresentation> 424 <PickupRepresentation> 425 <spawner-representation> 426 <StaticEntity> 427 <attached> 428 <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Sphere2" scale=0.1> 429 <attached> 430 <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Shrink" scale=0.7 /> 431 </attached> 432 </Billboard> 433 </attached> 434 </StaticEntity> 435 </spawner-representation> 436 </PickupRepresentation> 437 </Template> 438 439 <Template name=mediumshrinkpickup> 440 <InvisiblePickup 441 duration = 30.0 442 shrinkFactor = 5.0 443 activaionType = "immediate" 444 durationType = "continuous" 445 /> 446 </Template> 447 448 <Template name=hugeshrinkpickupRepresentation> 449 <PickupRepresentation> 450 <spawner-representation> 451 <StaticEntity> 452 <attached> 453 <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Sphere2" scale=0.1> 454 <attached> 455 <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Shrink" scale=1.0 /> 456 </attached> 457 </Billboard> 458 </attached> 459 </StaticEntity> 460 </spawner-representation> 461 </PickupRepresentation> 462 </Template> 463 464 <Template name=hugeshrinkpickup> 465 <InvisiblePickup 466 duration = 60.0 467 shrinkFactor = 10.0 393 468 activaionType = "immediate" 394 469 durationType = "continuous" -
code/branches/presentation/src/libraries/util/SubString.h
r7401 r8556 169 169 /// Returns the number of tokens stored in this SubString 170 170 inline unsigned int size() const { return this->tokens_.size(); } 171 /// Returns the i'th token from the subset of strings @param index The index of the requested doken171 /// Returns the i'th token from the subset of strings @param index The index of the requested token 172 172 inline const std::string& operator[](unsigned int index) const { return this->tokens_[index]; } 173 173 /// Returns the i'th token from the subset of strings @param index The index of the requested token -
code/branches/presentation/src/modules/objects/collisionshapes/BoxCollisionShape.cc
r6417 r8556 27 27 */ 28 28 29 /** 30 @file BoxCollisionShape.cc 31 @brief Implementation of the BoxCollisionShape class. 32 */ 33 29 34 #include "BoxCollisionShape.h" 30 35 … … 39 44 CreateFactory(BoxCollisionShape); 40 45 46 /** 47 @brief 48 Constructor. Registers and initializes the object. 49 */ 41 50 BoxCollisionShape::BoxCollisionShape(BaseObject* creator) : CollisionShape(creator) 42 51 { … … 44 53 45 54 this->halfExtents_ = Vector3(1, 1, 1); 46 updateShape();55 this->updateShape(); 47 56 48 57 this->registerVariables(); … … 51 60 BoxCollisionShape::~BoxCollisionShape() 52 61 { 62 // TODO: Move to CollisionShape? 53 63 if (this->isInitialized()) 54 64 delete this->collisionShape_; … … 70 80 } 71 81 82 /** 83 @brief 84 Is called when the scale of the BoxCollisionShape has changed. 85 */ 86 void BoxCollisionShape::changedScale() 87 { 88 CollisionShape::changedScale(); 89 90 // Resize the internal collision shape 91 // TODO: Assuming setLocalScaling works. 92 // this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D())); 93 if(!this->hasUniformScaling()) 94 { 95 CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl; 96 return; 97 } 98 99 this->setHalfExtents(this->halfExtents_ * this->getScale()); 100 } 101 102 /** 103 @brief 104 Creates a new internal collision shape for the BoxCollisionShape. 105 @return 106 Returns a pointer to the newly created btBoxShape. 107 */ 72 108 btCollisionShape* BoxCollisionShape::createNewShape() const 73 109 { -
code/branches/presentation/src/modules/objects/collisionshapes/BoxCollisionShape.h
r7601 r8556 43 43 namespace orxonox 44 44 { 45 46 /** 47 @brief 48 Wrapper for the bullet box collision shape class btBoxShape. 49 50 @author 51 Reto Grieder 52 53 @see btBoxShape 54 @ingroup Collisionshapes 55 */ 45 56 class _ObjectsExport BoxCollisionShape : public CollisionShape 46 57 { … … 51 62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 52 63 53 inline void setHalfExtents(const Vector3& extents) 54 { this->halfExtents_ = extents; updateShape(); } 64 /** 65 @brief Set the half extents of the BoxCollisionShape. 66 If the half extent changes, this causes the internal collision shape to be recreated. 67 @param extents A vector with the half extents. 68 The x-component is half the length, the y-component is half the height and the z-component is half the width. 69 @return Returns true if the half extent has changed, false if not. 70 */ 71 inline bool setHalfExtents(const Vector3& extents) 72 { if(this->halfExtents_ == extents) return false; this->halfExtents_ = extents; updateShape(); return true; } 73 /** 74 @brief Get the half extents of the BoxCollisionShape. 75 @return Returns a vector containing the half extents. 76 */ 55 77 inline const Vector3& getHalfExtents() const 56 78 { return halfExtents_;} 57 79 58 inline void setWidth(float value) 59 { this->halfExtents_.z = value / 2; updateShape(); } 80 /** 81 @brief Set the width of the BoxCollisionShape. 82 If the width changes, this causes the internal collision shape to be recreated. 83 @param value The width to be set. 84 @return Returns true if the width has changed, false if not. 85 */ 86 inline bool setWidth(float value) 87 { if(this->halfExtents_.z == value/2.0f) return false; this->halfExtents_.z = value / 2.0f; updateShape(); return true; } 88 /** 89 @brief Get the width of the BoxCollisionShape. 90 @return Returns the width of the BoxCollisionShape. 91 */ 60 92 inline float getWidth() const 61 { return this->halfExtents_.z * 2 ; }93 { return this->halfExtents_.z * 2.0f; } 62 94 63 inline void setHeight(float value) 64 { this->halfExtents_.y = value / 2; updateShape(); } 95 /** 96 @brief Set the height of the BoxCollisionShape. 97 If the height changes, this causes the internal collision shape to be recreated. 98 @param value The height to be set. 99 @return Returns true if the height has changed, false if not. 100 */ 101 inline bool setHeight(float value) 102 { if(this->halfExtents_.y == value/2.0f) return false; this->halfExtents_.y = value / 2.0f; updateShape(); return true; } 103 /** 104 @brief Get the height of the BoxCollisionShape. 105 @return Returns the height of the BoxCollisionShape. 106 */ 65 107 inline float getHeight() const 66 { return this->halfExtents_.y * 2 ; }108 { return this->halfExtents_.y * 2.0f; } 67 109 68 inline void setLength(float value) 69 { this->halfExtents_.x = value / 2; updateShape(); } 110 /** 111 @brief Set the length of the BoxCollisionShape. 112 If the length changes, this causes the internal collision shape to be recreated. 113 @param value The length to be set. 114 @return Returns true if the length has changed, false if not. 115 */ 116 inline bool setLength(float value) 117 { if(this->halfExtents_.x == value/2.0f) return false; this->halfExtents_.x = value / 2.0f; updateShape(); return true; } 118 /** 119 @brief Get the length of the BoxCollisionShape. 120 @return Returns the length of the BoxCollisionShape. 121 */ 70 122 inline float getLength() const 71 { return this->halfExtents_.x * 2; } 123 { return this->halfExtents_.x * 2.0f; } 124 125 virtual void changedScale(); // Is called when the scale of the BoxCollisionShape has changed. 72 126 73 127 private: 74 128 void registerVariables(); 75 129 76 btCollisionShape* createNewShape() const; 130 btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the BoxCollisionShape. 77 131 78 Vector3 halfExtents_; 132 Vector3 halfExtents_; //!< The half extents of the BoxCollisionShape. The x-component is half the length, the y-component is half the height and the z-component is half the width. 79 133 }; 80 134 } -
code/branches/presentation/src/modules/objects/collisionshapes/ConeCollisionShape.cc
r6417 r8556 27 27 */ 28 28 29 /** 30 @file ConeCollisionShape.cc 31 @brief Implementation of the ConeCollisionShape class. 32 */ 33 29 34 #include "ConeCollisionShape.h" 30 35 … … 33 38 #include "core/CoreIncludes.h" 34 39 #include "core/XMLPort.h" 40 #include "tools/BulletConversions.h" 35 41 36 42 namespace orxonox … … 38 44 CreateFactory(ConeCollisionShape); 39 45 46 /** 47 @brief 48 Constructor. Registers and initializes the object. 49 */ 40 50 ConeCollisionShape::ConeCollisionShape(BaseObject* creator) : CollisionShape(creator) 41 51 { … … 69 79 } 70 80 81 /** 82 @brief 83 Is called when the scale of the ConeCollisionShape has changed. 84 */ 85 void ConeCollisionShape::changedScale() 86 { 87 CollisionShape::changedScale(); 88 89 // Resize the internal collision shape 90 // TODO: Assuming setLocalScaling works. 91 //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D())); 92 if(!this->hasUniformScaling()) 93 { 94 CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl; 95 return; 96 } 97 98 this->radius_ *= this->getScale(); 99 this->height_ *= this->getScale(); 100 this->updateShape(); 101 } 102 103 /** 104 @brief 105 Creates a new internal collision shape for the ConeCollisionShape. 106 @return 107 Returns a pointer to the newly created btConeShape. 108 */ 71 109 btCollisionShape* ConeCollisionShape::createNewShape() const 72 110 { -
code/branches/presentation/src/modules/objects/collisionshapes/ConeCollisionShape.h
r7601 r8556 41 41 namespace orxonox 42 42 { 43 44 /** 45 @brief 46 Wrapper for the bullet cone collision shape class btConeShape. 47 48 @author 49 Reto Grieder 50 51 @see btConeShape 52 @ingroup Collisionshapes 53 */ 43 54 class _ObjectsExport ConeCollisionShape : public CollisionShape 44 55 { … … 49 60 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 61 51 inline void setRadius(float value) 52 { this->radius_ = value; updateShape(); } 62 /** 63 @brief Set the radius of the ConeCollisionShape. 64 If the radius changes, this causes the internal collision shape to be recreated. 65 @param value The radius to be set. 66 @return Returns true if the radius has changed, false if not. 67 */ 68 inline bool setRadius(float value) 69 { if(this->radius_ == value) return false; this->radius_ = value; updateShape(); return true; } 70 /** 71 @brief Get the radius of the ConeCollisionShape. 72 @return Returns the radius of the ConeCollisionShape. 73 */ 53 74 inline float getRadius() const 54 75 { return radius_; } 55 76 56 inline void setHeight(float value) 57 { this->height_ = value; updateShape(); } 77 /** 78 @brief Set the height of the ConeCollisionShape. 79 If the height changes, this causes the internal collision shape to be recreated. 80 @param value The height to be set. 81 @return Returns true if the height has changed, false if not. 82 */ 83 inline bool setHeight(float value) 84 { if(this->height_ == value) return false; this->height_ = value; updateShape(); return true; } 85 /** 86 @brief Get the height of the ConeCollisionShape. 87 @return Returns the height of the ConeCollisionShape. 88 */ 58 89 inline float getHeight() const 59 90 { return this->height_; } 91 92 virtual void changedScale(); // Is called when the scale of the ConeCollisionShape has changed. 60 93 61 94 private: 62 95 void registerVariables(); 63 96 64 btCollisionShape* createNewShape() const; 97 btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the ConeCollisionShape. 65 98 66 float radius_; 67 float height_; 99 float radius_; //!< The radius of the ConeCollisionShape. 100 float height_; //!< The height of the ConeCollisionShape. 68 101 }; 69 102 } -
code/branches/presentation/src/modules/objects/collisionshapes/PlaneCollisionShape.cc
r6417 r8556 27 27 */ 28 28 29 /** 30 @file PlaneCollisionShape.cc 31 @brief Implementation of the PlaneCollisionShape class. 32 */ 33 29 34 #include "PlaneCollisionShape.h" 30 35 … … 39 44 CreateFactory(PlaneCollisionShape); 40 45 46 /** 47 @brief 48 Constructor. Registers and initializes the object. 49 */ 41 50 PlaneCollisionShape::PlaneCollisionShape(BaseObject* creator) : CollisionShape(creator) 42 51 { … … 70 79 } 71 80 81 /** 82 @brief 83 Is called when the scale of the PlaneCollisionShape has changed. 84 */ 85 void PlaneCollisionShape::changedScale() 86 { 87 CollisionShape::changedScale(); 88 89 // Resize the internal collision shape 90 // TODO: Assuming setLocalScaling works. 91 //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D())); 92 if(!this->hasUniformScaling()) 93 { 94 CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl; 95 return; 96 } 97 98 this->setOffset(this->offset_*this->getScale()); 99 } 100 101 /** 102 @brief 103 Creates a new internal collision shape for the PlaneCollisionShape. 104 @return 105 Returns a pointer to the newly created btStaticPlaneShape. 106 */ 72 107 btCollisionShape* PlaneCollisionShape::createNewShape() const 73 108 { -
code/branches/presentation/src/modules/objects/collisionshapes/PlaneCollisionShape.h
r7601 r8556 43 43 namespace orxonox 44 44 { 45 46 /** 47 @brief 48 Wrapper for the bullet plane collision shape class btStaticPlaneShape. 49 50 @author 51 Martin Stypinski 52 53 @see btStaticPlaneShape 54 @ingroup Collisionshapes 55 */ 45 56 class _ObjectsExport PlaneCollisionShape : public CollisionShape 46 57 { … … 51 62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 52 63 53 inline void setNormal(const Vector3& normal) 54 { this->normal_ = normal; updateShape(); } 55 inline const Vector3& getNormal() 64 /** 65 @brief Set the normal of the PlaneCollisionShape. 66 If the normal changes, this causes the internal collision shape to be recreated. 67 @param normal The normal vector to be set. 68 @return Returns true if the normal has changed, false if not. 69 */ 70 inline bool setNormal(const Vector3& normal) 71 { if(this->normal_ == normal) return false; this->normal_ = normal; updateShape(); return true; } 72 /** 73 @brief Get the normal of the PlaneCollisionShape. 74 @return Returns the normal vector of the PlaneCollisionShape. 75 */ 76 inline const Vector3& getNormal() const 56 77 { return normal_;} 57 78 58 inline void setOffset(float offset) 59 { this->offset_ = offset; updateShape(); } 60 inline float getOffset() 79 /** 80 @brief Set the offset of the PlaneCollisionShape. 81 If the offset changes, this causes the internal collision shape to be recreated. 82 @param offset The offset to be set. 83 @return Returns true if the offset has changed, false if not. 84 */ 85 inline bool setOffset(float offset) 86 { if(this->offset_ == offset) return false; this->offset_ = offset; updateShape(); return true; } 87 /** 88 @brief Get the offset of the PlaneCollisionShape. 89 @return Returns the offset of the PlaneCollisionShape. 90 */ 91 inline float getOffset() const 61 92 { return this->offset_;} 93 94 virtual void changedScale(); // Is called when the scale of the PlaneCollisionShape has changed. 62 95 63 96 private: 64 97 void registerVariables(); 65 98 66 btCollisionShape* createNewShape() const;99 btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the PlaneCollisionShape. 67 100 68 Vector3 normal_; 69 float offset_; 101 Vector3 normal_; //!< The normal vector of the PlaneCollisionShape. 102 float offset_; //!< The offset of the PlaneCollisionShape. 70 103 }; 71 104 } -
code/branches/presentation/src/modules/objects/collisionshapes/SphereCollisionShape.cc
r5781 r8556 27 27 */ 28 28 29 /** 30 @file SphereCollisionShape.cc 31 @brief Implementation of the SphereCollisionShape class. 32 */ 33 29 34 #include "SphereCollisionShape.h" 30 35 … … 33 38 #include "core/CoreIncludes.h" 34 39 #include "core/XMLPort.h" 40 #include "tools/BulletConversions.h" 35 41 36 42 namespace orxonox … … 38 44 CreateFactory(SphereCollisionShape); 39 45 46 /** 47 @brief 48 Constructor. registers and initializes the object. 49 */ 40 50 SphereCollisionShape::SphereCollisionShape(BaseObject* creator) : CollisionShape(creator) 41 51 { … … 66 76 } 67 77 78 /** 79 @brief 80 Is called when the scale of the SphereCollisionShape has changed. 81 */ 82 void SphereCollisionShape::changedScale() 83 { 84 CollisionShape::changedScale(); 85 86 // Resize the internal collision shape 87 // TODO: Assuming setLocalScaling works. 88 //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D())); 89 if(!this->hasUniformScaling()) 90 { 91 CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl; 92 return; 93 } 94 95 this->setRadius(this->radius_*this->getScale()); 96 } 97 98 /** 99 @brief 100 Creates a new internal collision shape for the SphereCollisionShape. 101 @return 102 Returns a pointer to the newly created btSphereShape. 103 */ 68 104 btCollisionShape* SphereCollisionShape::createNewShape() const 69 105 { -
code/branches/presentation/src/modules/objects/collisionshapes/SphereCollisionShape.h
r7601 r8556 41 41 namespace orxonox 42 42 { 43 44 /** 45 @brief 46 Wrapper for the bullet sphere collision shape class btSphereShape. 47 48 @author 49 Reto Grieder 50 51 @see btSphereShape 52 @ingroup Collisionshapes 53 */ 43 54 class _ObjectsExport SphereCollisionShape : public CollisionShape 44 55 { … … 49 60 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 61 51 inline void setRadius(float radius) 52 { this->radius_ = radius; updateShape(); } 62 /** 63 @brief Set the radius of the SphereCollisionShape. 64 If the radius changes, this causes the internal collision shape to be recreated. 65 @param radius The radius to be set. 66 @return Returns true if the radius has changed, false if not. 67 */ 68 inline bool setRadius(float radius) 69 { if(this->radius_ == radius) return false; this->radius_ = radius; updateShape(); return true; } 70 /** 71 @brief Get the radius of the SphereCollisionShape. 72 @return Returns the radius of the SphereCollisionShape. 73 */ 53 74 inline float getRadius() const 54 75 { return this->radius_; } 76 77 virtual void changedScale(); // Is called when the scale of the SphereCollisionShape has changed. 55 78 56 79 private: … … 59 82 btCollisionShape* createNewShape() const; 60 83 61 float radius_; 84 float radius_; //!< The radius of the SphereCollisionShape. 62 85 }; 63 86 } -
code/branches/presentation/src/modules/pickup/PickupPrereqs.h
r8351 r8556 85 85 class SpeedPickup; 86 86 class ShieldPickup; 87 class ShrinkPickup; 87 88 88 89 } -
code/branches/presentation/src/modules/pickup/items/CMakeLists.txt
r7163 r8556 6 6 SpeedPickup.cc 7 7 ShieldPickup.cc 8 ShrinkPickup.cc 8 9 ) -
code/branches/presentation/src/modules/pickup/items/ShrinkPickup.cc
r8554 r8556 60 60 61 61 this->initialize(); 62 this->shrinkFactor_ = 5.0; 63 this->shrinkSpeed_ = 5.0; 64 this->duration_ = 5.0; 65 isActive_ = false; 66 isTerminating_ = false; 62 this->shrinkFactor_ = 5.0f; 63 this->shrinkSpeed_ = 5.0f; 64 this->duration_ = 5.0f; 65 this->isActive_ = false; 66 this->isTerminating_ = false; 67 68 this->size_ = 0; 69 this->defaultCameraPos_ = 0.0f; 70 this->defaultScale_ = Vector3::UNIT_SCALE; 71 this->actualScale_ = Vector3::UNIT_SCALE; 72 this->smallScale_ = Vector3::UNIT_SCALE; 73 this->defaultMass_ = 1.0f; 74 this->actualMass_ = 1.0f; 75 this->smallMass_ = 1.0f; 76 this->pawn_ = NULL; 67 77 } 68 78 … … 157 167 { 158 168 this->pawn_ = this->carrierToPawnHelper(); 159 if( pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.169 if(this->pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 160 170 this->Pickupable::destroy(); 161 171 162 172 //Collect scaling information. 163 defaultScale_ = this->pawn_->getScale3D();164 defaultMass_ = this->pawn_->getMass();165 166 smallScale_ = defaultScale_ /shrinkFactor_;167 smallMass_ = defaultMass_ /shrinkFactor_;168 169 actualScale_ =defaultScale_;170 actualMass_ =defaultMass_;171 172 cameraPositions_ = this->pawn_->getCameraPositions();173 size_ =cameraPositions_.size();174 isActive_ = true; //start shrinking now.175 durationTimer_.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); //Set timer for termination.173 this->defaultScale_ = this->pawn_->getScale3D(); 174 this->defaultMass_ = this->pawn_->getMass(); 175 176 this->smallScale_ = this->defaultScale_ / this->shrinkFactor_; 177 this->smallMass_ = this->defaultMass_ / this->shrinkFactor_; 178 179 this->actualScale_ = this->defaultScale_; 180 this->actualMass_ = this->defaultMass_; 181 182 this->cameraPositions_ = this->pawn_->getCameraPositions(); 183 this->size_ = this->cameraPositions_.size(); 184 this->isActive_ = true; //start shrinking now. 185 this->durationTimer_.setTimer(this->duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); //Set timer for termination. 176 186 } 177 187 } … … 185 195 void ShrinkPickup::tick(float dt) 186 196 { 187 if( isActive_ == true && actualScale_ >smallScale_) //if the ship has not reached the target scale, continue shrinking197 if(this->isActive_ == true && this->actualScale_ > this->smallScale_) //if the ship has not reached the target scale, continue shrinking 188 198 { 189 float factor _ = 1 + dt*shrinkSpeed_;190 191 actualScale_ /= factor_;192 actualMass_ /= factor_;193 194 this->pawn_->setScale3D( actualScale_);195 this->pawn_->setMass( actualMass_);196 197 for(int index = 0; index < size_; index++)199 float factor = 1 + dt*this->shrinkSpeed_; 200 201 this->actualScale_ /= factor; 202 this->actualMass_ /= factor; 203 204 this->pawn_->setScale3D(this->actualScale_); 205 this->pawn_->setMass(this->actualMass_); 206 207 for(int index = 0; index < this->size_; index++) 198 208 { 199 CameraPosition* cameraPos _= this->pawn_->getCameraPosition(index);200 if(cameraPos _== NULL)209 CameraPosition* cameraPos = this->pawn_->getCameraPosition(index); 210 if(cameraPos == NULL) 201 211 continue; 202 cameraPos _->setPosition(cameraPos_->getPosition()*factor_);212 cameraPos->setPosition(cameraPos->getPosition()*factor); 203 213 } 204 214 } 205 else isActive_ = false;206 207 if( isTerminating_ == true && actualScale_ <defaultScale_) //grow until the ship reaches its default scale.215 else this->isActive_ = false; 216 217 if(this->isTerminating_ == true && this->actualScale_ < this->defaultScale_) //grow until the ship reaches its default scale. 208 218 { 209 float factor _ = 1 + dt*shrinkSpeed_;210 211 actualScale_ *= factor_;212 actualMass_ *= factor_;213 214 this->pawn_->setScale3D( actualScale_);215 this->pawn_->setMass( actualMass_);216 217 for(int index = 0; index < size_; index++)219 float factor = 1 + dt*this->shrinkSpeed_; 220 221 this->actualScale_ *= factor; 222 this->actualMass_ *= factor; 223 224 this->pawn_->setScale3D(this->actualScale_); 225 this->pawn_->setMass(this->actualMass_); 226 227 for(int index = 0; index < this->size_; index++) 218 228 { 219 CameraPosition* cameraPos _= this->pawn_->getCameraPosition(index);220 if(cameraPos _== NULL)229 CameraPosition* cameraPos = this->pawn_->getCameraPosition(index); 230 if(cameraPos == NULL) 221 231 continue; 222 cameraPos _->setPosition(cameraPos_->getPosition()/factor_);232 cameraPos->setPosition(cameraPos->getPosition()/factor); 223 233 } 224 234 } 225 else if( isTerminating_ == true)235 else if(this->isTerminating_ == true) 226 236 this->Pickupable::destroy(); 227 237 … … 234 244 void ShrinkPickup::terminate(void) 235 245 { 236 isActive_ = false;237 isTerminating_ = true;246 this->isActive_ = false; 247 this->isTerminating_ = true; 238 248 setUsed(false); 239 249 } -
code/branches/presentation/src/orxonox/collisionshapes/CollisionShape.cc
r7401 r8556 26 26 * 27 27 */ 28 29 /** 30 @file CollisionShape.cc 31 @brief Implementation of the CollisionShape class. 32 */ 28 33 29 34 #include "CollisionShape.h" … … 39 44 namespace orxonox 40 45 { 46 47 /** 48 @brief 49 Constructor. Registers and initializes the object. 50 */ 41 51 CollisionShape::CollisionShape(BaseObject* creator) 42 52 : BaseObject(creator) … … 51 61 this->orientation_ = Quaternion::IDENTITY; 52 62 this->scale_ = Vector3::UNIT_SCALE; 63 this->uniformScale_ = true; 53 64 54 65 this->registerVariables(); 55 66 } 56 67 68 /** 69 @brief 70 Destructor. Detaches the CollisionShape from its parent. 71 */ 57 72 CollisionShape::~CollisionShape() 58 73 { 59 // Detach from parent 74 // Detach from parent CompoundCollisionShape. 60 75 if (this->isInitialized() && this->parent_) 61 76 this->parent_->detach(this); … … 75 90 } 76 91 92 /** 93 @brief 94 Register variables that need synchronizing over the network. 95 */ 77 96 void CollisionShape::registerVariables() 78 97 { 98 // Keep the shape's parent (can be either a CompoundCollisionShape or a WorldEntity) consistent over the network. 79 99 registerVariable(this->parentID_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged)); 80 100 } 81 101 102 /** 103 @brief 104 Notifies the CollisionShape of being attached to a CompoundCollisionShape. 105 @param newParent 106 A pointer to the CompoundCollisionShape the CollisionShape was attached to. 107 @return 108 Returns 109 */ 110 bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent) 111 { 112 // If the CollisionShape is attached to a CompoundCollisionShapes, detach it. 113 if (this->parent_) 114 this->parent_->detach(this); 115 116 this->parent_ = newParent; 117 118 // If the new parent is a WorldEntityCollisionShape, the parentID is set to the objectID of the WorldEntity that is its owner. 119 // TODO: Why? 120 WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent); 121 if (parentWECCS) 122 this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID(); 123 // Else it is set to the objectID of the CompoundCollisionShape. 124 else 125 this->parentID_ = newParent->getObjectID(); 126 127 return true; 128 } 129 130 /** 131 @brief 132 Notifies the CollisionShape of being detached from a CompoundCollisionShape. 133 */ 134 void CollisionShape::notifyDetached() 135 { 136 this->parent_ = 0; 137 this->parentID_ = OBJECTID_UNKNOWN; 138 } 139 140 /** 141 @brief 142 Updates the CompoundCollisionShape the CollisionShape belongs to (if it belongs to one), after the CollisionShape has changed. 143 */ 144 void CollisionShape::updateParent() 145 { 146 if (this->parent_) 147 this->parent_->updateAttachedShape(this); 148 } 149 150 /** 151 @brief 152 Is called when the parentID of the CollisionShape has changed. 153 Attaches it to the object with the changed parentID, which can either be a CompoundCollisionShape or a WorldEntity. 154 */ 82 155 void CollisionShape::parentChanged() 83 156 { 157 // Get the parent object from the network. 84 158 Synchronisable* parent = Synchronisable::getSynchronisable(this->parentID_); 159 85 160 // Parent can either be a WorldEntity or a CompoundCollisionShape. The reason is that the 86 161 // internal collision shape (which is compound) of a WE doesn't get synchronised. 87 162 CompoundCollisionShape* parentCCS = orxonox_cast<CompoundCollisionShape*>(parent); 163 164 // If the parent is a CompoundCollisionShape, attach the CollisionShape to it. 88 165 if (parentCCS) 89 166 parentCCS->attach(this); 90 167 else 91 168 { 169 // If the parent is a WorldEntity, attach the CollisionShape to its collision shapes. 92 170 WorldEntity* parentWE = orxonox_cast<WorldEntity*>(parent); 93 171 if (parentWE) … … 96 174 } 97 175 98 bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent) 99 { 100 if (this->parent_) 101 this->parent_->detach(this); 102 103 this->parent_ = newParent; 104 105 WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent); 106 if (parentWECCS) 107 this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID(); 108 else 109 this->parentID_ = newParent->getObjectID(); 110 111 return true; 112 } 113 114 void CollisionShape::notifyDetached() 115 { 116 this->parent_ = 0; 117 this->parentID_ = OBJECTID_UNKNOWN; 118 } 119 120 void CollisionShape::updateParent() 121 { 122 if (this->parent_) 123 this->parent_->updateAttachedShape(this); 124 } 125 176 /** 177 @brief 178 Check whether the CollisionShape has been either moved or rotated or both. (i.e. it doesn't have position zero and identity orientation any more) 179 @return 180 Returns true if it has been moved. 181 */ 126 182 bool CollisionShape::hasTransform() const 127 183 { … … 130 186 } 131 187 188 /** 189 @brief 190 Set the scale of the CollisionShape. 191 Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions. 192 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 193 Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes. 194 @param scale 195 The new scale to be set. Vector3::UNIT_SCALE is the initial scale. 196 */ 132 197 void CollisionShape::setScale3D(const Vector3& scale) 133 198 { 134 CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl; 135 } 136 199 if(this->scale_ == scale) 200 return; 201 202 // If the vectors are not in the same direction, then this is no longer a uniform scaling. 203 if(scale_.crossProduct(scale).squaredLength() != 0.0f) 204 { 205 CCOUT(2) << "Warning: Non-uniform scaling is not yet supported." << endl; 206 return; 207 } 208 209 this->scale_ = scale; 210 211 this->changedScale(); 212 this->updateParent(); 213 } 214 215 /** 216 @brief 217 Set the (uniform) scale of the CollisionShape. 218 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 219 @param scale 220 The scale to scale the CollisionShape with. 1.0f is the initial scale. 221 */ 137 222 void CollisionShape::setScale(float scale) 138 223 { 139 CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl; 140 } 141 224 if(this->scale_.length() == scale) 225 return; 226 227 this->scale_ = Vector3::UNIT_SCALE*scale; 228 229 this->changedScale(); 230 this->updateParent(); 231 } 232 233 /** 234 @brief 235 Is called when the scale of the CollisionShape has changed. 236 */ 237 void CollisionShape::changedScale() 238 { 239 // Adjust the position of the CollisionShape. 240 this->position_ *= this->getScale3D(); 241 } 242 243 /** 244 @brief 245 Updates the shape. 246 Is called when the internal parameters of the shape have changed such that a new shape needs to be created. 247 */ 142 248 void CollisionShape::updateShape() 143 249 { 144 250 btCollisionShape* oldShape = this->collisionShape_; 145 251 this->collisionShape_ = this->createNewShape(); 252 // If the CollisionShape has been rescaled, scale the shape to fit the current scale. 253 if(this->scale_ != Vector3::UNIT_SCALE) 254 this->changedScale(); 146 255 // When we recreate the shape, we have to inform the parent about this to update the shape 147 256 this->updateParent(); … … 150 259 } 151 260 261 /** 262 @brief 263 Calculates the local inertia of the collision shape. 264 @todo 265 Document. 266 */ 152 267 void CollisionShape::calculateLocalInertia(float mass, btVector3& inertia) const 153 268 { -
code/branches/presentation/src/orxonox/collisionshapes/CollisionShape.h
r7163 r8556 27 27 */ 28 28 29 /** 30 @file CollisionShape.h 31 @brief Definition of the CollisionShape class. 32 @ingroup Collisionshapes 33 */ 34 29 35 #ifndef _CollisionShape_H__ 30 36 #define _CollisionShape_H__ … … 38 44 namespace orxonox 39 45 { 46 47 /** 48 @brief 49 Wrapper for bullet collision shape class btCollisionShape. 50 51 @author 52 Reto Grieder 53 54 @see btCollisionShape 55 @ingroup Collisionshapes 56 */ 40 57 class _OrxonoxExport CollisionShape : public BaseObject, public Synchronisable 41 58 { … … 46 63 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 64 65 /** 66 @brief Set the position of the CollisionShape. 67 If the position changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 68 @param position A vector indicating the new position. 69 */ 48 70 inline void setPosition(const Vector3& position) 49 { this->position_ = position; this->updateParent(); } 71 { if(this->position_ == position) return; this->position_ = position; this->updateParent(); } 72 /** 73 @brief Get the position of the CollisionShape. 74 @return Returns the position of the CollisionShape as a vector. 75 */ 50 76 inline const Vector3& getPosition() const 51 77 { return this->position_; } 52 78 79 /** 80 @brief Set the orientation of the CollisionShape. 81 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 82 @param orientation A quaternion indicating the new orientation. 83 */ 53 84 inline void setOrientation(const Quaternion& orientation) 54 { this->orientation_ = orientation; this->updateParent(); } 85 { if(this->orientation_ == orientation) return; this->orientation_ = orientation; this->updateParent(); } 86 /** 87 @brief Get the orientation of the CollisionShape. 88 @return Returns the orientation of the CollisionShape as a quaternion. 89 */ 55 90 inline const Quaternion& getOrientation() const 56 91 { return this->orientation_; } 57 92 58 void yaw(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); } 59 void pitch(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); } 60 void roll(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); } 93 /** 94 @brief Rotate the CollisionShape around the y-axis by the specified angle. 95 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 96 @param angle The angle by which the CollisionShape is rotated. 97 */ 98 void yaw(const Degree& angle) 99 { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); } 100 /** 101 @brief Rotate the CollisionShape around the x-axis by the specified angle. 102 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 103 @param angle The angle by which the CollisionShape is rotated. 104 */ 105 void pitch(const Degree& angle) 106 { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); } 107 /** 108 @brief Rotate the CollisionShape around the z-axis by the specified angle. 109 If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 110 @param angle The angle by which the CollisionShape is rotated. 111 */ 112 void roll(const Degree& angle) 113 { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); } 61 114 62 virtual void setScale3D(const Vector3& scale); 63 virtual void setScale(float scale); 115 /** 116 @brief Scale the CollisionShape by the input vector. 117 Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions. 118 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 119 Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes. 120 @param scale The scaling vector by which the CollisionShape is scaled. 121 */ 122 inline void scale3D(const Vector3& scale) 123 { this->setScale3D(this->getScale3D()*scale); } 124 void setScale3D(const Vector3& scale); // Set the scale of the CollisionShape. 125 /** 126 @brief Get the scale of the CollisionShape. 127 @return Returns a vector indicating the scale of the CollisionShape. 128 */ 64 129 inline const Vector3& getScale3D() const 65 130 { return this->scale_; } 66 131 67 void updateShape(); 132 /** 133 @brief (Uniformly) scale the CollisionShape by the input scale. 134 If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated. 135 @param scale The value by which the CollisionShape is scaled. 136 */ 137 inline void scale(float scale) 138 { this->setScale3D(this->getScale3D()*scale); } 139 void setScale(float scale); // Set the (uniform) scale of the CollisionShape. 140 /** 141 @brief Get the (uniform) scale of the CollisionShape. 142 This is only meaningful if the CollisionShape has uniform scaling. 143 @return Returns the (uniform) scale of the CollisionShape. Returns 0.0f if the scaling is non-uniform. 144 */ 145 inline float getScale() 146 { if(this->hasUniformScaling()) return this->scale_.x; return 0.0f; } 68 147 69 void calculateLocalInertia(float mass, btVector3& inertia) const; 148 /** 149 @brief Check whether the CollisionShape is uniformly scaled. 150 @return Returns true if the CollisionShape is uniformly scaled, false if not. 151 */ 152 inline bool hasUniformScaling() 153 { return this->uniformScale_; } 154 virtual void changedScale(); // Is called when the scale of the CollisionShape has changed. 70 155 156 void updateShape(); // Updates the shape. 157 158 void calculateLocalInertia(float mass, btVector3& inertia) const; // Calculates the local inertia of the collision shape. 159 160 /** 161 @brief Get the bullet collision shape of this CollisionShape. 162 @return Returns a pointer to the bullet collision shape of this CollisionShape. 163 */ 71 164 inline btCollisionShape* getCollisionShape() const 72 165 { return this->collisionShape_; } 73 166 74 bool hasTransform() const; 167 bool hasTransform() const; // Check whether the CollisionShape has been either moved or rotated or both. 75 168 76 bool notifyBeingAttached(CompoundCollisionShape* newParent); 77 void notifyDetached(); 169 bool notifyBeingAttached(CompoundCollisionShape* newParent); // Notifies the CollisionShape of being attached to a CompoundCollisionShape. 170 void notifyDetached(); // Notifies the CollisionShape of being detached from a CompoundCollisionShape. 78 171 79 172 protected: 80 virtual void updateParent(); 81 virtual void parentChanged(); 173 virtual void updateParent(); // Updates the CompoundCollisionShape the CollisionShape belongs to, after the CollisionShape has changed. 174 virtual void parentChanged(); // Is called when the parentID of the CollisionShape has changed. 175 176 /** 177 @brief Create a new bullet collision shape depending on the internal parameters of the specific CollisionShape. 178 @return Returns a pointer to the new bullet collision shape. 179 */ 82 180 virtual btCollisionShape* createNewShape() const = 0; 83 181 84 btCollisionShape* collisionShape_; 85 CompoundCollisionShape* parent_; 86 unsigned int parentID_; 182 btCollisionShape* collisionShape_; //!< The bullet collision shape of this CollisionShape. 183 CompoundCollisionShape* parent_; //!< The CompoundCollisionShape this CollisionShape belongs to, NULL if it doesn't belong to one. 184 unsigned int parentID_; //!< The objectID of the parent of this CollisionShape, which can either be a CompoundCollisionShape or a WorldEntity. 87 185 88 186 private: 89 187 void registerVariables(); 90 188 91 Vector3 position_; 92 Quaternion orientation_; 93 Vector3 scale_; 189 Vector3 position_; //!< The position of the CollisionShape. 190 Quaternion orientation_; //!< The orientation of the CollisionShape. 191 Vector3 scale_; //!< The scale of the CollisionShape. 192 bool uniformScale_; //!< Whether the scale is uniform. 94 193 }; 95 194 } -
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 } -
code/branches/presentation/src/orxonox/collisionshapes/CompoundCollisionShape.h
r5781 r8556 27 27 */ 28 28 29 /** 30 @file CompoundCollisionShape.h 31 @brief Definition of the CompoundCollisionShape class. 32 @ingroup Collisionshapes 33 */ 34 29 35 #ifndef _CompoundCollisionShape_H__ 30 36 #define _CompoundCollisionShape_H__ … … 38 44 namespace orxonox 39 45 { 46 47 /** 48 @brief 49 Wrapper for the bullet compound collision shape class btCompoundShape. 50 51 @author 52 Reto Grieder 53 54 @see btCompoundShape 55 @ingroup Collisionshapes 56 */ 40 57 class _OrxonoxExport CompoundCollisionShape : public CollisionShape 41 58 { … … 53 70 void updateAttachedShape(CollisionShape* shape); 54 71 72 virtual void changedScale(); 73 55 74 private: 56 75 void updatePublicShape(); -
code/branches/presentation/src/orxonox/worldentities/WorldEntity.cc
r7937 r8556 642 642 void WorldEntity::setScale3D(const Vector3& scale) 643 643 { 644 /* 645 HACK HACK HACK 646 if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE) 647 { 648 CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl; 649 return; 650 } 651 HACK HACK HACK 652 */ 644 // If physics is enabled scale the attached CollisionShape. 645 /*if (this->hasPhysics() && this->collisionShape_ != NULL) 646 { 647 this->collisionShape_->setScale3D(scale); 648 }*/ 649 653 650 this->node_->setScale(scale); 654 651
Note: See TracChangeset
for help on using the changeset viewer.