Spinning Topp Logo BlackTopp Studios
inc
rigidproxy.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 _rigidproxy_h
41 #define _rigidproxy_h
42 
43 #include "collidableproxy.h"
44 #include "transform.h"
45 
46 class btRigidBody;
47 
48 namespace Mezzanine
49 {
50  class WorldObject;
51  class CollisionShape;
52 
53  namespace Physics
54  {
55  class RigidProxy;
56  class Generic6DofConstraint;
57 
58  // Sticky Stuff
59  typedef Generic6DofConstraint StickyConstraint;
60 
61  /// @struct StickyConstraintConstructionInfo
62  /// @headerfile rigidproxy.h
63  /// @brief Simple struct for holding information on how sticky constraints should be constructed.
65  {
66  Transform TransA;
67  Transform TransB;
68  RigidProxy* ProxA;
69  RigidProxy* ProxB;
70 
72  {
73  this->ProxA = NULL;
74  this->ProxB = NULL;
75  }
77  {
78  this->TransA = Other.TransA;
79  this->TransB = Other.TransB;
80  this->ProxA = Other.ProxA;
81  this->ProxB = Other.ProxB;
82  }
83  };//stickyconstraintconstructioninfo
84 
85  /// @struct StickyData
86  /// @headerfile rigidproxy.h
87  /// @brief This is a basic class for storing the data related to the sticky behavior available to rigid bodies.
89  {
90  StickyData() : MaxNumContacts(0) {};
91  std::vector<StickyConstraint*> StickyConstraints;
92  std::vector<StickyConstraintConstructionInfo> CreationQueue;
93  Whole MaxNumContacts;
94  };//stickydata
95 
96  ///////////////////////////////////////////////////////////////////////////////
97  /// @brief This is a proxy from which rigid body proxys are handled.
98  /// @details This class is used to hold and configure the physics information for a rigid body.
99  /// This class holds physics information from the physics sub-library and serves as a means to interact with it.
100  /// Direct interaction with the internal physics proxy is discouraged.
101  ///////////////////////////////////////
103  {
104  protected:
105  /// @internal
106  /// @brief RigidBody proxy used by the internal physics.
107  btRigidBody* PhysicsRigidBody;
108  /*/// @internal
109  /// @brief
110  /// @internal
111  /// @brief Data related to sticky behavior, if any is enabled.
112  StickyData* StickyContacts;*/
113 
114  /// @internal
115  /// @brief Used to create the physics representation of the rigid body.
116  /// @param Mass The mass of the rigid body to be created.
117  virtual void CreateRigidObject(const Real Mass);
118  public:
119  /// @brief Class Constructor.
120  /// @param ID The unique ID assigned to this proxy.
121  /// @param Mass The mass of the rigid body.
122  /// @param Creator A pointer to the manager that created this proxy.
123  RigidProxy(const UInt32 ID, const Real Mass, PhysicsManager* Creator);
124  /// @brief Class Constructor.
125  /// @param ID The unique ID assigned to this proxy.
126  /// @param Mass The mass of the rigid body.
127  /// @param Shape A pointer to the collision shape that will be applied to this proxy.
128  /// @param Creator A pointer to the manager that created this proxy.
129  RigidProxy(const UInt32 ID, const Real Mass, CollisionShape* Shape, PhysicsManager* Creator);
130  /// @brief XML constructor.
131  /// @param SelfRoot An XML::Node containing the data to populate this class with.
132  /// @param Creator A pointer to the manager that created this proxy.
133  RigidProxy(const XML::Node& SelfRoot, PhysicsManager* Creator);
134  /// @brief Class Destructor
135  virtual ~RigidProxy();
136 
137  ///////////////////////////////////////////////////////////////////////////////
138  // Utility
139 
140  /// @copydoc WorldProxy::GetProxyType() const
141  virtual Mezzanine::ProxyType GetProxyType() const;
142 
143  /// @copydoc WorldProxy::AddToWorld()
144  virtual void AddToWorld();
145  /// @copydoc WorldProxy::RemoveFromWorld()
146  virtual void RemoveFromWorld();
147 
148  ///////////////////////////////////////////////////////////////////////////////
149  // Collision Settings
150 
151  /// @copydoc CollidableProxy::SetCollisionShape(CollisionShape*)
152  virtual void SetCollisionShape(CollisionShape* Shape);
153 
154  ///////////////////////////////////////////////////////////////////////////////
155  // Movement Factors
156 
157  /// @brief Restricts movement on the axis or axies of your choice.
158  /// @details This function can lock or limit any and all axes you define.
159  /// 0.0 means no linear movement on that axis. 1.0 means normal movement.
160  /// @param Factor Vector3 containing the Factors for the 3 linear axes.
161  virtual void SetLinearMovementFactor(const Vector3& Factor);
162  /// @brief Gets the current linear factors being applied to this actor.
163  /// @return Returns a Vector3 representing the factors on the 3 linear axes.
164  virtual Vector3 GetLinearMovementFactor() const;
165  /// @brief Restricts movement on the axis or axes of your choice.
166  /// @details This function can lock or limit any and all axes you define.
167  /// 0.0 means no angular movement on that axis. 1.0 means normal movement.
168  /// @param Factor Vector3 containing the Factors for the 3 angular axes.
169  virtual void SetAngularMovementFactor(const Vector3& Factor);
170  /// @brief Gets the current angular factors being applied to this actor.
171  /// @return Returns a Vector3 representing the factors on the 3 angular axes.
172  virtual Vector3 GetAngularMovementFactor() const;
173 
174  ///////////////////////////////////////////////////////////////////////////////
175  // Rigid Physics Properties
176 
177  /// @brief Change the mass of the proxy.
178  /// @param Mass The amount of mass this should have.
179  virtual void SetMass(const Real Mass);
180  /// @brief Get the total Mass of the proxy
181  /// @return A Real with the Mass of the proxy
182  virtual Real GetMass() const;
183 
184  /// @brief Sets the Damping for this proxy.
185  /// @details Both of Linear Damping and Angular Damping default to zero. This is useful if you wish to simulate
186  /// something like air resistance. Values can range from 0.0 to 1.0.
187  /// @param LinDamping Real representing the amount of Linear Damping(Movement) to be applied.
188  /// @param AngDamping Real representing the amount of Angular Damping(Rotation) to be applied.
189  virtual void SetDamping(const Real LinDamping, const Real AngDamping);
190  /// @brief Get the linear damping
191  /// @return A Real that has the Linear damping.
192  virtual Real GetLinearDamping() const;
193  /// @brief Get the Angular damping
194  /// @return A Real that has the Angular damping.
195  virtual Real GetAngularDamping() const;
196 
197  /// @brief Sets the Linear Velocity of this proxy.
198  /// @param LinVel Vector3 representing the Linear Velocity to be set.
199  virtual void SetLinearVelocity(const Vector3& LinVel);
200  /// @brief Gets the Linear Velocity of this proxy.
201  /// @return Returns the currently set Linear Velocity of this proxy.
202  virtual Vector3 GetLinearVelocity() const;
203  /// @brief Sets the Angular Velocity of this proxy.
204  /// @param AngVel Vector3 representing the Angular Velocity to be set.
205  virtual void SetAngularVelocity(const Vector3& AngVel);
206  /// @brief Gets the Angular Velocity of this proxy.
207  /// @return Returns the currently set Angular Velocity of this proxy.
208  virtual Vector3 GetAngularVelocity() const;
209 
210  /// @brief Sets the gravity for only this proxy.
211  /// @details This value will override the world gravity.
212  /// @param Gravity Vector3 representing the direction and strength of gravity to be applied.
213  virtual void SetGravity(const Vector3& Gravity);
214  /// @brief Gets the gravity being applied to this proxy.
215  /// @details This is the gravity applied to this proxy, which may or may not be the same as the world gravity.
216  /// @return Returns a Vector3 representing the gravity currently being applied to this proxy.
217  virtual Vector3 GetGravity() const;
218 
219  /// @brief Push/Apply force to an proxy.
220  /// @param Force The amount and direction of the force in a Vector3
221  virtual void ApplyForce(const Vector3& Force);
222  /// @brief Get the total Force currently being applied to this proxy.
223  /// @return Returns a Vector3 representing the amount of linear force being applied on each axis.
224  virtual Vector3 GetAppliedForce() const;
225  /// @brief Spin/Apply torque to an proxy.
226  /// @param Torque The amount and direction of the torque in a Vector3
227  virtual void ApplyTorque(const Vector3& Torque);
228  /// @brief Get the total Torque currently being applied to this proxy.
229  /// @return Returns a Vector3 representing the amount of angular force being applied on each axis.
230  virtual Vector3 GetAppliedTorque() const;
231 
232  ///////////////////////////////////////////////////////////////////////////////
233  // Sticky Data
234 
235  /*/// @brief Sets the basic parameters for enabling sticky behavior with this proxy.
236  /// @param MaxNumContacts The maximum number of proxy this proxy can stick to or have stuck to it.
237  virtual void SetStickyData(const Whole& MaxNumContacts);
238  /// @brief Removes all the constraints currently active on this proxy
239  virtual void ClearStickyContacts();
240  /// @brief Gets the struct storing the data related to sticky behavior.
241  /// @return Returns a pointer to the struct storing the sticky data for this proxy.
242  virtual StickyData* GetStickyData() const;// */
243 
244  ///////////////////////////////////////////////////////////////////////////////
245  // Transform Syncronization
246 
247  /// @brief Adds a TransformableObject that will force it's transform to sync with this RigidProxy.
248  /// @param ToBeAdded A pointer to the WorldObject being added.
249  virtual void AddSyncObject(TransformableObject* ToBeAdded);
250  /// @brief Gets a TransformableObject being sync'd to this RigidProxy by it's index.
251  /// @param Index The index of the sync object to retrieve.
252  /// @return Returns a pointer to the TransformableObject at the specified Index.
253  virtual TransformableObject* GetSyncObject(const UInt32 Index) const;
254  /// @brief Gets the number of WorldProxies being sync'd to this RigidProxy.
255  /// @return Returns a UInt32 representing the number of WorldProxies being sync'd with this RigidProxy.
256  virtual UInt32 GetNumSyncObjects() const;
257  /// @brief Removes a proxy being sync'd, so it will no longer match it's transform with this RigidProxy.
258  /// @param ToBeRemoved A pointer to the TransformableObject to be removed.
259  virtual void RemoveSyncObject(TransformableObject* ToBeRemoved);
260  /// @brief Removes all WorldProxies being sync'd to this RigidProxy.
261  virtual void RemoveAllSyncObjects();
262 
263  ///////////////////////////////////////////////////////////////////////////////
264  // Serialization
265 
266  /// @copydoc WorldProxy::ProtoSerializeProperties(XML::Node&) const
267  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
268  /// @copydoc WorldProxy::ProtoDeSerializeProperties(const XML::Node&)
269  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
270 
271  /// @copydoc WorldProxy::GetDerivedSerializableName() const
272  virtual String GetDerivedSerializableName() const;
273  /// @copydoc WorldProxy::GetSerializableName()
274  static String GetSerializableName();
275 
276  ///////////////////////////////////////////////////////////////////////////////
277  // Internal Methods
278 
279  /// @internal
280  /// @brief Accessor for the internal rigid body physics proxy.
281  /// @return Returns a pointer to the internal proxy this proxy is based on.
282  virtual btRigidBody* _GetPhysicsObject() const;
283  /// @copydoc CollidableProxy::_GetBasePhysicsObject()
284  virtual btCollisionObject* _GetBasePhysicsObject() const;
285  };//RigidProxy
286  }//Physics
287 }//Mezzanine
288 
289 #endif
This is the base class for all collision shapes.
This is a basic class for storing the data related to the sticky behavior available to rigid bodies...
Definition: rigidproxy.h:88
This is an interface for all 3D objects that can have their full transforms manipulated.
Simple struct for holding information on how sticky constraints should be constructed.
Definition: rigidproxy.h:64
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
btRigidBody * PhysicsRigidBody
RigidBody proxy used by the internal physics.
Definition: rigidproxy.h:107
ProxyType
Used by all World proxies to describe what their derived types are.
Definition: enumerations.h:91
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
The defintion of the transform is stored in this file.
This is a proxy from which rigid body proxys are handled.
Definition: rigidproxy.h:102
Stores information about relative location and rotation in 3d space.
Definition: transform.h:62
This is a proxy from which physics objects that can collide with each other are handled.
This is simply a place for storing all the Physics Related functions.
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
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159