
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
| ファイル名 | 説明 |
|---|---|
| DXMen4.cs | 四面体を回転しながら描画 |
public void OnCreateDevice(object sender, EventArgs e)
{
Device dev = (Device)sender;
// VertexBuffer を生成して、OnCreateVertexBuffer で座標を格納
vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 6, dev, 0,
CustomVertex.PositionColored.Format, Pool.Default);
vertexBuffer.Created += new System.EventHandler(this.OnCreateVertexBuffer);
this.OnCreateVertexBuffer(vertexBuffer, null);
}
|
public void OnResetDevice(object sender, EventArgs e)
{
Device dev = (Device)sender;
// Turn off culling, so we see the front and back of the triangle
//dev.RenderState.CullMode = Cull.None;
// Turn off D3D lighting, since we are providing our own vertex colors
dev.RenderState.Lighting = false;
}
|
public void OnCreateVertexBuffer(object sender, EventArgs e)
{
VertexBuffer vb = (VertexBuffer)sender;
CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vb.Lock(0,0);
verts[0].X = -1.0f; verts[0].Y = -0.577f; verts[0].Z = 0.577f; verts[0].Color = System.Drawing.Color.Blue.ToArgb();
verts[1].X = 1.0f; verts[1].Y = -0.577f; verts[1].Z = 0.577f; verts[1].Color = System.Drawing.Color.Red.ToArgb();
verts[2].X = 0.0f; verts[2].Y = 1.15f; verts[2].Z = 0.0f; verts[2].Color = System.Drawing.Color.White.ToArgb();
verts[3].X = 0.0f; verts[3].Y = -0.577f; verts[3].Z = -1.15f;verts[3].Color = System.Drawing.Color.Green.ToArgb();
verts[4].X = -1.0f; verts[4].Y = -0.577f; verts[4].Z = 0.577f; verts[4].Color = System.Drawing.Color.Blue.ToArgb();
verts[5].X = 1.0f; verts[5].Y = -0.577f; verts[5].Z = 0.577f; verts[5].Color = System.Drawing.Color.Red.ToArgb();
vb.Unlock();
}
|
// ワールド座標の回転と描画環境の設定
private void SetupMatrices()
{
int iTime = Environment.TickCount % 5000;
float fAngle = iTime * (2.0f * (float)Math.PI) / 5000.0f;
device.Transform.World = Matrix.RotationY( fAngle );
device.Transform.View = Matrix.LookAtLH( new Vector3( 0.0f, 1.0f,4.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, 100.0f );
}
|
![]()
![]()