rendered paste bodyusing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DrawingLines1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private Device device;
private float angle;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque,true);
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(528, 389);
this.Name = "Form1";
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
using(Form1 frm = new Form1())
{
frm.Show();
frm.InitializeDevice();
Application.Run(frm);
}
}
public void InitializeDevice()
{
Microsoft.DirectX.Direct3D.PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
angle =0.0f;
device = new Device(0,
DeviceType.Hardware,
this,
CreateFlags.SoftwareVertexProcessing,
pp);
device.Transform.Projection=Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Width,1.0f,100.0f);
device.Transform.View=Matrix.LookAtLH(new Vector3(0,0,5.0f), new Vector3(), new Vector3(0,1.0f,0));
device.RenderState.Lighting=false;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
device.Clear(ClearFlags.Target,
System.Drawing.Color.CornflowerBlue,
1.0f,
0);
CustomVertex.PositionColored[] verts =
new CustomVertex.PositionColored[6];
//First line in x direction
verts[0].SetPosition(new Vector3(2.0f,0.0f,0.0f));
verts[0].Color=System.Drawing.Color.GreenYellow.ToArgb();
verts[1].SetPosition(new Vector3(-2.0f,0.0f,0.0f));
verts[1].Color=System.Drawing.Color.GreenYellow.ToArgb();
//Second line in y direction
verts[2].SetPosition(new Vector3(0.0f, 2.0f, 0.0f));
verts[2].Color=System.Drawing.Color.Red.ToArgb();
verts[3].SetPosition(new Vector3(0.0f, -2.0f, 0.0f));
verts[3].Color=System.Drawing.Color.Red.ToArgb();
//Third line in the z direction
verts[4].SetPosition(new Vector3(0.0f, 0.0f, 2.0f));
verts[4].Color=System.Drawing.Color.HotPink.ToArgb();
verts[5].SetPosition(new Vector3(0.0f, 0.0f, -2.0f));
verts[5].Color=System.Drawing.Color.HotPink.ToArgb();
CustomVertex.PositionColored[] v = new CustomVertex.PositionColored[100];
v[0].SetPosition(new Vector3(0.0f, 1.0f, 0.0f));
v[1].SetPosition(new Vector3(0.0f, 0.0f, 1.0f));
v[2].SetPosition(new Vector3(1.0f, 0.0f, 0.0f));
v[0].Color = Color.Gold.ToArgb();
v[1].Color = Color.Gold.ToArgb();
v[2].Color = Color.Gold.ToArgb();
v[3].SetPosition(new Vector3(0.0f, 1.0f, 0.0f));
v[4].SetPosition(new Vector3(0.0f, 0.0f, -1.0f));
v[5].SetPosition(new Vector3(-1.0f, 0.0f, 0.0f));
v[3].Color = Color.Teal.ToArgb();
v[4].Color = Color.Teal.ToArgb();
v[5].Color = Color.Teal.ToArgb();
v[6].SetPosition(new Vector3(0.0f, 1.0f, 0.0f));
v[7].SetPosition(new Vector3(-1.0f, 0.0f, 0.0f));
v[8].SetPosition(new Vector3(0.0f, 0.0f, 1.0f));
v[6].Color = Color.Tan.ToArgb();
v[7].Color = Color.Tan.ToArgb();
v[8].Color = Color.Tan.ToArgb();
v[9].SetPosition(new Vector3(0.0f, 1.0f, 0.0f));
v[10].SetPosition(new Vector3(1.0f, 0.0f, 0.0f));
v[11].SetPosition(new Vector3(0.0f, 0.0f, -1.0f));
v[9].Color = Color.SpringGreen.ToArgb();
v[10].Color = Color.SpringGreen.ToArgb();
v[11].Color = Color.SpringGreen.ToArgb();
v[12].SetPosition(new Vector3(-1.0f, 0.0f, 0.0f));
v[13].SetPosition(new Vector3(0.0f, 0.0f, -1.0f));
v[14].SetPosition(new Vector3(1.0f, 0.0f, 0.0f));
v[12].Color = Color.Black.ToArgb();
v[13].Color = Color.Black.ToArgb();
v[14].Color = Color.Black.ToArgb();
v[15].SetPosition(new Vector3(-1.0f, 0.0f, 0.0f));
v[16].SetPosition(new Vector3(1.0f, 0.0f, 0.0f));
v[17].SetPosition(new Vector3(0.0f, 0.0f, 1.0f));
v[15].Color = Color.Black.ToArgb();
v[16].Color = Color.Black.ToArgb();
v[17].Color = Color.Black.ToArgb();
device.Transform.World = Matrix.RotationAxis(new Vector3(angle / ((float)Math.PI * 2.0f), angle / ((float)Math.PI * 4.0f), angle / ((float)Math.PI * 6.0f)), angle / (float)Math.PI);
angle += 0.1f;
device.BeginScene(); //gonna draw something
device.VertexFormat=CustomVertex.PositionColored.Format; //what type of a drawing
device.DrawUserPrimitives(PrimitiveType.LineList,3,verts); //what are we gonna draw
device.DrawUserPrimitives(PrimitiveType.TriangleList,6,v); //what are we gonna draw
device.EndScene(); //done drawing
device.Present();
this.Invalidate();
}
}
}