MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
collidableproxy.h
1 // © Copyright 2010 - 2012 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 #include "axisalignedbox.h"
45 #include "worldproxy.h"
46 
47 class btCollisionObject;
48 class btCollisionShape;
49 
50 namespace Mezzanine
51 {
52  class WorldObject;
53  namespace Physics
54  {
55  class PhysicsManager;
56  class CollisionShape;
57  ///////////////////////////////////////////////////////////////////////////////
58  /// @brief This is a proxy from which physics objects that can collide with each other are handled.
59  /// @details This class is used to hold and configure the physics information for a world object.
60  /// This class holds physics information from the physics sub-library and serves as a means to interact with it.
61  /// Direct interaction with the internal physics object is discouraged.
62  ///////////////////////////////////////
64  {
65  protected:
66  /// @internal
67  /// @brief A vector3 storing the scaling applied to this body.
68  /// @note This exists because in bullet scaling is a property of shapes instead of bodies.
69  //Vector3 BodyScale;
70  /// @internal
71  /// @brief The physics shape of this proxy.
73  /// @internal
74  /// @brief This is an internal only shape that provides the ability for a collision shape to be scaled locally (to this object alone).
75  btCollisionShape* ScalerShape;
76  /// @internal
77  /// @brief This is a pointer to the physics manager that created and owns this proxy.
79  /// @internal
80  /// @brief The classifications pertaining to this object in regards to collisions.
82  /// @internal
83  /// @brief Stores the kind of World Objects that can collide with each other.
85  public:
86  /// @brief Standard Constructor.
87  /// @param Creator A pointer to the manager that created this proxy.
89  /// @brief Class Destructor.
90  virtual ~CollidableProxy();
91 
92  ///////////////////////////////////////////////////////////////////////////////
93  // Utility
94 
95  /// @brief Gets this proxies AABB.
96  /// @note This will only return valid values if this proxy is in the world. A proxy outside of the world has no AABB.
97  /// @return Returns an AxisAlignedBox containing the AABB of this physics proxy.
98  virtual AxisAlignedBox GetAABB() const;
99 
100  /// @copydoc WorldProxy::AddToWorld()
101  virtual void AddToWorld() = 0;
102  /// @copydoc WorldProxy::RemoveFromWorld()
103  virtual void RemoveFromWorld() = 0;
104  /// @copydoc WorldProxy::IsInWorld() const
105  virtual Boolean IsInWorld() const;
106 
107  /// @copydoc WorldProxy::GetCreator() const
108  virtual WorldManager* GetCreator() const;
109 
110  ///////////////////////////////////////////////////////////////////////////////
111  // Collision Settings
112 
113  /// @brief Set the collision group and mask for the proxy to determine what it should collide with.
114  /// @details These values are automatically calculated for you with some sane default values. Only edit these if you know what you are doing.
115  /// @param Group The collision group to which this proxy belongs.
116  /// @param Mask The other groups to which this proxy should collide with.
117  virtual void SetCollisionGroupAndMask(const Int16 Group, const Int16 Mask);
118  /// @brief Sets which collision group this proxy belongs to, which determines it's collision behavior.
119  /// @param Group The collision group to which this proxy belongs.
120  virtual void SetCollisionGroup(const Int16 Group);
121  /// @brief Sets the collision mask of this proxy, which determines which groups it will collide with.
122  /// @param Mask The other groups to which this proxy should collide with.
123  virtual void SetCollisionMask(const Int16 Mask);
124  /// @brief Gets the objects collision group.
125  /// @return Returns a Int16 representing the collision group this object is set to.
126  virtual Int16 GetCollisionGroup() const;
127  /// @brief Gets the object's collision mask.
128  /// @return Returns a Int16 representing what collision groups this object should collide with.
129  virtual Int16 GetCollisionMask() const;
130 
131  /// @brief Sets the collision shape to be used.
132  /// @param Shape The shape to be applied.
133  virtual void SetCollisionShape(CollisionShape* Shape);
134  /// @brief Gets the collision shape currently in use by this object.
135  /// @return Returns a pointer to the collision shape being used.
136  virtual CollisionShape* GetCollisionShape() const;
137 
138  /// @brief Sets the World Object to be able to collide with other objects in the world.
139  /// @details By default collision response is enabled. Only call this function if you have disabled collision response.
140  /// @param Enable Whether or not to enable collision response.
141  virtual void SetCollisionResponse(bool Enable);
142  /// @brief Will this respond to 3d collisions.
143  /// @return False is it does not respond to collisions, True if it will
144  virtual bool GetCollisionResponse() const;
145 
146  /// @brief Sets the collection of flags that help determine collision response for this object.
147  /// @details See Physics::CollisionFlags enum for more details on the available flags.
148  /// @param Flags A bitmask containing all the flags to be applied to this object.
149  virtual void SetCollisionFlags(const Whole Flags);
150  /// @brief Gets the collection of flags that help determine collision response for this object.
151  /// @return Returns a bitmask containing all the flags used to determine collision reponse for this object.
152  virtual Whole GetCollisionFlags() const;
153 
154  ///////////////////////////////////////////////////////////////////////////////
155  // Static or Kinematic Properties
156 
157  /// @brief Sets the state of the object to Kinematic.
158  /// @details This function will set the object to a Kinematic Object. @n
159  /// Kinematic Objects are like Static Objects but are also able to be moved directly by character controllers.
160  virtual void SetKinematic();
161  /// @brief Sets the state of the object to Static.
162  /// @details This function will set the object to a Static Object. @n
163  /// Static Objects don't move or have any force applied to them, but are cabable of exerting force on other objects.
164  virtual void SetStatic();
165  /// @brief Is the object kinematic.
166  /// @return True if the object is kinematic false if it is not.
167  virtual bool IsKinematic() const;
168  /// @brief Is the object static.
169  /// @return True if the object is Static false if it is not.
170  virtual bool IsStatic() const;
171  /// @brief Checks if the object is either static or kinematic.
172  /// @details Checks if the object is either static or kinematic, returns true if it is either.
173  /// @return Returns true if the object is static or kinematic.
174  virtual bool IsStaticOrKinematic() const;
175 
176  ///////////////////////////////////////////////////////////////////////////////
177  // Physics Properties
178 
179  /// @brief Sets the sliding friction coefficient.
180  /// @details Higher values will resist sliding across surfaces. This number is the
181  /// coefficient of friction. Range is from 0.0 to 2.0. Behavior in this regard is determined by the friction of both
182  /// colliding bodies. @n Default: 0.5
183  /// @param Friction A Real that is the sliding friction coefficient desired.
184  virtual void SetFriction(const Real Friction);
185  /// @brief Gets the sliding friction coefficient.
186  /// @return Returns a Real representing the sliding friction coefficient.
187  virtual Real GetFriction() const;
188 
189  /// @brief Sets the rolling friction coefficient.
190  /// @details This works on the same basic idea as "normal" friction but this is the coefficient to be used when the object
191  /// rolls across the surface instead of slides across.
192  /// @param Friction A Real that is the rolling friction coefficient desired.
193  virtual void SetRollingFriction(const Real Friction);
194  /// @brief Gets the rolling friction coefficient.
195  /// @return Returns a Real representing the rolling friction coefficient.
196  virtual Real GetRollingFriction() const;
197 
198  /// @brief Sets the anisotropic friction factor.
199  /// @details Anisotropic friction is when an object has different behaviors for sliding or rolling on different axes. An
200  /// example would be a skateboard that rolls easily back and forth, but resists side to side. @n @n
201  /// Note that only one Anisotropic Friction Flag can be set at a time.
202  /// @param Friction A Vector3 expressing the coefficients on each of this objects local axes that will be applied to the global friction value.
203  /// @param Mode The type of friction the passed in value should be set as. See Physics::AnisotropicFrictionFlags enum for more details.
204  virtual void SetAnisotropicFriction(const Vector3& Friction, const Whole Mode);
205  /// @brief Gets the current Anisotropic friction mode being applied to this proxy.
206  /// @return Returns a AnisotropicFrictionFlags enum value representing the anisotropic friction mode being used by this proxy.
207  virtual Physics::AnisotropicFrictionFlags GetAnisotropicFrictionMode() const;
208  /// @brief Gets whether or not anisotropic friction is being used in a specified mode.
209  /// @param Mode The Physics::AnisotropicFrictionFlags value to check for.
210  /// @return Returns true if the specified mode is the current mode of Anisotropic Friction being used.
211  virtual Boolean IsAnisotropicFrictionModeSet(const Whole Mode) const;
212  /// @brief Gets the anisotropic friction factor.
213  /// @return Returns a Vector3 representing the anisotropic friction factors on each of the linear axes.
214  virtual Vector3 GetAnisotropicFriction() const;
215 
216  /// @brief Sets the restitution coefficient.
217  /// @details Restitution determines how much energy is left after a collision with an object.
218  /// Range is from 0.0 to 1.0. Behavior in this regard is determined by the restitution of both colliding bodies.
219  /// @n Default: 0.0
220  /// @param Restitution A Real that is the restitution coefficient desired.
221  virtual void SetRestitution(const Real& Restitution);
222  /// @brief Gets the World Object restitution coefficient.
223  /// @return Returns a Real representing the World Object restitution coefficient.
224  virtual Real GetRestitution() const;
225 
226  ///////////////////////////////////////////////////////////////////////////////
227  // Activation State
228 
229  /// @brief Sets the activation state of the world object.
230  /// @param State The activation state to set for this proxy. See the ActivationState enum for more info.
231  /// @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.
232  virtual void SetActivationState(const Physics::ActivationState State, bool Force = false);
233  /// @brief Gets the current activation state of this proxy.
234  /// @return Returns a Physics::ActivationState value representing the current state of this proxy.
235  virtual Physics::ActivationState GetActivationState() const;
236  /// @brief Checks if the object is active in the simulation.
237  /// @return Returns true if the object is active, false if it's deactivated(at rest).
238  virtual bool IsActive() const;
239 
240  /// @brief Sets the amount of time this object needs to have no forces enacted upon it to be deactivated.
241  /// @details This deactivate simply means it is skipped on more robust checks and force checking. It does not mean
242  /// that it has to be manually reactivated by the user. A force being applied to it will re-activate it automatically.
243  /// This setting is a simple optimization.
244  /// @param Time The amount of time in seconds this object needs to deactivate.
245  virtual void SetDeactivationTime(const Real Time);
246  /// @brief Gets the current deactivation time for this object.
247  /// @return Returns a Real representing the current amount of time in seconds this object needs to be stationary to deactivate.
248  virtual Real GetDeactivationTime() const;
249 
250  ///////////////////////////////////////////////////////////////////////////////
251  // Transform Methods
252 
253  /// @copydoc WorldProxy::SetLocation(const Vector3&)
254  virtual void SetLocation(const Vector3& Loc);
255  /// @copydoc WorldProxy::SetLocation(const Real, const Real, const Real)
256  virtual void SetLocation(const Real X, const Real Y, const Real Z);
257  /// @copydoc WorldProxy::GetLocation() const
258  virtual Vector3 GetLocation() const;
259  /// @copydoc WorldProxy::SetOrientation(const Quaternion&)
260  virtual void SetOrientation(const Quaternion& Ori);
261  /// @copydoc WorldProxy::SetOrientation(const Real, const Real, const Real, const Real)
262  virtual void SetOrientation(const Real X, const Real Y, const Real Z, const Real W);
263  /// @copydoc WorldProxy::GetOrientation() const
264  virtual Quaternion GetOrientation() const;
265  /// @copydoc WorldProxy::SetScale(const Vector3&)
266  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
267  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
268  virtual void SetScale(const Vector3& Sc);
269  /// @copydoc WorldProxy::SetScale(const Real, const Real, const Real)
270  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
271  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
272  virtual void SetScale(const Real X, const Real Y, const Real Z);
273  /// @copydoc WorldProxy::GetScale() const
274  virtual Vector3 GetScale() const;
275 
276  /// @copydoc WorldProxy::Translate(const Vector3&)
277  virtual void Translate(const Vector3& Trans);
278  /// @copydoc WorldProxy::Translate(const Real, const Real, const Real)
279  virtual void Translate(const Real X, const Real Y, const Real Z);
280  /// @copydoc WorldProxy::Yaw(const Real)
281  virtual void Yaw(const Real Angle);
282  /// @copydoc WorldProxy::Pitch(const Real)
283  virtual void Pitch(const Real Angle);
284  /// @copydoc WorldProxy::Roll(const Real)
285  virtual void Roll(const Real Angle);
286  /// @copydoc WorldProxy::Rotate(const Vector3&, const Real)
287  virtual void Rotate(const Vector3& Axis, const Real Angle);
288  /// @copydoc WorldProxy::Rotate(const Quaternion&)
289  virtual void Rotate(const Quaternion& Rotation);
290  /// @copydoc WorldProxy::Scale(const Vector3&)
291  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
292  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
293  virtual void Scale(const Vector3& Scale);
294  /// @copydoc WorldProxy::Scale(const Real, const Real, const Real)
295  /// @note In order to preserve consistent functionality between physics proxies and proxies of other subsystems, in the
296  /// event this proxy can't be locally scaled, it will globally scale the collision shape it is currently using.
297  virtual void Scale(const Real X, const Real Y, const Real Z);
298 
299  ///////////////////////////////////////////////////////////////////////////////
300  // Serialization
301 
302  /// @copydoc WorldProxy::ProtoSerialize(XML::Node&) const
303  virtual void ProtoSerialize(XML::Node& ParentNode) const;
304  /// @copydoc WorldProxy::ProtoSerializeProperties(XML::Node& SelfRoot) const
305  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
306  /// @brief Convert the shape of this class to an XML::Node ready for serialization.
307  /// @param SelfRoot The root node containing all the serialized data for this instance.
308  virtual void ProtoSerializeShape(XML::Node& SelfRoot) const;
309 
310  /// @copydoc WorldProxy::ProtoDeSerialize(const XML::Node&)
311  virtual void ProtoDeSerialize(const XML::Node& SelfRoot);
312  /// @copydoc WorldProxy::ProtoDeSerializeProperties(const XML::Node& SelfRoot)
313  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
314  /// @brief Take the data stored in an XML Node and overwrite the shape of this object with it.
315  /// @param SelfRoot An XML::Node containing the data to populate this class with.
316  virtual void ProtoDeSerializeShape(const XML::Node& SelfRoot);
317 
318  /// @copydoc WorldProxy::GetDerivedSerializableName() const
319  virtual String GetDerivedSerializableName() const;
320  /// @copydoc WorldProxy::GetSerializableName()
321  static String GetSerializableName();
322 
323  ///////////////////////////////////////////////////////////////////////////////
324  // Internal Methods
325 
326  /// @internal
327  /// @brief Gets the unique ID assigned to the internal object.
328  /// @return Returns a unique number greater than zero if the object is in the world, or Zero if the
329  virtual Integer _GetBroadphaseUniqueID() const;
330  /// @internal
331  /// @brief Sets the maximum distance to be considered for processing collisions with this object.
332  /// @param Threshold The maximum distance in world units that will be considered a collision with this object.
333  virtual void _SetContactProcessingThreshold(const Real Threshold);
334  /// @internal
335  /// @brief Gets the maximum distance to be considered for processing collisions with this object.
336  /// @return Returns a Real represnting the maximum distance in world units that is considered a collision with this object.
337  virtual Real _GetContactProcessingThreshold() const;
338  /// @internal
339  /// @brief Accessor for the internal physics object.
340  /// @return Returns a pointer to the internal object of this proxy.
341  virtual btCollisionObject* _GetBasePhysicsObject() const = 0;
342  };// ©ollidableProxy
343  }//Physics
344 }//Mezzanine
345 
346 #endif