其他分享
首页 > 其他分享> > Direct2D (7) : 空间变换

Direct2D (7) : 空间变换

作者:互联网

Direct2D (7) : 空间变换


{相关方法} 
TDirect2DCanvas.RenderTarget.SetTransform();
TDirect2DCanvas.RenderTarget.GetTransform();

{相关结构}
TD2DMatrix3x2F (或D2D_MATRIX_3X2_F) //因第三列的值在这里是固定的(0,0,1),所以这里用的是 3*2 的矩阵;该结构重载了 * 运算符

{TD2DMatrix3x2FHelper 为 TD2DMatrix3x2F 提供的方法(多为 class 方法)}
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 := TD2DMatrix3x2F.Translation(90, 50);
  cvs.RenderTarget.SetTransform(matrix);
  cvs.Pen.Color := clRed;
  cvs.Polygon(pts);

  {放缩}
  matrix := TD2DMatrix3x2F.Scale(1.5, 0.5, pts[0]);
  cvs.RenderTarget.SetTransform(matrix);
  cvs.Pen.Color := clBlue;
  cvs.Polygon(pts);

  {旋转}
  matrix := TD2DMatrix3x2F.Rotation(90, pts[0]);
//  D2D1MakeRotateMatrix(90, pts[0], @matrix); //同上一行
  cvs.RenderTarget.SetTransform(matrix);
  cvs.Pen.Color := clGreen;
  cvs.Polygon(pts);

  {斜切}
  matrix := TD2DMatrix3x2F.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;


效果图:

o_201103322.png

posted on 2011-04-01 12:32  万一  阅读(2163)  评论(2)  编辑  收藏

标签:matrix,变换,cvs,RenderTarget,Pen,Direct2D,空间,pts,TD2DMatrix3x2F
来源: https://blog.51cto.com/u_14617575/2745418