using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Road
{
public class Road : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
enum Direction { FORWARD, BACK, LEFT, RIGHT, UP, DOWN };
const int ZDEPTH = 512;
const long MAX_POINTS = 2048;
private long index = 0;
private int halfWidth;
private int halfHeight;
private Bitmap bmp;
private Pen pn;
Graphics dc;
struct Point3D
{
public double x, y, z;
}
Point3D[] map;
public Road()
{
InitializeComponent();
map = new Point3D[MAX_POINTS];
halfWidth = (this.Width)/2;
halfHeight = (this.Height)/2;
bmp = new Bitmap(this.Width, this.Height);
pn = new Pen(Color.Green);
int x,z;
for (x=-1024; x < 1024; x+=50)
{
for (z=0; z < 1024; z+=50)
{
if (index < MAX_POINTS)
{
map[index].x = x;
map[index].y = 80;
map[index].z = -z;
index++;
}
}
}
dc = this.CreateGraphics();
Render();
}
private void Render()
{
//Bitmap bmp = new Bitmap(this.Width, this.Height);
//Graphics dc = Graphics.FromImage(bmp);
dc.Clear(Color.Black);
this.Show();
for (int i=0; i < index; i++)
{
if (map[i].z == 0)
map[i].z = 1;
int gx = halfWidth + (int)(ZDEPTH*map[i].x/map[i].z);
int gy = halfHeight - (int)(ZDEPTH*map[i].y/map[i].z);
if (gx < this.Width-1 && gy < this.Height-1 && gx > 1 && gy > 1)
dc.FillEllipse(pn.Brush, gx, gy, 2, 2);
//bmp.SetPixel(gx, gy, Color.DarkGreen);
//dc.DrawImage(bmp, 0, 0);
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// Road
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(634, 448);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Road";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Road";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Road_KeyDown);
this.DoubleClick += new System.EventHandler(this.Road_DoubleClick);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Road());
}
private void Road_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
Application.Exit();
if (e.KeyCode == Keys.Up)
RotateMap(map, Direction.FORWARD);
if (e.KeyCode == Keys.Down)
RotateMap(map, Direction.BACK);
if (e.KeyCode == Keys.Left)
RotateMap(map, Direction.LEFT);
if (e.KeyCode == Keys.Right)
RotateMap(map, Direction.RIGHT);
if (e.KeyCode == Keys.A)
RotateMap(map, Direction.UP);
if (e.KeyCode == Keys.Z)
RotateMap(map, Direction.DOWN);
}
private void RotateMap(Point3D[] m, Direction d)
{
switch (d)
{
case Direction.FORWARD:
for (int i=0; i