グリッドと軸
- 3D頂点座標、頂点色
- CustomVertex.PositionColored
- 1辺が1のラインをX方向、Z方向にそれぞれ11本=11*2ライン
- X軸、Y軸、Z軸=3ライン
- PrimitiveType.LineListで描画
- とりあえず全体を5倍で描画
private VertexBuffer grid_axis = null;
private void CreateGridAndAxis()
{
CustomVertex.PositionColored[] v = new CustomVertex.PositionColored[ 44 + 6 ];
int color = Color.FromArgb( 0xcc, 0xcc, 0xcc ).ToArgb();
float x = -0.5f, z = -0.5f;
int index = 0;
for( int i = 0; i < 11; i ++ )
{
v[ index + 0 ] = new CustomVertex.PositionColored( -0.5f, 0.0f, z, color );
v[ index + 1 ] = new CustomVertex.PositionColored( 0.5f, 0.0f, z, color );
index += 2;
z += 0.1f;
}
for( int i = 0; i < 11; i ++ )
{
v[ index + 0 ] = new CustomVertex.PositionColored( x, 0.0f, -0.5f, color );
v[ index + 1 ] = new CustomVertex.PositionColored( x, 0.0f, 0.5f, color );
index += 2;
x += 0.1f;
}
v[ index + 0 ] = new CustomVertex.PositionColored( -1.0f, 0.0f, 0.0f, Color.Black.ToArgb() );
v[ index + 1 ] = new CustomVertex.PositionColored( 1.0f, 0.0f, 0.0f, Color.Red.ToArgb() );
v[ index + 2 ] = new CustomVertex.PositionColored( 0.0f, -1.0f, 0.0f, Color.Black.ToArgb() );
v[ index + 3 ] = new CustomVertex.PositionColored( 0.0f, 1.0f, 0.0f, Color.FromArgb( 0, 255, 0 ).ToArgb() );
v[ index + 4 ] = new CustomVertex.PositionColored( 0.0f, 0.0f, -1.0f, Color.Black.ToArgb() );
v[ index + 5 ] = new CustomVertex.PositionColored( 0.0f, 0.0f, 1.0f, Color.Blue.ToArgb() );
grid_axis = new VertexBuffer( typeof(CustomVertex.PositionColored), v.Length, device, Usage.None, CustomVertex.PositionColored.Format, Pool.Managed );
using( GraphicsStream data = grid_axis.Lock( 0, 0, LockFlags.None ) )
{
data.Write( v );
grid_axis.Unlock();
}
}
if (grid_axis != null)
{
grid_axis.Dispose();
grid_axis = null;
}
device.Transform.World = Matrix.Scaling( 5.0f, 5.0f, 5.0f );
device.SetStreamSource( 0, grid_axis, 0 );
device.SetTexture( 0, null );
device.VertexFormat = CustomVertex.PositionColored.Format;
device.DrawPrimitives( PrimitiveType.LineList, 0, 22 + 3 );