Matrix transformationMatrix

The transformation matrix of this display object relative to this display object's parent.

The transformation matrix is calculated according the following properties of this display object: x, y, pivotX, pivotY, rotation, scaleX, scaleY, skewX and skewY

Source

@override
Matrix get transformationMatrix {

  // _transformationMatrix.identity();
  // _transformationMatrix.translate(-_pivotX, -_pivotY);
  // _transformationMatrix.scale(_scaleX, _scaleY);
  // _transformationMatrix.rotate(_rotation);
  // _transformationMatrix.translate(_x, _y);

  if (_transformationMatrixRefresh) {

    _transformationMatrixRefresh = false;

    var matrix = _transformationMatrix;
    num rotation = _rotation;
    num scaleX = _scaleX;
    num scaleY = _scaleY;
    num skewX = _skewX;
    num skewY = _skewY;

    // Having a scale of 0 is bad, the matrix.det gets zero which causes
    // infinite values on a inverted matrix. It also causes a bug on
    // Firefox in some Linux distrubutions:
    // https://bugzilla.mozilla.org/show_bug.cgi?id=661452

    if (scaleX > -0.0001 && scaleX < 0.0001) scaleX = (scaleX >= 0) ? 0.0001 : -0.0001;
    if (scaleY > -0.0001 && scaleY < 0.0001) scaleY = (scaleY >= 0) ? 0.0001 : -0.0001;

    if (skewX != 0.0 || skewY != 0.0) {
      num ma = scaleX * cos(skewY + rotation);
      num mb = scaleX * sin(skewY + rotation);
      num mc = -scaleY * sin(skewX + rotation);
      num md = scaleY * cos(skewX + rotation);
      num mx = _x - _pivotX * ma - _pivotY * mc;
      num my = _y - _pivotX * mb - _pivotY * md;
      matrix.setTo(ma, mb, mc, md, mx, my);
    } else if (rotation != 0.0) {
      num cr = cos(rotation);
      num sr = sin(rotation);
      num ma = scaleX * cr;
      num mb = scaleX * sr;
      num mc = -scaleY * sr;
      num md = scaleY * cr;
      num mx = _x - _pivotX * ma - _pivotY * mc;
      num my = _y - _pivotX * mb - _pivotY * md;
      matrix.setTo(ma, mb, mc, md, mx, my);
    } else {
      num mx = _x - _pivotX * scaleX;
      num my = _y - _pivotY * scaleY;
      matrix.setTo(scaleX, 0.0, 0.0, scaleY, mx, my);
    }
  }

  return _transformationMatrix;
}