erincatto / box2d

Box2D is a 2D physics engine for games

Home Page:https://box2d.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Halt criteria for b2GearJoint::SolvePositionConstraints

louis-langholtz opened this issue · comments

I've noticed that the return value for b2GearJoint::SolvePositionConstraints of return linearError < b2_linearSlop is commented with TODO_ERIN not implemented and that the linearError variable is only initialized to 0.0f making the function always return true.

Might something like the following be an algorithmic description of an implementation for this that would be reasonable/desirable/helpful?

  1. Set a linear error variable to the max magnitude of the linear position deltas (of m_mA * impulse * JvA, m_mB * impulse * JvBD, etc.).
  2. Set a angular error variable to the max angular position delta (of aA += m_iA * impulse * JwA, aB += m_iB * impulse * JwB, etc.).
  3. Return true if the linear error is less than b2_linearSlop and the angular error is less than b2_angularSlop, or return false otherwise.

With potentially an optimization like using the magnitude squared instead of the magnitude to avoid doing the square roots and compensating with using the squared value of b2_linearSlop.