Matrix3DProjection 类

定义

Matrix3D 投影应用于 对象。

public ref class Matrix3DProjection sealed : Projection
/// [Microsoft.UI.Xaml.Markup.ContentProperty(Name="ProjectionMatrix")]
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class Matrix3DProjection final : Projection
[Microsoft.UI.Xaml.Markup.ContentProperty(Name="ProjectionMatrix")]
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class Matrix3DProjection : Projection
Public NotInheritable Class Matrix3DProjection
Inherits Projection
<Matrix3DProjection .../>
-or-
<!--xmlns:m3d="using:Windows.UI.Xaml.Media.Media3D"-->
<Matrix3DProjection>
  <m3d:Matrix3D>matrix3DInitializationString</m3d:Matrix3D>
</Matrix3DProjection>
继承
Object Platform::Object IInspectable DependencyObject Projection Matrix3DProjection
属性

示例

本示例使用简单的 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 类型相比,可以使用 Matrix3DProjection 和 Matrix3D 类型实现更复杂的半三维方案。 Matrix3DProjection 提供了一个完整的三维转换矩阵,可应用于任何 UIElement (将其用作 UIElement.Projection 属性) 的值。 通过矩阵,可以将任意模型转换矩阵和透视矩阵应用于视觉元素。

构造函数

Matrix3DProjection()

初始化 Matrix3DProjection 类的新实例。

属性

Dispatcher

始终在Windows 应用 SDK应用中返回 null 。 请改用 DispatcherQueue

(继承自 DependencyObject)
DispatcherQueue

获取 DispatcherQueue 与此 对象关联的 。 DispatcherQueue表示可以访问 DependencyObject UI 线程上的 的功能,即使代码是由非 UI 线程启动的。

(继承自 DependencyObject)
ProjectionMatrix

获取或设置用于应用于 对象的投影的 Matrix3D

ProjectionMatrixProperty

标识 ProjectionMatrix 依赖属性。

方法

ClearValue(DependencyProperty)

清除依赖属性的本地值。

(继承自 DependencyObject)
GetAnimationBaseValue(DependencyProperty)

返回为依赖属性建立的任何基值,该基值适用于动画未处于活动状态的情况。

(继承自 DependencyObject)
GetValue(DependencyProperty)

DependencyObject 返回依赖属性的当前有效值。

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

如果设置了本地值,则返回依赖属性的本地值。

(继承自 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

注册一个通知函数,用于侦听此 DependencyObject 实例上特定 DependencyProperty 的更改。

(继承自 DependencyObject)
SetValue(DependencyProperty, Object)

设置 DependencyObject 上依赖属性的本地值。

(继承自 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消以前通过调用 RegisterPropertyChangedCallback 注册的更改通知。

(继承自 DependencyObject)

适用于

另请参阅