Task 039: Terrain Generation

Your task is to create a program that will generate a fractal terrain. The user should be able to set the number of iterations used by the algorithm, and the smoothness / roughness of the result. With this assignment you should, among other things, learn how to work with 3D data, and try some basic procedural scene modelling methods.

Screenshot of an older version of the application 039terrain: Terrain Screenshot

Principle

The algorithm starts with four vertices located at the corners of a square, which are assigned random heights. In the middle of the square we add a new point. The height of this point is calculated as the average height of the four corner points ("diamond step"). After addition of the middle point, its four neighbouring vertices must be defined. Their heights can again be calculated as the average of heights of (here 3, but in later iterations typically 4) adjacent vertices ("square step"). This method is recursively applied until target grid resolution is achieved. The principle of the algorithm is illustrated in FIG.

If the algorithm only proceeded as just described, all it would generate is a smooth surface. However, one can introduce random vertical displacements to the points during recursion. The displacement magnitude and its change with recursion level determine the final appearance of the generated terrain.

Steps of the algorithm

Literature

Further information can e.g. be found here:

If you want, you can also implement additional non-trivial techniques to gain bonus points, e.g.:

Implementation

The template application 039terrain from the repository grcis serves as the basis of this project. Your main task will be to extend the Regenerate() method, that is invoked after any change of the parameters, and while pressing the "Regenerate terrain" button.
Helper class SceneBrep manages scene data - you can easily add new vertices (AddVertex()), their normals (SetNormal()), texture coordinates (SetTxtCoord()) and colours (SetColor(), see the method Render()); its usage can be seen in glControl1_Load(). The rendering of the scene data contained in the SceneBrep, and a simple camera are implemented in Render() and SetCamera(), respectively. For a successful completion of this assignment, it is not necessary (but also not prohibited) to alter these two classes - conversion of the generated terrain to a triangle mesh is sufficient. Conversion of the data in SceneBrep and their transfer to the video card is done via the method PrepareData(). A utility library for texture management can be found in TexLib.cs.

Application behaviour when "Regenerate terrain:" is pressed: the application should not exhibit sudden changes in the terrain shape when "regenerate" is invoked if only a finer/coarser resolution of the same mesh is desired. Of course the terrain appearance can and should change if parameters are altered: but if only fineness-like parameters are altered, the overall shape should stay the same.

Flight over the terrain ("hovercraft")

Optionally (for additional bonus points) you can try to implement interactive flights above the ground in a hovercraft. A hovercraft has very limited mobility in the vertical direction, and basically always follows the terrain (i.e. flies at some fixed height above it). Hovercraft should be controlled with classical keyboard controls (arrow keys or "WASD"), or the mouse. You can also implement a viewing direction that is partially independent of the vehicle's forward movement - a hovercraft can have considerable inertia, but rotate around the vertical axis faster. You can freely chose relevant parameters, such as the flight altitude over the terrain, acceleration, inertia, gravity influence, or smoother movement over rough terrain (height smoothing function terrain). Just make sure you properly document what you do in this regard, so that we can give you the extra points you deserve!

The flight simulation should call the method Simulate (double time). As with other tasks in this course, time is measured in seconds and the task of this function is to "simulate" movement from the last call until a given time. This method is always called immediately before the rendering of scene.

What to hand in

As solution of the assignment, you minimally have to send us the file Terrain.cs. If you have used a different terrain generation method than the one described above, please also describe it in a short accompanying text. The same goes for any interesting extensions you implemented. You can also send in a screenshot of your app in action, or a link to a gallery of images rendered with it (but this is not required).

Deadline

Hand in the assignment until: 28. 2. 2023

Points

Up to 26 points + bonus according to the following scoring system:

  • 10 points - basic generation of a non-textured / monochrome terrain with settings for smoothness / roughness and the number of iterations. At least some normals are set, and there is a possibility for setting the dimensions of the terrain.
  • 4 points - initialisation of the terrain via a PNG image.
  • 2 points - correct normals at all vertices, which leads to nice shading.
  • 2 points - basic non-trivial texturing of the terrain.
  • 3 to 8 points - ability to fly over the terrain ("hovercraft mode").
  • bonus - for interesting additions, and particularly pretty rendering. Possible additions: volcanoes, rivers, controllable sea-level. Rendering: bonus for multiple textures, semi-transparent water, etc.).

Project

Visual Studio project: 039terrain.

Source file

Modify and hand in the source file: Terrain.cs
As a comment in the first line, please include your name!
Please also return your name as parameter of the function Form1.InitParams()!
Also, if you add any features beyond the baseline ones (hovercraft mode, etc.), please include a description!


Copyright (C) 2016 J. Pelikán & A. Wilkie, last change: 2022-12-15 12:45:36 +0100 (Thu, 15 Dec 2022)