- Timestamp:
- May 8, 2011, 11:45:32 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.