zoomMatrix method

Matrix4 zoomMatrix(
  1. double zoomRatio, {
  2. Offset? center,
})

Calculate the matrix that changes zoom ratio.

center specifies the center of the zoom operation in widget's "local" coordinates. e.g. TapDownDetails.localPosition

Implementation

Matrix4 zoomMatrix(double zoomRatio, {Offset? center}) {
  final ratio = zoomRatio / this.zoomRatio;
  final offset = this.offset;
  final dx = center?.dx ?? _state!._lastViewSize!.width * 0.5;
  final dy = center?.dy ?? _state!._lastViewSize!.height * 0.5;
  final left = clampX((offset.dx + dx) * ratio - dx, zoomRatio);
  final top = clampY((offset.dy + dy) * ratio - dy, zoomRatio);
  return Matrix4.compose(
    math64.Vector3(-left, -top, 0),
    math64.Quaternion.identity(),
    math64.Vector3(zoomRatio, zoomRatio, 1),
  );
}