Matrix3D 構造体

定義

3-D 空間での変換に使用される 4 × 4 行列を表します。 Matrix3DProjection.ProjectionMatrix の値として使用されます。

public value class Matrix3D
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
struct Matrix3D
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
public struct Matrix3D
Public Structure Matrix3D
<Matrix3DProjection ProjectionMatrix="m11, m12, m13, m14, 
  m21, m22, m23, m24, m31, m32, m33, m34, offsetX, offsetY, offsetZ, m44" />
- or -
<!--xmlns:m3d="using:Windows.UI.Xaml.Media.Media3D"-->
<m3d:Matrix3D>
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, offsetX, offsetY, offsetZ, m44
</m3d:Matrix3D>
継承
Matrix3D
属性

この例では、単純な Matrix3D 行列を使用して、イメージをクリックしたときに X 方向と Y 方向の画像を変換します。

<!-- When you click on the image, the projection is applied. -->
<Image PointerPressed="ApplyProjection" x:Name="BeachImage" Source="guy_by_the_beach.jpg"
       Width="200"/>
private void ApplyProjection(Object sender, PointerRoutedEventArgs e)
{
    Matrix3D m = new Matrix3D();

    // This matrix simply translates the image 100 pixels
    // down and 100 pixels right.
    m.M11 = 1.0; m.M12 = 0.0; m.M13 = 0.0; m.M14 = 0.0;
    m.M21 = 0.0; m.M22 = 1.0; m.M23 = 0.0; m.M24 = 0.0;
    m.M31 = 0.0; m.M32 = 0.0; m.M33 = 1.0; m.M34 = 0.0;
    m.OffsetX = 100; m.OffsetY = 100; m.OffsetZ = 0; m.M44 = 1.0;

    Matrix3DProjection m3dProjection = new Matrix3DProjection();
    m3dProjection.ProjectionMatrix = m;

    BeachImage.Projection = m3dProjection;

}
<Image Source="guy_by_the_beach.jpg">
    <Image.Projection>
        <Matrix3DProjection  ProjectionMatrix="2, 0, 0, 0,
                                              0, 2, 0, 0,
                                              0, 0, 1, 0,
                                              100, 100, 0, 1"/>
    </Image.Projection>
</Image>
<!-- When you click on the image, the projection is applied. -->
<Image PointerPressed="ApplyProjection" x:Name="BeachImage" Source="guy_by_the_beach.jpg" 
       Width="200"/>
private void ApplyProjection(Object sender, PointerRoutedEventArgs e)
{
    // Translate the image along the negative Z-axis such that it occupies 50% of the
    // vertical field of view.
    double fovY = Math.PI / 2.0;
    double translationZ = -BeachImage.ActualHeight / Math.Tan(fovY / 2.0);
    double theta = 20.0 * Math.PI / 180.0;

    // You can create a 3D effect by creating a number of simple 
    // tranformation Matrix3D matrices and then multiply them together.
    Matrix3D centerImageAtOrigin = TranslationTransform(
             -BeachImage.ActualWidth / 2.0,
             -BeachImage.ActualHeight / 2.0, 0);
    Matrix3D invertYAxis = CreateScaleTransform(1.0, -1.0, 1.0);
    Matrix3D rotateAboutY = RotateYTransform(theta);
    Matrix3D translateAwayFromCamera = TranslationTransform(0, 0, translationZ);
    Matrix3D perspective = PerspectiveTransformFovRH(fovY,
            LayoutRoot.ActualWidth / LayoutRoot.ActualHeight,   // aspect ratio
            1.0,                                                // near plane
            1000.0);                                            // far plane
    Matrix3D viewport = ViewportTransform(LayoutRoot.ActualWidth, LayoutRoot.ActualHeight);

    Matrix3D m = Matrix3DHelper.Multiply(centerImageAtOrigin,invertYAxis);
    m = Matrix3D.Multiply(m ,rotateAboutY);
    m = Matrix3D.Multiply(m,translateAwayFromCamera);
    m = Matrix3D.Multiply(m,perspective);
    m = Matrix3D.Multiply(m,viewport);

    Matrix3DProjection m3dProjection = new Matrix3DProjection();
    m3dProjection.ProjectionMatrix = m;

    BeachImage.Projection = m3dProjection;
}

