Terrain Edit

Kevin Nyman
kn42 _AT_ drexel.edu

Index


  1. Overview
  2. Controls
  3. Tools
  4. Terrain
  5. Layers
  6. Building
  7. Source
  8. Notes
  9. Special Thanks
  10. Screen Shots

Overview


This is a project I worked on for my Interactive Computer Graphics Class at Drexel University. The goal was to have editable terrain during runtime by clicking on the terrain to edit the height and textures that are on the terrain.

To run, just execute any of the *.bat files in the src directory. Each one loads a different "level." The application (in src/Release) takes the *.xml world to load as an argument and the *.bat files do this.

Controls


Z Unlock/Lock the Camera
W Forward
S Reverse
A Strafe Left
D Strafe Right
Q or Esc Quit

Tools


There are multiple tools to assist with editing the terrain and other settings.
Altitude tool Changes the current tool to the altitude tool.
Flatten tool Changes the current tool to the flatten tool.
Layer tool Changes the current tool to the layer tool.
Foliage tool Changes the current tool to the foliage tool.
Sphere area Changes the selection area to a sphere.
Cube area Changes the selection area to a cube.
Slider area _ Changes the size of the tool.

Terrain


Terrain is organized into square chunks. For now the default chunk size is 64 x 64. The terrain is stored as an image which holds the height values (red). The more intense the red is, the higher the terrain. The terrain is editable during runtime with the altitude tool or the flatten tool . When the terrain height is changed, the brightness is adjusted based on the height of the current vertices.

altitude tool

  • Left Click - raise terrain in selection area
  • Right Click - lower terrain in selection area
flatten tool
  • Left Click - match anchored height in selection area
  • Right Click - create an anchor height value at the current mouse position

<object type="chunk" x="0" y="31" z="0"">
   <terrain name="terrain1.tga">
      <layer>
         ... SEE LAYER ...
      </layer>
   </terrain>
   <foliagegroup name="foliage.xml" />
</object>

object - Defines an object and the x, y, and z offsets (x and z are in world units, while y is in its own units.
terrain - Defines the height value file.
layer - Defines a layer for the terrain (multiple can be added).
foliagegroup - Defines the file that has a foliage group for the terrain.

Layers


Layers can be added in the world.xml for a given chunk. The current example has three different layers. There must be at least one layer which is the base. The layers are drawn in the order consistent with the XML file. By clicking on the layer tool , the layer tool is activated and the current active layer is changed to the next. The first layer (base layer) is not editable. If you want to change the order of the layers, just reorder the XML.

  • Left Click - apply texture
  • Right Click - remove texture

<layer>
   <texture name="res/textures/grass.tga" />
   <lightmap name="terrain1glm.tga" />
</layer>

texture - Defines the texture that is tiled.
lightmap - Defines the color values as well as where the texture is applied based on the alpha value.
When saving the layers, the lightmap is saved. Also, the dimensions o the layers needs to match the dimensions of the terrain ( 64 x 64 for the default ).

Foliage


Foliage can be added to the terrain. To activate this click on the foliage tool . By clicking on the terrain, the foliage will be applied a the location of the cursor. Foliage can be erased by right clicking as well. Each chunk can have multiple groups of foliage. Each foliage group is organized based on the texture used.

  • Left Click - apply one bush with the current scale
  • Right Click - remove foliage in the selection tool area


<foliagegroup r="4" name="res/foliage/grass.tga">
   <scale x="1" y="1.5" z="1"/>
   <p x="1.01744" y="10.9645" z="6.0082"/>
   <p x="1.04" y="1.95" z="5.0082"/>
   <p x="1.04" y="0.95" z="56.0082">
      <s x="1" y="1.5" z="0.2343"/>
   </p>
   <p x="1.44" y="5.96" z="5.82"/>
</foliagegroup>

foliagegroup - Defines a group of foliage based on the texture name.
@param r - How many rotations are used to render the foliage. Each rotation is 180.0f / r
scale - Defines the default scale for all of the bushes
p - Position of a bush
s - Scale of a bush

When the terrain is changed, the foliage will be moved to be correctly displayed on the terrain.

Building


Mac OS X - Open up the makefile in src/ and uncomment the line specifying for Mac, and comment out the linux build. Watch the tabbing because it's a make file. Then follow the Linux build directions.

Linux - Navigate to src/ dir and type "make" and cross your fingers. This will generate the libs and place them in lib/debug as well as the *.o files and put them in tmp/debug. Once these are built, I attempt to compile all the specific code to the project and link in the libraries. (lib*.a files) Sometimes there was an issue where tinyxml was not rebuilding properly, do a "make clean" in src directory, then "make setup" which creates the necessary dir structure. Navigate to src/common/thirdparty/tinyxml/ and type "make" which should create the library and put it in lib/debug/. Also note, this was ported to linux, so you get about 1.3 trillion warnings about the end of the file eating your children. My makefiles don't have anything set for optimization, I recommend setting them because of the huge difference it made on win32.

Win32 - Navigate to src/ dir and open up the *.sln. This is a .NET 2003 file, however, it can be reverted to 2k2 by following the directions in the notes section. I have created release and debug modes - release runs 10x faster on my laptop than debug does, so I recommend you do the same unless you want to step through the code with the debugger. Also, sometimes doing a full rebuild does not build the *.lib files in the right order and if it says that one wasn't found, build that one individually then build the FinalProject.vcproj file.

Source


Source was done mostly in .NET 2k3 and Textpad. I am releasing my source since I learn from other people and I believe in sharing (besides how much of this is 100% original?). However if you intend to use a part of this application please at the least remember where it was from and give some credit. I also ask that you don't copy and paste, but actually understand and implement (learn the right way =P). I also recommend www.gamedev.net or nehe.gamedev.net for tutorials that are useful. If you have any questions please feel free to email me.

Notes


The camera needs to be locked so the position can be reset. This is done because there was no cross platform way of hiding the mouse cursor or centering the cursor. It is clunky at first, but makes life easier to select tools etc.

This is a GLUT build of most of my code base. I normally develop on plain Win32 - non MFC but it doesn't really matter since I just use it to setup a window and handle basic user input. I ported my code base to work with glut and developed makefiles to compile on linux.

GUI config is "gui.xml", and can be configured. Listeners can be added as long as they are bound in C++(so if you can't compile you can't add new function calls etc). In game save and reload of the GUI works.

"world.xml" contains some configurable parameters for the terrain. Multiple chunks can be entered, but newer ones cannot be modified since I'm still prototyping other features before I load multiple chunks. Also, I will probably scrap the Brute Force method of rendering terrain once I have time to research more advanced methods.

Other than glut and opengl tinyxml which is used for parsing XML, most if not all the code here I have written at one point or another.

The *.sln and *.vcproj files were done with VS .NET 2003. I have also popped open the XML and reverted the revisions from 8.00 to 7.00 in the *.sln files and 7.10 to 7.00 in the *.vcrpoj files and had no problems compiling. If you would like linux versions - or MAC I can arrange that as well.

I recommend running doxygen if you want to analyze the relationships between some of the classes. I tried to make most of the stuff decoupled. If you have any questions feel free to email me.

Special Thanks


Bruce Macay for helping out with the OS X and Linux makefiles.
Anyone who looked at, ran, tested, or gave their opinion. Thank you =D

Screenshots