パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v4.0.1

matrix4_transform

Matrix4 変換を簡単に作成するためのヘルパー数学クラスで、Container の transform パラメータやその他の場所で使用できます。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
7.3万
いいね数
185
Pub ポイント
150

パッケージをインストール

flutter pub add matrix4_transform

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

Flutterでの2Dおよび3DグラフィックスのMatrix4変換の作成を簡素化する軽量なDartユーティリティパッケージです。Containerなどのウィジェットでtransformパラメータを使用するための変換行列を構築するための直感的なメソッドを提供し、回転、スケーリング、トランスレーション、スキューを正確に制御できます。アニメーション、カスタムレイアウト、高度な変換が必要なインタラクティブUI要素に最適です。このパッケージはプラットフォーム非依存であり、Flutterプロジェクトにシームレスに統合可能です。

用途

  • 複雑な変換を使用してUI要素をアニメーション化する
  • カスタム2D/3Dレイアウトの作成
  • インタラクティブなジェスチャーベースのインターフェースの構築
  • カメラまたはビューの回転を実装する
  • スケーラブルなゲームまたは可視化コンポーネントの設計

主な機能

  • シンプルでチェーン可能な行列の構築
  • 回転、スケーリング、トランスレーション、スキューをサポート
  • 一般的な変換操作向けの直感的な API
  • Container の transform プロパティと直接連携します
  • 軽量で依存関係なし

適している対象

  • 正確な行列制御が必要なFlutter開発者
  • アニメーションやインタラクティブなレイアウトに取り組むUIデザイナー
  • ゲームまたはビジュアライゼーションアプリの作成者
  • Flutterにおける3D変換について学ぶ初心者

注意事項

  • 重い数学的計算には適していない
  • Matrix4 の概念を理解している必要がある
  • 変形関連のユーティリティに限定
  • 組み込みのアニメーションサポートなし
  • 動的な効果を実現するために、アニメーションコントローラーと併用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

pub package

matrix4_transform

Have you noticed the transform parameter in the Container and Transform widgets, which lets you move, rotate, resize, and flip?

This package provides a helper math class that makes it easy to create Matrix4 transformations.

Example:

// Rotates the Container 45 degrees and then
// translates 25 pixels to the right. 
Container(
   transform:
     Matrix4Transform()
       .rotateDegrees(45, origin: Offset(25, 25))
       .translate(x: 25)
       .matrix4,
   child: ...
);

To see it in action, run the example in the example tab.

How to use it

Matrix4Transform is immutable (in contrast, Matrix4 is mutable).

First create a Matrix4Transform:

Matrix4Transform();

Then call the methods to transform it. For example:

Matrix4Transform()
   .scale(1.5)
   .upRight(35)
   .rotate(pi/2);

In the end, call matrix4:

Matrix4 myMatrix 
   = Matrix4Transform()
     .scale(1.5)
     .upRight(35)
     .rotate(pi/2)
     .matrix4;                        

Note: The transformations will be applied in order, and their order may change the end result.

If you already have a matrix4 and want to further transform it, you can use the from constructor:

Matrix4 myMatrix = ...;

var myTransform = Matrix4Transform.from(myMatrix);

Methods you can use

  • rotate(double angleRadians, {Offset origin})
  • rotateDegrees(double angleDegrees, {Offset origin})
  • rotateByCenterDegrees(double angleDegrees, Size size)
  • rotateByCenter(_toRadians(angleDegrees), size)
  • translate({double x = 0, double y = 0})
  • translateOriginalCoordinates({double x = 0, double y = 0})
  • scale(double factor, {Offset origin})
  • scaleBy({double x = 1, double y = 1, Offset origin})
  • scaleHorizontally(double factor)
  • scaleVertically(double factor)
  • translateOffset(Offset offset)
  • up(double distance)
  • down(double distance)
  • right(double distance)
  • left(double distance)
  • direction(double directionRadians, double distance)
  • directionDegrees(double directionDegrees, double distance)
  • upRight(double distance)
  • upLeft(double distance)
  • downRight(double distance)
  • downLeft(double distance)
  • flipDiagonally({Offset origin})
  • flipHorizontally({Offset origin})
  • flipVertically({Offset origin})

And, of course:

  • Matrix4 toMatrix4

Tween

A Matrix4TransformTween is provided in this package, and can be used in animations.

Animate it

A Matrix4Transform can be used to animate:

  • AlignPositioned or AnimatedAlignPositioned widgets from the AlignPositioned package, that accept a Matrix4Transform directly. The center of rotation/scale can be defined by their alignment parameter.

  • Any widget that accepts a Matrix4 transformation parameter, like Container, or AnimatedContainer. Note: Since Matrix4Tween will not animate linearly as you'd expect, it's possible that the intermediary transformations will be "strange", although the start and end should be correct.


Special thanks to Martin Kamleithner and Simon Lightfoot.


By Marcelo Glasberg

glasberg.dev
github.com/marcglasberg
linkedin.com/in/marcglasberg/
twitter.com/glasbergmarcelo
stackoverflow.com/users/3411681/marcg
medium.com/@marcglasberg

My article in the official Flutter documentation:

The Flutter packages I've authored:

My Medium Articles:

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト