MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
generic6dofspringconstraint.h
1 // © Copyright 2010 - 2014 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  /// @headerfile constraint.h
54  /// @brief Creates a constraint as configurable as the 6Dof constraint, but has added support for spring motion.
55  /// @details When using functions of this class that require you to specify the index, the springs are arranged like so: @n
56  /// - 0: Translation X
57  /// - 1: Translation Y
58  /// - 2: Translation Z
59  /// - 3: Rotation X
60  /// - 4: Rotation Y
61  /// - 5: Rotation Z
62  ///////////////////////////////////////
64  {
65  protected:
66  /// @brief Inheritance Constructor.
67  /// @details This is only called by derived classes, and shouldn't be called manually.
69  /// @copydoc TypedConstraint::GetConstraintBase() const
70  virtual btGeneric6DofSpringConstraint* Generic6dofSpring() const;
71  public:
72  /// @brief Identify the Axis a bit easier when iterating over them is less convienent than typing an Identifier
73  enum UsableAxis{
74  LinearX = 0, ///< Translation on the X axis
75  LinearY = 1, ///< Translation on the Y axis
76  LinearZ = 2, ///< Translation on the Z axis
77  AngularX = 3, ///< Rotation on the X axis
78  AngularY = 4, ///< Rotation on the Y axis
79  AngularZ = 5 ///< Rotation on the Z axis
80  };
81 
82  ////////////////////////////////////////////////////////////////////////////////
83  // Generic6DofSpringConstraint Construction and Destruction
84 
85  /// @brief Two proxy Verbose constructor.
86  /// @param ProxyA The First proxy to be bound.
87  /// @param ProxyB The Second proxy to be bound.
88  /// @param VectorA The offset from ProxyAs center of gravity to get to match an offset from ProxyB.
89  /// @param VectorB The offset from ProxyBs center of gravity.
90  /// @param QuaternionA Relative rotation from ProxyA.
91  /// @param QuaternionB Relative rotation from ProxyB.
92  /// @param UseLinearReferenceA Perform Linear math from ProxyA's perspective, default to false.
93  Generic6DofSpringConstraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& VectorA, const Vector3& VectorB, const Quaternion& QuaternionA, const Quaternion& QuaternionB, bool UseLinearReferenceA = false);
94  /// @brief Two proxy Terse constructor.
95  /// @param ProxyA The First proxy to be bound.
96  /// @param ProxyB The Second proxy to be bound.
97  /// @param TransformA The offset and rotation from ProxyAs center of gravity to get to match an offset from ProxyB.
98  /// @param TransformB The offset and rotation from ProxyBs center of gravity.
99  /// @param UseLinearReferenceA Perform Linear math from ProxyA's perspective, default to false.
100  Generic6DofSpringConstraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransformA, const Transform& TransformB, bool UseLinearReferenceA = false);
101  /// @brief Class destructor.
102  /// @details The class destructor.
103  virtual ~Generic6DofSpringConstraint();
104 
105  ////////////////////////////////////////////////////////////////////////////////
106  // Generic6DofSpringConstraint Linear Spring Settings
107 
108  /// @brief Set the Stiffness of the springs on each Linear Axis.
109  /// @param Stiffies A Vector3 containing the X, Y and Z stiffnesses.
110  virtual void SetSpringLinearStiffness(const Vector3& Stiffies);
111  /// @brief Set the Damping of the springs on each Linear Axis.
112  /// @param Damps A Vector3 containing the X, Y and Z desired damping.
113  virtual void SetSpringLinearDamping(const Vector3& Damps);
114  /// @brief Set the Stiffness of the springs on each Linear Axis.
115  /// @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.
116  virtual void SetSpringLinearEnabled(const Vector3& Enableness);
117 
118  /// @brief Get the Stiffness for all Linear Axis
119  /// @return A Vector3 with the Stiffness on the X, Y and Z Linear Axis.
120  virtual Vector3 GetSpringLinearStiffness() const;
121  /// @brief Get the Damping for all Linear Axis
122  /// @return A Vector3 with the Damping on the X, Y and Z Linear Axis.
123  virtual Vector3 GetSpringLinearDamping() const;
124  /// @brief Get the Enabled Status for all Linear Axis
125  /// @return A Vector3 with the Enabled Status on the X, Y and Z Linear Axis.
126  virtual Vector3 GetSpringLinearEnabled() const;
127 
128  ////////////////////////////////////////////////////////////////////////////////
129  // Generic6DofSpringConstraint Angular Spring Settings
130 
131  /// @brief Set the Stiffness of the springs on each Angular Axis.
132  /// @param Stiffies A Vector3 containing the X, Y and Z stiffnesses.
133  virtual void SetSpringAngularStiffness(const Vector3& Stiffies);
134  /// @brief Set the Damping of the springs on each Angular Axis.
135  /// @param Damps A Vector3 containing the X, Y and Z desired damping.
136  virtual void SetSpringAngularDamping(const Vector3& Damps);
137  /// @brief Set the Stiffness of the springs on each Angular Axis.
138  /// @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.
139  virtual void SetSpringAngularEnabled(const Vector3& Enableness);
140 
141  /// @brief Get the Stiffness for all Angular Axis
142  /// @return A Vector3 with the Stiffness on the X, Y and Z Angular Axis.
143  virtual Vector3 GetSpringAngularStiffness() const;
144  /// @brief Get the Damping for all Angular Axis
145  /// @return A Vector3 with the Damping on the X, Y and Z Angular Axis.
146  virtual Vector3 GetSpringAngularDamping() const;
147  /// @brief Get the Enabled Status for all Angular Axis
148  /// @return A Vector3 with the Enabled Status on the X, Y and Z Angular Axis.
149  virtual Vector3 GetSpringAngularEnabled() const;
150 
151  ////////////////////////////////////////////////////////////////////////////////
152  // Generic6DofSpringConstraint Per Axis Spring Settings
153 
154  /// @brief Set the spring stiffness on a given axis
155  /// @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;
156  /// @param Stiffness A real with the new desired stiffness.
157  virtual void SetSpringStiffness(int Index, Real Stiffness);
158  /// @brief Set the spring Damping on a given axis.
159  /// @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;
160  /// @param Damping A real with the new desired Damping.
161  virtual void SetSpringDamping(int Index, Real Damping);
162  /// @brief Set the spring's enabled status on a given axis.
163  /// @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;
164  /// @param Enable A bool with the spring's enabled status.
165  virtual void SetSpringEnabled(int Index, bool Enable);
166 
167  /// @brief Retrieve the Stiffness of the spring on the given axis
168  /// @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;
169  /// @return A real with the requested value;
170  virtual Real GetSpringStiffness(int Index) const;
171  /// @brief Retrieve the Damping of the spring on the given axis
172  /// @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;
173  /// @return A real with the requested value.
174  virtual Real GetSpringDamping(int Index) const;
175  /// @brief Retrieve the EnabledStatus of the spring on the given axis
176  /// @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;
177  /// @return A bool with the requested value.
178  virtual bool GetSpringEnabled(int Index) const;
179 
180  ////////////////////////////////////////////////////////////////////////////////
181  // Generic6DofSpringConstraint Calculated Items
182 
183  /// @internal
184  virtual void CalculateSpringEquilibriumPoint();
185  /// @internal
186  virtual void CalculateSpringEquilibriumPoint(int Index);
187 
188  /// @internal
189  virtual Vector3 GetCurrentSpringAngularEquilibriumPoints() const;
190  /// @internal
191  virtual Vector3 GetCurrentSpringLinearEquilibriumPoints() const;
192  /// @internal
193  virtual Real GetCurrentSpringEquilibriumPoint(int Index) const;
194 
195  ////////////////////////////////////////////////////////////////////////////////
196  // Generic6DofSpringConstraint Serialization
197 
198  /// @brief Convert this class to an XML::Node ready for serialization
199  /// @param CurrentRoot The point in the XML hierarchy that all this vectorw should be appended to.
200  virtual void ProtoSerialize(XML::Node& CurrentRoot) const;
201  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
202  /// @param OneNode and XML::Node containing the data.
203  /// @warning A precondition of using this is that all of the actors intended for use must already be Deserialized.
204  virtual void ProtoDeSerialize(const XML::Node& OneNode);
205  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
206  /// @return A string containing "Generic6DofConstraint"
207  static String SerializableName();
208  };//Generic6DofSpringConstraint
209  }//Physics
210 }//Mezzanine
211 
212 ///////////////////////////////////////////////////////////////////////////////
213 // Class External << Operators for streaming or assignment
214 
215 /// @copydoc operator << (std::ostream& stream, const Mezzanine::Physics::Constraint& x)
216 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Physics::Generic6DofSpringConstraint& x);
217 /// @copydoc operator >> (std::istream& stream, Mezzanine::Physics::Constraint& x)
218 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Physics::Generic6DofSpringConstraint& x);
219 /// @copydoc operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::Physics::Constraint& x)
220 void operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::Physics::Generic6DofSpringConstraint& x);
221 
222 #endif