Random Terrain Assignment

due: 3/30 by the end of the day.

Write a C++ program that implements the three random terrain algorithms discussed in class: random hills, particle deposition and random faults. Write three functions to implement the three algorithms.

Each function should receive a reference to a PGMImage object as the first parameter. You may include other parameters as appropriate to vary your algorithms. For example, you may write the random hill function so you can pass in the number of hills to create and a maximum height for each hill (so the actual height is chosen randomly from 0 to the maximum). In this case your function header would look like:

void randomHills(PGMImage &image, int numHills, int maxHeight)

The functions should add (or subtract or not) to the existing pixel values so that you can run your image through multiple functions.

The images you create should be 513 by 513 pixels, so we can use them in conjunction with Ogre. Use an image processing program e.g. Gimp to view them and convert them to a format Ogre can load. I recommend png.

Experiment with your algorithms' parameters and your OgreTerrain program from class. When you test them in your terrain renderer, you may want to set the WorldTexture and DetailTexture to terrain_texture.jpg and terrain_detail.jpg respectively although you may use other textures if you prefer.

Program Notes

Items to submit.

Example Function

The following is a function to add random heights to every point of the height map.
//add random values to every point in the terrain.
//values added will run from 1..max_amt
void randomTerrain(PGMImage &img, int max_amt){
  for(int y = 0; y < HEIGHT; y++){
    for(int x = 0; x < WIDTH; x++){
      int p = img.getPixel() + (rand() % max_amt) + 1;
      if(p > 255){
	p = 255;
      }
      img.setPixel(x, y, p);
    }
  }
}


Clif Presser<cpresser@gettysburg.edu>
Last modified: Thu Mar 24 10:27:14 EDT 2011