computeTransformMatrix method

Matrix4 computeTransformMatrix()

Computes the transformation matrix of this node. This method can be overriden if a custom matrix is required. There is usually no reason to call this method directly.

Implementation

Matrix4 computeTransformMatrix() {
  double cx, sx, cy, sy;

  if (_rotation == 0.0) {
    cx = 1.0;
    sx = 0.0;
    cy = 1.0;
    sy = 0.0;
  } else {
    double radiansX = convertDegrees2Radians(_rotation);
    double radiansY = convertDegrees2Radians(_rotation);

    cx = math.cos(radiansX);
    sx = math.sin(radiansX);
    cy = math.cos(radiansY);
    sy = math.sin(radiansY);
  }

  // Create transformation matrix for scale, position and rotation
  Matrix4 matrix = Matrix4(
      cy * _scaleX,
      sy * _scaleX,
      0.0,
      0.0,
      -sx * _scaleY,
      cx * _scaleY,
      0.0,
      0.0,
      0.0,
      0.0,
      1.0,
      0.0,
      _position.dx,
      _position.dy,
      0.0,
      1.0);

  if (_skewX != 0.0 || _skewY != 0.0) {
    // Needs skew transform
    Matrix4 skew = Matrix4(
        1.0,
        math.tan(radians(_skewX)),
        0.0,
        0.0,
        math.tan(radians(_skewY)),
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0);
    matrix.multiply(skew);
  }

  return matrix;
}