GearJoint.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_GEARJOINT_HPP
23 #define PLAYRHO_DYNAMICS_JOINTS_GEARJOINT_HPP
24 
28 
29 namespace playrho {
30 namespace d2 {
31 
46 class GearJoint : public Joint
47 {
48 public:
49 
51  static bool IsOkay(const GearJointConf& data) noexcept;
52 
57  GearJoint(const GearJointConf& data);
58 
59  void Accept(JointVisitor& visitor) const override;
60  void Accept(JointVisitor& visitor) override;
61 
62  Length2 GetAnchorA() const override;
63  Length2 GetAnchorB() const override;
64 
65  Momentum2 GetLinearReaction() const override;
66  AngularMomentum GetAngularReaction() const override;
67 
69  Length2 GetLocalAnchorA() const noexcept { return m_localAnchorA; }
70 
72  Length2 GetLocalAnchorB() const noexcept { return m_localAnchorB; }
73 
75  NonNull<Joint*> GetJoint1() const noexcept { return m_joint1; }
76 
78  NonNull<Joint*> GetJoint2() const noexcept { return m_joint2; }
79 
81  void SetRatio(Real ratio);
82 
84  Real GetRatio() const noexcept;
85 
87  Real GetConstant() const noexcept;
88 
89 private:
90 
91  void InitVelocityConstraints(BodyConstraintsMap& bodies, const StepConf& step,
92  const ConstraintSolverConf& conf) override;
93  bool SolveVelocityConstraints(BodyConstraintsMap& bodies, const StepConf& step) override;
94  bool SolvePositionConstraints(BodyConstraintsMap& bodies,
95  const ConstraintSolverConf& conf) const override;
96 
97  NonNull<Joint*> m_joint1;
98  NonNull<Joint*> m_joint2;
99 
100  JointType m_typeA;
101  JointType m_typeB;
102 
103  // Body A is connected to body C
104  // Body B is connected to body D
105  Body* m_bodyC;
106  Body* m_bodyD;
107 
108  // Solver shared
109  Length2 m_localAnchorA;
110  Length2 m_localAnchorB;
111  Length2 m_localAnchorC;
112  Length2 m_localAnchorD;
113 
114  UnitVec m_localAxisC;
115  UnitVec m_localAxisD;
116 
117  Angle m_referenceAngleA;
118  Angle m_referenceAngleB;
119 
120  Real m_constant;
121  Real m_ratio;
122 
123  Momentum m_impulse = 0_Ns;
124 
125  // Solver temp
126  Vec2 m_JvAC = Vec2{};
127  Vec2 m_JvBD;
128  Length m_JwA = 0_m;
129  Length m_JwB;
130  Length m_JwC;
131  Length m_JwD;
132  Real m_mass;
133 };
134 
135 inline Real GearJoint::GetRatio() const noexcept
136 {
137  return m_ratio;
138 }
139 
140 inline Real GearJoint::GetConstant() const noexcept
141 {
142  return m_constant;
143 }
144 
145 } // namespace d2
146 } // namespace playrho
147 
148 #endif // PLAYRHO_DYNAMICS_JOINTS_GEARJOINT_HPP