private Matrix3D TranslationTransform(double tx, double ty, double tz)
{
    Matrix3D m = new Matrix3D();

    m.M11 = 1.0; m.M12 = 0.0; m.M13 = 0.0; m.M14 = 0.0;
    m.M21 = 0.0; m.M22 = 1.0; m.M23 = 0.0; m.M24 = 0.0;
    m.M31 = 0.0; m.M32 = 0.0; m.M33 = 1.0; m.M34 = 0.0;
    m.OffsetX = tx; m.OffsetY = ty; m.OffsetZ = tz; m.M44 = 1.0;

    return m;
}

private Matrix3D CreateScaleTransform(double sx, double sy, double sz)
{
    Matrix3D m = new Matrix3D();

    m.M11 = sx; m.M12 = 0.0; m.M13 = 0.0; m.M14 = 0.0;
    m.M21 = 0.0; m.M22 = sy; m.M23 = 0.0; m.M24 = 0.0;
    m.M31 = 0.0; m.M32 = 0.0; m.M33 = sz; m.M34 = 0.0;
    m.OffsetX = 0.0; m.OffsetY = 0.0; m.OffsetZ = 0.0; m.M44 = 1.0;

    return m;
}

private Matrix3D RotateYTransform(double theta)
{
    double sin = Math.Sin(theta);
    double cos = Math.Cos(theta);

    Matrix3D m = new Matrix3D();

    m.M11 = cos; m.M12 = 0.0; m.M13 = -sin; m.M14 = 0.0;
    m.M21 = 0.0; m.M22 = 1.0; m.M23 = 0.0; m.M24 = 0.0;
    m.M31 = sin; m.M32 = 0.0; m.M33 = cos; m.M34 = 0.0;
    m.OffsetX = 0.0; m.OffsetY = 0.0; m.OffsetZ = 0.0; m.M44 = 1.0;

    return m;
}

private Matrix3D RotateZTransform(double theta)
{
    double cos = Math.Cos(theta);
    double sin = Math.Sin(theta);

    Matrix3D m = new Matrix3D();
    m.M11 = cos; m.M12 = sin; m.M13 = 0.0; m.M14 = 0.0;
    m.M21 = -sin; m.M22 = cos; m.M23 = 0.0; m.M24 = 0.0;
    m.M31 = 0.0; m.M32 = 0.0; m.M33 = 1.0; m.M34 = 0.0;
    m.OffsetX = 0.0; m.OffsetY = 0.0; m.OffsetZ = 0.0; m.M44 = 1.0;
    return m;
}

private Matrix3D PerspectiveTransformFovRH(double fieldOfViewY, double aspectRatio, double zNearPlane, double zFarPlane)
{
    double height = 1.0 / Math.Tan(fieldOfViewY / 2.0);
    double width = height / aspectRatio;
    double d = zNearPlane - zFarPlane;

    Matrix3D m = new Matrix3D();
    m.M11 = width; m.M12 = 0; m.M13 = 0; m.M14 = 0;
    m.M21 = 0; m.M22 = height; m.M23 = 0; m.M24 = 0;
    m.M31 = 0; m.M32 = 0; m.M33 = zFarPlane / d; m.M34 = -1;
    m.OffsetX = 0; m.OffsetY = 0; m.OffsetZ = zNearPlane * zFarPlane / d; m.M44 = 0;

    return m;
}

private Matrix3D ViewportTransform(double width, double height)
{
    Matrix3D m = new Matrix3D();

    m.M11 = width / 2.0; m.M12 = 0.0; m.M13 = 0.0; m.M14 = 0.0;
    m.M21 = 0.0; m.M22 = -height / 2.0; m.M23 = 0.0; m.M24 = 0.0;
    m.M31 = 0.0; m.M32 = 0.0; m.M33 = 1.0; m.M34 = 0.0;
    m.OffsetX = width / 2.0; m.OffsetY = height / 2.0; m.OffsetZ = 0.0; m.M44 = 1.0;

    return m;
}

注釈

PlaneProjection 型の場合よりも複雑な半-3-D シナリオでは、Matrix3DProjection 型と Matrix3D 型を使用できます。 Matrix3DProjection は、すべての UIElement に適用する完全な 3-D 変換マトリックスを提供します ( UIElement.Projection プロパティの値として使用します)。 マトリックスを使用すると、任意のモデル変換行列とパースペクティブ 行列をビジュアル要素に適用できます。

Matrix3D には、次の行ベクトル構文があります。

M11M12M13M14
M21M22M23M24
M31M32M33M34
OffsetXOffsetYOffsetZM44

4 番目の列にアクセスできるため、Matrix3D はアフィン変換と非アフィン変換の両方を表すことができます。

