Orxonox  0.0.5 Codename: Arcturus
CollisionShape.h
Go to the documentation of this file.
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 
35 #ifndef _CollisionShape_H__
36 #define _CollisionShape_H__
37 
38 #include "OrxonoxPrereqs.h"
39 
40 #include "util/Math.h"
41 #include "core/BaseObject.h"
43 
44 namespace orxonox
45 {
46 
58  {
59  public:
60  CollisionShape(Context* context);
61  virtual ~CollisionShape();
62 
63  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
64 
70  inline void setPosition(const Vector3& position)
71  { if(this->position_ == position) return; this->position_ = position; this->updateParent(); }
76  inline const Vector3& getPosition() const
77  { return this->position_; }
78 
84  inline void setOrientation(const Quaternion& orientation)
85  { if(this->orientation_ == orientation) return; this->orientation_ = orientation; this->updateParent(); }
90  inline const Quaternion& getOrientation() const
91  { return this->orientation_; }
92 
98  void yaw(const Degree& angle)
99  { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); }
105  void pitch(const Degree& angle)
106  { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); }
112  void roll(const Degree& angle)
113  { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); }
114 
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.
129  inline const Vector3& getScale3D() const
130  { return this->scale_; }
131 
137  inline void scale(float scale)
138  { this->setScale3D(this->getScale3D()*scale); }
139  void setScale(float scale); // Set the (uniform) scale of the CollisionShape.
145  inline float getScale()
146  { if(this->hasUniformScaling()) return this->scale_.x; return 0.0f; }
147 
152  inline bool hasUniformScaling()
153  { return this->uniformScale_; }
154  virtual void changedScale(); // Is called when the scale of the CollisionShape has changed.
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 
164  inline btCollisionShape* getCollisionShape() const
165  { return this->collisionShape_; }
166 
167  bool hasTransform() const; // Check whether the CollisionShape has been either moved or rotated or both.
168 
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.
171 
172  protected:
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 
180  virtual btCollisionShape* createNewShape() const = 0;
181 
182  btCollisionShape* collisionShape_;
184  unsigned int parentID_;
185 
186  private:
187  void registerVariables();
188 
189  Vector3 position_;
190  Quaternion orientation_;
191  Vector3 scale_;
193  };
194 }
195 
196 #endif /* _CollisionShape_H__ */
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
void setOrientation(const Quaternion &orientation)
Set the orientation of the CollisionShape.
Definition: CollisionShape.h:84
unsigned int parentID_
The objectID of the parent of this CollisionShape, which can either be a CompoundCollisionShape or a ...
Definition: CollisionShape.h:184
const Quaternion & getOrientation() const
Get the orientation of the CollisionShape.
Definition: CollisionShape.h:90
This class is the base class of all the Objects in the universe that need to be synchronised over the...
Definition: Synchronisable.h:142
void setPosition(const Vector3 &position)
Set the position of the CollisionShape.
Definition: CollisionShape.h:70
void yaw(const Degree &angle)
Rotate the CollisionShape around the y-axis by the specified angle.
Definition: CollisionShape.h:98
void pitch(const Degree &angle)
Rotate the CollisionShape around the x-axis by the specified angle.
Definition: CollisionShape.h:105
void roll(const Degree &angle)
Rotate the CollisionShape around the z-axis by the specified angle.
Definition: CollisionShape.h:112
Vector3 position_
The position of the CollisionShape.
Definition: CollisionShape.h:189
btCollisionShape * collisionShape_
The bullet collision shape of this CollisionShape.
Definition: CollisionShape.h:182
CompoundCollisionShape * parent_
The CompoundCollisionShape this CollisionShape belongs to, nullptr if it doesn&#39;t belong to one...
Definition: CollisionShape.h:183
Vector3 scale_
The scale of the CollisionShape.
Definition: CollisionShape.h:191
bool hasUniformScaling()
Check whether the CollisionShape is uniformly scaled.
Definition: CollisionShape.h:152
xmlelement
Definition: Super.h:519
const Vector3 & getPosition() const
Get the position of the CollisionShape.
Definition: CollisionShape.h:76
Quaternion orientation_
The orientation of the CollisionShape.
Definition: CollisionShape.h:190
Wrapper for the bullet compound collision shape class btCompoundShape.
Definition: CompoundCollisionShape.h:57
Declaration and implementation of several math-functions, typedefs of some Ogre::Math classes to the ...
bool uniformScale_
Whether the scale is uniform.
Definition: CollisionShape.h:192
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Mode
Definition: CorePrereqs.h:102
const Vector3 & getScale3D() const
Get the scale of the CollisionShape.
Definition: CollisionShape.h:129
Shared library macros, enums, constants and forward declarations for the orxonox library ...
Declaration of BaseObject, the base class of all objects in Orxonox.
Definition: Context.h:45
btCollisionShape * getCollisionShape() const
Get the bullet collision shape of this CollisionShape.
Definition: CollisionShape.h:164
#define _OrxonoxExport
Definition: OrxonoxPrereqs.h:60
Wrapper for bullet collision shape class btCollisionShape.
Definition: CollisionShape.h:57
void scale3D(const Vector3 &scale)
Scale the CollisionShape by the input vector.
Definition: CollisionShape.h:122
void scale(float scale)
(Uniformly) scale the CollisionShape by the input scale.
Definition: CollisionShape.h:137
float getScale()
Get the (uniform) scale of the CollisionShape.
Definition: CollisionShape.h:145