Changeset 8422 for code/branches
- Timestamp:
- May 8, 2011, 11:45:32 PM (14 years ago)
- Location:
- code/branches/pickup/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup/src/modules/objects/collisionshapes/BoxCollisionShape.cc
r6417 r8422 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/pickup/src/modules/objects/collisionshapes/BoxCollisionShape.h
r7601 r8422 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 @ingroup Collisionshapes 54 */ 45 55 class _ObjectsExport BoxCollisionShape : public CollisionShape 46 56 { … … 51 61 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 52 62 53 inline void setHalfExtents(const Vector3& extents) 54 { this->halfExtents_ = extents; updateShape(); } 63 /** 64 @brief Set the half extents of the BoxCollisionShape. 65 If the half extent changes, this causes the internal collision shape to be recreated. 66 @param extents A vector with the half extents. 67 The x-component is half the length, the y-component is half the height and the z-component is half the width. 68 @return Returns true if the half extent has changed, false if not. 69 */ 70 inline bool setHalfExtents(const Vector3& extents) 71 { if(this->halfExtents_ == extents) return false; this->halfExtents_ = extents; updateShape(); return true; } 72 /** 73 @brief Get the half extents of the BoxCollisionShape. 74 @return Returns a vector containing the half extents. 75 */ 55 76 inline const Vector3& getHalfExtents() const 56 77 { return halfExtents_;} 57 78 58 inline void setWidth(float value) 59 { this->halfExtents_.z = value / 2; updateShape(); } 79 /** 80 @brief Set the width of the BoxCollisionShape. 81 If the width changes, this causes the internal collision shape to be recreated. 82 @param value The width to be set. 83 @return Returns true if the width has changed, false if not. 84 */ 85 inline bool setWidth(float value) 86 { if(this->halfExtents_.z == value/2.0f) return false; this->halfExtents_.z = value / 2.0f; updateShape(); return true; } 87 /** 88 @brief Get the width of the BoxCollisionShape. 89 @return Returns the width of the BoxCollisionShape. 90 */ 60 91 inline float getWidth() const 61 { return this->halfExtents_.z * 2 ; }92 { return this->halfExtents_.z * 2.0f; } 62 93 63 inline void setHeight(float value) 64 { this->halfExtents_.y = value / 2; updateShape(); } 94 /** 95 @brief Set the height of the BoxCollisionShape. 96 If the height changes, this causes the internal collision shape to be recreated. 97 @param value The height to be set. 98 @return Returns true if the height has changed, false if not. 99 */ 100 inline bool setHeight(float value) 101 { if(this->halfExtents_.y == value/2.0f) return false; this->halfExtents_.y = value / 2.0f; updateShape(); return true; } 102 /** 103 @brief Get the height of the BoxCollisionShape. 104 @return Returns the height of the BoxCollisionShape. 105 */ 65 106 inline float getHeight() const 66 { return this->halfExtents_.y * 2 ; }107 { return this->halfExtents_.y * 2.0f; } 67 108 68 inline void setLength(float value) 69 { this->halfExtents_.x = value / 2; updateShape(); } 109 /** 110 @brief Set the length of the BoxCollisionShape. 111 If the length changes, this causes the internal collision shape to be recreated. 112 @param value The length to be set. 113 @return Returns true if the length has changed, false if not. 114 */ 115 inline bool setLength(float value) 116 { if(this->halfExtents_.x == value/2.0f) return false; this->halfExtents_.x = value / 2.0f; updateShape(); return true; } 117 /** 118 @brief Get the length of the BoxCollisionShape. 119 @return Returns the length of the BoxCollisionShape. 120 */ 70 121 inline float getLength() const 71 { return this->halfExtents_.x * 2; } 122 { return this->halfExtents_.x * 2.0f; } 123 124 virtual void changedScale(); // Is called when the scale of the BoxCollisionShape has changed. 72 125 73 126 private: 74 127 void registerVariables(); 75 128 76 btCollisionShape* createNewShape() const; 129 btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the BoxCollisionShape. 77 130 78 Vector3 halfExtents_; 131 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 132 }; 80 133 } -
code/branches/pickup/src/modules/objects/collisionshapes/ConeCollisionShape.cc
r6417 r8422 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/pickup/src/modules/objects/collisionshapes/ConeCollisionShape.h
r7601 r8422 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 @ingroup Collisionshapes. 52 */ 43 53 class _ObjectsExport ConeCollisionShape : public CollisionShape 44 54 { … … 49 59 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 60 51 inline void setRadius(float value) 52 { this->radius_ = value; updateShape(); } 61 /** 62 @brief Set the radius of the ConeCollisionShape. 63 If the radius changes, this causes the internal collision shape to be recreated. 64 @param value The radius to be set. 65 @return Returns true if the radius has changed, false if not. 66 */ 67 inline bool setRadius(float value) 68 { if(this->radius_ == value) return false; this->radius_ = value; updateShape(); return true; } 69 /** 70 @brief Get the radius of the ConeCollisionShape. 71 @return Returns the radius of the ConeCollisionShape. 72 */ 53 73 inline float getRadius() const 54 74 { return radius_; } 55 75 56 inline void setHeight(float value) 57 { this->height_ = value; updateShape(); } 76 /** 77 @brief Set the height of the ConeCollisionShape. 78 If the height changes, this causes the internal collision shape to be recreated. 79 @param value The height to be set. 80 @return Returns true if the height has changed, false if not. 81 */ 82 inline bool setHeight(float value) 83 { if(this->height_ == value) return false; this->height_ = value; updateShape(); return true; } 84 /** 85 @brief Get the height of the ConeCollisionShape. 86 @return Returns the height of the ConeCollisionShape. 87 */ 58 88 inline float getHeight() const 59 89 { return this->height_; } 90 91 virtual void changedScale(); // Is called when the scale of the ConeCollisionShape has changed. 60 92 61 93 private: 62 94 void registerVariables(); 63 95 64 btCollisionShape* createNewShape() const; 96 btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the ConeCollisionShape. 65 97 66 float radius_; 67 float height_; 98 float radius_; //!< The radius of the ConeCollisionShape. 99 float height_; //!< The height of the ConeCollisionShape. 68 100 }; 69 101 } -
code/branches/pickup/src/modules/objects/collisionshapes/PlaneCollisionShape.cc
r6417 r8422 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/pickup/src/modules/objects/collisionshapes/PlaneCollisionShape.h
r7601 r8422 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 @ingroup Collisionshapes 54 */ 45 55 class _ObjectsExport PlaneCollisionShape : public CollisionShape 46 56 { … … 51 61 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 52 62 53 inline void setNormal(const Vector3& normal) 54 { this->normal_ = normal; updateShape(); } 55 inline const Vector3& getNormal() 63 /** 64 @brief Set the normal of the PlaneCollisionShape. 65 If the normal changes, this causes the internal collision shape to be recreated. 66 @param normal The normal vector to be set. 67 @return Returns true if the normal has changed, false if not. 68 */ 69 inline bool setNormal(const Vector3& normal) 70 { if(this->normal_ == normal) return false; this->normal_ = normal; updateShape(); return true; } 71 /** 72 @brief Get the normal of the PlaneCollisionShape. 73 @return Returns the normal vector of the PlaneCollisionShape. 74 */ 75 inline const Vector3& getNormal() const 56 76 { return normal_;} 57 77 58 inline void setOffset(float offset) 59 { this->offset_ = offset; updateShape(); } 60 inline float getOffset() 78 /** 79 @brief Set the offset of the PlaneCollisionShape. 80 If the offset changes, this causes the internal collision shape to be recreated. 81 @param offset The offset to be set. 82 @return Returns true if the offset has changed, false if not. 83 */ 84 inline bool setOffset(float offset) 85 { if(this->offset_ == offset) return false; this->offset_ = offset; updateShape(); return true; } 86 /** 87 @brief Get the offset of the PlaneCollisionShape. 88 @return Returns the offset of the PlaneCollisionShape. 89 */ 90 inline float getOffset() const 61 91 { return this->offset_;} 92 93 virtual void changedScale(); // Is called when the scale of the PlaneCollisionShape has changed. 62 94 63 95 private: 64 96 void registerVariables(); 65 97 66 btCollisionShape* createNewShape() const;98 btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the PlaneCollisionShape. 67 99 68 Vector3 normal_; 69 float offset_; 100 Vector3 normal_; //!< The normal vector of the PlaneCollisionShape. 101 float offset_; //!< The offset of the PlaneCollisionShape. 70 102 }; 71 103 } -
code/branches/pickup/src/modules/objects/collisionshapes/SphereCollisionShape.cc
r5781 r8422 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/pickup/src/modules/objects/collisionshapes/SphereCollisionShape.h
r7601 r8422 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 @ingroup Collisionshapes 52 */ 43 53 class _ObjectsExport SphereCollisionShape : public CollisionShape 44 54 { … … 49 59 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 60 51 inline void setRadius(float radius) 52 { this->radius_ = radius; updateShape(); } 61 /** 62 @brief Set the radius of the SphereCollisionShape. 63 If the radius changes, this causes the internal collision shape to be recreated. 64 @param radius The radius to be set. 65 @return Returns true if the radius has changed, false if not. 66 */ 67 inline bool setRadius(float radius) 68 { if(this->radius_ == radius) return false; this->radius_ = radius; updateShape(); return true; } 69 /** 70 @brief Get the radius of the SphereCollisionShape. 71 @return Returns the radius of the SphereCollisionShape. 72 */ 53 73 inline float getRadius() const 54 74 { return this->radius_; } 75 76 virtual void changedScale(); // Is called when the scale of the SphereCollisionShape has changed. 55 77 56 78 private: … … 59 81 btCollisionShape* createNewShape() const; 60 82 61 float radius_; 83 float radius_; //!< The radius of the SphereCollisionShape. 62 84 }; 63 85 } -
code/branches/pickup/src/orxonox/collisionshapes/CollisionShape.cc
r7401 r8422 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/pickup/src/orxonox/collisionshapes/CollisionShape.h
r7163 r8422 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/pickup/src/orxonox/collisionshapes/CompoundCollisionShape.cc
r5929 r8422 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 // Iterate through all attached CollisionShapes. 264 for(std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++) 265 { 266 // Rescale the CollisionShape. 267 it->first->setScale3D(this->getScale3D()); 268 this->updateAttachedShape(it->first); 269 } 270 271 this->updatePublicShape(); 272 } 192 273 } -
code/branches/pickup/src/orxonox/collisionshapes/CompoundCollisionShape.h
r5781 r8422 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 @ingroup Collisionshapes 55 */ 40 56 class _OrxonoxExport CompoundCollisionShape : public CollisionShape 41 57 { … … 53 69 void updateAttachedShape(CollisionShape* shape); 54 70 71 virtual void changedScale(); 72 55 73 private: 56 74 void updatePublicShape(); -
code/branches/pickup/src/orxonox/worldentities/WorldEntity.cc
r7937 r8422 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 (false && 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.