transformationMatrix property

Matrix transformationMatrix
override

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

Implementation

@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;
    var rotation = _rotation;
    var scaleX = _scaleX;
    var scaleY = _scaleY;
    var skewX = _skewX;
    var 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) {
      var ma = scaleX * cos(skewY + rotation);
      var mb = scaleX * sin(skewY + rotation);
      var mc = -scaleY * sin(skewX + rotation);
      var md = scaleY * cos(skewX + rotation);
      var mx = _x - _pivotX * ma - _pivotY * mc;
      var my = _y - _pivotX * mb - _pivotY * md;
      matrix.setTo(ma, mb, mc, md, mx, my);
    } else if (rotation != 0.0) {
      var cr = cos(rotation);
      var sr = sin(rotation);
      var ma = scaleX * cr;
      var mb = scaleX * sr;
      var mc = -scaleY * sr;
      var md = scaleY * cr;
      var mx = _x - _pivotX * ma - _pivotY * mc;
      var my = _y - _pivotX * mb - _pivotY * md;
      matrix.setTo(ma, mb, mc, md, mx, my);
    } else {
      var mx = _x - _pivotX * scaleX;
      var my = _y - _pivotY * scaleY;
      matrix.setTo(scaleX, 0.0, 0.0, scaleY, mx, my);
    }
  }

  return _transformationMatrix;
}