{相關方法}
TDirect2DCanvas.RenderTarget.SetTransform();
TDirect2DCanvas.RenderTarget.GetTransform();
{相關結構}
TD2DMatrix3x2F (或D2D_MATRIX_3X2_F) //因第三列的值在這裡是固定的(0,0,1),所以這裡用的是 3*2 的矩陣;該結構重載了 * 運算符
{TD2DMatrix3x2FHelper 為 TD2DMatrix3x2F 提供的方法}
Identity(); //初始化 TD2DMatrix3x2F,默認值:_11、_22 為 1.0,其它是 0
Translation(); //平移
Scale(); //放縮
Rotation(); //旋轉
Skew(); //斜切
Determinant(); //計算行列式
IsInvertible(); //是否可逆
Invert(); //逆向運算
SetProduct(); //乘
{相關全局函數}
D2D1MakeRotateMatrix(); //旋轉
D2D1MakeSkewMatrix(); //斜切
D2D1IsMatrixInvertible(); //是否可逆
D2D1InvertMatrix(); //逆向運算
測試代碼:
uses Direct2D, D2D1;
procedure TForm1.FormPaint(Sender: TObject);
var
cvs: TDirect2DCanvas;
pts: array[0..2] of TPoint;
matrix: TD2DMatrix3x2F;
begin
pts[0] := Point(ClientWidth div 2, ClIEntHeight div 2);
pts[1] := Point(ClientWidth div 5, ClIEntHeight div 2);
pts[2] := Point(ClientWidth div 2, ClIEntHeight div 5);
cvs := TDirect2DCanvas.Create(Canvas, ClIEntRect);
cvs.BeginDraw;
cvs.Brush.Style := bsClear;
{原始}
cvs.Pen.Color := clSilver;
cvs.Pen.Width := 9;
cvs.Polygon(pts);
cvs.Pen.Width := 2;
{平移}
matrix := matrix.Identity;
matrix := matrix.Translation(90, 50);
cvs.RenderTarget.SetTransform(matrix);
cvs.Pen.Color := clRed;
cvs.Polygon(pts);
{放縮}
matrix := matrix.Identity;
matrix := matrix.Scale(1.5, 0.5, pts[0]);
cvs.RenderTarget.SetTransform(matrix);
cvs.Pen.Color := clBlue;
cvs.Polygon(pts);
{旋轉}
matrix := matrix.Identity;
matrix := matrix.Rotation(90, pts[0]);
// D2D1MakeRotateMatrix(90, pts[0], @matrix); //同上一行
cvs.RenderTarget.SetTransform(matrix);
cvs.Pen.Color := clGreen;
cvs.Polygon(pts);
{斜切}
matrix := matrix.Identity;
matrix := matrix.Skew(60, 0, pts[0]);
// D2D1MakeSkewMatrix(60, 10, pts[0], @matrix); //同上一行
cvs.RenderTarget.SetTransform(matrix);
cvs.Pen.Color := clPurple;
cvs.Polygon(pts);
cvs.EndDraw;
cvs.Free;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
Repaint;
end;
效果圖: