TargetJoint.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2007 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_MOUSEJOINT_HPP
23 #define PLAYRHO_DYNAMICS_JOINTS_MOUSEJOINT_HPP
24 
27 
28 namespace playrho {
29 namespace d2 {
30 
42 class TargetJoint : public Joint
43 {
44 public:
45 
47  static bool IsOkay(const TargetJointConf& def) noexcept;
48 
53  TargetJoint(const TargetJointConf& def);
54 
55  void Accept(JointVisitor& visitor) const override;
56  void Accept(JointVisitor& visitor) override;
57  Length2 GetAnchorA() const override;
58  Length2 GetAnchorB() const override;
59  Momentum2 GetLinearReaction() const override;
60  AngularMomentum GetAngularReaction() const override;
61  bool ShiftOrigin(const Length2 newOrigin) override;
62 
64  Length2 GetLocalAnchorB() const noexcept;
65 
67  void SetTarget(const Length2 target) noexcept;
68 
70  Length2 GetTarget() const noexcept;
71 
73  void SetMaxForce(NonNegative<Force> force) noexcept;
74 
76  NonNegative<Force> GetMaxForce() const noexcept;
77 
79  void SetFrequency(NonNegative<Frequency> hz) noexcept;
80 
82  NonNegative<Frequency> GetFrequency() const noexcept;
83 
85  void SetDampingRatio(NonNegative<Real> ratio) noexcept;
86 
88  NonNegative<Real> GetDampingRatio() const noexcept;
89 
90 private:
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 
98  Mass22 GetEffectiveMassMatrix(const BodyConstraint& body) const noexcept;
99 
100  Length2 m_targetA;
101  Length2 m_localAnchorB;
102  NonNegative<Frequency> m_frequency = NonNegative<Frequency>{0_Hz};
103  NonNegative<Real> m_dampingRatio = NonNegative<Real>{0};
104  NonNegative<Force> m_maxForce = NonNegative<Force>{0_N};
105  InvMass m_gamma = InvMass{0};
106 
107  Momentum2 m_impulse = Momentum2{};
108 
109  // Solver variables. These are only valid after InitVelocityConstraints called.
110  Length2 m_rB;
111  Mass22 m_mass;
112  LinearVelocity2 m_C;
113 };
114 
115 inline Length2 TargetJoint::GetLocalAnchorB() const noexcept
116 {
117  return m_localAnchorB;
118 }
119 
120 inline Length2 TargetJoint::GetTarget() const noexcept
121 {
122  return m_targetA;
123 }
124 
125 inline void TargetJoint::SetMaxForce(NonNegative<Force> force) noexcept
126 {
127  m_maxForce = force;
128 }
129 
131 {
132  return m_maxForce;
133 }
134 
136 {
137  m_frequency = hz;
138 }
139 
141 {
142  return m_frequency;
143 }
144 
146 {
147  m_dampingRatio = ratio;
148 }
149 
151 {
152  return m_dampingRatio;
153 }
154 
155 } // namespace d2
156 } // namespace playrho
157 
158 #endif // PLAYRHO_DYNAMICS_JOINTS_MOUSEJOINT_HPP