void VPathRenderingData::RemoveLinkRoll(hkvMat3 const& mPrevRot, hkvMat3& mRot, bool& bDirection) const
{
  hkvMat3 mPrevRotInv(mPrevRot);
  VVERIFY(mPrevRotInv.invert() == HKV_SUCCESS);

  // Calculate the rotation of the current link in the space of the
  // previous link
  hkvMat3 mThisInPrev = mPrevRotInv.multiply(mRot);

  // Check whether we are changing direction (that is, we have a sharp angle 
  // between two links). In this case, we need to change how we adjust the roll.
  hkvVec3 v2(mThisInPrev * hkvVec3(1, 0, 0));
  bool bChangingDirection = bDirection ? v2[0] > 0 : v2[0] < 0;
  if (bChangingDirection)
    bDirection = !bDirection;

  // Adjust the roll component
  float rgfThisInPrev[3];
  mThisInPrev.getAsEulerAngles(rgfThisInPrev[2], rgfThisInPrev[1], rgfThisInPrev[0]);

  if (bDirection)
    rgfThisInPrev[2] = 180.f;
  else
    rgfThisInPrev[2] = 0.f;

  mRot.setFromEulerAngles(rgfThisInPrev[2], rgfThisInPrev[1], rgfThisInPrev[0]);

  // Transform back to global space
  mRot = mPrevRot.multiply(mRot);
}