Matrix3DProjection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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>
- 繼承
- 屬性
範例
本範例會使用簡單的 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;
}
備註
您可以將 Matrix3DProjection 和 Matrix3D 類型用於比 PlaneProjection 類型更複雜的半-3D 案例。 Matrix3DProjection 提供完整的 3D 轉換矩陣,以套用至任何 UIElement (您使用此矩陣作為 UIElement.Projection 属性的值) 。 矩陣可讓您將任意模型轉換矩陣和透視矩陣套用至視覺元素。
建構函式
Matrix3DProjection() |
初始化 Matrix3DProjection 類別的新實例。 |
屬性
Dispatcher |
一律會在 Windows 應用程式 SDK 應用程式中傳 |
DispatcherQueue |
|
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) |