Toggle navigation
PlayRho
0.9.0
GitHub
Main Page
Modules
Classes
Files
Examples
File List
File Members
Dynamics
Joints
WheelJoint.hpp
Go to the documentation of this file.
1
/*
2
* Original work Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
3
* Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
4
*
5
* This software is provided 'as-is', without any express or implied
6
* warranty. In no event will the authors be held liable for any damages
7
* arising from the use of this software.
8
*
9
* Permission is granted to anyone to use this software for any purpose,
10
* including commercial applications, and to alter it and redistribute it
11
* freely, subject to the following restrictions:
12
*
13
* 1. The origin of this software must not be misrepresented; you must not
14
* claim that you wrote the original software. If you use this software
15
* in a product, an acknowledgment in the product documentation would be
16
* appreciated but is not required.
17
* 2. Altered source versions must be plainly marked as such, and must not be
18
* misrepresented as being the original software.
19
* 3. This notice may not be removed or altered from any source distribution.
20
*/
21
22
#ifndef PLAYRHO_DYNAMICS_JOINTS_WHEELJOINT_HPP
23
#define PLAYRHO_DYNAMICS_JOINTS_WHEELJOINT_HPP
24
25
#include <
PlayRho/Dynamics/Joints/Joint.hpp
>
26
#include <
PlayRho/Dynamics/Joints/WheelJointConf.hpp
>
27
28
namespace
playrho
{
29
namespace
d2 {
30
43
class
WheelJoint
:
public
Joint
44
{
45
public
:
46
51
WheelJoint
(
const
WheelJointConf
& def);
52
53
void
Accept
(
JointVisitor
& visitor)
const override
;
54
void
Accept
(
JointVisitor
& visitor)
override
;
55
56
Length2
GetAnchorA
()
const override
;
57
Length2
GetAnchorB
()
const override
;
58
59
Momentum2
GetLinearReaction
()
const override
;
60
AngularMomentum
GetAngularReaction
()
const override
;
61
63
Length2
GetLocalAnchorA
()
const
{
return
m_localAnchorA; }
64
66
Length2
GetLocalAnchorB
()
const
{
return
m_localAnchorB; }
67
69
UnitVec
GetLocalAxisA
()
const
{
return
m_localXAxisA; }
70
72
bool
IsMotorEnabled
() const noexcept {
return
m_enableMotor; }
73
75
void
EnableMotor
(
bool
flag);
76
79
RotInertia
GetMotorMass
() const noexcept {
return
m_motorMass; }
80
82
void
SetMotorSpeed
(
AngularVelocity
speed);
83
85
AngularVelocity
GetMotorSpeed
()
const
;
86
88
void
SetMaxMotorTorque
(
Torque
torque);
89
91
Torque
GetMaxMotorTorque
()
const
;
92
95
void
SetSpringFrequency
(
Frequency
frequency);
96
98
Frequency
GetSpringFrequency
()
const
;
99
101
void
SetSpringDampingRatio
(
Real
ratio);
102
104
Real
GetSpringDampingRatio
()
const
;
105
106
private
:
107
108
void
InitVelocityConstraints(
BodyConstraintsMap
& bodies,
const
StepConf
& step,
109
const
ConstraintSolverConf
& conf)
override
;
110
bool
SolveVelocityConstraints(
BodyConstraintsMap
& bodies,
const
StepConf
& step)
override
;
111
bool
SolvePositionConstraints(
BodyConstraintsMap
& bodies,
112
const
ConstraintSolverConf
& conf)
const override
;
113
114
// Solver shared
115
Length2
m_localAnchorA;
116
Length2
m_localAnchorB;
117
UnitVec
m_localXAxisA;
118
UnitVec
m_localYAxisA;
119
120
Frequency
m_frequency;
121
Real
m_dampingRatio;
122
123
Momentum
m_impulse = 0;
124
AngularMomentum
m_motorImpulse = 0;
125
Momentum
m_springImpulse = 0;
126
127
Torque
m_maxMotorTorque;
128
AngularVelocity
m_motorSpeed;
129
bool
m_enableMotor;
130
131
// Solver temp
132
UnitVec
m_ax;
133
UnitVec
m_ay;
134
135
Length
m_sAx;
136
Length
m_sBx;
137
Length
m_sAy;
138
Length
m_sBy;
139
140
Mass
m_mass = 0_kg;
141
RotInertia
m_motorMass =
RotInertia
{0};
142
Mass
m_springMass = 0_kg;
143
144
LinearVelocity
m_bias = 0_mps;
145
InvMass
m_gamma =
InvMass
{0};
146
};
147
148
inline
AngularMomentum
WheelJoint::GetAngularReaction
()
const
149
{
150
return
m_motorImpulse;
151
}
152
153
inline
AngularVelocity
WheelJoint::GetMotorSpeed
()
const
154
{
155
return
m_motorSpeed;
156
}
157
158
inline
Torque
WheelJoint::GetMaxMotorTorque
()
const
159
{
160
return
m_maxMotorTorque;
161
}
162
163
inline
void
WheelJoint::SetSpringFrequency
(
Frequency
hz)
164
{
165
m_frequency = hz;
166
}
167
168
inline
Frequency
WheelJoint::GetSpringFrequency
()
const
169
{
170
return
m_frequency;
171
}
172
173
inline
void
WheelJoint::SetSpringDampingRatio
(
Real
ratio)
174
{
175
m_dampingRatio = ratio;
176
}
177
178
inline
Real
WheelJoint::GetSpringDampingRatio
()
const
179
{
180
return
m_dampingRatio;
181
}
182
183
// Free functions on WheelJoint instances.
184
187
Length
GetJointTranslation
(
const
WheelJoint
& joint) noexcept;
188
191
AngularVelocity
GetAngularVelocity
(
const
WheelJoint
& joint) noexcept;
192
194
inline
Torque
GetMotorTorque
(
const
WheelJoint
& joint,
Frequency
inv_dt) noexcept
195
{
196
return
joint.GetAngularReaction() * inv_dt;
197
}
198
199
}
// namespace d2
200
}
// namespace playrho
201
202
#endif // PLAYRHO_DYNAMICS_JOINTS_WHEELJOINT_HPP