The Axiom engine is an open source 3D graphics/game engine written in C#. It has bindings for rendering with OpenGL and Managed DirectX. This article takes you through the process of creating a simple demo. It should be enough to get you up and running and whet your appetite. Any further exploration is up to you ;-)
I kept trying to find some sort of business case to have an excuse to write something about Axiom, after all, it's a "game" engine. But you know what? screw it ... what ever happened to the days where I would code something just for fun? well, I gotta tell ya, they're coming back. I long to have fun programming again, and for anyone who has every looked at a video game and secretly wished they could do the same, this one's for you ;-)
The purpose of this isn't to show you how to make games, or even really anything about 3D ... I'll save that for another article. The purpose is to walk you through the process until you've got a development process going, and you are able to run your own code. As with many articles of this type, we're simply going to be taking some existing code, copying it, and modifying it. That will show you what you have to do, and what you have to hook into to get something going.
Getting Started
You can download the source code for the engine at axiomengine.sourceforge.net. At the time of this writing, it seems that the CVS repository is going through some restructuring so the guy has a backup of the latest stable release (ironically, listed under the unstable source snapshots) available for download in a zip file. If you're brave, one of the forum members has posted a small tutorial on building Axiom from CVS.
But for the purposes of what we're trying to achieve, the release available on the site will do just fine. Once downloaded, you will notice that there are no Visual Studio solution files anywhere in the directories.
- Open the directory you unzipped the axiom source into.
- Select the batch file for the editor of your choice
- SharpDevelop.bat
- VS2002.bat
- VS2003.bat
This will create the project files for the solution using a pretty nifty tool called .NET Pre-Build. The cool thing about this is that it opens up the door for hobbyist programmers that don't have the cash to shell out for a copy of visual studio.
We'll be going with the Visual Studio 2003 solution as that is what I have installed.
Running the Demo Browser
Once you've got the Axiom.sln running in Visual Studio, you must right click on the Demos project and select "Set as Startup Project". Compile the solution to make sure everything works appropriately and run it. The Demo Browser will come up.
Double clicking on one of the images brings up a dialog that allows you to choose your renderer, resolution, and whether you want it to run full screen or not. Several of the demos may not run depending on what kind of video card you have, but the one we'll be focusing on should probably run on just about anything. It's impressive to see that the OpenGL and DirectX renderers run and look exactly the same ... I intend on really diving into the architecture of Axiom because it is obviously really well designed to be able to abstract the details of each API into a generic one.
Creating your own Demo
What we're going to do is simply copy one of the existing demos and make a few very simple changes.
- Navigate to the Demos folder in the Demos project and find Tutorial1.cs.
- Create a copy of Tutorial1.cs and rename it to MyTutorial1.cs
- Open the new file and replace the class name and all related symbols with MyTutorial1
- Change the namespace to something like MyDemos ... this is to avoid collisions with several of the classes defined in the demo.
Ok, at this point, try to compile the project to make sure you haven't missed anything. The next step is to customize the new demo and get it displaying in the Demo Browser.
Customizing the Code
Open up your newly created code and find the CreateScene method. You will notice that all of the geometry is being loaded into Axiom.Core.SceneManager (instance variable being this.scene ). Axiom uses what's called a scene graph to manage all of the in-game objects. This allows you to work with heirarchies of objects ... a technique wil will come into play when you want to get into things like skeletal animation. But back to the task at hand. All we are going to do is change one (1) line of code (line 87 in the code I have).
Change
MultipyControllerFunction func = new
MultipyControllerFunction(50);
To
WaveformControllerFunction func = new
WaveformControllerFunction(Axiom.Controllers.WaveformType.Sawtooth);
What this is telling the engine is that instead of just multiplying a given value by something (50), it is instead going to modify the value using a sawtooth pattern. This is going to give us a staggered animation effect instead of the smooth rotation of the original. To get the code to display in the demo browser, only one simple change needs to be made. Open up DemoTest.cs and find the DemoBrowser_Load event handler. Simply add the following line immediately following the other lines that are similar:
demoTable.Rows.Add(new object[] {23, "My Tutorial 1",
"MyDemos.MyTutorial1", "Tutorial1.jpg", "staggered spinning triangle demo using
the engine.", "Tutorials"});
That was line 255 in my code. At this point, you should be able to compile and run the application. Find the demo entitled "My Tutorial 1", double click on it, and voila! your very first Axiom demo. As I mentioned earlier, I really want to dive into the architecture of this engine ... it seems pretty slick.