updateTransformation method

void updateTransformation(
  1. CanvasRenderingContext2D ctx
)

Sets the rendering context such that all drawing commands given in terms of the world coordinate system will display correctly on the canvas screen.

Implementation

void updateTransformation(CanvasRenderingContext2D ctx) {
  // Clear all previous transformation.
  ctx.setTransform(1, 0, 0, 1, 0, 0);

  // Translate to the center of the canvas screen. This will be considered the
  // actual origin.
  ctx.translate(extents.x, extents.y);

  // Translate to account for the currently applied translation.
  ctx.translate(translation.x, translation.y);

  // Scale everything according to the current scale and mirror the y-axis.
  ctx.scale(scale, -scale);
}