zoukankan      html  css  js  c++  java
  • 绘制三角形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

  • 相关阅读:
    实现图片加载时显示百分比思路——serverpush
    我对大项目的看法(定义)
    lucene
    Access常用内置SQL函数
    闰年算法
    DotFuscator使用步骤
    软件加密狗破解思路和方法
    Lucene(.net)学习
    .Net 代码安全保护产品DNGuard HVM使用
    为什么动态创建的控件没有显示出来
  • 原文地址:https://www.cnblogs.com/sharpfeng/p/1951909.html
Copyright © 2011-2022 走看看