viscositySkew static method
A utility method which creates a Matrix4 that skews widgets in the
direction of the DoughTransformerContext.delta based on the
DoughRecipe.viscosity
. If an DoughTransformerContext.axis is
specified, the resulting matrix will be constrained to the provided axis.
Implementation
static Matrix4 viscositySkew(DoughTransformerContext context) {
final skewSize =
context.t * context.delta.length / context.recipe.viscosity;
if (context.axis == Axis.vertical) {
return Matrix4.identity()..scale(1, skewSize, 1);
} else if (context.axis == Axis.horizontal) {
return Matrix4.identity()..scale(skewSize, 1, 1);
}
final rotateAway = Matrix4.rotationZ(-context.deltaAngle);
final rotateTowards = Matrix4.rotationZ(context.deltaAngle);
final skew = Matrix4.columns(
vmath.Vector4(1, skewSize, 0, 0),
vmath.Vector4(skewSize, 1, 0, 0),
vmath.Vector4(0, 0, 1, 0),
vmath.Vector4(0, 0, 0, 1),
);
return rotateAway.multiplied(skew).multiplied(rotateTowards);
}