Animation Windows Composition API是否支持2.5D投影旋转?

Animation Windows Composition API是否支持2.5D投影旋转?,animation,uwp,rotation,windows-composition-api,2.5d,Animation,Uwp,Rotation,Windows Composition Api,2.5d,我已经开始在UWP应用程序中使用Windows Composition API来设置UI元素的动画 视觉元素显示RotationAngleInDegrees和RotationAngle属性以及RotationAxis属性 当我围绕Y轴为矩形对象的RotationAngleInDegrees值设置动画时,矩形会像我预期的那样旋转,但在2D应用程序窗口中,它似乎不会以2.5D投影显示 有没有办法通过合成api获得旋转的2.5D投影效果 这取决于你想要的效果。GitHub上有一个fluent desi

我已经开始在UWP应用程序中使用Windows Composition API来设置UI元素的动画

视觉元素显示RotationAngleInDegrees和RotationAngle属性以及RotationAxis属性

当我围绕Y轴为矩形对象的RotationAngleInDegrees值设置动画时,矩形会像我预期的那样旋转,但在2D应用程序窗口中,它似乎不会以2.5D投影显示


有没有办法通过合成api获得旋转的2.5D投影效果

这取决于你想要的效果。GitHub上有一个fluent design应用程序示例,是链接。您将能够从下载演示。你可以从深度样本中得到一些想法。例如,“翻转显示”显示了一种旋转图像卡的方法,您可以从中找到源代码。有关更多详细信息,请查看示例和演示

通常,动画将基于X轴旋转:

矩形Visual.RotationAxis=新系统.Numerics.Vector31f,0f,0f

然后使用旋转动画根据旋转角度索引进行旋转


您也可以通过使用from image control直接在XAML平台上执行此操作

正如@BarryWang给我指出的示例所示,在执行动画之前,有必要将TransformMatrix应用于页面或父容器,以获得旋转的2.5D效果,或使用合成api的其他空间变换动画

    private void UpdatePerspective()
    {
        Visual visual = ElementCompositionPreview.GetElementVisual(MainPanel);

        // Get the size of the area we are enabling perspective for
        Vector2 sizeList = new Vector2((float)MainPanel.ActualWidth, (float)MainPanel.ActualHeight);

        // Setup the perspective transform.
        Matrix4x4 perspective = new Matrix4x4(

                    1.0f, 0.0f, 0.0f, 0.0f,

                    0.0f, 1.0f, 0.0f, 0.0f,

                    0.0f, 0.0f, 1.0f, -1.0f / sizeList.X,

                    0.0f, 0.0f, 0.0f, 1.0f);

        // Set the parent transform to apply perspective to all children
        visual.TransformMatrix =

                           Matrix4x4.CreateTranslation(-sizeList.X / 2, -sizeList.Y / 2, 0f) *      // Translate to origin

                           perspective *                                                            // Apply perspective at origin

                           Matrix4x4.CreateTranslation(sizeList.X / 2, sizeList.Y / 2, 0f);         // Translate back to original position
    }

感谢@BarryWang为我提供了一个样本。我已经在使用基于RotationAngleInDegrees的动画来绕Y轴旋转卡片。但是,默认情况下,旋转不会应用透视投影。秘密似乎是,对于2.5D投影效果,您还需要对页面应用TransformMatrix。如果这种效果是您想要的,那么TransformMatrix实际上就是答案。您还应该能够使用XAML的PerspectiveTransform3D属性“`@JohnnyWestlake,太棒了,我没有意识到这是在Windows10XAML中实现的,也没有意识到它与合成API一起工作。