MotorJoint.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2012 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_MOTORJOINT_HPP
23 #define PLAYRHO_DYNAMICS_JOINTS_MOTORJOINT_HPP
24 
27 
28 namespace playrho {
29 namespace d2 {
30 
38 class MotorJoint : public Joint
39 {
40 public:
41 
46  MotorJoint(const MotorJointConf& def);
47 
48  void Accept(JointVisitor& visitor) const override;
49  void Accept(JointVisitor& visitor) override;
50 
51  Length2 GetAnchorA() const override;
52  Length2 GetAnchorB() const override;
53 
54  Momentum2 GetLinearReaction() const override;
55  AngularMomentum GetAngularReaction() const override;
56 
58  Length2 GetLinearOffset() const noexcept;
59 
61  void SetLinearOffset(const Length2 linearOffset);
62 
64  Angle GetAngularOffset() const noexcept;
65 
67  void SetAngularOffset(Angle angularOffset);
68 
70  NonNegative<Force> GetMaxForce() const noexcept;
71 
73  void SetMaxForce(NonNegative<Force> force);
74 
76  NonNegative<Torque> GetMaxTorque() const noexcept;
77 
79  void SetMaxTorque(NonNegative<Torque> torque);
80 
82  Real GetCorrectionFactor() const noexcept;
83 
85  void SetCorrectionFactor(Real factor);
86 
89  Length2 GetLinearError() const noexcept;
90 
93  Angle GetAngularError() const noexcept;
94 
95 private:
96 
97  void InitVelocityConstraints(BodyConstraintsMap& bodies, const StepConf& step,
98  const ConstraintSolverConf& conf) override;
99  bool SolveVelocityConstraints(BodyConstraintsMap& bodies, const StepConf& step) override;
100  bool SolvePositionConstraints(BodyConstraintsMap& bodies,
101  const ConstraintSolverConf& conf) const override;
102 
103  // Solver shared
104  Length2 m_linearOffset{};
105  Angle m_angularOffset{};
106  Momentum2 m_linearImpulse{};
107  AngularMomentum m_angularImpulse{};
108  NonNegative<Force> m_maxForce = NonNegative<Force>{0_N};
109  NonNegative<Torque> m_maxTorque = NonNegative<Torque>{0_Nm};
110  Real m_correctionFactor{};
111 
112  // Solver temp
113  Length2 m_rA;
114  Length2 m_rB;
115  Length2 m_linearError{};
116  Angle m_angularError{0_deg};
117  Mass22 m_linearMass;
118  RotInertia m_angularMass;
119 };
120 
122 {
123  return m_maxForce;
124 }
125 
127 {
128  m_maxForce = force;
129 }
130 
132 {
133  return m_maxTorque;
134 }
135 
137 {
138  m_maxTorque = torque;
139 }
140 
141 inline Length2 MotorJoint::GetLinearOffset() const noexcept
142 {
143  return m_linearOffset;
144 }
145 
146 inline Angle MotorJoint::GetAngularOffset() const noexcept
147 {
148  return m_angularOffset;
149 }
150 
152 {
153  return m_linearImpulse;
154 }
155 
157 {
158  return m_angularImpulse;
159 }
160 
161 inline Real MotorJoint::GetCorrectionFactor() const noexcept
162 {
163  return m_correctionFactor;
164 }
165 
166 inline Length2 MotorJoint::GetLinearError() const noexcept
167 {
168  return m_linearError;
169 }
170 
171 inline Angle MotorJoint::GetAngularError() const noexcept
172 {
173  return m_angularError;
174 }
175 
176 } // namespace d2
177 } // namespace playrho
178 
179 #endif // PLAYRHO_DYNAMICS_JOINTS_MOTORJOINT_HPP