Spinning Topp Logo BlackTopp Studios
inc
collidableproxy.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4 The Mezzanine Engine is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 The Mezzanine Engine is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18 'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21 Build professional software and charge for their product.
22 
23 However there are some practical restrictions, so if your project involves
24 any of the following you should contact us and we will try to work something
25 out:
26 - DRM or Copy Protection of any kind(except Copyrights)
27 - Software Patents You Do Not Wish to Freely License
28 - Any Kind of Linking to Non-GPL licensed Works
29 - Are Currently In Violation of Another Copyright Holder's GPL License
30 - If You want to change our code and not add a few hundred MB of stuff to
31 your distribution
32 
33 These and other limitations could cause serious legal problems if you ignore
34 them, so it is best to simply contact us or the Free Software Foundation, if
35 you have any questions.
36 
37 Joseph Toppi - toppij@gmail.com
38 John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _collidableproxy_h
41 #define _collidableproxy_h
42 
43 #include "Physics/physicsenumerations.h"
44 
45 #ifndef SWIG
46  #include "axisalignedbox.h"
47 #endif
48 #include "worldproxy.h"
49 
50 class btCollisionObject;
51 class btCollisionShape;
52 
53 namespace Mezzanine
54 {
55  class WorldObject;
56  namespace Physics
57  {
58  class PhysicsManager;
59  class CollisionShape;
60  ///////////////////////////////////////////////////////////////////////////////
61  /// @brief This is a proxy from which physics objects that can collide with each other are handled.
62  /// @details This class is used to hold and configure the physics information for a world object.
63  /// This class holds physics information from the physics sub-library and serves as a means to interact with it.
64  /// Direct interaction with the internal physics object is discouraged.
65  ///////////////////////////////////////
67  {
68  protected:
69  /*/// @internal
70  /// @brief A vector3 storing the scaling applied to this body.
71  /// @note This exists because in bullet scaling is a property of shapes instead of bodies.
72  Vector3 BodyScale;// */
73  /// @internal
74  /// @brief The physics shape of this proxy.
76  /// @internal
77  /// @brief This is an internal only shape that provides the ability for a collision shape to be scaled locally (to this object alone).
78  btCollisionShape* ScalerShape;
79  /// @internal
80  /// @brief This is a pointer to the physics manager that created and owns this proxy.
82  /// @internal
83  /// @brief The classifications pertaining to this object in regards to collisions.
85  /// @internal
86  /// @brief Stores the kind of World Objects that can collide with each other.
88 
89  /// @copydoc WorldProxy::ProtoSerializeImpl(XML::Node&) const
90  virtual void ProtoSerializeImpl(XML::Node& SelfRoot) const;
91  /// @copydoc WorldProxy::ProtoDeSerializeImpl(const XML::Node&)
92  virtual void ProtoDeSerializeImpl(const XML::Node& SelfRoot);
93  public:
94  /// @brief XML-assist Constructor.
95  /// @param Creator A pointer to the manager that created this proxy.
97  /// @brief Normal Constructor.
98  /// @param ID The unique ID assigned to this proxy.
99  /// @param Creator A pointer to the manager that created this proxy.
100  CollidableProxy(const UInt32 ID, PhysicsManager* Creator);
101  /// @brief Class Destructor.
102  virtual ~CollidableProxy();
103 
104  ///////////////////////////////////////////////////////////////////////////////
105  // Utility
106 
107  /// @brief Gets this proxies AABB.
108  /// @note This will only return valid values if this proxy is in the world. A proxy outside of the world has no AABB.
109  /// @return Returns an AxisAlignedBox containing the AABB of this physics proxy.
110  virtual AxisAlignedBox GetAABB() const;
111 
112  /// @copydoc WorldProxy::AddToWorld()
113  virtual void AddToWorld() = 0;
114  /// @copydoc WorldProxy::RemoveFromWorld()
115  virtual void RemoveFromWorld() = 0;
116  /// @copydoc WorldProxy::IsInWorld() const
117  virtual Boole IsInWorld() const;
118 
119  /// @copydoc WorldProxy::GetCreator() const
120  virtual WorldManager* GetCreator() const;
121 
122  ///////////////////////////////////////////////////////////////////////////////
123  // Collision Settings
124 
125  /// @brief Set the collision group and mask for the proxy to determine what it should collide with.
126  /// @details These values are automatically calculated for you with some sane default values. Only edit these if you know what you are doing.
127  /// @param Group The collision group to which this proxy belongs.
128  /// @param Mask The other groups to which this proxy should collide with.
129  virtual void SetCollisionGroupAndMask(const Int16 Group, const Int16 Mask);
130  /// @brief Sets which collision group this proxy belongs to, which determines it's collision behavior.
131  /// @param Group The collision group to which this proxy belongs.
132  virtual void SetCollisionGroup(const Int16 Group);
133  /// @brief Sets the collision mask of this proxy, which determines which groups it will collide with.
134  /// @param Mask The other groups to which this proxy should collide with.
135  virtual void SetCollisionMask(const Int16 Mask);
136  /// @brief Gets the objects collision group.
137  /// @return Returns a Int16 representing the collision group this object is set to.
138  virtual Int16 GetCollisionGroup() const;
139  /// @brief Gets the object's collision mask.
140  /// @return Returns a Int16 representing what collision groups this object should collide with.
141  virtual Int16 GetCollisionMask() const;
142 
143  /// @brief Sets the collision shape to be used.
144  /// @param Shape The shape to be applied.
145  virtual void SetCollisionShape(CollisionShape* Shape);
146  /// @brief Gets the collision shape currently in use by this object.
147  /// @return Returns a pointer to the collision shape being used.
148  virtual CollisionShape* GetCollisionShape() const;
149 
150  /// @brief Sets the World Object to be able to collide with other objects in the world.
151  /// @details By default collision response is enabled. Only call this function if you have disabled collision response.
152  /// @param Enable Whether or not to enable collision response.
153  virtual void SetCollisionResponse(Boole Enable);
154  /// @brief Will this respond to 3d collisions.
155  /// @return False is it does not respond to collisions, True if it will
156  virtual Boole GetCollisionResponse() const;
157 
158  /// @brief Sets the collection of flags that help determine collision response for this object.
159  /// @details See Physics::CollisionFlags enum for more details on the available flags.
160  /// @param Flags A bitmask containing all the flags to be applied to this object.
161  virtual void SetCollisionFlags(const Whole Flags);
162  /// @brief Gets the collection of flags that help determine collision response for this object.
163  /// @return Returns a bitmask containing all the flags used to determine collision reponse for this object.
164  virtual Whole GetCollisionFlags() const;
165 
166  ///////////////////////////////////////////////////////////////////////////////
167  // Static or Kinematic Properties
168 
169  /// @brief Sets the state of the object to Kinematic.
170  /// @details This function will set the object to a Kinematic Object. @n
171  /// Kinematic Objects are like Static Objects but are also able to be moved directly by character controllers.
172  virtual void SetKinematic();
173  /// @brief Sets the state of the object to Static.
174  /// @details This function will set the object to a Static Object. @n
175  /// Static Objects don't move or have any force applied to them, but are cabable of exerting force on other objects.
176  virtual void SetStatic();
177  /// @brief Is the object kinematic.
178  /// @return True if the object is kinematic false if it is not.
179  virtual Boole IsKinematic() const;
180  /// @brief Is the object static.
181  /// @return True if the object is Static false if it is not.
182  virtual Boole IsStatic() const;
183  /// @brief Checks if the object is either static or kinematic.
184  /// @details Checks if the object is either static or kinematic, returns true if it is either.
185  /// @return Returns true if the object is static or kinematic.
186  virtual Boole IsStaticOrKinematic() const;
187 
188  ///////////////////////////////////////////////////////////////////////////////
189  // Physics Properties
190 
191  /// @brief Sets the sliding friction coefficient.
192  /// @details Higher values will resist sliding across surfaces. This number is the
193  /// coefficient of friction. Range is from 0.0 to 2.0. Behavior in this regard is determined by the friction of both
194  /// colliding bodies. @n Default: 0.5
195  /// @param Friction A Real that is the sliding friction coefficient desired.
196  virtual void SetFriction(const Real Friction);
197  /// @brief Gets the sliding friction coefficient.
198  /// @return Returns a Real representing the sliding friction coefficient.
199  virtual Real GetFriction() const;
200 
201  /// @brief Sets the rolling friction coefficient.
202  /// @details This works on the same basic idea as "normal" friction but this is the coefficient to be used when the object
203  /// rolls across the surface instead of slides across.
204  /// @param Friction A Real that is the rolling friction coefficient desired.
205  virtual void SetRollingFriction(const Real Friction);
206  /// @brief Gets the rolling friction coefficient.
207  /// @return Returns a Real representing the rolling friction coefficient.
208  virtual Real GetRollingFriction() const;
209 
210  /// @brief Sets the anisotropic friction factor.
211  /// @details Anisotropic friction is when an object has different behaviors for sliding or rolling on different axes. An
212  /// example would be a skateboard that rolls easily back and forth, but resists side to side. @n @n
213  /// Note that only one Anisotropic Friction Flag can be set at a time.
214  /// @param Friction A Vector3 expressing the coefficients on each of this objects local axes that will be applied to the global friction value.
215  /// @param Mode The type of friction the passed in value should be set as. See Physics::AnisotropicFrictionFlags enum for more details.
216  virtual void SetAnisotropicFriction(const Vector3& Friction, const Whole Mode);
217  /// @brief Gets the current Anisotropic friction mode being applied to this proxy.
218  /// @return Returns a AnisotropicFrictionFlags enum value representing the anisotropic friction mode being used by this proxy.
219  virtual Physics::AnisotropicFrictionFlags GetAnisotropicFrictionMode() const;
220  /// @brief Gets whether or not anisotropic friction is being used in a specified mode.
221  /// @param Mode The Physics::AnisotropicFrictionFlags value to check for.
222  /// @return Returns true if the specified mode is the current mode of Anisotropic Friction being used.
223  virtual Boole IsAnisotropicFrictionModeSet(const Whole Mode) const;
224  /// @brief Gets the anisotropic friction factor.
225  /// @return Returns a Vector3 representing the anisotropic friction factors on each of the linear axes.
226  virtual Vector3 GetAnisotropicFriction() const;
227 
228  /// @brief Sets the restitution coefficient.
229  /// @details Restitution determines how much energy is left after a collision with an object.
230  /// Range is from 0.0 to 1.0. Behavior in this regard is determined by the restitution of both colliding bodies.
231  /// @n Default: 0.0
232  /// @param Restitution A Real that is the restitution coefficient desired.
233  virtual void SetRestitution(const Real& Restitution);
234  /// @brief Gets the World Object restitution coefficient.
235  /// @return Returns a Real representing the World Object restitution coefficient.
236  virtual Real GetRestitution() const;
237 
238  ///////////////////////////////////////////////////////////////////////////////
239  // Activation State
240 
241  /// @brief Sets the activation state of the world object.
242  /// @param State The activation state to set for this proxy. See the ActivationState enum for more info.
243  /// @param Force Whether or not you want to force the state. Some states may not apply based on the condition of the proxy if this is set to false.
244  virtual void SetActivationState(const Physics::ActivationState State, Boole Force = false);
245  /// @brief Gets the current activation state of this proxy.
246  /// @return Returns a Physics::ActivationState value representing the current state of this proxy.
247  virtual Physics::ActivationState GetActivationState() const;
248  /// @brief Checks if the object is active in the simulation.
249  /// @return Returns true if the object is active, false if it's deactivated(at rest).
250  virtual Boole IsActive() const;
251 
252  /// @brief Sets the amount of time this object needs to have no forces enacted upon it to be deactivated.
253  /// @details This deactivate simply means it is skipped on more robust checks and force checking. It does not mean
254  /// that it has to be manually reactivated by the user. A force being applied to it will re-activate it automatically.
255  /// This setting is a simple optimization.
256  /// @param Time The amount of time in seconds this object needs to deactivate.
257  virtual void SetDeactivationTime(const Real Time);
258  /// @brief Gets the current deactivation time for this object.
259  /// @return Returns a Real representing the current amount of time in seconds this object needs to be stationary to deactivate.
260  virtual Real GetDeactivationTime() const;
261 
262  ///////////////////////////////////////////////////////////////////////////////
263  // Transform Methods
264 
265  /// @copydoc WorldProxy::SetLocation(const Vector3&)
266  virtual void SetLocation(const Vector3& Loc);
267  /// @copydoc WorldProxy::SetLocation(const Real, const Real, const Real)
268  virtual void SetLocation(const Real X, const Real Y, const Real Z);
269  /// @copydoc WorldProxy::GetLocation() const
270  virtual Vector3 GetLocation() const;
271  /// @copydoc WorldProxy::SetOrientation(const Quaternion&)
272  virtual void SetOrientation(const Quaternion& Ori);
273  /// @copydoc WorldProxy::SetOrientation(const Real, const Real, const Real, const Real)
274  virtual void SetOrientation(const Real X, const Real Y, const Real Z, const Real W);
275  /// @copydoc WorldProxy::GetOrientation() const
276  virtual Quaternion GetOrientation() const;
277  /// @copydoc WorldProxy::SetScale(const Vector3&)
278  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
279  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
280  virtual void SetScale(const Vector3& Sc);
281  /// @copydoc WorldProxy::SetScale(const Real, const Real, const Real)
282  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
283  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
284  virtual void SetScale(const Real X, const Real Y, const Real Z);
285  /// @copydoc WorldProxy::GetScale() const
286  virtual Vector3 GetScale() const;
287 
288  /// @copydoc WorldProxy::Translate(const Vector3&)
289  virtual void Translate(const Vector3& Trans);
290  /// @copydoc WorldProxy::Translate(const Real, const Real, const Real)
291  virtual void Translate(const Real X, const Real Y, const Real Z);
292  /// @copydoc WorldProxy::Yaw(const Real)
293  virtual void Yaw(const Real Angle);
294  /// @copydoc WorldProxy::Pitch(const Real)
295  virtual void Pitch(const Real Angle);
296  /// @copydoc WorldProxy::Roll(const Real)
297  virtual void Roll(const Real Angle);
298  /// @copydoc WorldProxy::Rotate(const Vector3&, const Real)
299  virtual void Rotate(const Vector3& Axis, const Real Angle);
300  /// @copydoc WorldProxy::Rotate(const Quaternion&)
301  virtual void Rotate(const Quaternion& Rotation);
302  /// @copydoc WorldProxy::Scale(const Vector3&)
303  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
304  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
305  virtual void Scale(const Vector3& Scale);
306  /// @copydoc WorldProxy::Scale(const Real, const Real, const Real)
307  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
308  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
309  virtual void Scale(const Real X, const Real Y, const Real Z);
310 
311  ///////////////////////////////////////////////////////////////////////////////
312  // Serialization
313 
314  /// @copydoc WorldProxy::ProtoSerializeProperties(XML::Node&) const
315  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
316  /// @brief Convert the shape of this class to an XML::Node ready for serialization.
317  /// @param SelfRoot The root node containing all the serialized data for this instance.
318  virtual void ProtoSerializeShape(XML::Node& SelfRoot) const;
319 
320  /// @copydoc WorldProxy::ProtoDeSerializeProperties(const XML::Node&)
321  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
322  /// @brief Take the data stored in an XML Node and overwrite the shape of this object with it.
323  /// @param SelfRoot An XML::Node containing the data to populate this class with.
324  virtual void ProtoDeSerializeShape(const XML::Node& SelfRoot);
325 
326  /// @copydoc WorldProxy::GetDerivedSerializableName() const
327  virtual String GetDerivedSerializableName() const;
328  /// @copydoc WorldProxy::GetSerializableName()
329  static String GetSerializableName();
330 
331  ///////////////////////////////////////////////////////////////////////////////
332  // Internal Methods
333 
334  /// @internal
335  /// @brief Gets the unique ID assigned to the internal object.
336  /// @return Returns a unique number greater than zero if the object is in the world, or Zero if the
337  virtual Integer _GetBroadphaseUniqueID() const;
338  /// @internal
339  /// @brief Sets the maximum distance to be considered for processing collisions with this object.
340  /// @param Threshold The maximum distance in world units that will be considered a collision with this object.
341  virtual void _SetContactProcessingThreshold(const Real Threshold);
342  /// @internal
343  /// @brief Gets the maximum distance to be considered for processing collisions with this object.
344  /// @return Returns a Real represnting the maximum distance in world units that is considered a collision with this object.
345  virtual Real _GetContactProcessingThreshold() const;
346  /// @internal
347  /// @brief Accessor for the internal physics object.
348  /// @return Returns a pointer to the internal object of this proxy.
349  virtual btCollisionObject* _GetBasePhysicsObject() const = 0;
350  };// CollidableProxy
351  }//Physics
352 }//Mezzanine
353 
354 #endif
This is the base class for all collision shapes.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
PhysicsManager * Manager
This is a pointer to the physics manager that created and owns this proxy.
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
btCollisionShape * ScalerShape
This is an internal only shape that provides the ability for a collision shape to be scaled locally (...
ActivationState
This is used by physics proxies to monitor and set their physics activation.
This file contains the AxisAlignedBox class for representing AABB's of objects in the world...
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
Int16 CollisionGroup
The classifications pertaining to this object in regards to collisions.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This is the base class for proxy objects belonging to the various 3D subsystems.
Definition: worldproxy.h:53
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
CollisionShape * ProxyShape
The physics shape of this proxy.
This is the base class for all managers that belong to a single world instance.
Definition: worldmanager.h:55
This is a proxy from which physics objects that can collide with each other are handled.
int16_t Int16
An 16-bit integer.
Definition: datatypes.h:120
This is simply a place for storing all the Physics Related functions.
A container for the metrics of time relevant for the timer class.
Definition: extendedtimer.h:52
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Int16 CollisionMask
Stores the kind of World Objects that can collide with each other.
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
AnisotropicFrictionFlags
This is used by physics proxies to help determine the behavior of it's anistropic friction behavior...
This is a utility class used to represent the Axis-Aligned Bounding Boxes of objects in various subsy...