Spinning Topp Logo BlackTopp Studios
inc
universalconstraint.cpp
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 _physicsuniversalconstraint_cpp
41 #define _physicsuniversalconstraint_cpp
42 
43 #include "Physics/universalconstraint.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  // UniversalConstraint Constraint Functions
57 
58  UniversalConstraint::UniversalConstraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& Anchor, const Vector3& Axis1, const Vector3& Axis2, PhysicsManager* Creator) :
59  Generic6DofConstraint(ID,ProxyA,ProxyB,Creator)
60  { this->CreateConstraint(ProxyA,ProxyB,Anchor,Axis1,Axis2); }
61 
62  UniversalConstraint::UniversalConstraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransA, const Transform& TransB, PhysicsManager* Creator) :
63  Generic6DofConstraint(ID,ProxyA,ProxyB,Creator)
64  { this->CreateConstraint(ProxyA,ProxyB,TransA,TransB); }
65 
67  Generic6DofConstraint(0,NULL,Creator)
68  { this->ProtoDeSerialize(SelfRoot); }
69 
71  { /* Generic6Dof class will handle the cleanup */ }
72 
73  btUniversalConstraint* UniversalConstraint::Universal() const
74  { return static_cast<btUniversalConstraint*>( this->Generic6dof ); }
75 
76  void UniversalConstraint::CreateConstraint(RigidProxy* RigidA, RigidProxy* RigidB, const Transform& TransA, const Transform& TransB)
77  {
78  if( this->Generic6dof == NULL ) {
79  btVector3 TempOrigin(0,0,0);
80  btVector3 TempAxis1(0,1,0);
81  btVector3 TempAxis2(1,0,0);
82  this->Generic6dof = new btUniversalConstraint(*(ProxA->_GetPhysicsObject()),*(ProxB->_GetPhysicsObject()),TempOrigin,TempAxis1,TempAxis2);
83  this->Generic6dof->setFrames(TransA.GetBulletTransform(),TransB.GetBulletTransform());
84  }
85  }
86 
87  void UniversalConstraint::CreateConstraint(RigidProxy* ProxA, RigidProxy* ProxB, const Vector3& Anchor, const Vector3& Axis1, const Vector3& Axis2)
88  {
89  if( this->Generic6dof == NULL ) {
90  btVector3 TempOrigin = Anchor.GetBulletVector3();
91  btVector3 TempAxis1 = Axis1.GetBulletVector3();
92  btVector3 TempAxis2 = Axis2.GetBulletVector3();
93  this->Generic6dof = new btUniversalConstraint(*(ProxA->_GetPhysicsObject()),*(ProxB->_GetPhysicsObject()),TempOrigin,TempAxis1,TempAxis2);
94  }
95  }
96 
97  ///////////////////////////////////////////////////////////////////////////////
98  // Limits
99 
100  void UniversalConstraint::SetUpperLimit(const Real Ang1Max, const Real Ang2Max)
101  { this->Universal()->setUpperLimit(Ang1Max,Ang2Max); }
102 
103  void UniversalConstraint::SetLowerLimit(const Real Ang1Min, const Real Ang2Min)
104  { this->Universal()->setLowerLimit(Ang1Min,Ang2Min); }
105 
106  ///////////////////////////////////////////////////////////////////////////////
107  // Serialization
108 
111 
113  { return "UniversalConstraint"; }
114  }//Physics
115 }//Mezzanine
116 
117 #endif
static String GetSerializableName()
Get the name of the the XML tag the class will leave behind as its instances are serialized.
virtual void CreateConstraint(RigidProxy *RigidA, RigidProxy *RigidB, const Transform &TransA, const Transform &TransB)
Creates the internal constraint.
virtual void SetLowerLimit(const Real Ang1Min, const Real Ang2Min)
Sets the minimum angular limits of this constraint.
Create simple but specific limits on any axis of movement or rotation.
virtual void SetUpperLimit(const Real Ang1Max, const Real Ang2Max)
Sets the maximum angular limits of this constraint.
virtual btUniversalConstraint * Universal() const
UniversalConstraint(const UInt32 ID, RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &Anchor, const Vector3 &Axis1, const Vector3 &Axis2, PhysicsManager *Creator)
Convenience axis constructor.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
The interface for serialization.
btTransform GetBulletTransform() const
Gets a Bullet Transform.
Definition: transform.cpp:71
btVector3 GetBulletVector3() const
Gets a Bullet vector3.
Definition: vector3.cpp:555
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
virtual ~UniversalConstraint()
Class destructor.
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
btGeneric6DofConstraint * Generic6dof
The internal constraint that this class encapsulates.
virtual btRigidBody * _GetPhysicsObject() const
Accessor for the internal rigid body physics proxy.
Definition: rigidproxy.cpp:406
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
This is simply a place for storing all the Physics Related functions.
RigidProxy * ProxA
The first Collidable this constraint applies to.
Definition: constraint.h:130
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
RigidProxy * ProxB
The second Collidable this constraint applies to.
Definition: constraint.h:133
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this Constraint.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159