Introduction
Required for debugging: DirectX9 SDK for .NET
This is my first try to write my own 3D game engine in C# using managed directX.
To get this done, I had to solve many small and complex problems.
Here are some of the implemented features:
Basics
- Setting up a d3d device
- Reading keyboard and mouse input
- Drawing fonts
- Drawing primitives
- Loading and drawing meshes
- Using light and fog basics
Advanced
- Rotating and translating world and meshes around the camera
- Integrate automativ collision detection between meshes
- Effects that collision has on the player's movement
- Logic for opening doors and using elevators
My backgound is easy. Like thousands, I have a dream of writing my own game sometime.
Unfurtunately I've not got enough free time to finalize it...
Using the Code
Sorry my code is a hell of 'non documentation'. Give me feedback, if there's interest, I'll add a full documentation of the code.
But if you want to read it, you should begin with OnPaint method in Form1. This is the main loop which calls all relevant functions.
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (WorldLive.Exit)
{
Application.Exit();
}
IConsole.DisplayText = "";
for (int i=0;i<WorldLive.MovingGameObjects.Count;i++)
{
if (WorldLive.MovingGameObjects[i].PU != null)
{
WorldLive.MovingGameObjects[i].PU.Move();
}
}
DateTime DT = DateTime.Now;
WorldLive.CheckInterceptions();
TimeSpan TS = DateTime.Now - DT;
IConsole.DisplayText += "CheckInterceptions " + TS.Ticks.ToString() + "\n";
WorldLive.TouchMasters();
IConsole.DebugInfo();
DT = DateTime.Now;
WorldLive.HandleInterceptions();
TS = DateTime.Now - DT; IConsole.DisplayText +=
"HandleInterceptions " + TS.Ticks.ToString() + "\n";
DT = DateTime.Now;
WorldLive.RealizePreCalcPosition();
TS = DateTime.Now - DT; IConsole.DisplayText +=
"RealizePrecalc " + TS.Ticks.ToString() + "\n";
DT = DateTime.Now;
WorldLive.ClearInterceptions();
TS = DateTime.Now - DT; IConsole.DisplayText +=
"ClearInterceptions " + TS.Ticks.ToString() + "\n";
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
Color.DarkGray, 1.0f, 0);
DT = DateTime.Now;
device.BeginScene();
device.RenderState.Ambient = Color.DarkSlateGray ;
WorldLive.DrawGameObjects();
TS = DateTime.Now - DT; IConsole.DisplayText +=
"Scene " + TS.Ticks.ToString() + "\n";
text.DrawText(null, IConsole.DisplayText, new Point(10, 20), Color.White);
device.EndScene();
device.Present();
displayText = "";
this.Invalidate();
}
History
- 6th November, 2007: Initial post