MezzanineEngine
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Mezzanine
src
Physics
gearconstraint.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 _physicsgearconstraint_cpp
41
#define _physicsgearconstraint_cpp
42
43
#include "Physics/gearconstraint.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
GearConstraint::GearConstraint
(
RigidProxy
* ProxyA,
RigidProxy
* ProxyB,
const
Vector3
& AxisA,
const
Vector3
& AxisB,
const
Real
Ratio)
56
{
57
this->
SetBodies
(ProxyA,ProxyB);
58
59
this->
Gear
=
new
btGearConstraint(*(
ProxA
->
_GetPhysicsObject
()), *(
ProxB
->
_GetPhysicsObject
()), AxisA.
GetBulletVector3
(), AxisB.
GetBulletVector3
(), Ratio);
60
}
61
62
GearConstraint::~GearConstraint
()
63
{
delete
this->
Gear
; }
64
65
///////////////////////////////////////////////////////////////////////////////
66
// Axis configuration
67
68
void
GearConstraint::SetAxisA
(
const
Vector3
& Axis)
69
{ this->
Gear
->setAxisInA(Axis.
GetBulletVector3
()); }
70
71
void
GearConstraint::SetAxisB
(
const
Vector3
& Axis)
72
{ this->
Gear
->setAxisInB(Axis.
GetBulletVector3
()); }
73
74
Vector3
GearConstraint::GetAxisA
()
const
75
{
return
Vector3
( this->
Gear
->getAxisInA() ); }
76
77
Vector3
GearConstraint::GetAxisB
()
const
78
{
return
Vector3
( this->
Gear
->getAxisInB() ); }
79
80
///////////////////////////////////////////////////////////////////////////////
81
// Ratio Configuration
82
83
void
GearConstraint::SetRotationRatio
(
const
Real
Ratio)
84
{ this->
Gear
->setRatio(Ratio); }
85
86
Real
GearConstraint::GetRotationRatio
()
const
87
{
return
this->
Gear
->getRatio(); }
88
89
///////////////////////////////////////////////////////////////////////////////
90
// Parameter Configuration
91
92
Constraint::ParamList
GearConstraint::ValidParamOnAxis
(
int
Axis)
const
93
{
94
Constraint::ParamList
Results;
95
return
Results;
96
}
97
98
Constraint::AxisList
GearConstraint::ValidLinearAxis
()
const
99
{
100
Constraint::AxisList
Results;
101
return
Results;
102
}
103
104
Constraint::AxisList
GearConstraint::ValidAngularAxis
()
const
105
{
106
Constraint::AxisList
Results;
107
return
Results;
108
}
109
110
bool
GearConstraint::HasParamBeenSet
(
ConstraintParam
Param,
int
Axis)
const
111
{
112
return
false
;
113
}
114
115
///////////////////////////////////////////////////////////////////////////////
116
// Serialization
117
118
void
GearConstraint::ProtoSerialize
(
XML::Node
& CurrentRoot)
const
119
{
120
XML::Node
P2PNode = CurrentRoot.
AppendChild
(this->
GearConstraint::SerializableName
());
// The base node all the base constraint stuff will go in
121
if
(!P2PNode)
122
{
SerializeError
(
"Create P2PNode"
,
SerializableName
()); }
123
124
XML::Attribute
VerAttr = P2PNode.
AppendAttribute
(
"Version"
);
125
XML::Attribute
RatioAttr = P2PNode.
AppendAttribute
(
"Ratio"
);
126
127
if
( VerAttr && RatioAttr )
128
{
129
VerAttr.
SetValue
(1);
130
RatioAttr.
SetValue
(this->
GetRotationRatio
());
131
}
else
{
132
SerializeError
(
"Create P2PNode Attributes"
,
SerializableName
());
133
}
134
135
XML::Node
ActorANode = P2PNode.
AppendChild
(
"ActorA"
);
136
if
(!ActorANode)
137
{
SerializeError
(
"Create ActorANode"
,
SerializableName
()); }
138
this->
GetAxisA
().
ProtoSerialize
(ActorANode);
139
140
XML::Node
ActorBNode = P2PNode.
AppendChild
(
"ActorB"
);
141
if
(!ActorBNode)
142
{
SerializeError
(
"Create ActorBNode"
,
SerializableName
()); }
143
this->
GetAxisB
().
ProtoSerialize
(ActorBNode);
144
145
this->
Constraint::ProtoSerialize
(P2PNode);
146
}
147
148
void
GearConstraint::ProtoDeSerialize
(
const
XML::Node
& OneNode)
149
{
150
if
(
Mezzanine::String
(OneNode.
Name
())==this->
GearConstraint::SerializableName
() )
151
{
152
if
(OneNode.
GetAttribute
(
"Version"
).
AsInt
() == 1)
153
{
154
this->
Constraint::ProtoDeSerialize
(OneNode.
GetChild
(
"Constraint"
));
155
156
this->
SetRotationRatio
(OneNode.
GetAttribute
(
"Ratio"
).
AsReal
());
157
158
XML::Node
ActorANode = OneNode.
GetChild
(
"ActorA"
);
159
if
(!ActorANode)
160
{
DeSerializeError
(
"Could not find ActorA axis"
,
SerializableName
()); }
161
162
XML::Node
ActorBNode = OneNode.
GetChild
(
"ActorB"
);
163
if
(!ActorBNode)
164
{
DeSerializeError
(
"Could not find ActorB axis"
,
SerializableName
()); }
165
166
Vector3
temp;
167
temp.
ProtoDeSerialize
(ActorANode.GetFirstChild());
168
this->
SetAxisA
(temp);
169
temp.
ProtoDeSerialize
(ActorBNode.
GetFirstChild
());
170
this->
SetAxisB
(temp);
171
}
else
{
172
DeSerializeError
(
"find usable serialization version"
,
SerializableName
());
173
}
174
}
else
{
175
DeSerializeError
(
String
(
"find correct class to deserialize, found a "
)+OneNode.
Name
(),
SerializableName
());
176
}
177
}
178
179
String
GearConstraint::SerializableName
()
180
{
return
"GearConstraint"
; }
181
182
///////////////////////////////////////////////////////////////////////////////
183
// Internal Methods
184
185
btTypedConstraint*
GearConstraint::GetConstraintBase
()
const
186
{
return
this->
Gear
; }
187
}
//Physics
188
}
//Mezzanine
189
190
#endif
Generated on Mon Jan 6 2014 20:58:05 for MezzanineEngine by
1.8.4