MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rigidproxy.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 _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 Standard Constructor.
120  /// @param Mass The mass of the rigid body.
121  /// @param Creator A pointer to the manager that created this proxy.
122  RigidProxy(const Real Mass, PhysicsManager* Creator);
123  /// @brief XML constructor.
124  /// @param SelfRoot An XML::Node containing the data to populate this class with.
125  /// @param Creator A pointer to the manager that created this proxy.
126  RigidProxy(const XML::Node& SelfRoot, PhysicsManager* Creator);
127  /// @brief Class Destructor
128  virtual ~RigidProxy();
129 
130  ///////////////////////////////////////////////////////////////////////////////
131  // Utility
132 
133  /// @copydoc WorldProxy::GetProxyType() const
134  virtual Mezzanine::ProxyType GetProxyType() const;
135 
136  /// @copydoc WorldProxy::AddToWorld()
137  virtual void AddToWorld();
138  /// @copydoc WorldProxy::RemoveFromWorld()
139  virtual void RemoveFromWorld();
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  // Collision Settings
143 
144  /// @copydoc CollidableProxy::SetCollisionShape(CollisionShape*)
145  virtual void SetCollisionShape(CollisionShape* Shape);
146 
147  ///////////////////////////////////////////////////////////////////////////////
148  // Movement Factors
149 
150  /// @brief Restricts movement on the axis or axies of your choice.
151  /// @details This function can lock or limit any and all axes you define.
152  /// 0.0 means no linear movement on that axis. 1.0 means normal movement.
153  /// @param Factor Vector3 containing the Factors for the 3 linear axes.
154  virtual void SetLinearMovementFactor(const Vector3& Factor);
155  /// @brief Gets the current linear factors being applied to this actor.
156  /// @return Returns a Vector3 representing the factors on the 3 linear axes.
157  virtual Vector3 GetLinearMovementFactor() const;
158  /// @brief Restricts movement on the axis or axes of your choice.
159  /// @details This function can lock or limit any and all axes you define.
160  /// 0.0 means no angular movement on that axis. 1.0 means normal movement.
161  /// @param Factor Vector3 containing the Factors for the 3 angular axes.
162  virtual void SetAngularMovementFactor(const Vector3& Factor);
163  /// @brief Gets the current angular factors being applied to this actor.
164  /// @return Returns a Vector3 representing the factors on the 3 angular axes.
165  virtual Vector3 GetAngularMovementFactor() const;
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // Rigid Physics Properties
169 
170  /// @brief Change the mass of the proxy.
171  /// @param NewMass The amount of mass this should have.
172  virtual void SetMass(const Real Mass);
173  /// @brief Get the total Mass of the proxy
174  /// @return A Real with the Mass of the proxy
175  virtual Real GetMass() const;
176 
177  /// @brief Sets the Damping for this proxy.
178  /// @details Both of Linear Damping and Angular Damping default to zero. This is useful if you wish to simulate
179  /// something like air resistance. Values can range from 0.0 to 1.0.
180  /// @param LinDamping Real representing the amount of Linear Damping(Movement) to be applied.
181  /// @param AngDamping Real representing the amount of Angular Damping(Rotation) to be applied.
182  virtual void SetDamping(const Real LinDamping, const Real AngDamping);
183  /// @brief Get the linear damping
184  /// @return A Real that has the Linear damping.
185  virtual Real GetLinearDamping() const;
186  /// @brief Get the Angular damping
187  /// @return A Real that has the Angular damping.
188  virtual Real GetAngularDamping() const;
189 
190  /// @brief Sets the Linear Velocity of this proxy.
191  /// @param LinVel Vector3 representing the Linear Velocity to be set.
192  virtual void SetLinearVelocity(const Vector3& LinVel);
193  /// @brief Gets the Linear Velocity of this proxy.
194  /// @return Returns the currently set Linear Velocity of this proxy.
195  virtual Vector3 GetLinearVelocity() const;
196  /// @brief Sets the Angular Velocity of this proxy.
197  /// @param AngVel Vector3 representing the Angular Velocity to be set.
198  virtual void SetAngularVelocity(const Vector3& AngVel);
199  /// @brief Gets the Angular Velocity of this proxy.
200  /// @return Returns the currently set Angular Velocity of this proxy.
201  virtual Vector3 GetAngularVelocity() const;
202 
203  /// @brief Sets the gravity for only this proxy.
204  /// @details This value will override the world gravity.
205  /// @param Gravity Vector3 representing the direction and strength of gravity to be applied.
206  virtual void SetGravity(const Vector3& Gravity);
207  /// @brief Gets the gravity being applied to this proxy.
208  /// @details This is the gravity applied to this proxy, which may or may not be the same as the world gravity.
209  /// @return Returns a Vector3 representing the gravity currently being applied to this proxy.
210  virtual Vector3 GetGravity() const;
211 
212  /// @brief Push/Apply force to an proxy.
213  /// @param Force The amount and direction of the force in a Vector3
214  virtual void ApplyForce(const Vector3& Force);
215  /// @brief Get the total Force currently being applied to this proxy.
216  /// @return Returns a Vector3 representing the amount of linear force being applied on each axis.
217  virtual Vector3 GetAppliedForce() const;
218  /// @brief Spin/Apply torque to an proxy.
219  /// @param Torque The amount and direction of the torque in a Vector3
220  virtual void ApplyTorque(const Vector3& Torque);
221  /// @brief Get the total Torque currently being applied to this proxy.
222  /// @return Returns a Vector3 representing the amount of angular force being applied on each axis.
223  virtual Vector3 GetAppliedTorque() const;
224 
225  ///////////////////////////////////////////////////////////////////////////////
226  // Sticky Data
227 
228  /*/// @brief Sets the basic parameters for enabling sticky behavior with this proxy.
229  /// @param MaxNumContacts The maximum number of proxy this proxy can stick to or have stuck to it.
230  virtual void SetStickyData(const Whole& MaxNumContacts);
231  /// @brief Removes all the constraints currently active on this proxy
232  virtual void ClearStickyContacts();
233  /// @brief Gets the struct storing the data related to sticky behavior.
234  /// @return Returns a pointer to the struct storing the sticky data for this proxy.
235  virtual StickyData* GetStickyData() const;//*/
236 
237  ///////////////////////////////////////////////////////////////////////////////
238  // Transform Syncronization
239 
240  /// @brief Adds a TransformableObject that will force it's transform to sync with this RigidProxy.
241  /// @param ToBeAdded A pointer to the WorldObject being added.
242  virtual void AddSyncObject(TransformableObject* ToBeAdded);
243  /// @brief Gets a TransformableObject being sync'd to this RigidProxy by it's index.
244  /// @param Index The index of the sync object to retrieve.
245  /// @return Returns a pointer to the TransformableObject at the specified Index.
246  virtual TransformableObject* GetSyncObject(const UInt32 Index) const;
247  /// @brief Gets the number of WorldProxies being sync'd to this RigidProxy.
248  /// @return Returns a UInt32 representing the number of WorldProxies being sync'd with this RigidProxy.
249  virtual UInt32 GetNumSyncObjects() const;
250  /// @brief Removes a proxy being sync'd, so it will no longer match it's transform with this RigidProxy.
251  /// @param ToBeRemoved A pointer to the TransformableObject to be removed.
252  virtual void RemoveSyncObject(TransformableObject* ToBeRemoved);
253  /// @brief Removes all WorldProxies being sync'd to this RigidProxy.
254  virtual void RemoveAllSyncObjects();
255 
256  ///////////////////////////////////////////////////////////////////////////////
257  // Serialization
258 
259  /// @copydoc WorldProxy::ProtoSerializeProperties(XML::Node&) const
260  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
261  /// @copydoc WorldProxy::ProtoDeSerializeProperties(const XML::Node&)
262  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
263 
264  /// @copydoc WorldProxy::GetDerivedSerializableName() const
265  virtual String GetDerivedSerializableName() const;
266  /// @copydoc WorldProxy::GetSerializableName()
267  static String GetSerializableName();
268 
269  ///////////////////////////////////////////////////////////////////////////////
270  // Internal Methods
271 
272  /// @internal
273  /// @brief Accessor for the internal rigid body physics proxy.
274  /// @return Returns a pointer to the internal proxy this proxy is based on.
275  virtual btRigidBody* _GetPhysicsObject() const;
276  /// @copydoc CollidableProxy::_GetBasePhysicsObject()
277  virtual btCollisionObject* _GetBasePhysicsObject() const;
278  };//RigidProxy
279  }//Physics
280 }//Mezzanine
281 
282 #endif