如何倾斜对象

若要倾斜(或剪切)对象,则表示通过 x 轴、y 轴或两者中的指定角度扭曲对象。 例如,当倾斜正方形时,它将成为平行四边形。

Matrix3x2F::Skew 方法采用 3 个参数:

  • angleX:x 轴倾斜角度,而该角度是从 y 轴逆时针旋转测得的角度度数。
  • angleY:y 轴的倾斜角,以度为单位,从 x 轴开始顺时针测量。
  • centerPoint:执行倾斜的中心点。

要预测倾斜转换的效果,请将 angleX 视为从 y 轴逆时针旋转测得的倾斜角度度数。 例如,如果 angleX 设置为 30,则对象以 centerPoint为中心,沿 y 轴逆时针偏斜 30 度。 下图显示了以正方形左上角为中心点水平倾斜 30 度的正方形。

插图描述了一个正方形从 y 轴反时针倾斜 30 度 从 y 轴逆时针倾斜 30 度的正方形插图

同样,angleY 是从 x 轴顺时针旋转测得的倾斜角度度数。 例如,如果 angleY 设置为 30,则对象围绕 centerPoint沿 x 轴顺时针倾斜 30 度。 下图显示了以正方形左上角为中心点垂直倾斜 30 度的正方形。

从 x 轴顺时针倾斜 30 度的正方形插图 顺时针倾斜 30 度的正方形图示

如果将 angleXangleY 设置为 30 度,并且将 centerPoint 设置为正方形左上角,将看到以下倾斜的正方形(实心轮廓)。 请注意,倾斜的正方形从 y 轴逆时针倾斜 30 度,从 x 轴顺时针倾斜 30 度。

显示一个正方形的插图,该正方形从 y 轴逆时针倾斜 30 度,从 x 轴顺时针倾斜 30 度

下面的代码示例将正方形绕其左上角水平倾斜 45 度。

    // Create a rectangle.
    D2D1_RECT_F rectangle = D2D1::Rect(126.0f, 301.5f, 186.0f, 361.5f);

    // Draw the outline of the rectangle.
    m_pRenderTarget->DrawRectangle(
        rectangle,
        m_pOriginalShapeBrush,
        1.0f,
        m_pStrokeStyleDash
        );

    // Apply the skew transform to the render target.
    m_pRenderTarget->SetTransform(
        D2D1::Matrix3x2F::Skew(
            45.0f,
            0.0f,
            D2D1::Point2F(126.0f, 301.5f))
        );

    // Paint the interior of the rectangle.
    m_pRenderTarget->FillRectangle(rectangle, m_pFillBrush);

    // Draw the outline of the rectangle.
    m_pRenderTarget->DrawRectangle(rectangle, m_pTransformedShapeBrush);

下图显示了将倾斜转换应用于正方形的效果,其中原始正方形是点状轮廓,倾斜对象(平行影像)是实心轮廓。 请注意,倾斜角度是从 y 轴逆时针的 45 度。

示意图,正方形从 y 轴逆时针倾斜 45 度

Direct2D 转换概述

Direct2D 参考