To understand how this works imagine the following:
- Position both objects so that their origin is on an arbitary line. The direction of this line is called the pin vector.
- Define a reference vector for each object that is perpendicular to the pin vector and passes through the objects' origins. You can imagine up-vectors/front-vectors or whatever you prefer.
- Determine the angle between these two reference vectors as they meet the pin vector (and are superimposed so you are measuring the relative rotation of the two bodies around the pin).
- This angle is the error angle and must be signed.
- Pass the angle and the pin values to NewtonUserJointAddAngularRow and Newton will drive the relative angular position, velocity and acceleration to zero. It does this by applying torque to both bodies.
- Experiment with the sign to make sure the bodies move in the right direction (the wrong sign will blow up the joint).
This will be used in the next section to remove all rotation from the 2D joint.