Matrix3D の XAML 構文

Matrix3D 値は XAML で宣言できますが、構文は制限されており、XAML UI の他のWindows ランタイム構造体 (Thickness など) のサポート値に基づいて想定される方法とは異なります。+ Matrix3D 型プロパティの最も一般的な使用方法は、Matrix3D 型に組み込まれている初期化文字列の動作に依存し、Matrix3D 値を属性として使用する値を設定することです。 Matrix3D 値を作成するには、文字列を "初期化テキスト" 形式で指定します。16 個の Double 値をそれぞれコンマまたはスペースで区切って指定します。 XAML で使用されているこの形式は、以下の「例」で確認できます。

  • Matrix3D 値を使用する既存のプロパティは 1 つだけです: Matrix3DProjection.ProjectionMatrix。 そのため、ここでは主要な XAML 構文として示されています。
  • 次に示すセカンダリ XAML 構文には、実際の Matrix3D オブジェクト要素があります。 ただし、XAML 名前空間プレフィックスがあることに注意してください。 Windows。UI。Xaml.Media.Media3D 名前空間は、Windows ランタイム XAML パーサーが既定の XAML 名前空間に使用するコード名前空間のセットに含まれていませんでした。 XAML で要素として Matrix3D を使用するには、Windows参照する xmlns 宣言を XAML に含める必要があります。Ui。**using:** ステートメントによる Xaml.Media.Media3D。 次に、Windowsの型にマップした xmlns プレフィックスで Matrix3D を修飾します。Ui。Xaml.Media.Media3D
  • このマッピングを行っても、Matrix3D オブジェクト要素は 16 個のプロパティを設定するための属性値を持つことができません。XAML パーサーでは有効になりません (他の XAML 構造体には、属性としてのプロパティ構文の特殊な処理があります。Matrix3D は、これを持っていない場合があります)。 16 個の値を文字列の連続するアトムとして設定する初期化テキストを引き続き使用する必要があります。 この場合、文字列は Matrix3D オブジェクト要素の "内部テキスト" / コンテンツとして含まれます。
  • ご覧のように、オブジェクト要素の構文は Matrix3DProjection.ProjectionMatrix のインライン属性構文よりも読みやすく、使用が容易ではないので、詳細な Matrix3D オブジェクト要素の構文は一般的ではありません。

Matrix3D のプロジェクションとメンバー

Microsoft .NET言語 (C#) を使用している場合、Matrix3D には非データ メンバーが使用でき、そのデータ メンバーはフィールドではなく読み取り/書き込みプロパティとして公開されます。

Windows ランタイム テンプレート ライブラリ (WRL) を使用して C++ を使用してプログラミングする場合、データ メンバー フィールドのみが Matrix3D のメンバーとして存在し、メンバー テーブルに示されているユーティリティ メソッドまたはプロパティを使用することはできません。 WRL コードは、 Matrix3DHelper クラスに存在する同様のユーティリティ メソッドにアクセスできます。

個々の XAML 属性を使用して XAML で Matrix3D のプロパティを設定することはできません。 16 個の値をすべて指定する初期化文字列を使用して Matrix3D オブジェクト要素を初期化するか、同じ文字列形式を使用する Matrix3DProjection.ProjectionMatrix の属性構文を使用する必要があります。

フィールド

名前 説明
M11

この Matrix3D の最初の行と最初の列の値。

M12

この Matrix3D の最初の行と 2 番目の列の値。

M13

この Matrix3D の最初の行と 3 番目の列の値。

M14

この Matrix3D の最初の行と 4 番目の列の値。

M21

この Matrix3D の 2 番目の行と最初の列の値。

M22

この Matrix3D の 2 番目の行と 2 番目の列の値。

M23

この Matrix3D の 2 行目と 3 列目の値。

M24

この Matrix3D の 2 行目と 4 列目の値。

M31

この Matrix3D の 3 番目の行と最初の列の値。

M32

この Matrix3D の 3 番目の行と 2 番目の列の値。

M33

この Matrix3D の 3 番目の行と 3 番目の列の値。

M34

この Matrix3D の 3 行目と 4 列目の値。

M44

この Matrix3D の 4 行目と 4 列目の値。

OffsetX

この Matrix3D の 4 番目の行と最初の列の値。

OffsetY

この Matrix3D の 4 行目と 2 列目の値。

OffsetZ

この Matrix3D の 4 行目と 3 列目の値。

適用対象

こちらもご覧ください