Entropy Terrain Tutorial

From LagoonWiki

Jump to: navigation, search

This tutorial tells you how to put some terrain into the Galaga/Entropy/Ogre3D engine, and how to modify it.

Contents

Obtaining Some Artwork to Start With

  • Move to the directory above where you checked out Entropy:
pushd /cs381/<teamname>
  • Check out a kit that includes some game assets:
svn checkout svn+ssh://pine.cse.unr.edu/staff/sushil/svnroot/entropy_dependencies
  • Unpack the tarball where the assets are stored:
pushd entropy_dependencies
tar -xzf ogrenew.tgz
popd
  • Now move to the Entropy directory, which is where you will do most of your work for this tutorial:
pushd entropy
  • Copy the terrain configuration file from the kit:
cp ../entropy_dependencies/ogrenew/Samples/Media/terrain.cfg .
  • Make a place to store the terrain data:
mkdir galaga/data/terrain
  • Copy the terrain files into the new directory:
 cp ../entropy_dependencies/ogrenew/Samples/Media/materials/textures/terrain* galaga/data/terrain/

Loading the Existing Artwork into the Engine

  • Tell the engine to load that data upon startup, by editing resources.cfg and adding the new galaga/data/terrain directory to the bottom of the list.
  • Tell the engine's scene manager that you want to use a scene with terrain, by editing core/ogre/ogreApplication.cc, commenting out this line:
this->sceneManager = this->root->createSceneManager(ST_GENERIC, "SMInstance");
and adding this line:
 this->sceneManager = this->root->createSceneManager(ST_EXTERIOR_CLOSE, "mySM");
The first argument tells the scene manager what kind of environment will be used, and the second just gives it a name.
  • Tell the engine's scene manager what terrain configuration file to use by adding this line:
sceneManager->setWorldGeometry("terrain.cfg");
after this line that is already commented out:
//mSceneMgr->setWorldGeometry("terrain.cfg");

Additional Engine Modifications

  • Move the camera by finding these lines in galaga/galaga_startup.py -
from camera import camera
var_pos = camera.find_var(varHandle_pos)
var_pos.set(Vec3f(0,100,0))
and changing the last line to:
var_pos.set(Vec3f(750,100,750))
This puts the camera near the center of the 1500x1500 block of terrain. (You can tell the world size by looking at PageWorldX and PageWorldY in terrain.cfg.)
  • Now rebuild the engine and see if the terrain loaded properly:
make && python go.py galaga
The "&&" is UNIX-speak for "do the next command if-and-only-if the first finishes without error".

Make the Camera Movable

We will work with controls more later, but here is a quick hack that will let the arrow keys move the camera forward/back or left/right. Notice that these directions are relative to its current orientation rather than relative to the game axes.

  • Edit galaga/data/galaga_keymapping.yaml (YAML - "Yet Another Markup Language" is just something the author of Entropy chose for data representation.) Change all occurences of player_movement to camera_movement. You may want to change all the +1.0 and -1.0 to +/- 2.0 or 5.0, if the camera moves two slow for you.
  • Rebuild the engine and test your changes.

Modify the Terrain

terrain.cfg defines three graphics files that are used to construct the terrain:

WorldTexture=terrain_texture.jpg
DetailTexture=terrain_detail.jpg
Heightmap.image=terrain.png

You can change the filenames if you wish, but the file as-is matches what you just copied into galaga/data/terrain/.

Heightmap.image specifies a greyscale file that defines the elevation, with black = low and white = high.

  • The vertical scale for the terrain is controlled by MaxHeight in terrain.cfg.

DetailTexture specifies a file that will be used to "paint" the landscape by tiling the map with it at a small scale.

WorldTexture specifies a file that will be painted over DetailTexture on a larger scale, with the single image stretched to cover the entire landscape. It is rendered semi-transparently so that it will not completely obscure DetailTexture. The darker the color in this file, the more opaquely it will be rendered: wherever it is dark it will completely hide DetailTexture, wherever it is light it will not show up over DetailTexture at all, and intermediate shades will let you see a mixture of the two textures.

Try these:

  • Use The GIMP to modify terrain.png. Create a deep round hole near the center and four tall towers around it, and restart the engine to observe the changes.
  • Try larger and smaller values for MaxHeight in the configuration file, and observe how it changes the vertical stretch for the terrain when you restart the engine.
  • Put light and dark spots or lines in terrain_detail.jpg and observe the repeating patterns painted on the landscape when you restart the engine.
  • Use The GIMP to convert terrain_texture.jpg into an image with a smooth gradient from black to white, and observe its effect on the way the landscape is painted when you restart the engine.
    • Try it again with a gradient from dark to light using colors other than black and white.

Note: You can control the absolute size of your terrain by modifying PageWorldX and PageWorldY in your terrain.cfg. However, the skybox remains at a constant distance from the camera, so there is no way to gracefully close the gap around the edge of the terrain. (You could make the terrain bigger than the fixed distance to the skybox, but then the terrain would slide through the wall of the skybox as you move the camera. We will have to use other means to hide the gap between the edge of the terrain and the skybox.)

Update Your Script(s)

  • Save all the new or modified files in your own directory tree.
  • Update your script to create the new data directory and copy all your saved files to their proper places.
    • Your script does not have to check out entropy_dependencies. You have the files you need from it, and those files will be copied out of your own directory tree.

Notice that positions in the world are given by 3D vectors (x,y,z), where the x and y axes have the same orientation as they do on a plot, i.e. -x is to the left and +x is to the right, -y is down and +y is up. The z axis goes through the screen, with +z toward you and -z away from you. (Of course, this all changes when you move the camera.) Thus when we set the camera at (750,100,750) it is at elevation 100, and 750x750 away from the origin in the horizontal plane.

Now Make it Nice

  • Modify the terrain to suit your sky box, and be prepared to demonstrate it next week.