Skip to content

Commit

Permalink
Issue #560
Browse files Browse the repository at this point in the history
Removed limit state from rope joint. Instead you can get the
current length
  • Loading branch information
erincatto committed Apr 19, 2020
1 parent 4de0ea3 commit 1025f9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
4 changes: 2 additions & 2 deletions include/box2d/b2_rope_joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class b2RopeJoint : public b2Joint
void SetMaxLength(float length) { m_maxLength = length; }
float GetMaxLength() const;

b2LimitState GetLimitState() const;
// Get current length
float GetLength() const;

/// Dump joint to dmLog
void Dump() override;
Expand Down Expand Up @@ -112,7 +113,6 @@ class b2RopeJoint : public b2Joint
float m_invIA;
float m_invIB;
float m_mass;
b2LimitState m_state;
};

#endif
19 changes: 5 additions & 14 deletions src/dynamics/b2_rope_joint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ b2RopeJoint::b2RopeJoint(const b2RopeJointDef* def)

m_mass = 0.0f;
m_impulse = 0.0f;
m_state = e_inactiveLimit;
m_length = 0.0f;
}

Expand Down Expand Up @@ -77,14 +76,6 @@ void b2RopeJoint::InitVelocityConstraints(const b2SolverData& data)
m_length = m_u.Length();

float C = m_length - m_maxLength;
if (C > 0.0f)
{
m_state = e_atUpperLimit;
}
else
{
m_state = e_inactiveLimit;
}

if (m_length > b2_linearSlop)
{
Expand Down Expand Up @@ -176,8 +167,8 @@ bool b2RopeJoint::SolvePositionConstraints(const b2SolverData& data)
b2Vec2 rB = b2Mul(qB, m_localAnchorB - m_localCenterB);
b2Vec2 u = cB + rB - cA - rA;

float length = u.Normalize();
float C = length - m_maxLength;
m_length = u.Normalize();
float C = m_length - m_maxLength;

C = b2Clamp(C, 0.0f, b2_maxLinearCorrection);

Expand All @@ -194,7 +185,7 @@ bool b2RopeJoint::SolvePositionConstraints(const b2SolverData& data)
data.positions[m_indexB].c = cB;
data.positions[m_indexB].a = aB;

return length - m_maxLength < b2_linearSlop;
return m_length - m_maxLength < b2_linearSlop;
}

b2Vec2 b2RopeJoint::GetAnchorA() const
Expand Down Expand Up @@ -224,9 +215,9 @@ float b2RopeJoint::GetMaxLength() const
return m_maxLength;
}

b2LimitState b2RopeJoint::GetLimitState() const
float b2RopeJoint::GetLength() const
{
return m_state;
return m_length;
}

void b2RopeJoint::Dump()
Expand Down

0 comments on commit 1025f9a

Please sign in to comment.