getMatrix4 method
Implementation
Matrix4? getMatrix4(Map? spec) {
if (spec == null || spec.isEmpty) {
return null;
}
final type = spec["_type"] ?? "default";
switch (type) {
case "scale":
return Matrix4.diagonal3Values(
parseDouble(spec["scaleX"], defaultValue: 1),
parseDouble(spec["scaleY"], defaultValue: 1),
1.0);
case "translate":
final offset = getOffset(spec["offset"]) ?? Offset.zero;
return Matrix4.translationValues(offset.dx, offset.dy, 0.0);
case "rotate":
createZRotation(sin, cos) {
final Matrix4 result = Matrix4.zero();
result.storage[0] = cos;
result.storage[1] = sin;
result.storage[4] = -sin;
result.storage[5] = cos;
result.storage[10] = 1.0;
result.storage[15] = 1.0;
return result;
}
computeRotation(radians) {
if (radians == 0.0) {
return Matrix4.identity();
}
final double sin = math.sin(radians);
if (sin == 1.0) {
return createZRotation(1.0, 0.0);
}
if (sin == -1.0) {
return createZRotation(-1.0, 0.0);
}
final double cos = math.cos(radians);
if (cos == -1.0) {
return createZRotation(0.0, -1.0);
}
return createZRotation(sin, cos);
}
return computeRotation(parseDouble(spec["angle"]) * math.pi / 180);
case "flip":
return Matrix4.diagonal3Values(parseBool(spec["flipX"]) ? -1.0 : 1.0,
parseBool(spec["flipY"]) ? -1.0 : 1.0, 1.0);
default:
return null;
}
}