perspectiveWarp static method

Matrix4 perspectiveWarp(
  1. DoughTransformerContext context
)

A utility method which creates a Matrix4 that perspectively rotates wigets around their yaw and pitch axes based on DoughTransformerContext.delta and DoughRecipe.viscosity.

Implementation

static Matrix4 perspectiveWarp(DoughTransformerContext context) {
  if (!context.recipe.usePerspectiveWarp) {
    return Matrix4.identity();
  }

  final perspDelta = -context.delta * context.t / context.recipe.viscosity;
  return Matrix4.identity()
    ..setEntry(3, 2, context.recipe.perspectiveWarpDepth)
    ..rotateY(-perspDelta.x)
    ..rotateX(perspDelta.y)
    ..scale(perspDelta.length / context.recipe.viscosity + 1);
}