Writing a 3D Flight Simulator – in Delphi

There was a time before I became a die-hard fan of C++. Back then in high school, I believed – for some reasons – that learning Delphi was a good idea. Even worse, I thought it would make an excellent choice to write 3D games!

Even worse, I didn’t even stop when tutorials recommended to use hacked OpenGL headers, that “somehow” worked with Delphi. It took a lot of effort to take off, but it shows that you can build cool stuff, even if your choice of programming language is not the best. Even today, I am still much more interested too see awesome projects coming into life, instead of participating in the endless discussions about which programming language is now the best to learn!

Back then in 2007, I was inspired by games such as GTA3, UT99, and SNES Star Wing – and after reading a book “how to write a 3D engine”, I decided that my next game would be a 3D engine for flight simulator games!

The name of the game is MBDAK 3, which is a complex German acronym, and can be roughly translated to “carnage the invaders, until the doctors arrive”. In this project, I focussed on creating an engine of highest flexiblity. It was the first time I came in contact with dynamic linked libraries, and the engine supports an abstracted rendering and audio layer, and is therefore independent on the actually used 3D API. Both the graphical and the audio subsystem are encapsulated in separate DLL files. Different implementations of these DLLs allow the use of different graphic libraries. Implementations were done for the Direct3D and OpenGL API, thus it is possible to change the 3D rendering API by just exchanging the DLLs. The sound subsystem uses the FMOD audio library, which is also stored in an encapsulated dynamic library file.

The layout of the game is also completely configured in xml files to describe the environemnt. Each level iteself consists of a set of building blocks, the so called level entities (i.e. scyscrapers, cranes, streets and other level elements). Each entity provides a file containing the 3D data for rendering and a collision model file, and several attributes (destroyable, material properties, additional data for light and particle effects). Each entity can then be placed multiple times at any position in the 3D scene. The properties of the aircraft flown by the player is also configured in these xml files: its weapon arsenal and other important attributes (starting position, position light data, etc) are all configurable. This was done to provide a maximum of flexibility in the level design.

The collision detection works using a tree structure: the first level of the tree is the subdivion of the environment into large invisible cubes. The collision detection algorithm only takes the cube(s) into account, that are currently accessed by the player. Only objects within this cube are then considered for collision detection. The second stage of collision detection is done using spheres, where each entitiy has a sphere that encompasses it. Only if the sphere of the player and another object overlap, collision detection is done on a triangle level. The triangle models used for collision detection are greatly simplified variants of the original model, in order to keep the number of necessary computations to a minimum.

3D collision detection using spheres, encompassing the triangle meshes of the entities

Another important goal during the development of this engine was to make the simulation as realistic as possible and to become familiar with the latest rendering technologies at that time. The engine therefore uses MipMapping texture filters, fog and dynamic lighting and uses dynamic real-time shadow calculation using the Carmack’s Reverse method. However, interesting things such as bump mapping or shaders were not been used. The reason for this was first, because compatibility with non-T&L-capable video cards (I am a huge fan of old 3dfx video cards and the game was developed on a Voodoo5) was desired and second, because of the lack of time. I still had to go to school at this time.

I would like to thank Mr. Plöchinger, also known as DungeonKeeper1 in the german VoodooAlert board, for providing the MBDAK 3 soundtrack! The 3D models were partially created by myself using Milkshape 3D, while some others were extracted from older computer games. For this reason, I unfortunately cannot publish this game.

Abilities of the 3D Engine

  • Selectable 3D API: Direct3D 8, OpenGL und 3dfx Glide are supported
  • Support of real-time dynamic stencil buffer shadows
  • MipMapping texture filters
  • Dynamic environment loading systen
  • Collision detection using separate collision models based on a combination of octree data organisation and spheres / triangle collision detection for best performance
  • A simple particle system supporting alpha blending and z ordering

Shown below are several screenshots of the current development stage. Unfortunately, I cancelled the project after two years of development due to other priorities (studying). Besides that, creating 3D simulations using Delphi was not the smartest choice and the quality of the source code was miserable as only structures and no classes were used.

MBDAK 3 - Flugsimulator
MBDAK 3 with highest details: real-time shadow calculation, fog, particles and hightest texture quality

Screenshot of the main menu
MBDAK 3 menu intro. Graphics were hand-drawn, scanned and colorized… with Microsoft Paint.

Menu screen starfield simulator
MBDAK 3 menu. Graphics were done with Adobe Fireworks. The little preview window in the top left corner is inspired by Nintendo’s Starwing. It contains a little starfield simulator.

Download

Source Code

You can find the ugly, terribly documented source code on my GitHub:

https://github.com/Danaozhong/sw.game.mbdak3_flight_simulator

Leave a Reply