| 構造体 | 位置 | トランスフォーム 済み頂点※1 |
法線 データ |
ディフューズ 色 |
テクスチャ 座標 |
|---|---|---|---|---|---|
| Position | Transformed | Normal | Colored | Textured | |
| PositionOnly | ○ | ||||
| PositionTextured | ○ | ○ | |||
| PositionColored | ○ | ○ | |||
| PositionColoredTextured | ○ | ○ | ○ | ||
| PositionNormal | ○ | ○ | |||
| PositionNormalColored | ○ | ○ | ○ | ||
| PositionNormalTextured | ○ | ○ | ○ | ||
| Transformed | ○ | ||||
| TransformedTextured | ○ | ○ | |||
| TransformedColored | ○ | ○ | |||
| TransformedColoredTextured | ○ | ○ | ○ |
頂点データは、
CustomVertex.PositionColored[] vertex = new CustomVertex.PositionColored[ 2 ];
のように配列として作成します。
位置の設定はPositionプロパティから、Vector3構造体で行います。
vertex[ 0 ].Position = new Vector3( 0.0f, 0.0f, 0.0f );
またはX、Y、Zのそれぞれのフィールドからも設定できます。
vertex[ 0 ].X = 0.0f; vertex[ 0 ].Y = 0.0f; vertex[ 0 ].Z = 0.0f;
色はColorフィールドから設定します。int型で指定する必要があるため、System.DrawingのColor構造体から設定するにはToArgb()メソッドでint型の値として取得してから行います。
vertex[ 0 ].Color = System.Drawing.Color.Red.ToArgb();
デバイスに設定する頂点形式 (VertexFormats列挙型) は、CustomVertex構造体のFormatフィールドから取得できます。
device.VertexFormat = CustomVertex.PositionColored.Format;
頂点データの描画方法は、それをそのまま使用する以外にバッファを用いる方法もあります。
| 描画方法 | メソッド |
|---|---|
| 頂点データをそのまま使用 | DrawUserPrimitives |
| 頂点バッファ (Vertex Buffers) | DrawPrimitives |
| インデックス バッファ (Index Buffers) | DrawIndexedPrimitives |
public void DrawUserPrimitives(
PrimitiveType primitiveType, // 描画するプリミティブの種類
int primitiveCount, // 描画するプリミティブの数
object vertexStreamZeroData // 描画する頂点データ
);
// 頂点データの作成 CustomVertex.PositionColored[] vertex = new CustomVertex.PositionColored[ 2 ]; // 座標の設定 vertex[ 0 ].Position = new Vector3( 0.0f, 0.0f, 0.0f ); vertex[ 1 ].Position = new Vector3( 1.0f, 0.0f, 0.0f ); // 色の設定 vertex[ 0 ].Color = Color.Red.ToArgb(); vertex[ 1 ].Color = Color.Red.ToArgb(); device.BeginScene(); // デバイスへの頂点形式の指定 device.VertexFormat = CustomVertex.PositionColored.Format; // 頂点データからレンダリング device.DrawUserPrimitives( PrimitiveType.LineList, 1, vertex ); divice.EndScene();