Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/objects/collisionshapes/BoxCollisionShape.h @ 10008

Last change on this file since 10008 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 5.3 KB
Line 
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
29/**
30    @file BoxCollisionShape.h
31    @brief Definition of the BoxCollisionShape class.
32    @ingroup Collisionshapes
33*/
34
35#ifndef _BoxCollisionShape_H__
36#define _BoxCollisionShape_H__
37
38#include "objects/ObjectsPrereqs.h"
39
40#include "util/Math.h"
41#include "collisionshapes/CollisionShape.h"
42
43namespace orxonox
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    */
56    class _ObjectsExport BoxCollisionShape : public CollisionShape
57    {
58        public:
59            BoxCollisionShape(Context* context);
60            virtual ~BoxCollisionShape();
61
62            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
63
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            */
77            inline const Vector3& getHalfExtents() const
78                { return halfExtents_;}
79
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            */
92            inline float getWidth() const
93                { return this->halfExtents_.z * 2.0f; }
94
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            */
107            inline float getHeight() const
108                { return this->halfExtents_.y * 2.0f; }
109
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            */
122            inline float getLength() const
123                { return this->halfExtents_.x * 2.0f; }
124
125            virtual void changedScale(); // Is called when the scale of the BoxCollisionShape has changed.
126
127        private:
128            void registerVariables();
129
130            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the BoxCollisionShape.
131
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.
133     };
134}
135
136#endif /* _BoxCollisionShape_H__ */
Note: See TracBrowser for help on using the repository browser.