Spinning Topp Logo BlackTopp Studios
inc
generic6dofspringconstraint.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 _physicsgeneric6dofspringconstraint_h
41 #define _physicsgeneric6dofspringconstraint_h
42 
43 #include "Physics/generic6dofconstraint.h"
44 
45 class btGeneric6DofSpringConstraint;
46 
47 namespace Mezzanine
48 {
49  namespace Physics
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class Generic6DofSpringConstraint
53  /// @brief Creates a constraint as configurable as the 6Dof constraint, but has added support for spring motion.
54  /// @details When using functions of this class that require you to specify the index, the springs are arranged like so: @n
55  /// - 0: Translation X
56  /// - 1: Translation Y
57  /// - 2: Translation Z
58  /// - 3: Rotation X
59  /// - 4: Rotation Y
60  /// - 5: Rotation Z
61  ///////////////////////////////////////
63  {
64  protected:
65  /// @copydoc TypedConstraint::_GetConstraintBase() const
66  virtual btGeneric6DofSpringConstraint* Generic6dofSpring() const;
67 
68  /// @copydoc DualTransformConstraint::CreateConstraint(RigidProxy*, RigidProxy*, const Transform&, const Transform&)
69  virtual void CreateConstraint(RigidProxy* RigidA, RigidProxy* RigidB, const Transform& TransA, const Transform& TransB);
70 
71  /// @internal
72  /// @brief Single body inheritance constructor.
73  /// @param ID The unique identifier assigned to this constraint.
74  /// @param Prox1 A pointer to the first/only proxy that will be constrained.
75  /// @param Creator A pointer to the manager that created this constraint.
76  Generic6DofSpringConstraint(const UInt32 ID, RigidProxy* Prox1, PhysicsManager* Creator);
77  /// @internal
78  /// @brief Dual body inheritance constructor.
79  /// @param ID The unique identifier assigned to this constraint.
80  /// @param Prox1 A pointer to the first proxy that will be constrained.
81  /// @param Prox2 A pointer to the second proxy that will be constrained.
82  /// @param Creator A pointer to the manager that created this constraint.
83  Generic6DofSpringConstraint(const UInt32 ID, RigidProxy* Prox1, RigidProxy* Prox2, PhysicsManager* Creator);
84  public:
85  /// @brief Two proxy Terse constructor.
86  /// @param ID The unique identifier assigned to this constraint.
87  /// @param ProxyA The First proxy to be bound.
88  /// @param ProxyB The Second proxy to be bound.
89  /// @param TransA The offset and rotation from ProxyAs center of gravity to get to match an offset from ProxyB.
90  /// @param TransB The offset and rotation from ProxyBs center of gravity.
91  /// @param Creator A pointer to the manager that created this constraint.
92  Generic6DofSpringConstraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransA, const Transform& TransB, PhysicsManager* Creator);
93  /// @brief XML constructor.
94  /// @param SelfRoot An XML::Node containing the data to populate this class with.
95  /// @param Creator A pointer to the manager that created this constraint.
96  Generic6DofSpringConstraint(const XML::Node& SelfRoot, PhysicsManager* Creator);
97  /// @brief Class destructor.
98  virtual ~Generic6DofSpringConstraint();
99 
100  ////////////////////////////////////////////////////////////////////////////////
101  // Utility
102 
103  /// @brief Autogenerates the equalibrium points on each axis of this constraint.
104  /// @remarks The current offsets of both bodies in constraint space is what is used as
105  /// the equalibrium points for each axis.
106  virtual void CalculateSpringEquilibriumPoints();
107 
108  ////////////////////////////////////////////////////////////////////////////////
109  // Linear Spring Settings
110 
111  /// @brief Set the Stiffness of the springs on each Linear Axis.
112  /// @param Stiffness A Vector3 containing the X, Y and Z stiffnesses.
113  virtual void SetLinearSpringStiffness(const Vector3& Stiffness);
114  /// @brief Get the Stiffness for all Linear Axis
115  /// @return A Vector3 with the Stiffness on the X, Y and Z Linear Axis.
116  virtual Vector3 GetLinearSpringStiffness() const;
117  /// @brief Sets the stiffness on a specific linear axis on this constraint.
118  /// @param Stiffness The amount of resistence to compressing force the spring should have.
119  /// @param TranslationAxis The Axis to work with.
120  virtual void SetLinearSpringStiffnessOnAxis(const Real Stiffness, Whole TranslationAxis);
121  /// @brief Gets the stiffness on a specific linear axis on this constraint.
122  /// @param TranslationAxis The Axis to work with.
123  /// @return Returns the currently set stiffness on the specified axis.
124  virtual Real GetLinearSpringStiffnessOnAxis(Whole TranslationAxis) const;
125 
126  /// @brief Set the Damping of the springs on each Linear Axis.
127  /// @param Damps A Vector3 containing the X, Y and Z desired damping.
128  virtual void SetLinearSpringDamping(const Vector3& Damps);
129  /// @brief Get the Damping for all Linear Axis
130  /// @return A Vector3 with the Damping on the X, Y and Z Linear Axis.
131  virtual Vector3 GetLinearSpringDamping() const;
132  /// @brief Sets the damping on a specific linear axis on this constraint.
133  /// @param Damping The amount of damping to apply to all movement on the spring.
134  /// @param TranslationAxis The Axis to work with.
135  virtual void SetLinearSpringDampingOnAxis(const Real Damping, Whole TranslationAxis);
136  /// @brief Gets the damping on a specific linear axis on this constraint.
137  /// @param TranslationAxis The Axis to work with.
138  /// @return Returns the currently set damping on the specified axis.
139  virtual Real GetLinearSpringDampingOnAxis(Whole TranslationAxis) const;
140 
141  /// @brief Set whether or not a spring is enabled on a specific linear axis on this constraint.
142  /// @param Stiffies A Vector3 containing the X, Y and Z enabled statuses. This is interpretted as 0 for false and any other value for true.
143  virtual void SetLinearSpringEnabled(const Vector3& Enabled);
144  /// @brief Get the Enabled Status for all Linear Axis
145  /// @return A Vector3 with the Enabled Status on the X, Y and Z Linear Axis.
146  virtual Vector3 GetLinearSpringEnabled() const;
147  /// @brief Set whether or not a spring is enabled on a specific linear axis on this constraint.
148  /// @param Enabled The enabled status of the spring on the specified axis.
149  /// @param TranslationAxis The Axis to work with.
150  virtual void SetLinearSpringEnabledOnAxis(const Boole Enabled, Whole TranslationAxis);
151  /// @brief Get whether or not a spring is enabled on a specific linear axis on this constraint.
152  /// @param TranslationAxis The Axis to work with.
153  /// @return Returns true if the spring on the specified axis is enabled, false otherwise.
154  virtual Boole GetLinearSpringEnabledOnAxis(Whole TranslationAxis) const;
155 
156  /// @brief Gets the rest point of the spring on each Linear axis.
157  /// @return Returns a Vector3 containing the values of the rest position on the respective axis in constraint space.
158  virtual Vector3 GetLinearSpringEquilibriumPoints() const;
159 
160  ////////////////////////////////////////////////////////////////////////////////
161  // Angular Spring Settings
162 
163  /// @brief Set the Stiffness of the springs on each Angular Axis.
164  /// @param Stiffness A Vector3 containing the X, Y and Z stiffnesses.
165  virtual void SetAngularSpringStiffness(const Vector3& Stiffness);
166  /// @brief Get the Stiffness for all Angular Axis
167  /// @return A Vector3 with the Stiffness on the X, Y and Z Angular Axis.
168  virtual Vector3 GetAngularSpringStiffness() const;
169  /// @brief Sets the stiffness on a specific angular axis on this constraint.
170  /// @param Stiffness The amount of resistence to compressing force the spring should have.
171  /// @param RotationAxis The Axis to work with.
172  virtual void SetAngularSpringStiffnessOnAxis(const Real Stiffness, Whole RotationAxis);
173  /// @brief Gets the stiffness on a specific angular axis on this constraint.
174  /// @param RotationAxis The Axis to work with.
175  /// @return Returns the currently set stiffness on the specified axis.
176  virtual Real GetAngularSpringStiffnessOnAxis(Whole RotationAxis) const;
177 
178  /// @brief Set the Damping of the springs on each Angular Axis.
179  /// @param Damps A Vector3 containing the X, Y and Z desired damping.
180  virtual void SetAngularSpringDamping(const Vector3& Damps);
181  /// @brief Get the Damping for all Angular Axis
182  /// @return A Vector3 with the Damping on the X, Y and Z Angular Axis.
183  virtual Vector3 GetAngularSpringDamping() const;
184  /// @brief Sets the damping on a specific angular axis on this constraint.
185  /// @param Damping The amount of damping to apply to all movement on the spring.
186  /// @param RotationAxis The Axis to work with.
187  virtual void SetAngularSpringDampingOnAxis(const Real Damping, Whole RotationAxis);
188  /// @brief Gets the damping on a specific angular axis on this constraint.
189  /// @param RotationAxis The Axis to work with.
190  /// @return Returns the currently set damping on the specified axis.
191  virtual Real GetAngularSpringDampingOnAxis(Whole RotationAxis) const;
192 
193  /// @brief Set the Stiffness of the springs on each Angular Axis.
194  /// @param Stiffies A Vector3 containing the X, Y and Z enabled statuses. This is interpretted as 0 for false and any other value for true.
195  virtual void SetAngularSpringEnabled(const Vector3& Enableness);
196  /// @brief Get the Enabled Status for all Angular Axis
197  /// @return A Vector3 with the Enabled Status on the X, Y and Z Angular Axis.
198  virtual Vector3 GetAngularSpringEnabled() const;
199  /// @brief Set whether or not a spring is enabled on a specific angular axis on this constraint.
200  /// @param Enabled The enabled status of the spring on the specified axis.
201  /// @param RotationAxis The Axis to work with.
202  virtual void SetAngularSpringEnabledOnAxis(const Boole Enabled, Whole RotationAxis);
203  /// @brief Get whether or not a spring is enabled on a specific angular axis on this constraint.
204  /// @param RotationAxis The Axis to work with.
205  /// @return Returns true if the spring on the specified axis is enabled, false otherwise.
206  virtual Boole GetAngularSpringEnabledOnAxis(Whole RotationAxis) const;
207 
208  /// @brief Gets the rest point of the spring on each Angular axis.
209  /// @return Returns a Vector3 containing the values of the rest position on the respective axis in constraint space.
210  virtual Vector3 GetAngularSpringEquilibriumPoints() const;
211 
212  ////////////////////////////////////////////////////////////////////////////////
213  // Combined Linear and Angular Axis Spring Settings
214 
215  /// @brief Set the spring stiffness on a given axis
216  /// @param Index The Desired axis. This accepts 0,1,2 for Linear X,Y, and Z or 3,4,5 for Angular X,Y, and Z. This can also accept Item from this classes Usable Axis enum;
217  /// @param Stiffness A real with the new desired stiffness.
218  virtual void SetSpringStiffness(int Index, Real Stiffness);
219  /// @brief Retrieve the Stiffness of the spring on the given axis
220  /// @param Index The Desired axis. This accepts 0,1,2 for Linear X,Y, and Z or 3,4,5 for Angular X,Y, and Z. This can also accept Item from this classes Usable Axis enum;
221  /// @return A real with the requested value;
222  virtual Real GetSpringStiffness(int Index) const;
223 
224  /// @brief Set the spring Damping on a given axis.
225  /// @param Index The Desired axis. This accepts 0,1,2 for Linear X,Y, and Z or 3,4,5 for Angular X,Y, and Z. This can also accept Item from this classes Usable Axis enum;
226  /// @param Damping A real with the new desired Damping.
227  virtual void SetSpringDamping(int Index, Real Damping);
228  /// @brief Retrieve the Damping of the spring on the given axis
229  /// @param Index The Desired axis. This accepts 0,1,2 for Linear X,Y, and Z or 3,4,5 for Angular X,Y, and Z. This can also accept Item from this classes Usable Axis enum;
230  /// @return A real with the requested value.
231  virtual Real GetSpringDamping(int Index) const;
232 
233  /// @brief Set the spring's enabled status on a given axis.
234  /// @param Index The Desired axis. This accepts 0,1,2 for Linear X,Y, and Z or 3,4,5 for Angular X,Y, and Z. This can also accept Item from this classes Usable Axis enum;
235  /// @param Enable A Boole with the spring's enabled status.
236  virtual void SetSpringEnabled(int Index, Boole Enable);
237  /// @brief Retrieve the EnabledStatus of the spring on the given axis
238  /// @param Index The Desired axis. This accepts 0,1,2 for Linear X,Y, and Z or 3,4,5 for Angular X,Y, and Z. This can also accept Item from this classes Usable Axis enum;
239  /// @return A Boole with the requested value.
240  virtual Boole GetSpringEnabled(int Index) const;
241 
242  /// @brief Automatically assigns the rest point of the spring on the specified axis based on the current offset of both constrained bodies.
243  /// @param Index The Axis to work with.
244  virtual void CalculateSpringEquilibriumPoint(int Index);
245  /// @brief Sets the rest point of the spring on the specified axis.
246  /// @param Index The Axis to work with.
247  /// @param Point The position in constraint space on the specified Axis to set as the rest spot.
248  virtual void SetSpringEquilibriumPoint(int Index, const Real Point);
249  /// @brief Gets the rest point of the spring on the specified axis.
250  /// @param Index The Axis to work with.
251  virtual Real GetSpringEquilibriumPoint(int Index) const;
252 
253  ////////////////////////////////////////////////////////////////////////////////
254  // Serialization
255 
256  /// @copydoc Constraint::ProtoSerializeProperties(XML::Node&) const
257  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
258  /// @copydoc Constraint::ProtoDeSerializeProperties(const XML::Node&)
259  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
260 
261  /// @copydoc Constraint::GetDerivedSerializableName() const
262  virtual String GetDerivedSerializableName() const;
263  /// @brief Get the name of the the XML tag the class will leave behind as its instances are serialized.
264  /// @return A string containing the name of this class.
265  static String GetSerializableName();
266  };//Generic6DofSpringConstraint
267  }//Physics
268 }//Mezzanine
269 
270 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Create simple but specific limits on any axis of movement or rotation.
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
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
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 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
Creates a constraint as configurable as the 6Dof constraint, but has added support for spring motion...
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159