RopeJoint.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_ROPEJOINT_HPP
23 #define PLAYRHO_DYNAMICS_JOINTS_ROPEJOINT_HPP
24 
27 
28 namespace playrho {
29 namespace d2 {
30 
44 class RopeJoint : public Joint
45 {
46 public:
47 
52  RopeJoint(const RopeJointConf& data);
53 
54  void Accept(JointVisitor& visitor) const override;
55  void Accept(JointVisitor& visitor) override;
56 
57  Length2 GetAnchorA() const override;
58  Length2 GetAnchorB() const override;
59 
60  Momentum2 GetLinearReaction() const override;
61  AngularMomentum GetAngularReaction() const override;
62 
64  Length2 GetLocalAnchorA() const { return m_localAnchorA; }
65 
67  Length2 GetLocalAnchorB() const { return m_localAnchorB; }
68 
70  void SetMaxLength(Length length) { m_maxLength = length; }
71 
73  Length GetMaxLength() const;
74 
76  LimitState GetLimitState() const;
77 
78 private:
79 
80  void InitVelocityConstraints(BodyConstraintsMap& bodies, const StepConf& step,
81  const ConstraintSolverConf& conf) override;
82  bool SolveVelocityConstraints(BodyConstraintsMap& bodies, const StepConf& step) override;
83  bool SolvePositionConstraints(BodyConstraintsMap& bodies,
84  const ConstraintSolverConf& conf) const override;
85 
86  // Solver shared
87  Length2 m_localAnchorA;
88  Length2 m_localAnchorB;
89  Length m_maxLength;
90  Length m_length = 0;
91  Momentum m_impulse = 0_Ns;
92 
93  // Solver temp
94  UnitVec m_u;
95  Length2 m_rA;
96  Length2 m_rB;
97  Mass m_mass = 0_kg;
98  LimitState m_state = e_inactiveLimit;
99 };
100 
101 } // namespace d2
102 } // namespace playrho
103 
104 #endif // PLAYRHO_DYNAMICS_JOINTS_ROPEJOINT_HPP