Spinning Topp Logo BlackTopp Studios
inc
conetwistconstraint.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 _physicsconetwistconstraint_h
41 #define _physicsconetwistconstraint_h
42 
43 #include "Physics/dualtransformconstraint.h"
44 
45 class btConeTwistConstraint;
46 
47 namespace Mezzanine
48 {
49  namespace Physics
50  {
51  ///////////////////////////////////////////////////////////////////////////////
52  /// @class ConeTwistConstraint
53  /// @brief This is a constraint that will limit the movement allowed from one body to within a cone area around another object.
54  /// @details This constraint is commonly used to simulate limbs for a ragdoll and moves similarly to a ball in a socket. @n @n
55  /// In a kinematic or character chain of bones, the child limbs should be defined as Body/Proxy A, and the parents as B.
56  ///////////////////////////////////////
58  {
59  protected:
60  /// @internal
61  /// @brief The internal constraint that this class encapsulates.
62  btConeTwistConstraint* ConeTwist;
63 
64  /// @copydoc DualTransformConstraint::CreateConstraint(RigidProxy*, RigidProxy*, const Transform&, const Transform&)
65  virtual void CreateConstraint(RigidProxy* RigidA, RigidProxy* RigidB, const Transform& TransA, const Transform& TransB);
66  /// @copydoc DualTransformConstraint::DestroyConstraint()
67  virtual void DestroyConstraint();
68  public:
69  /// @brief Class constructor.
70  /// @param ID The unique identifier assigned to this constraint.
71  /// @param ProxyA The first proxy to apply this constraint to.
72  /// @param ProxyB The second proxy to apply this constraint to.
73  /// @param TransA The transform in ProxyA's local space to attach this constraint to.
74  /// @param TransB The transform in ProxyB's local space to attach this constraint to.
75  /// @param Creator A pointer to the manager that created this constraint.
76  ConeTwistConstraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransA, const Transform& TransB, PhysicsManager* Creator);
77  /// @brief Single body constructor.
78  /// @param ID The unique identifier assigned to this constraint.
79  /// @param ProxyA The first proxy to apply this constraint to.
80  /// @param TransA The transform in ProxyA's local space to attach this constraint to.
81  /// @param Creator A pointer to the manager that created this constraint.
82  ConeTwistConstraint(const UInt32 ID, RigidProxy* ProxyA, const Transform& TransA, PhysicsManager* Creator);
83  /// @brief XML constructor.
84  /// @param SelfRoot An XML::Node containing the data to populate this class with.
85  /// @param Creator A pointer to the manager that created this constraint.
86  ConeTwistConstraint(const XML::Node& SelfRoot, PhysicsManager* Creator);
87  /// @brief Class destructor.
88  virtual ~ConeTwistConstraint();
89 
90  ///////////////////////////////////////////////////////////////////////////////
91  // Utility Methods
92 
93 
94  /// @brief Gets whether or not the child object is outside the set limits for the constraint.
95  /// @return Returns true if the child body is out of bounds and needs force applied to correct it's transform.
96  Boole IsPassedSwingLimit() const;
97  /// @brief Gets the current angle of thw twist applied to the constraint.
98  /// @return Returns a Real representing the amount of rotation currently applied on the twisting axis in radians.
99  Real GetTwistAngle() const;
100 
101  /// @copydoc DualTransformConstraint::SetPivotATransform(const Transform&)
102  virtual void SetPivotATransform(const Transform& TransA);
103  /// @copydoc DualTransformConstraint::SetPivotBTransform(const Transform&)
104  virtual void SetPivotBTransform(const Transform& TransB);
105  /// @copydoc DualTransformConstraint::GetPivotATransform()
106  virtual Transform GetPivotATransform() const;
107  /// @copydoc DualTransformConstraint::GetPivotBTransform()
108  virtual Transform GetPivotBTransform() const;
109 
110  ///////////////////////////////////////////////////////////////////////////////
111  // Configuration Methods
112 
113  /// @brief Enables (or disables) the motor of this constraint.
114  /// @param Enable If true, the constraint will push the child body towards the orientation set as the motor target.
115  virtual void EnableMotor(const Boole Enable);
116  /// @brief Gets whether or not the motor is enabled.
117  /// @return Returns true if the motor is enabled, false otherwise.
118  virtual Boole IsMotorEnabled() const;
119 
120  virtual void SetAngularOnly(const Boole AngularOnly);
121  virtual Boole GetAngularOnly() const;
122 
123  /// @brief Sets a constraint limit based on Index.
124  /// @remarks The valid indexes that can be specified are 3, 4, and 5. Any other index being specified will perform no action. @n
125  /// The indexes are mapped thusly: @n
126  /// Index 3 is the TwistSpan. @n
127  /// Index 4 is SwingSpan 2. @n
128  /// Index 5 is SwingSpan 1.
129  /// @param LimitIndex The index of the constraint limit to alter.
130  /// @param LimitValue The value to set for the specified limit.
131  virtual void SetLimit(const Integer LimitIndex, const Real LimitValue);
132  /// @brief Sets all constraint limits.
133  /// @param SwingSpan1 The first parameter that determines the size/shape of the cone in which the body will be able to move (in radians). If different from SwingSpan2 this will create a non-circular area of movement.
134  /// @param SwingSpan2 The second parameter that determines the size/shape of the cone in which the body will be able to move (in radians). If different from SwingSpan1 this will create a non-circular area of movement.
135  /// @param TwistSpan The amount of rotation that is allowed on the axis the constraint is connected, aka how much the body is allowed to twist in radians.
136  /// @param Softness A scalar value representing the % of the limits which are free to move. Above this value limits will start to be enforced with a force related to how
137  /// close to the limit the constraint is. Lower values mean smoother forces being applied to keep an object within the swing limits. A value of 1.0 means the object is
138  /// free to swing however within the strictly defined limits. Generally this shouldn't be below 0.8. @n Range: 0.0-1.0. @n Initial value: 1.0.
139  /// @param BiasFactor A scalar value representing how strong the the forces used to enforce the "twist" limit set on this constraint. In most cases this should remain in the range of 0.0-0.6. @n
140  /// Allowed range: 0.0-1.0.
141  /// @param RelaxationFactor A scalar value representing how strong the forces used to enforce the "swing" limits set on this constraint. In most cases this should remain near
142  /// 1.0. @n Range: 0.0-1.0.
143  virtual void SetLimits(const Real SwingSpan1, const Real SwingSpan2, const Real TwistSpan, const Real Softness = 1.0, const Real BiasFactor = 0.3, const Real RelaxationFactor = 1.0);
144  /// @brief Gets a constraint limit based on Index.
145  /// @remarks The valid indexes to that be retrieved by this method are 3, 4, and 5. Any other index being specified will assert. @n
146  /// The indexes are mapped thusly: @n
147  /// Index 3 is the TwistSpan. @n
148  /// Index 4 is SwingSpan 2. @n
149  /// Index 5 is SwingSpan 1.
150  /// @param LimitIndex The index of the constraint limit to retrieve.
151  virtual Real GetLimit(const Integer LimitIndex) const;
152  /// @brief Gets the currently set value for the constraint Swing span on the Y axis.
153  /// @return Returns a Real representing the allowed range of "swing" on the Y axis in radians.
154  virtual Real GetSwingSpan1() const;
155  /// @brief Gets the currently set value for the constraint Swing span on the Z axis.
156  /// @return Returns a Real representing the allowed range of "swing" on the Z axis in radians.
157  virtual Real GetSwingSpan2() const;
158  /// @brief Gets the currently set value for the constraint Twist span on the X axis.
159  /// @return Returns a Real representing the allowed range of "twist" on the X axis in radians.
160  virtual Real GetTwistSpan() const;
161  /// @brief Gets the % portion of the swing limit in which to start enforcing the limit.
162  /// @return Returns a Real representing how close to the limit to start enforcing the swing limits.
163  virtual Real GetLimitSoftness() const;
164  /// @brief Gets the strength of the force enforcing the twist limits.
165  /// @return Returns a Real representing the strength of the force to be used when enforcing the twist limits.
166  virtual Real GetBiasFactor() const;
167  /// @brief Gets the strength of the force enforcing the swing limits.
168  /// @return Returns a Real representing the strength of the force to be used when enforcing the swing limits.
169  virtual Real GetRelaxationFactor() const;
170 
171  virtual void SetDamping(const Real Damping);
172  virtual Real GetDamping() const;
173  virtual void SetMaxMotorImpulse(const Real MaxMotorImpulse);
174  virtual void SetMaxMotorImpulseNormalized(const Real MaxMotorImpulse);
175  virtual Boole IsMaxMotorImpulseNormalized() const;
176  virtual Real GetMaxMotorImpulse() const;
177  virtual void SetFixThresh(const Real FixThresh);
178  virtual Real GetFixThresh() const;
179  virtual void SetMotorTarget(const Quaternion& Quat);
180  virtual void SetMotorTargetInConstraintSpace(const Quaternion& Quat);
181  /// @note The returned target is always in constraint space and clamped to be within the allowed limits for the constraint.
182  virtual Quaternion GetMotorTarget() const;
183 
184  ///////////////////////////////////////////////////////////////////////////////
185  // Constraint Parameters
186 
187  /// @copydoc Constraint::GetValidParamsOnAxis(int) const
188  virtual ParamList GetValidParamsOnAxis(int Axis) const;
189  /// @copydoc Constraint::GetValidLinearAxes() const
190  virtual AxisList GetValidLinearAxes() const;
191  /// @copydoc Constraint::GetValidAngularAxes() const
192  virtual AxisList GetValidAngularAxes() const;
193  /// @copydoc Constraint::HasParamBeenSet(ConstraintParam,int) const
194  virtual Boole HasParamBeenSet(ConstraintParam Param, int Axis) const;
195 
196  ///////////////////////////////////////////////////////////////////////////////
197  // Serialization
198 
199  /// @copydoc Constraint::ProtoSerializeProperties(XML::Node&) const
200  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
201  /// @copydoc Constraint::ProtoDeSerializeProperties(const XML::Node&)
202  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
203 
204  /// @copydoc Constraint::GetDerivedSerializableName() const
205  virtual String GetDerivedSerializableName() const;
206  /// @brief Get the name of the the XML tag the class will leave behind as its instances are serialized.
207  /// @return A string containing the name of this class.
208  static String GetSerializableName();
209 
210  ///////////////////////////////////////////////////////////////////////////////
211  // Internal
212 
213  /// @copydoc Constraint::_GetConstraintBase() const
214  virtual btTypedConstraint* _GetConstraintBase() const;
215  };//ConeTwistConstraint
216  }//Physics
217 }//Mezzanine
218 
219 #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
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
This is a constraint that will limit the movement allowed from one body to within a cone area around ...
btConeTwistConstraint * ConeTwist
The internal 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.
#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