• 绘制三角形2


    public partial class MainForm : Form
    {
       public MainForm()
       {
           InitializeComponent();
     
           this.InitialDX();
       }
     
       private Device device;
       private void InitialDX()
       {
           PresentParameters presentParams = new PresentParameters();
           presentParams.Windowed = true;
           presentParams.SwapEffect = SwapEffect.Discard;
     
           device = new Device(
               0,
               DeviceType.Hardware,
               this,
               CreateFlags.SoftwareVertexProcessing,
               presentParams);
     
           device.RenderState.Lighting = false;
           device.RenderState.CullMode = Cull.None;
     
           //摄像机和投影设置
           Matrix camaraMx = Matrix.LookAtLH(
               new Vector3(0, 0, -150),
               new Vector3(0, 0, 0),
               new Vector3(0, 1, 0));
     
           Matrix projectionMx = Matrix.PerspectiveFovLH(
               (float)Math.PI / 4,
               this.Width / this.Height,
               10,
               200);
     
           device.Transform.Projection = projectionMx;
           device.Transform.View = camaraMx;
       }
     
       protected override void OnPaint(PaintEventArgs e)
       {
           base.OnPaint(e);
           this.DrawMyDX();
       }
     
       private void DrawMyDX()
       {
           device.Clear(ClearFlags.Target,
               Color.AliceBlue,
               1f,
               0);
           device.BeginScene();
           this.DrawMyGraphics();
           device.EndScene();
           device.Present();
       }
     
       private void DrawMyGraphics()
       {
           CustomVertex.PositionColored[] vertics = new CustomVertex.PositionColored[3];
           vertics[0].Position = new Vector3(
               -50, 0, 0);
           vertics[0].Color = Color.Red.ToArgb();
     
           vertics[1].Position = new Vector3(
               0, 30, 0);
           vertics[1].Color = Color.Green.ToArgb();
     
           vertics[2].Position = new Vector3(
               50, 0, 0);
           vertics[2].Color = Color.Blue.ToArgb();
     
           device.VertexFormat = CustomVertex.PositionColored.Format;
           device.DrawUserPrimitives(PrimitiveType.TriangleList,
               1,
               vertics);
       }
    }

    效果图:

    image

  • 相关阅读:
    医学影像
    阿里云九卿 大数据产业化
    陈海青 阿里
    店铺高频问题主动生成知识点机器 大脑+人脑 知识库
    数据总线和流计算在城市大脑中的应用
    无推荐不APP
    ww
    业务架构
    jd算法大赛 一个user_id只需映射到一个sku_id, 但是一个sku_id能否映射到多个user_id
    短URL DH 密钥交换算法
  • 原文地址:https://www.cnblogs.com/sharpfeng/p/1951909.html
Copyright © 2020-2023  润新知