DrawHexClass.cs
上传用户:lslight
上传日期:2022-01-10
资源大小:14248k
文件大小:3k
源码类别:

DirextX编程

开发平台:

C#

  1. ///////////////////////////////////////////////////////////////////////
  2. //      ■■■■     ■■■■■       ■■■■       ■       ■      //
  3. //    ■                 ■         ■               ■       ■      //
  4. //    ■                 ■         ■    ■■■     ■       ■      //
  5. //    ■                 ■         ■       ■      ■       ■      //
  6. //      ■■■■         ■           ■■■■         ■■■■       //
  7. // Copyright (c) 三峡大学水利与环境学院 肖泽云. All rights reserved.  //
  8. ////////////////////////////////////////////////////////////////////////
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Text;
  12. using System.Drawing;
  13. using Microsoft.DirectX;
  14. using Microsoft.DirectX.Direct3D;
  15. namespace 绘制基本几何体
  16. {
  17.     class DrawHexClass
  18.     {
  19.         /// <summary>
  20.         /// <para name="device">定义设备对象</para>
  21.         /// </summary>
  22.         public Device device;
  23.         public Vector3[] pointVectors;
  24.         public CustomVertex.PositionColored[] vertices;
  25.         private int[] indexData;
  26.         public DrawHexClass(Device _device, Vector3[] _pointVectors)
  27.         {
  28.             device = _device;
  29.             pointVectors=_pointVectors;
  30.             vertices = new CustomVertex.PositionColored[8];
  31.             vertices[0].Position = pointVectors[0]; 
  32.             vertices[0].Color = Color.Yellow.ToArgb();
  33.             vertices[1].Position = pointVectors[1]; 
  34.             vertices[1].Color = Color.Red.ToArgb();
  35.             vertices[2].Position = pointVectors[2]; 
  36.             vertices[2].Color = Color.Green.ToArgb();
  37.             vertices[3].Position = pointVectors[3];
  38.             vertices[3].Color = Color.Gold.ToArgb();
  39.             vertices[4].Position = pointVectors[4]; 
  40.             vertices[4].Color = Color.GhostWhite.ToArgb();
  41.             vertices[5].Position = pointVectors[5];
  42.             vertices[5].Color = Color.LightPink.ToArgb();
  43.             vertices[6].Position = pointVectors[6];
  44.             vertices[6].Color = Color.Maroon.ToArgb();
  45.             vertices[7].Position = pointVectors[7]; 
  46.             vertices[7].Color = Color.Orange.ToArgb();
  47.             IndicesDeclaration();//定义索引
  48.         }
  49.         private void IndicesDeclaration()//定义索引
  50.         {
  51.             indexData=new int[36];
  52.             //顶部三角形
  53.             indexData[0] = 0; indexData[1] = 1; indexData[2] = 3;
  54.             indexData[3] = 3; indexData[4] = 1; indexData[5] = 2;
  55.             //周围三角形
  56.             indexData[6] = 4; indexData[7] = 0; indexData[8] = 7;
  57.             indexData[9] = 7; indexData[10] = 0; indexData[11] = 3;
  58.             indexData[12] = 7; indexData[13] = 3; indexData[14] = 6;
  59.             indexData[15] = 6; indexData[16] = 3; indexData[17] = 2;
  60.             indexData[18] = 6; indexData[19] = 2; indexData[20] = 5;
  61.             indexData[21] = 5; indexData[22] = 2; indexData[23] = 1;
  62.             indexData[24] = 5; indexData[25] = 1; indexData[26] = 4;
  63.             indexData[27] = 4; indexData[28] = 1; indexData[29] = 0;
  64.             //底部三角形
  65.             indexData[30] = 5; indexData[31] = 4; indexData[32] = 7;
  66.             indexData[33] = 7; indexData[34] = 6; indexData[35] = 5;
  67.         }
  68.         public void DrawHex()
  69.         {
  70.             device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, 8, 12, indexData, false, vertices);
  71.         }
  72.     }
  73. }