MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sliderconstraint.cpp
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 _physicssliderconstraint_cpp
41 #define _physicssliderconstraint_cpp
42 
43 #include "Physics/sliderconstraint.h"
44 #include "Physics/rigidproxy.h"
45 
46 #include "stringtool.h"
47 #include "serialization.h"
48 
49 #include <btBulletDynamicsCommon.h>
50 
51 namespace Mezzanine
52 {
53  namespace Physics
54  {
55  /////////////////////////////////////////
56  // Slider Constraint Functions
57 
58  SliderConstraint::SliderConstraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& VectorA, const Vector3& VectorB, const Quaternion& QuaternionA, const Quaternion& QuaternionB, bool UseLinearReferenceA)
59  {
60  this->SetBodies(ProxyA,ProxyB);
61 
62  btTransform transa(QuaternionA.GetBulletQuaternion(), VectorA.GetBulletVector3());
63  btTransform transb(QuaternionB.GetBulletQuaternion(), VectorB.GetBulletVector3());
64  this->Slider = new btSliderConstraint(*(ProxA->_GetPhysicsObject()), *(ProxB->_GetPhysicsObject()), transa, transb, UseLinearReferenceA);
65  }
66 
67  SliderConstraint::SliderConstraint(RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransformA, const Transform& TransformB, bool UseLinearReferenceA)
68  {
69  this->SetBodies(ProxyA,ProxyB);
70  this->Slider = new btSliderConstraint(*(ProxA->_GetPhysicsObject()), *(ProxB->_GetPhysicsObject()), TransformA.GetBulletTransform(), TransformB.GetBulletTransform(), UseLinearReferenceA);
71  }
72 
73  SliderConstraint::SliderConstraint(RigidProxy* ProxyB, const Vector3& VectorB, const Quaternion& QuaternionB, bool UseLinearReferenceA)
74  {
75  this->SetBodies(ProxyB);
76 
77  btTransform transb(QuaternionB.GetBulletQuaternion(), VectorB.GetBulletVector3());
78  this->Slider = new btSliderConstraint(*(ProxA->_GetPhysicsObject()), transb, UseLinearReferenceA);
79  }
80 
82  {
83  delete this->Slider;
84  }
85 
86  ////////////////////////////////////////////////////////////////////////////////
87  // Generic6DofConstraint Location and Rotation
88 
90  { this->Slider->getFrameOffsetA() = TranA.GetBulletTransform(); }
91 
93  { this->Slider->getFrameOffsetB() = TranB.GetBulletTransform(); }
94 
96  { return this->Slider->getFrameOffsetA(); }
97 
99  { return this->Slider->getFrameOffsetB(); }
100 
101 
103  { this->Slider->getFrameOffsetA().setOrigin(Location.GetBulletVector3()); }
104 
106  { this->Slider->getFrameOffsetB().setOrigin(Location.GetBulletVector3()); }
107 
109  { return Vector3(this->Slider->getFrameOffsetA().getOrigin()); }
110 
112  { return Vector3(this->Slider->getFrameOffsetB().getOrigin()); }
113 
114 
116  { this->Slider->getFrameOffsetA().setRotation(Rotation.GetBulletQuaternion()); }
117 
119  { this->Slider->getFrameOffsetA().setRotation(Rotation.GetBulletQuaternion()); }
120 
122  { return Quaternion(this->Slider->getFrameOffsetA().getRotation()); }
123 
125  { return Quaternion(this->Slider->getFrameOffsetB().getRotation()); }
126 
127  void SliderConstraint::SetUpperLinLimit(const Real& UpperLimit)
128  {
129  this->Slider->setUpperLinLimit(UpperLimit);
130  }
131 
132  void SliderConstraint::SetUpperAngLimit(const Real& UpperLimit)
133  {
134  this->Slider->setUpperAngLimit(UpperLimit);
135  }
136 
137  void SliderConstraint::SetLowerLinLimit(const Real& LowerLimit)
138  {
139  this->Slider->setLowerLinLimit(LowerLimit);
140  }
141 
142  void SliderConstraint::SetLowerAngLimit(const Real& LowerLimit)
143  {
144  this->Slider->setLowerAngLimit(LowerLimit);
145  }
146 
147  void SliderConstraint::SetPoweredLinMotor(bool OnOff)
148  {
149  this->Slider->setPoweredLinMotor(OnOff);
150  }
151 
152  void SliderConstraint::SetTargetLinMotorVelocity(const Real& TargetLinMotorVelocity)
153  {
154  this->Slider->setTargetLinMotorVelocity(TargetLinMotorVelocity);
155  }
156 
157  void SliderConstraint::SetMaxLinMotorForce(const Real& MaxLinMotorForce)
158  {
159  this->Slider->setMaxLinMotorForce(MaxLinMotorForce);
160  }
161 
162  void SliderConstraint::SetPoweredAngMotor(bool OnOff)
163  {
164  this->Slider->setPoweredAngMotor(OnOff);
165  }
166 
167  void SliderConstraint::SetTargetAngMotorVelocity(const Real& TargetAngMotorVelocity)
168  {
169  this->Slider->setTargetAngMotorVelocity(TargetAngMotorVelocity);
170  }
171 
172  void SliderConstraint::SetMaxAngMotorForce(const Real& MaxAngMotorForce)
173  {
174  this->Slider->setMaxAngMotorForce(MaxAngMotorForce);
175  }
176 
177  void SliderConstraint::SetUseFrameOffset(bool FrameOffset)
178  {
179  this->Slider->setUseFrameOffset(FrameOffset);
180  }
181 
182  void SliderConstraint::SetSoftnessDirLin(const Real& SoftnessDirLin)
183  {
184  this->Slider->setSoftnessDirLin(SoftnessDirLin);
185  }
186 
187  void SliderConstraint::SetRestitutionDirLin(const Real& RestitutionDirLin)
188  {
189  this->Slider->setRestitutionDirLin(RestitutionDirLin);
190  }
191 
192  void SliderConstraint::SetDampingDirLin(const Real& DampingDirLin)
193  {
194  this->Slider->setDampingDirLin(DampingDirLin);
195  }
196 
197  void SliderConstraint::SetSoftnessDirAng(const Real& SoftnessDirAng)
198  {
199  this->Slider->setSoftnessDirAng(SoftnessDirAng);
200  }
201 
202  void SliderConstraint::SetRestitutionDirAng(const Real& RestitutionDirAng)
203  {
204  this->Slider->setRestitutionDirAng(RestitutionDirAng);
205  }
206 
207  void SliderConstraint::SetDampingDirAng(const Real& DampingDirAng)
208  {
209  this->Slider->setDampingDirAng(DampingDirAng);
210  }
211 
212  void SliderConstraint::SetSoftnessLimLin(const Real& SoftnessLimLin)
213  {
214  this->Slider->setSoftnessLimLin(SoftnessLimLin);
215  }
216 
217  void SliderConstraint::SetRestitutionLimLin(const Real& RestitutionLimLin)
218  {
219  this->Slider->setRestitutionLimLin(RestitutionLimLin);
220  }
221 
222  void SliderConstraint::SetDampingLimLin(const Real& DampingLimLin)
223  {
224  this->Slider->setDampingLimLin(DampingLimLin);
225  }
226 
227  void SliderConstraint::SetSoftnessLimAng(const Real& SoftnessLimAng)
228  {
229  this->Slider->setSoftnessLimAng(SoftnessLimAng);
230  }
231 
232  void SliderConstraint::SetRestitutionLimAng(const Real& RestitutionLimAng)
233  {
234  this->Slider->setRestitutionLimAng(RestitutionLimAng);
235  }
236 
237  void SliderConstraint::SetDampingLimAng(const Real& DampingLimAng)
238  {
239  this->Slider->setDampingLimAng(DampingLimAng);
240  }
241 
242  void SliderConstraint::SetSoftnessOrthoLin(const Real& SoftnessOrthoLin)
243  {
244  this->Slider->setSoftnessOrthoLin(SoftnessOrthoLin);
245  }
246 
247  void SliderConstraint::SetRestitutionOrthoLin(const Real& RestitutionOrthoLin)
248  {
249  this->Slider->setRestitutionOrthoLin(RestitutionOrthoLin);
250  }
251 
252  void SliderConstraint::SetDampingOrthoLin(const Real& DampingOrthoLin)
253  {
254  this->Slider->setDampingOrthoLin(DampingOrthoLin);
255  }
256 
257  void SliderConstraint::SetSoftnessOrthoAng(const Real& SoftnessOrthoAng)
258  {
259  this->Slider->setSoftnessOrthoAng(SoftnessOrthoAng);
260  }
261 
262  void SliderConstraint::SetRestitutionOrthoAng(const Real& RestitutionOrthoAng)
263  {
264  this->Slider->setRestitutionOrthoAng(RestitutionOrthoAng);
265  }
266 
267  void SliderConstraint::SetDampingOrthoAng(const Real& DampingOrthoAng)
268  {
269  this->Slider->setDampingOrthoAng(DampingOrthoAng);
270  }
271 
272  ////////////////////////////////////////////////////////////////////////////////
273  // SliderConstraint Axis, Params and other Details
274 
276  {
277  Constraint::ParamList Results;
278  if(0<=Axis && 5>=Axis)
279  {
280  Results.push_back(Con_Stop_ERP);
281  Results.push_back(Con_CFM);
282  Results.push_back(Con_Stop_CFM);
283  }
284  return Results;
285  }
286 
288  {
289  Constraint::AxisList Results;
290  Results.push_back(0);
291  Results.push_back(1);
292  Results.push_back(2);
293  return Results;
294  }
295 
297  {
298  Constraint::AxisList Results;
299  Results.push_back(3);
300  Results.push_back(4);
301  Results.push_back(5);
302  return Results;
303  }
304 
306  {
307  // the logic here should match the logic in the source at http://bulletphysics.com/Bullet/BulletFull/btGeneric6DofConstraint_8cpp_source.html#l00964
308  if(0>Axis || 5<Axis)
309  { return false; }
310 
311  if( Con_Stop_ERP == Param )
312  {
313  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_ERP_LIMLIN ) return true;
314  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_ERP_ORTLIN ) return true;
315  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_ERP_LIMANG ) return true;
316  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_ERP_ORTANG ) return true;
317  }
318  else if( Con_Stop_CFM == Param )
319  {
320  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_CFM_DIRLIN ) return true;
321  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_CFM_DIRANG ) return true;
322  }
323  else if( Con_CFM == Param )
324  {
325  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_CFM_LIMLIN ) return true;
326  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_CFM_ORTLIN ) return true;
327  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_CFM_LIMANG ) return true;
328  if( this->Slider->getFlags() & BT_SLIDER_FLAGS_CFM_ORTANG ) return true;
329  }
330  return false;
331  }
332 
333  btTypedConstraint* SliderConstraint::GetConstraintBase() const
334  { return this->Slider; }
335  }//Physics
336 }//Mezzanine
337 
338 #endif