Spinning Topp Logo BlackTopp Studios
inc
hinge2constraint.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 _physicshinge2constraint_cpp
41 #define _physicshinge2constraint_cpp
42 
43 #include "Physics/hinge2constraint.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  // Hinge2 Constraint Functions
57 
58  Hinge2Constraint::Hinge2Constraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Vector3& Anchor, const Vector3& Axis1, const Vector3& Axis2, PhysicsManager* Creator) :
59  Generic6DofSpringConstraint(ID,ProxyA,ProxyB,Creator)
60  { this->CreateConstraint(ProxyA,ProxyB,Anchor,Axis1,Axis2); }
61 
62  Hinge2Constraint::Hinge2Constraint(const UInt32 ID, RigidProxy* ProxyA, RigidProxy* ProxyB, const Transform& TransA, const Transform& TransB, PhysicsManager* Creator) :
63  Generic6DofSpringConstraint(ID,ProxyA,ProxyB,Creator)
64  { this->CreateConstraint(ProxyA,ProxyB,TransA,TransB); }
65 
67  Generic6DofSpringConstraint(0,NULL,Creator)
68  { this->ProtoDeSerialize(SelfRoot); }
69 
71  { /* Generic6Dof class will handle the cleanup */ }
72 
73  btHinge2Constraint* Hinge2Constraint::Hinge2() const
74  { return static_cast<btHinge2Constraint*>( this->Generic6dof ); }
75 
76  void Hinge2Constraint::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 btHinge2Constraint(*(RigidA->_GetPhysicsObject()),*(RigidB->_GetPhysicsObject()),TempOrigin,TempAxis1,TempAxis2);
83  this->Generic6dof->setFrames(TransA.GetBulletTransform(),TransB.GetBulletTransform());
84  }
85  }
86 
87  void Hinge2Constraint::CreateConstraint(RigidProxy* RigidA, RigidProxy* RigidB, 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 btHinge2Constraint(*(RigidA->_GetPhysicsObject()),*(RigidB->_GetPhysicsObject()),TempOrigin,TempAxis1,TempAxis2);
94  }
95  }
96 
97  ///////////////////////////////////////////////////////////////////////////////
98  // Limits
99 
101  { this->Hinge2()->setUpperLimit(Ang1Max); }
102 
104  { this->Hinge2()->setLowerLimit(Ang1Min); }
105 
106  ///////////////////////////////////////////////////////////////////////////////
107  // Serialization
108 
111 
113  { return "Hinge2Constraint"; }
114  }//Physics
115 }//Mezzanine
116 
117 #endif
Hinge2Constraint(const UInt32 ID, RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &Anchor, const Vector3 &Axis1, const Vector3 &Axis2, PhysicsManager *Creator)
Convenience constructor.
virtual ~Hinge2Constraint()
Class destructor.
static String GetSerializableName()
Get the name of the the XML tag the class will leave behind as its instances are serialized.
virtual btHinge2Constraint * Hinge2() const
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
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
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this Constraint.
virtual void SetUpperLimit(const Real AngelMax)
Convenience method for setting the maximum allowed turning angle.
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.
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.
virtual void SetLowerLimit(const Real AngelMin)
Convenience method for setting the minimum allowed turning angle.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
Creates a constraint as configurable as the 6Dof constraint, but has added support for spring motion...
virtual void CreateConstraint(RigidProxy *RigidA, RigidProxy *RigidB, const Transform &TransA, const Transform &TransB)
Creates the internal constraint.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159