transformMatrix property
Matrix4
get
transformMatrix
The total transformation matrix for the component. This matrix combines translation, rotation, reflection and scale transforms into a single entity. The matrix is cached and gets recalculated only as necessary.
The returned matrix must not be modified by the user.
Implementation
Matrix4 get transformMatrix {
if (_recalculate) {
// The transforms below are equivalent to:
// _transformMatrix = Matrix4.identity()
// .. translate(_position.x, _position.y)
// .. rotateZ(_angle)
// .. scale(_scale.x, _scale.y, 1)
// .. translate(_offset.x, _offset.y);
final m = _transformMatrix.storage;
final cosA = math.cos(_angle);
final sinA = math.sin(_angle);
m[0] = cosA * _scale.x;
m[1] = sinA * _scale.x;
m[4] = -sinA * _scale.y;
m[5] = cosA * _scale.y;
m[12] = _position.x + m[0] * _offset.x + m[4] * _offset.y;
m[13] = _position.y + m[1] * _offset.x + m[5] * _offset.y;
_recalculate = false;
}
return _transformMatrix;
}