cscの作法 その117

# 概要
cscの作法、調べてみた。
managed directxやってみた。
プリミティブを使ってみた。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/5a298925-0583-f402-ee31-1c9e24d3d38d.png)


# サンプルコード

```

using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace mdx
{
	public partial class Form1 : Form {
		private Device device = null; 
		private Mesh _boxMesh = null;
		private Mesh _cylinderMesh = null;
		private Mesh _polygonMesh = null;
		private Mesh _sphereMesh = null;
		private Mesh _teapotMesh = null;
		private Mesh _torusMesh = null;
		public Form1() {
			Text = "Form1";
			this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
			PresentParameters pp = new PresentParameters();
			pp.Windowed = true;
			pp.SwapEffect = SwapEffect.Discard;
			device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp);
			_boxMesh = Mesh.Box(device, 2.0f, 1.0f, 0.5f);
			_cylinderMesh = Mesh.Cylinder(device, 0.5f, 0.8f, 1.5f, 8, 1);
			_polygonMesh = Mesh.Polygon(device, 1.0f, 5);
			_sphereMesh = Mesh.Sphere(device, 0.8f, 8, 6);
			_teapotMesh = Mesh.Teapot(device); 
			_torusMesh = Mesh.Torus(device, 0.1f, 0.6f, 6, 12);
			this.Paint += Form1_Paint;
		}
		private void Form1_Paint(object sender, PaintEventArgs e) {
			device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 1.0f, 10.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
			device.Transform.Projection = Matrix.PerspectiveFovLH((float)(Math.PI / 4), 1.0f, 1.0f, 1000.0f);
			device.Lights[0].Direction = Vector3.Normalize(new Vector3(-1, -2, -3));
			device.Lights[0].Type = LightType.Directional;
			device.Lights[0].Diffuse = Color.White;
			device.Lights[0].Ambient = Color.FromArgb(255, 40, 40, 40);
			device.Lights[0].Enabled = true;
			device.Lights[0].Update();
			device.Clear(ClearFlags.Target, Color.DarkBlue, 1.0f, 0);
			device.BeginScene();
			device.SetTransform(TransformType.World, Matrix.Identity);
			device.RenderState.Lighting = true;
			Material mtrl = new Material();
			mtrl.Diffuse = Color.White;
			mtrl.Ambient = Color.FromArgb(255, 128, 128, 128);
			device.Material = mtrl;
			Matrix rotateMatrix = Matrix.RotationY(Environment.TickCount / 1000.0f);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(0.0f, 2.0f, 0.0f)));
			_boxMesh.DrawSubset(0);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(-2.5f, 0.8f, 0.0f)));
			_cylinderMesh.DrawSubset(0);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(-2.5f, -0.8f, 0.0f)));
			_polygonMesh.DrawSubset(0);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(0.0f, -2.0f, 0.0f)));
			_sphereMesh.DrawSubset(0);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(0.0f, 0.0f, 0.0f)));
			_teapotMesh.DrawSubset(0);
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(2.5f, -0.8f, 0.0f)));
			device.SetTransform(TransformType.World, rotateMatrix * Matrix.Translation(new Vector3(2.5f, 0.8f, 0.0f)));
			_torusMesh.DrawSubset(0);
			device.EndScene();
			device.Present();
			this.Invalidate();
		}
		[STAThread]
		public static void Main() {
			Application.Run(new Form1());
		}
	}
}





```

以上。