$updateTransformationMatrices method

void $updateTransformationMatrices(
  1. double? x,
  2. double? y,
  3. double pivotX,
  4. double pivotY,
  5. double scaleX,
  6. double scaleY,
  7. double skewX,
  8. double skewY,
  9. double rotation,
  10. GMatrix out,
)

(Internal usage) Updates the transformation matrices of a display object based on the given parameters.

  • x: The horizontal position of the display object.
  • y: The vertical position of the display object.
  • pivotX: The horizontal position of the display object's pivot point.
  • pivotY: The vertical position of the display object's pivot point.
  • scaleX: The horizontal scaling factor of the display object.
  • scaleY: The vertical scaling factor of the display object.
  • skewX: The horizontal skew angle of the display object in radians.
  • skewY: The vertical skew angle of the display object in radians.
  • rotation: The rotation of the display object in radians.
  • out: The output matrix where the updated transformation matrix will be stored.

Implementation

void $updateTransformationMatrices(
  double? x,
  double? y,
  double pivotX,
  double pivotY,
  double scaleX,
  double scaleY,
  double skewX,
  double skewY,
  double rotation,
  GMatrix out,
) {
  out.identity();
  if (skewX == 0 && skewY == 0) {
    /// optimization, no skewing.
    if (rotation == 0) {
      out.setTo(
        scaleX,
        0,
        0,
        scaleY,
        x! - pivotX * scaleX,
        y! - pivotY * scaleY,
      );
    } else {
      final cos = Math.cos(rotation);
      final sin = Math.sin(rotation);
      final a = scaleX * cos;
      final b = scaleX * sin;
      final c = scaleY * -sin;
      final d = scaleY * cos;
      final tx = x! - pivotX * a - pivotY * c;
      final ty = y! - pivotX * b - pivotY * d;
      out.setTo(a, b, c, d, tx, ty);
    }
  } else {
    out.identity();
    out.scale(scaleX, scaleY);
    out.skew(skewX, skewY); // MatrixUtils.skew(out, skewX, skewY);
    out.rotate(rotation);
    out.translate(x!, y!);
    if (pivotX != 0 || pivotY != 0) {
      out.tx = x - out.a * pivotX - out.c * pivotY;
      out.ty = y - out.b * pivotX - out.d * pivotY;
    }
  }
}