如何翻譯物件
若要轉譯 2D 物件,是沿著 X 軸、y 軸或兩者移動物件。 您可以呼叫下列兩種方法之一來建立翻譯轉換。
- Translation(D2D1_SIZE_F size):採用有序對,定義沿著 x 軸和 y 軸平移的距離。
- Translation(float x, float y):表示沿著 x 軸的平移距離,以及沿著 y 軸的平移距離。
下列程式代碼會建立轉譯轉換矩陣,將正方形 20 單位沿著 x 軸向右移動,沿著 y 軸向下移動 10 個單位。
// Create a rectangle.
D2D1_RECT_F rectangle = D2D1::Rect(126.0f, 80.5f, 186.0f, 140.5f);
// Draw the outline of the rectangle.
m_pRenderTarget->DrawRectangle(
rectangle,
m_pOriginalShapeBrush,
1.0f,
m_pStrokeStyleDash
);
// Apply the translation transform to the render target.
m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Translation(20, 10));
// Paint the interior of the rectangle.
m_pRenderTarget->FillRectangle(rectangle, m_pFillBrush);
// Draw the outline of the rectangle.
m_pRenderTarget->DrawRectangle(rectangle, m_pTransformedShapeBrush);
下圖顯示將翻譯轉換套用至方塊的效果,其中原始方塊是虛線外框,而翻譯的正方形則是實心外框。
相關主題