October 31, 2010

ISSUE 1: The one hour 3D world

Panda3d Logo

All of the Issues in Volume 1 rely on something called Panda3D.  Panda3D is a 3D game engine provided completely free by the Carnegie Mellon Entertainment Technology Center.  A game engine is a Software Development Kit (SDK) that takes the pain out of the common tasks involved in game development.  For example, Panda3D provides libraries for graphics, physics, lighting, audio, keyboard/mouse/other input and so on.  You really would not want to find yourself having to write all of these routines yourself (you’d never finish a single game on your own!).  There are other game engines out there but we really like Panda3D due it’s ability to run on Windows, Linux and Mac and its support for Python:

Once you have a working game engine, you need a means to tell it what to do.  You need a programming language.  Like other languages, programming languages have their own vocabulary, syntax, semantics and so on.  To communicate with a person, you might choose English.  Though there are, of course, other options and they vary wildly (Russian and Chinese, for example, even have a completely different alphabet).  There are various merits to different languages and, likewise, pitfalls and problems (or ‘limitations’).

Panda3D supports game development using either the C++ or Python programming languages.  We will be using the Python language. In later issues we will discuss and compare other programming languages but for now trust us, Python is a good choice for getting started quickly.  Down the line, you will also learn about programming language versions.  Yes, there are different versions of Python.  Do not worry about this for now as we’ll guide you through a setup that works with Panda3D but if you’re pondering what difference a ‘version’ could make consider the difference between Old English and the English we use today!

Download and install Panda3D

Head over to http://www.panda3d.org/download/ and download the latest version of Panda3D for your operating system.

If you are using Microsoft Windows, there is a “one-step” installer that will install Panda3D and Python in one shot.  Nice and quick!

For Linux and Mac OS X users, again, you should find packages are available for your distribution.  If not, you’re in the land of compiling the source manually and that’s a bit beyond the scope of this issue (though we will likely hit on meddling in the Panda3D source code down the line).

The Panda3D download for Linux does not include the Python programming language but is usually matched to work with the default version of Python available in your package manager (add/remove software).

If you are using Apple Mac OS X there is, again, a one-step installer though, like the Linux version, it does not include the Python programming language.  It also requires you to install the NVIDIA Cg Toolkit. The necessary links are on the Panda3D download page for Mac OS X.

If you run into any problems at all take a little time to read through the Manual on the Panda3D website.  Panda3D is incredibly well documented, you’ll be visiting the site often as you progress to dip in and out of both the manual and SDK reference guide.

Let’s create a world (the easy way!)

As the old saying goes, there’s more than one way to skin a cat (never did understand why you would want to skin a cat, but there you go).  In the interests of getting going quickly, we’re going to use a really simple technique to create your new world.  We are going to create our 3D world from 2 images.  That’s it, 2 regular image files!

  • Image 1 is what we call a height map.  A height map is a grey scale image, no colour.  It represents an overhead view of your landscape (like a map!).  The lighter areas in the image represent high terrain (peaks, mountains).  The darker areas are lower.  It’s that simple.  Thus, any part of the image that is pure white will be ‘as high as is possible’ while anything in black is ‘as low as possible’.
  • Image 2 is our colour map (or ‘texture’).  It is dropped on to our height map like a cloth, colouring the terrain to our design.
Height map plus Colour map yields 3D map

You could create both images in your favourite image editor but we’re a little slicker than that here.  We’re going to use another piece of free software to design our world.

Let’s make it even easier!

As noted, you can make your height/colour maps in almost any image editor.  But, wouldn’t it be nice to have a ‘world designer’ to assist?  There is a free application called L3DT.  Natively, the program only runs on Microsoft Windows.  However, if you are a Linux user it will run admirably using Wine (available in your package manager) while Mac OS X users should Google for ‘mac crossover’ to achieve the same.

L3DT is nice and easy to use.  Essentially, the steps are:

  1. Download and install L3DT from http://www.bundysoft.com/L3DT/
  2. Load L3DT, hit File -> New Project then select ‘Designable Map’.
  3. The inbuilt design wizard will guide you through the rest of the process, the default options are fine (just hit next!) for all but the “Calculation Queue” screen, where you should enable Attributes, Height field and Texture map.
  4. Once finished, select the height map from the available tabs and hit File -> Export map Layer. Export theheight map as an image file (PNG).
  5. Repeat this step again, this time by selecting the colour (texture) map tab. Again, export as a PNG.

L3DT offers a wealth of features including editing your map in full 3D.  We recommend experimenting to achieve the design you want, for your game.