Spinning Topp Logo BlackTopp Studios
inc
sliderconstraint.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 _physicssliderconstraint_h
41 #define _physicssliderconstraint_h
42 
43 #include "Physics/dualtransformconstraint.h"
44 
45 class btSliderConstraint;
46 
47 namespace Mezzanine
48 {
49  namespace Physics
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class SliderConstraint
53  /// @brief This is a constraint for permitting movement on only a singular linear or angular axis.
54  /// @details This class comes with an unusually high amount of parameters that can be set. A lot of the parameters are obsolete but remain
55  /// in the class in case they become used again or their boilerplate is proven to be useful. In other words, they exist because they are
56  /// still there in the internal implementation so we reflect that.
57  /// @n @n
58  /// Like other constraints with limits, such as the ConeTwistConstraint, there are a small series of parameters that control how the constraint
59  /// is to behave when near, at, or beyond it's set limits. In the case of the Slider they are; Softness, Damping, and Restituion. @n
60  /// Constraint Softness is the act of applying a pre-emptive force to smooth out the force to be applied. Lower values means a smoother
61  /// transition from further away from the limit whereas higher values mean a more rapid transition closer to the limit. Values should be in
62  /// a range of 0.0-1.0. Values in the higher end of the range (0.9-1.0) are recommended. @n
63  /// Constraint Damping is similar to damping in other parts of the physics engine. It is more-or-less something that inhibits movement along
64  /// appropriate axes. Damping is useful to simulate some forms of friction, or even air resistance. Values should be in a range of 0.0-1.0.
65  /// Values in the higher end of the range (0.7-1.0) are recommended. @n
66  /// Constraint Restitution is also similar to other parts of the physics engine. It is the force applied back after a limit is reached, based
67  /// on the size of the force that hit the limit. Larger values mean it'll bounce back more, whereas lower values will give little to no bounce
68  /// back. Values should in a range of 0.0-1.0. Values in the lower end of the range (0.0-0.3) are recommended.
69  /// @n @n
70  /// To further complicate the SliderConstraint compared to other systems in the physics subsystem, there are multiple types of limits defined.
71  /// The different properties mentioned above can be used at different times depending on the position of the child object and how it is moving. @n
72  /// The definition of the "Dir" prefix used in the SliderConstraint methods is unknown, but it applies to whenever the child object is within
73  /// the set limits of the constraint and moving along the configured axis of the constraint. @n
74  /// The definition of the "Lim" prefix is "Limit", and it applies to whenever the child object hits the configured limit of the constraint along
75  /// the configured axis of the constraint. @n
76  /// The definition of the "Ortho" prefix is "Orthogonal", and it applies to any forces that are enacted on the child object that force it to
77  /// move against the configured axis on the constraint.
78  ///////////////////////////////////////
80  {
81  protected:
82  /// @internal
83  /// @brief Bullet constraint that this class encapsulates.
84  btSliderConstraint* Slider;
85 
86  /// @copydoc DualTransformConstraint::CreateConstraint(RigidProxy*, RigidProxy*, const Transform&, const Transform&)
87  virtual void CreateConstraint(RigidProxy* RigidA, RigidProxy* RigidB, const Transform& TransA, const Transform& TransB);
88  /// @copydoc DualTransformConstraint::DestroyConstraint()
89  virtual void DestroyConstraint();
90  public:
91  /// @brief Two body Terse constructor.
92  /// @param ID The unique identifier assigned to this constraint.
93  /// @param ProxyA The First proxy to be bound.
94  /// @param ProxyB The Second proxy to be bound.
95  /// @param TransA The offset and rotation from ProxyA's center of gravity to get to match an offset from ProxyB.
96  /// @param TransB The offset and rotation from ProxyB's center of gravity.
97  /// @param Creator A pointer to the manager that created this constraint.
98  SliderConstraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransA, const Transform& TransB, PhysicsManager* Creator);
99  /// @brief Standard one body constructor.
100  /// @param ID The unique identifier assigned to this constraint.
101  /// @param ProxyA The First proxy to be bound.
102  /// @param TransA The offset and rotation from ProxyA's center of gravity.
103  /// @param Creator A pointer to the manager that created this constraint.
104  SliderConstraint(const UInt32 ID, RigidProxy* ProxyA, const Transform& TransA, PhysicsManager* Creator);
105  /// @brief XML constructor.
106  /// @param SelfRoot An XML::Node containing the data to populate this class with.
107  /// @param Creator A pointer to the manager that created this constraint.
108  SliderConstraint(const XML::Node& SelfRoot, PhysicsManager* Creator);
109  /// @brief Class destructor.
110  virtual ~SliderConstraint();
111 
112  ////////////////////////////////////////////////////////////////////////////////
113  // Location and Rotation
114 
115  /// @copydoc DualTransformConstraint::SetPivotTransforms(const Transform&, const Transform&)
116  virtual void SetPivotTransforms(const Transform& TransA, const Transform& TransB);
117  /// @copydoc DualTransformConstraint::SetPivotATransform(const Transform&)
118  virtual void SetPivotATransform(const Transform& TranA);
119  /// @copydoc DualTransformConstraint::SetPivotBTransform(const Transform&)
120  virtual void SetPivotBTransform(const Transform& TranB);
121  /// @copydoc DualTransformConstraint::GetPivotATransform()
122  virtual Transform GetPivotATransform() const;
123  /// @copydoc DualTransformConstraint::GetPivotBTransform()
124  virtual Transform GetPivotBTransform() const;
125 
126  /// @copydoc DualTransformConstraint::SetPivotALocation(const Vector3&)
127  virtual void SetPivotALocation(const Vector3& Location);
128  /// @copydoc DualTransformConstraint::SetPivotBLocation(const Vector3&)
129  virtual void SetPivotBLocation(const Vector3& Location);
130  /// @copydoc DualTransformConstraint::GetPivotALocation()
131  virtual Vector3 GetPivotALocation() const;
132  /// @copydoc DualTransformConstraint::GetPivotBLocation()
133  virtual Vector3 GetPivotBLocation() const;
134 
135  /// @copydoc DualTransformConstraint::SetPivotARotation(const Quaternion&)
136  virtual void SetPivotARotation(const Quaternion& Rotation);
137  /// @copydoc DualTransformConstraint::SetPivotBRotation(const Quaternion&)
138  virtual void SetPivotBRotation(const Quaternion& Rotation);
139  /// @copydoc DualTransformConstraint::GetPivotARotation()
140  virtual Quaternion GetPivotARotation() const;
141  /// @copydoc DualTransformConstraint::GetPivotBRotation()
142  virtual Quaternion GetPivotBRotation() const;
143 
144  ////////////////////////////////////////////////////////////////////////////////
145  // Utility
146 
147  /// @brief Sets whether or not an offset of the constraint frame should be used to calculate internal data.
148  /// @param FrameOffset The full effect of this being true or false is uknown, but internal documentation suggests "true" provides more stable results.
149  virtual void SetUseFrameOffset(const Boole FrameOffset);
150  /// @brief Gets whether or not an offset of the constraint frame should be used to calculate internal data.
151  /// @return Returns whether or not an offset in the constraint frame is being used by the internal constraint.
152  virtual Boole GetUseFrameOffset() const;
153 
154  /// @brief Sets the upper linear limit of this slider.
155  /// @param UpperLimit The upper limit for sliding on the linear axis.
156  virtual void SetUpperLinLimit(const Real UpperLimit);
157  /// @brief Gets the upper linear limit of this slider.
158  /// @return Returns a Real representing the current upper limit for sliding on the linear axis.
159  virtual Real GetUpperLinLimit() const;
160  /// @brief Sets the upper angular limit of this slider.
161  /// @param UpperLimit The upper limit for sliding on the angular axis.
162  virtual void SetUpperAngLimit(const Real UpperLimit);
163  /// @brief Gets the upper angular limit of this slider.
164  /// @return Returns a Real representing the current upper limit for sliding on the angular axis.
165  virtual Real GetUpperAngLimit() const;
166  /// @brief Sets the lower linear limit of this slider.
167  /// @param LowerLimit The lower limit for sliding on the linear axis.
168  virtual void SetLowerLinLimit(const Real LowerLimit);
169  /// @brief Gets the lower linear limit of this slider.
170  /// @return Returns a Real representing the current lower limit for sliding on the linear axis.
171  virtual Real GetLowerLinLimit() const;
172  /// @brief Sets the lower angular limit of this slider.
173  /// @param LowerLimit The lower limit for sliding on the angular axis.
174  virtual void SetLowerAngLimit(const Real LowerLimit);
175  /// @brief Gets the lower angular limit of this slider.
176  /// @return Returns a Real representing the current lower limit for sliding on the angular axis.
177  virtual Real GetLowerAngLimit() const;
178 
179  /// @brief Sets whether or not the motor for the linear axis of this constraint is enabled.
180  /// @param OnOff True to enabled the motor, false to disable it.
181  virtual void SetPoweredLinMotor(const Boole OnOff);
182  /// @brief Gets whether or not the motor for the linear axis of this constraint is enabled.
183  /// @return Returns true if the motor is currently enabled, false otherwise.
184  virtual Boole GetPoweredLinMotor() const;
185  /// @brief Sets whether or not the motor for the angular axis of this constraint is enabled.
186  /// @param OnOffTrue to enabled the motor, false to disable it.
187  virtual void SetPoweredAngMotor(const Boole OnOff);
188  /// @brief Gets whether or not the motor for the angular axis of this constraint is enabled.
189  /// @return Returns true if the motor is currently enabled, false otherwise.
190  virtual Boole GetPoweredAngMotor() const;
191  /// @brief Sets the target velocity of the motor on the linear axis of ths constraint.
192  /// @param TargetLinMotorVelocity The target velocity to acheive, which determines the amount of force to apply on the axis.
193  virtual void SetTargetLinMotorVelocity(const Real TargetLinMotorVelocity);
194  /// @brief Gets the target velocity of the motor on the linear axis of ths constraint.
195  /// @return Returns a Real representing how fast the motor should drive the constrained object on the linear axis of the constraint.
196  virtual Real GetTargetLinMotorVelocity() const;
197  /// @brief Sets the target velocity of the motor on the angular axis of ths constraint.
198  /// @param TargetAngMotorVelocity The target velocity to acheive, which determines the amount of force to apply on the axis.
199  virtual void SetTargetAngMotorVelocity(const Real TargetAngMotorVelocity);
200  /// @brief Gets the target velocity of the motor on the angular axis of ths constraint.
201  /// @return Returns a Real representing how fast the motor should drive the constrained object on the angular axis of the constraint.
202  virtual Real GetTargetAngMotorVelocity() const;
203  /// @brief Sets the maximum force allowed to be applied on the linear axis of this constraint.
204  /// @param MaxLinMotorForce The cap for the force that can be appled to the child object on the linear axis of this constraint.
205  virtual void SetMaxLinMotorForce(const Real MaxLinMotorForce);
206  /// @brief Gets the maximum force allowed to be applied on the linear axis of this constraint.
207  /// @return Returns a Real representing the maximum allowed force on the linear axis of this constraint.
208  virtual Real GetMaxLinMotorForce() const;
209  /// @brief Sets the maximum force allowed to be applied on the angular axis of this constraint.
210  /// @param MaxAngMotorForce The cap for the force that can be appled to the child object on the angular axis of this constraint.
211  virtual void SetMaxAngMotorForce(const Real MaxAngMotorForce);
212  /// @brief Gets the maximum force allowed to be applied on the angular axis of this constraint.
213  /// @return Returns a Real representing the maximum allowed force on the angular axis of this constraint.
214  virtual Real GetMaxAngMotorForce() const;
215 
216  /// @brief Sets the softness value to be used when hitting the linear limit of this constraint.
217  /// @param SoftnessLimLin The softness value to be set for the linear axis.
218  virtual void SetSoftnessLimLin(const Real SoftnessLimLin);
219  /// @brief Gets the softness value to be used when hitting the linear limit of this constraint.
220  /// @return Returns a Real representing the current softness on the linear axis.
221  virtual Real GetSoftnessLimLin() const;
222  /// @brief Sets the softness value to be used when hitting the angular limit of this constraint.
223  /// @param SoftnessLimAng The softness value to be set for the angular axis.
224  virtual void SetSoftnessLimAng(const Real SoftnessLimAng);
225  /// @brief Gets the softness value to be used when hitting the angular limit of this constraint.
226  /// @return Returns a Real representing the current softness on the angular axis.
227  virtual Real GetSoftnessLimAng() const;
228  /// @brief Sets the softness value to be used when force is applied against the configured linear axis of this constraint.
229  /// @param SoftnessOrthoLin The softness value to be set for the linear axis.
230  virtual void SetSoftnessOrthoLin(const Real SoftnessOrthoLin);
231  /// @brief Gets the softness value to be used when force is applied against the configured linear axis of this constraint.
232  /// @return Returns a Real representing the current softness on the linear axis.
233  virtual Real GetSoftnessOrthoLin() const;
234  /// @brief Sets the softness value to be used when force is applied against the configured angular axis of this constraint.
235  /// @param SoftnessOrthoAng The softness value to be set for the angular axis.
236  virtual void SetSoftnessOrthoAng(const Real SoftnessOrthoAng);
237  /// @brief Gets the softness value to be used when force is applied against the configured angular axis of this constraint.
238  /// @return Returns a Real representing the current softness on the angular axis.
239  virtual Real GetSoftnessOrthoAng() const;
240 
241  ///////////////////////////////////////////////////////////////////////////////
242  // Obsolete Methods - All methods listed in this subsection appears to alter deprecated/unused data
243 
244  /// @brief Sets the softness value to be used when within the linear limits of this constraint.
245  /// @param SoftnessDirLin The softness value to be set for the linear axis.
246  virtual void SetSoftnessDirLin(const Real SoftnessDirLin);
247  /// @brief Gets the softness value to be used when within the linear limits of this constraint.
248  /// @return Returns a Real representing the current softness on the linear axis.
249  virtual Real GetSoftnessDirLin() const;
250  /// @brief Sets the softness value to be used when within the angular limits of this constraint.
251  /// @param SoftnessDirAng The softness value to be set for the angular axis.
252  virtual void SetSoftnessDirAng(const Real SoftnessDirAng);
253  /// @brief Gets the softness value to be used when within the angular limits of this constraint.
254  /// @return Returns a Real representing the current softness on the angular axis.
255  virtual Real GetSoftnessDirAng() const;
256 
257  /// @brief Sets the damping value to be used when within the linear limits of this constraint.
258  /// @param DampingDirLin The damping value to be set for the linear axis.
259  virtual void SetDampingDirLin(const Real DampingDirLin);
260  /// @brief Gets the damping value to be used when within the linear limits of this constraint.
261  /// @return Returns a Real representing the current damping on the linear axis.
262  virtual Real GetDampingDirLin() const;
263  /// @brief Sets the damping value to be used when within the angular limits of this constraint.
264  /// @param DampingDirAng The damping value to be set for the angular axis.
265  virtual void SetDampingDirAng(const Real DampingDirAng);
266  /// @brief Gets the damping value to be used when within the angular limits of this constraint.
267  /// @return Returns a Real representing the current damping on the angular axis.
268  virtual Real GetDampingDirAng() const;
269  /// @brief Sets the damping value to be used when hitting the linear limit of this constraint.
270  /// @param DampingLimLin The damping value to be set for the linear axis.
271  virtual void SetDampingLimLin(const Real DampingLimLin);
272  /// @brief Gets the damping value to be used when hitting the linear limit of this constraint.
273  /// @return Returns a Real representing the current damping on the linear axis.
274  virtual Real GetDampingLimLin() const;
275  /// @brief Sets the damping value to be used when hitting the angular limit of this constraint.
276  /// @param DampingLimAng The damping value to be set for the angular axis.
277  virtual void SetDampingLimAng(const Real DampingLimAng);
278  /// @brief Gets the damping value to be used when hitting the angular limit of this constraint.
279  /// @return Returns a Real representing the current damping on the angular axis.
280  virtual Real GetDampingLimAng() const;
281  /// @brief Sets the damping value to be used when force is applied against the configured linear axis of this constraint.
282  /// @param DampingOrthoLin The damping value to be set for the linear axis.
283  virtual void SetDampingOrthoLin(const Real DampingOrthoLin);
284  /// @brief Gets the damping value to be used when force is applied against the configured linear axis of this constraint.
285  /// @return Returns a Real representing the current damping on the linear axis.
286  virtual Real GetDampingOrthoLin() const;
287  /// @brief Sets the damping value to be used when force is applied against the configured angular axis of this constraint.
288  /// @param DampingOrthoAng The damping value to be set for the angular axis.
289  virtual void SetDampingOrthoAng(const Real DampingOrthoAng);
290  /// @brief Gets the damping value to be used when force is applied against the configured angular axis of this constraint.
291  /// @return Returns a Real representing the current damping on the angular axis.
292  virtual Real GetDampingOrthoAng() const;
293 
294  /// @brief Sets the restitution value to be used when within the linear limits of this constraint.
295  /// @param RestitutionDirLin The restitution value to be set for the linear axis.
296  virtual void SetRestitutionDirLin(const Real RestitutionDirLin);
297  /// @brief Gets the restitution value to be used when within the linear limits of this constraint.
298  /// @return Returns a Real representing the current restitution on the linear axis.
299  virtual Real GetRestitutionDirLin() const;
300  /// @brief Sets the restitution value to be used when within the angular limits of this constraint.
301  /// @param RestitutionDirAng The restitution value to be set for the angular axis.
302  virtual void SetRestitutionDirAng(const Real RestitutionDirAng);
303  /// @brief Gets the restitution value to be used when within the angular limits of this constraint.
304  /// @return Returns a Real representing the current restitution on the angular axis.
305  virtual Real GetRestitutionDirAng() const;
306  /// @brief Sets the restitution value to be used when hitting the linear limit of this constraint.
307  /// @param RestitutionLimLin The restitution value to be set for the linear axis.
308  virtual void SetRestitutionLimLin(const Real RestitutionLimLin);
309  /// @brief Gets the restitution value to be used when hitting the linear limit of this constraint.
310  /// @return Returns a Real representing the current restitution on the linear axis.
311  virtual Real GetRestitutionLimLin() const;
312  /// @brief Sets the restitution value to be used when hitting the angular limit of this constraint.
313  /// @param RestitutionLimAng The restitution value to be set for the angular axis.
314  virtual void SetRestitutionLimAng(const Real RestitutionLimAng);
315  /// @brief Gets the restitution value to be used when hitting the angular limit of this constraint.
316  /// @return Returns a Real representing the current restitution on the angular axis.
317  virtual Real GetRestitutionLimAng() const;
318  /// @brief Sets the restitution value to be used when force is applied against the configured linear axis of this constraint.
319  /// @param RestitutionOrthoLin The restitution value to be set for the linear axis.
320  virtual void SetRestitutionOrthoLin(const Real RestitutionOrthoLin);
321  /// @brief Gets the restitution value to be used when force is applied against the configured linear axis of this constraint.
322  /// @return Returns a Real representing the current restitution on the linear axis.
323  virtual Real GetRestitutionOrthoLin() const;
324  /// @brief Sets the restitution value to be used when force is applied against the configured angular axis of this constraint.
325  /// @param RestitutionOrthoAng The restitution value to be set for the angular axis.
326  virtual void SetRestitutionOrthoAng(const Real RestitutionOrthoAng);
327  /// @brief Gets the restitution value to be used when force is applied against the configured angular axis of this constraint.
328  /// @return Returns a Real representing the current restitution on the angular axis.
329  virtual Real GetRestitutionOrthoAng() const;
330 
331  ///////////////////////////////////////////////////////////////////////////////
332  // Parameter Configuration
333 
334  /// @copydoc Constraint::GetValidParamsOnAxis(int) const
335  virtual Constraint::ParamList GetValidParamsOnAxis(int Axis) const;
336  /// @copydoc Constraint::GetValidLinearAxes() const
337  virtual Constraint::AxisList GetValidLinearAxes() const;
338  /// @copydoc Constraint::GetValidAngularAxes() const
339  virtual Constraint::AxisList GetValidAngularAxes() const;
340  /// @copydoc Constraint::ValidAngularAxis(ConstraintParam,int) const
341  virtual Boole HasParamBeenSet(ConstraintParam Param, int Axis) const;
342 
343  ///////////////////////////////////////////////////////////////////////////////
344  // Serialization
345 
346  /// @copydoc Constraint::ProtoSerializeProperties(XML::Node&) const
347  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
348  /// @copydoc Constraint::ProtoDeSerializeProperties(const XML::Node&)
349  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
350 
351  /// @copydoc Constraint::GetDerivedSerializableName() const
352  virtual String GetDerivedSerializableName() const;
353  /// @brief Get the name of the the XML tag the class will leave behind as its instances are serialized.
354  /// @return A string containing the name of this class.
355  static String GetSerializableName();
356 
357  ///////////////////////////////////////////////////////////////////////////////
358  // Internal
359 
360  /// @copydoc Constraint::_GetConstraintBase() const
361  virtual btTypedConstraint* _GetConstraintBase() const;
362  };//SliderConstraint
363  }//Physics
364 }//Mezzanine
365 
366 #endif
std::vector< int > AxisList
Used to Store lists of Int Axis for return types.
Definition: constraint.h:124
All constraints that track rotation and location of the Pivot relative to each Actor inherit from thi...
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This is a constraint for permitting movement on only a singular linear or angular axis...
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
btSliderConstraint * Slider
Bullet constraint that this class encapsulates.
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
ConstraintParam
Used by constraints for setting some parameters.
Definition: constraint.h:61
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
std::vector< ConstraintParam > ParamList
Used to Store lists of param for return types.
Definition: constraint.h:120
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
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