DrawHexClass.cs
上传用户:lslight
上传日期:2022-01-10
资源大小:14248k
文件大小:3k
- ///////////////////////////////////////////////////////////////////////
- // ■■■■ ■■■■■ ■■■■ ■ ■ //
- // ■ ■ ■ ■ ■ //
- // ■ ■ ■ ■■■ ■ ■ //
- // ■ ■ ■ ■ ■ ■ //
- // ■■■■ ■ ■■■■ ■■■■ //
- // Copyright (c) 三峡大学水利与环境学院 肖泽云. All rights reserved. //
- ////////////////////////////////////////////////////////////////////////
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Drawing;
- using Microsoft.DirectX;
- using Microsoft.DirectX.Direct3D;
- namespace 绘制基本几何体
- {
- class DrawHexClass
- {
- /// <summary>
- /// <para name="device">定义设备对象</para>
- /// </summary>
- public Device device;
- public Vector3[] pointVectors;
- public CustomVertex.PositionColored[] vertices;
- private int[] indexData;
- public DrawHexClass(Device _device, Vector3[] _pointVectors)
- {
- device = _device;
- pointVectors=_pointVectors;
- vertices = new CustomVertex.PositionColored[8];
- vertices[0].Position = pointVectors[0];
- vertices[0].Color = Color.Yellow.ToArgb();
- vertices[1].Position = pointVectors[1];
- vertices[1].Color = Color.Red.ToArgb();
- vertices[2].Position = pointVectors[2];
- vertices[2].Color = Color.Green.ToArgb();
- vertices[3].Position = pointVectors[3];
- vertices[3].Color = Color.Gold.ToArgb();
- vertices[4].Position = pointVectors[4];
- vertices[4].Color = Color.GhostWhite.ToArgb();
- vertices[5].Position = pointVectors[5];
- vertices[5].Color = Color.LightPink.ToArgb();
- vertices[6].Position = pointVectors[6];
- vertices[6].Color = Color.Maroon.ToArgb();
- vertices[7].Position = pointVectors[7];
- vertices[7].Color = Color.Orange.ToArgb();
- IndicesDeclaration();//定义索引
- }
- private void IndicesDeclaration()//定义索引
- {
- indexData=new int[36];
- //顶部三角形
- indexData[0] = 0; indexData[1] = 1; indexData[2] = 3;
- indexData[3] = 3; indexData[4] = 1; indexData[5] = 2;
- //周围三角形
- indexData[6] = 4; indexData[7] = 0; indexData[8] = 7;
- indexData[9] = 7; indexData[10] = 0; indexData[11] = 3;
- indexData[12] = 7; indexData[13] = 3; indexData[14] = 6;
- indexData[15] = 6; indexData[16] = 3; indexData[17] = 2;
- indexData[18] = 6; indexData[19] = 2; indexData[20] = 5;
- indexData[21] = 5; indexData[22] = 2; indexData[23] = 1;
- indexData[24] = 5; indexData[25] = 1; indexData[26] = 4;
- indexData[27] = 4; indexData[28] = 1; indexData[29] = 0;
- //底部三角形
- indexData[30] = 5; indexData[31] = 4; indexData[32] = 7;
- indexData[33] = 7; indexData[34] = 6; indexData[35] = 5;
- }
- public void DrawHex()
- {
- device.DrawIndexedUserPrimitives(PrimitiveType.TriangleList, 0, 8, 12, indexData, false, vertices);
- }
- }
- }