Spinning Topp Logo BlackTopp Studios
inc
hingeconstraint.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 _physicshingeconstraint_h
41 #define _physicshingeconstraint_h
42 
43 #include "Physics/dualtransformconstraint.h"
44 
45 class btHingeConstraint;
46 
47 namespace Mezzanine
48 {
49  namespace Physics
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class HingeConstraint
53  /// @brief This is a constraint to be used to restrict the movement between two objects to angular rotation on a single axis.
54  /// @details As the name suggests, this constraint essentially works like a door Hinge.
55  ///////////////////////////////////////
57  {
58  protected:
59  /// @internal
60  /// @brief Bullet constraint that this class encapsulates.
61  btHingeConstraint* Hinge;
62 
63  /// @copydoc DualTransformConstraint::CreateConstraint(RigidProxy*, RigidProxy*, const Transform&, const Transform&)
64  virtual void CreateConstraint(RigidProxy* RigidA, RigidProxy* RigidB, const Transform& TransA, const Transform& TransB);
65  /// @internal
66  /// @brief Creates the internal constraint.
67  /// @param RigidA The first proxy to apply this constraint to.
68  /// @param RigidB The second proxy to apply this constraint to.
69  /// @param PivotA The location in ProxyA's local space to apply the constraint to.
70  /// @param PivotB The location in ProxyB's local space to apply the constraint to.
71  /// @param AxisInA The axis(for ProxyA) on which the hinge is to act. For example, a door hinge would be (0.0,1.0,0.0), aka the positive Y axis.
72  /// @param AxisInB The axis(for ProxyB) on which the hinge is to act. For example, a door hinge would be (0.0,1.0,0.0), aka the positive Y axis.
73  virtual void CreateConstraint(RigidProxy* RigidA, RigidProxy* RigidB, const Vector3& PivotInA, const Vector3& PivotInB, const Vector3& AxisInA, const Vector3& AxisInB);
74  /// @copydoc DualTransformConstraint::DestroyConstraint()
75  virtual void DestroyConstraint();
76  public:
77  /// @brief Convenience axis constructor.
78  /// @param ID The unique identifier assigned to this constraint.
79  /// @param ProxyA The first proxy to apply this constraint to.
80  /// @param ProxyB The second proxy to apply this constraint to.
81  /// @param PivotA The location in ProxyA's local space to apply the constraint to.
82  /// @param PivotB The location in ProxyB's local space to apply the constraint to.
83  /// @param AxisInA The axis(for ProxyA) on which the hinge is to act. For example, a door hinge would be (0.0,1.0,0.0), aka the positive Y axis.
84  /// @param AxisInB The axis(for ProxyB) on which the hinge is to act. For example, a door hinge would be (0.0,1.0,0.0), aka the positive Y axis.
85  /// @param Creator A pointer to the manager that created this constraint.
86  HingeConstraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& PivotInA, const Vector3& PivotInB, const Vector3& AxisInA, const Vector3& AxisInB, PhysicsManager* Creator);
87  /// @brief Transform constructor.
88  /// @param ID The unique identifier assigned to this constraint.
89  /// @param ProxyA The first proxy to apply this constraint to.
90  /// @param ProxyB The second proxy to apply this constraint to.
91  /// @param TransA The offset and rotation from ProxyAs center of gravity to get to match an offset from ProxyB.
92  /// @param TransB The offset and rotation from ProxyBs center of gravity.
93  /// @param Creator A pointer to the manager that created this constraint.
94  HingeConstraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransA, const Transform& TransB, PhysicsManager* Creator);
95  /// @brief Single body axis constructor.
96  /// @param ID The unique identifier assigned to this constraint.
97  /// @param ProxyA The proxy to apply this constraint to.
98  /// @param PivotInA The point in the objects(ProxyA) local space where the constraint is to be attached to world space.
99  /// @param AxisInA The axis(for ProxyA) on which the hinge is to act. For example, a door hinge would be (0.0,1.0,0.0), aka the positive Y axis.
100  /// @param Creator A pointer to the manager that created this constraint.
101  HingeConstraint(const UInt32 ID, RigidProxy* ProxyA, const Vector3& PivotInA, const Vector3& AxisInA, PhysicsManager* Creator);
102  /// @brief Single body transform constructor.
103  /// @param ID The unique identifier assigned to this constraint.
104  /// @param ProxyA The first proxy to apply this constraint to.
105  /// @param TransB The offset and rotation from ProxyAs center of gravity.
106  /// @param Creator A pointer to the manager that created this constraint.
107  HingeConstraint(const UInt32 ID, RigidProxy* ProxyA, const Transform& TransA, PhysicsManager* Creator);
108  /// @brief XML constructor.
109  /// @param SelfRoot An XML::Node containing the data to populate this class with.
110  /// @param Creator A pointer to the manager that created this constraint.
111  HingeConstraint(const XML::Node& SelfRoot, PhysicsManager* Creator);
112  /// @brief Class destructor.
113  virtual ~HingeConstraint();
114 
115  ////////////////////////////////////////////////////////////////////////////////
116  // Position and Orientation
117 
118  /// @copydoc DualTransformConstraint::SetPivotTransforms(const Transform&, const Transform&)
119  /// @remarks This implements a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
120  virtual void SetPivotTransforms(const Transform& TransA, const Transform& TransB);
121  /// @copydoc DualTransformConstraint::SetTransformA
122  virtual void SetPivotATransform(const Transform& TransA);
123  /// @copydoc DualTransformConstraint::SetTransformB
124  virtual void SetPivotBTransform(const Transform& TransB);
125  /// @copydoc DualTransformConstraint::GetTransformA
126  virtual Transform GetPivotATransform() const;
127  /// @copydoc DualTransformConstraint::GetTransformB
128  virtual Transform GetPivotBTransform() const;
129 
130  /// @copydoc DualTransformConstraint::SetPivotALocation(const Vector3&)
131  /// @remarks Ultimately this information winds up being stored in the TransformA. This implements
132  /// a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
133  virtual void SetPivotALocation(const Vector3& Location);
134  /// @copydoc DualTransformConstraint::SetPivotBLocation(const Vector3&)
135  /// @remarks Ultimately this information winds up being stored in the TransformB. This implements
136  /// a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
137  virtual void SetPivotBLocation(const Vector3& Location);
138  /// @copydoc DualTransformConstraint::GetPivotALocation() const
139  /// @remarks This implements a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
140  virtual Vector3 GetPivotALocation() const;
141  /// @copydoc DualTransformConstraint::GetPivotBLocation() const
142  /// @remarks This implements a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
143  virtual Vector3 GetPivotBLocation() const;
144 
145  /// @copydoc DualTransformConstraint::SetAPivotRotation(const Quaternion&)
146  /// @remarks Ultimately this information winds up being stored in the TransformA. This implements
147  /// a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
148  virtual void SetAPivotRotation(const Quaternion& Rotation);
149  /// @copydoc DualTransformConstraint::SetBPivotRotation(const Quaternion&)
150  /// @remarks Ultimately this information winds up being stored in the TransformB. This implements
151  /// a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
152  virtual void SetBPivotRotation(const Quaternion& Rotation);
153  /// @copydoc DualTransformConstraint::GetAPivotRotation() const
154  /// @remarks This implements a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
155  virtual Quaternion GetAPivotRotation() const;
156  /// @copydoc DualTransformConstraint::GetBPivotRotation() const
157  /// @remarks This implements a more Hinge specific version of the logic than DualTransformConstraint for efficiency reasons.
158  virtual Quaternion GetBPivotRotation() const;
159 
160  ////////////////////////////////////////////////////////////////////////////////
161  // Utility
162 
163  /// @brief Sets the axis on which this constraint acts.
164  /// @param AxisInA A vector3 representing the axis to be used with this constraint.
165  virtual void SetAxis(const Vector3& AxisInA);
166  /// @brief Gets the current angle of the hinge.
167  /// @return Gets the amount of rotation this hinge is off from it's origin in radians.
168  virtual Real GetHingeAngle();
169 
170  /// @brief Sets whether or not an offset of the constraint frame should be used to calculate internal data.
171  /// @param FrameOffset The full effect of this being true or false is uknown, but internal documentation suggests "true" provides more stable results.
172  virtual void SetUseFrameOffset(const Boole FrameOffset);
173  /// @brief Gets whether or not an offset of the constraint frame should be used to calculate internal data.
174  /// @return Returns whether or not an offset in the constraint frame is being used by the internal constraint.
175  virtual Boole GetUseFrameOffset() const;
176 
177  /// @brief Sets whether or not to perform linear math from ProxyA's perspective.
178  /// @param UseRefFrameA True to perform math from ProxyA's perspective, false to perform math from ProxyB's perspective. Initial Value: false.
179  virtual void SetUseReferenceFrameA(const Boole UseRefFrameA);
180  /// @brief Gets whether or not to perform linear math from ProxyA's perspective.
181  /// @return Returns true if math is being done from ProxyA's perspective, false if math is being done from ProxyB's perspective.
182  virtual Boole GetUseReferenceFrameA() const;
183 
184  ////////////////////////////////////////////////////////////////////////////////
185  // Limits
186 
187  /// @brief Sets the angle limits of the constraint in radians.
188  /// @param Low The minimum angle limit for the constraint in radians.
189  /// @param High The maximum angle limit for the constraint in radians.
190  /// @param Softness Not currently used internally.
191  /// @param BiasFactor Multiplier for the constraint error, constraint appears more "soft" when closer to zero.
192  /// @param RelaxationFactor The amount of bounce to apply when the constraint reaches it's limit. Range: 0.0-1.0.
193  virtual void SetLimits(const Real Low, const Real High, const Real Softness = 0.9, const Real BiasFactor = 0.3, const Real RelaxationFactor = 1.0);
194  /// @brief Return the Lower Limit of the hinge
195  /// @return A real containing the Lower Limit
196  virtual Real GetLimitLow() const;
197  /// @brief Return the Upper Limit of the hinge
198  /// @return A real containing the Higher Limit
199  virtual Real GetLimitHigh() const;
200  /// @brief Return the Softness of the hinge
201  /// @return A real containing the Softness
202  virtual Real GetLimitSoftness() const;
203  /// @brief Return the bias factor of the hinge (Not entirely certain hat this on is)
204  /// @return A real containing the bias Factor
205  virtual Real GetLimitBiasFactor() const;
206  /// @brief Return the Relaxation Factor of the hinge
207  /// @return A real containing the Relaxation Factor
208  virtual Real GetLimitRelaxationFactor() const;
209 
210  ////////////////////////////////////////////////////////////////////////////////
211  // Angular Motor
212 
213  /// @brief Enables(or Disables) the motor on the hinge and sets it's parameters.
214  /// @param EnableMotor Sets whether or not the motor on this constraint is enabled.
215  /// @param TargetVelocity The desired velocity of rotation the motor will have. This may or may not be achieved based on obstructions in the simulation.
216  /// @param MaxMotorImpulse The maximum amount of force the motor is to apply to try and reach it's target velocity.
217  virtual void EnableMotor(const Boole EnableMotor, const Real TargetVelocity, const Real MaxMotorImpulse);
218  /// @brief Enables(or Disables) the motor on the hinge.
219  /// @warning Be sure to set values for the Motor max impulse and/or velocity before enabling the motor, or else you may get a crash.
220  /// @param EnableMotor Sets whether or not the motor on this constraint is enabled.
221  virtual void SetMotorEnabled(const Boole EnableMotor);
222  /// @brief Is this motor on this hinge enabled?
223  /// @return True if it is, false otherwise.
224  virtual Boole GetMotorEnabled() const;
225 
226  /// @brief Sets the maximum amount of force the motor is to apply.
227  /// @param MaxMotorImpulse The maximum amount of force the motor is to apply to try and reach it's target velocity.
228  virtual void SetMaxMotorImpulse(const Real MaxMotorImpulse);
229  /// @brief Retrieve the maximimum value that the acceleration of the motor can be increased.
230  /// @return A real containing the maximum impulse.
231  virtual Real GetMaxMotorImpulse() const;
232 
233  /// @brief Desired angular velocity of the motor
234  /// @param TargetVelocity The Desired velocity
235  /// @warning Causes segfaults in some tests.
236  virtual void SetMotorTargetVelocity(const Real TargetVelocity);
237  /// @brief Get the Target Velocity.
238  /// @return the target valocity as a real.
239  virtual Real GetMotorTargetVelocity() const;
240 
241  /// @brief Sets a Target Velocity, indirectly using the angle stored in a quaternion.
242  /// @param QuatAInB The angle a quaternion relative to the two objects in the constraint.
243  /// @param Delta The Desired Time steps that the target rotational velocity should be reached in.
244  virtual void SetMotorTarget(const Quaternion& QuatAInB, const Real Delta);
245  /// @brief Set the Rotational velocity in a more direct fashion
246  /// @param TargetAngle The desired angle in radians.
247  /// @param Delta The Desired Time steps that the target rotational velocity should be reached in.
248  virtual void SetMotorTarget(const Real TargetAngle, const Real Delta);
249 
250  ////////////////////////////////////////////////////////////////////////////////
251  // Parameter Configuration
252 
253  /// @copydoc Constraint::GetValidParamsOnAxis(int) const
254  virtual Constraint::ParamList GetValidParamsOnAxis(int Axis) const;
255  /// @copydoc Constraint::GetValidLinearAxes() const
256  virtual Constraint::AxisList GetValidLinearAxes() const;
257  /// @copydoc Constraint::GetValidAngularAxes() const
258  virtual Constraint::AxisList GetValidAngularAxes() const;
259  /// @copydoc Constraint::ValidAngularAxis(ConstraintParam,int) const
260  virtual Boole HasParamBeenSet(ConstraintParam Param, int Axis) const;
261 
262  ////////////////////////////////////////////////////////////////////////////////
263  // Serialization
264 
265  /// @copydoc Constraint::ProtoSerializeProperties(XML::Node&) const
266  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
267  /// @copydoc Constraint::ProtoDeSerializeProperties(const XML::Node&)
268  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
269 
270  /// @copydoc Constraint::GetDerivedSerializableName() const
271  virtual String GetDerivedSerializableName() const;
272  /// @brief Get the name of the the XML tag the class will leave behind as its instances are serialized.
273  /// @return A string containing the name of this class.
274  static String GetSerializableName();
275 
276  ////////////////////////////////////////////////////////////////////////////////
277  // Internal
278 
279  /// @copydoc Constraint::_GetConstraintBase() const
280  virtual btTypedConstraint* _GetConstraintBase() const;
281  };//HingeConstraint
282  }//Physics
283 }//Mezzanine
284 
285 ///////////////////////////////////////////////////////////////////////////////
286 // Class External << Operators for streaming or assignment
287 
288 #ifndef SWIG
289 /// @copydoc operator << (std::ostream& stream, const Mezzanine::Physics::Constraint& x)
290 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Physics::HingeConstraint& x);
291 /// @copydoc operator >> (std::istream& stream, Mezzanine::Physics::Constraint& x)
292 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Physics::HingeConstraint& x);
293 /// @copydoc operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::Physics::Constraint& x)
295 #endif
296 
297 
298 #endif
std::ostream & operator<<(std::ostream &stream, const Mezzanine::LinearInterpolator< T > &Lint)
Used to Serialize an Mezzanine::LinearInterpolator to a human readable stream.
Definition: interpolator.h:433
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
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
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 a constraint to be used to restrict the movement between two objects to angular rotation on a...
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
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
Definition: interpolator.h:448
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
btHingeConstraint * Hinge
Bullet constraint that this class encapsulates.