Toggle navigation
PlayRho
0.9.0
GitHub
Main Page
Modules
Classes
Files
Examples
File List
File Members
Dynamics
Joints
PrismaticJoint.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_PRISMATICJOINT_HPP
23
#define PLAYRHO_DYNAMICS_JOINTS_PRISMATICJOINT_HPP
24
25
#include <
PlayRho/Dynamics/Joints/Joint.hpp
>
26
#include <
PlayRho/Dynamics/Joints/PrismaticJointConf.hpp
>
27
#include <
PlayRho/Common/BoundedValue.hpp
>
28
29
namespace
playrho
{
30
namespace
d2 {
31
46
class
PrismaticJoint
:
public
Joint
47
{
48
public
:
49
54
PrismaticJoint
(
const
PrismaticJointConf
& def);
55
56
void
Accept
(
JointVisitor
& visitor)
const override
;
57
void
Accept
(
JointVisitor
& visitor)
override
;
58
59
Length2
GetAnchorA
()
const override
;
60
Length2
GetAnchorB
()
const override
;
61
62
Momentum2
GetLinearReaction
()
const override
;
63
AngularMomentum
GetAngularReaction
()
const override
;
64
66
Length2
GetLocalAnchorA
()
const
{
return
m_localAnchorA; }
67
69
Length2
GetLocalAnchorB
()
const
{
return
m_localAnchorB; }
70
72
UnitVec
GetLocalAxisA
()
const
{
return
m_localXAxisA; }
73
75
Angle
GetReferenceAngle
()
const
{
return
m_referenceAngle; }
76
78
bool
IsLimitEnabled
() const noexcept;
79
81
void
EnableLimit
(
bool
flag) noexcept;
82
84
Length
GetLowerLimit
() const noexcept;
85
87
Length
GetUpperLimit
() const noexcept;
88
90
void
SetLimits
(
Length
lower,
Length
upper) noexcept;
91
93
bool
IsMotorEnabled
() const noexcept;
94
96
void
EnableMotor
(
bool
flag) noexcept;
97
99
void
SetMotorSpeed
(
AngularVelocity
speed) noexcept;
100
102
AngularVelocity
GetMotorSpeed
() const noexcept;
103
105
void
SetMaxMotorForce
(
Force
force) noexcept;
106
108
Force
GetMaxMotorForce
() const noexcept {
return
m_maxMotorForce; }
109
111
Momentum
GetMotorImpulse
() const noexcept {
return
m_motorImpulse; }
112
116
LimitState
GetLimitState
() const noexcept;
117
118
private:
119
void
InitVelocityConstraints(
BodyConstraintsMap
& bodies, const
StepConf
& step,
120
const
ConstraintSolverConf
& conf) override;
121
bool
SolveVelocityConstraints(
BodyConstraintsMap
& bodies, const
StepConf
& step) override;
122
bool
SolvePositionConstraints(
BodyConstraintsMap
& bodies,
123
const
ConstraintSolverConf
& conf) const override;
124
125
// Solver shared
126
Length2
m_localAnchorA;
127
Length2
m_localAnchorB;
128
UnitVec
m_localXAxisA;
129
UnitVec
m_localYAxisA;
130
Angle
m_referenceAngle;
131
Vec3
m_impulse =
Vec3
{};
132
Momentum
m_motorImpulse = 0;
133
Length
m_lowerTranslation;
134
Length
m_upperTranslation;
135
Force
m_maxMotorForce;
136
AngularVelocity
m_motorSpeed;
137
bool
m_enableLimit;
138
bool
m_enableMotor;
139
LimitState
m_limitState =
e_inactiveLimit
;
140
141
// Solver temp
142
UnitVec m_axis =
UnitVec::GetZero
();
143
UnitVec m_perp =
UnitVec::GetZero
();
144
Length
m_s1;
145
Length
m_s2;
146
Length
m_a1;
147
Length
m_a2;
148
Mat33
m_K;
149
Mass
m_motorMass = 0_kg;
150
};
151
152
inline
Length
PrismaticJoint::GetLowerLimit
() const noexcept
153
{
154
return
m_lowerTranslation;
155
}
156
157
inline
Length
PrismaticJoint::GetUpperLimit
() const noexcept
158
{
159
return
m_upperTranslation;
160
}
161
162
inline
bool
PrismaticJoint::IsLimitEnabled
() const noexcept
163
{
164
return
m_enableLimit;
165
}
166
167
inline
bool
PrismaticJoint::IsMotorEnabled
() const noexcept
168
{
169
return
m_enableMotor;
170
}
171
172
inline
AngularVelocity
PrismaticJoint::GetMotorSpeed
() const noexcept
173
{
174
return
m_motorSpeed;
175
}
176
177
inline
Joint::LimitState
PrismaticJoint::GetLimitState
() const noexcept
178
{
179
return
m_limitState;
180
}
181
184
Length
GetJointTranslation
(
const
PrismaticJoint
& joint) noexcept;
185
188
LinearVelocity
GetLinearVelocity
(
const
PrismaticJoint
& joint) noexcept;
189
192
inline
Force
GetMotorForce
(
const
PrismaticJoint
& joint,
Frequency
inv_dt) noexcept
193
{
194
return
joint.GetMotorImpulse() * inv_dt;
195
}
196
197
}
// namespace d2
198
}
// namespace playrho
199
200
#endif // PLAYRHO_DYNAMICS_JOINTS_PRISMATICJOINT_HPP