[2486] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Reto Grieder |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[7601] | 29 | /** |
---|
| 30 | @file BoxCollisionShape.h |
---|
| 31 | @brief Definition of the BoxCollisionShape class. |
---|
| 32 | @ingroup Collisionshapes |
---|
| 33 | */ |
---|
| 34 | |
---|
[2486] | 35 | #ifndef _BoxCollisionShape_H__ |
---|
| 36 | #define _BoxCollisionShape_H__ |
---|
| 37 | |
---|
[5730] | 38 | #include "objects/ObjectsPrereqs.h" |
---|
[2486] | 39 | |
---|
[3196] | 40 | #include "util/Math.h" |
---|
[5735] | 41 | #include "collisionshapes/CollisionShape.h" |
---|
[2486] | 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[8706] | 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 | */ |
---|
[5730] | 56 | class _ObjectsExport BoxCollisionShape : public CollisionShape |
---|
[2486] | 57 | { |
---|
| 58 | public: |
---|
| 59 | BoxCollisionShape(BaseObject* creator); |
---|
| 60 | virtual ~BoxCollisionShape(); |
---|
| 61 | |
---|
| 62 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 63 | |
---|
[8706] | 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 | */ |
---|
[2486] | 77 | inline const Vector3& getHalfExtents() const |
---|
| 78 | { return halfExtents_;} |
---|
| 79 | |
---|
[8706] | 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 | */ |
---|
[2486] | 92 | inline float getWidth() const |
---|
[8706] | 93 | { return this->halfExtents_.z * 2.0f; } |
---|
[2486] | 94 | |
---|
[8706] | 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 | */ |
---|
[2486] | 107 | inline float getHeight() const |
---|
[8706] | 108 | { return this->halfExtents_.y * 2.0f; } |
---|
[2486] | 109 | |
---|
[8706] | 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 | */ |
---|
[2486] | 122 | inline float getLength() const |
---|
[8706] | 123 | { return this->halfExtents_.x * 2.0f; } |
---|
[2486] | 124 | |
---|
[8706] | 125 | virtual void changedScale(); // Is called when the scale of the BoxCollisionShape has changed. |
---|
| 126 | |
---|
[2514] | 127 | private: |
---|
[7163] | 128 | void registerVariables(); |
---|
| 129 | |
---|
[8706] | 130 | btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the BoxCollisionShape. |
---|
[2486] | 131 | |
---|
[8706] | 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. |
---|
[2486] | 133 | }; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | #endif /* _BoxCollisionShape_H__ */ |
---|