constrainRotation method

void constrainRotation(
  1. BoneChain fk,
  2. double rotation
)

Implementation

void constrainRotation(BoneChain fk, double rotation) {
  ActorBone bone = fk.bone;
  Mat2D parentWorld = bone.parent!.worldTransform;
  Mat2D transform = bone.transform;
  TransformComponents c = fk.transformComponents;

  if (rotation == 0.0) {
    Mat2D.identity(transform);
  } else {
    Mat2D.fromRotation(transform, rotation);
  }
  // Translate
  transform[4] = c.x;
  transform[5] = c.y;
  // Scale
  double scaleX = c.scaleX;
  double scaleY = c.scaleY;
  transform[0] *= scaleX;
  transform[1] *= scaleX;
  transform[2] *= scaleY;
  transform[3] *= scaleY;
  // Skew
  double skew = c.skew;
  if (skew != 0.0) {
    transform[2] = transform[0] * skew + transform[2];
    transform[3] = transform[1] * skew + transform[3];
  }

  Mat2D.multiply(bone.worldTransform, parentWorld, transform);
}