Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/modules/objects/collisionshapes/BoxCollisionShape.h @ 12177

Last change on this file since 12177 was 12177, checked in by siramesh, 5 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 5.2 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
61            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
62
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            */
76            inline const Vector3& getHalfExtents() const
77                { return halfExtents_;}
78
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            */
91            inline float getWidth() const
92                { return this->halfExtents_.z * 2.0f; }
93
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            */
106            inline float getHeight() const
107                { return this->halfExtents_.y * 2.0f; }
108
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            */
121            inline float getLength() const
122                { return this->halfExtents_.x * 2.0f; }
123
124            virtual void changedScale(); // Is called when the scale of the BoxCollisionShape has changed.
125
126        private:
127            void registerVariables();
128
129            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the BoxCollisionShape.
130
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.
132     };
133}
134
135#endif /* _BoxCollisionShape_H__ */
Note: See TracBrowser for help on using the repository browser.