3D Fractal Landscapes using the Diamond Square Algorithm
Due: We. Sept. 22nd, 2pm. EXTENDED TO SEPT. 29th, 2pm. 2 bonus points for finishing until sept. 22nd !
Teamwork highly recommended
Score: 10 points (+2 bonuspts.)
- in time: 100%
- one week delay: 65%
- two weeks delay: 40%
- else: 20%
Creating the Terrain
Create a heightfield terrain map in C++ using the Diamond Square Algorithm as presented in the lecture. As a help i programmed a MATLAB version (did i
tell you that MATLAB is one of the most convenient programming languages out there ?), which you can download and analyse. If you understood what's
going on there, then you simply have to translate it to C++ . Watch the index behaviour of MATLAB: MATLAB starts indexing matrices (=arrays) with
1 instead of 0.
The MATLAB function creates a fractal terrain as a matrix, you can display this matrix using 'plotMatrix3d.mat' also delivered here.
If you want to see some terrains, simply type into MATLAB:
plotMatrix3d; axis equal;
and you'll be excited, i hope.
HERE is the MATLAB code for the terrain
HERE is the MATLAB code for the display
This is an example terrain created by the program:
Displaying the Terrain
You display your terrain using OpenGL. We didn't talk too much about OpenGL so far, so i decided to give you the whole
framework to show a terrain heightfield as C++ program.
Your task is still to CREATE the values of the heightfield though, using the approach described above.
What is delivered ?
- A C++ program displaying a randomly intitialized heightfield, as Visual Studio 6 project. The project is a
console application, i.e. it doesn't contain any windows specific parts. The windows are handled by GLUT.
- The project contains 2 files (+ '.h' files) , i.e. the main program, creating and displaying the window, and
the second file, containing a class framework 'HeightField' representing the heightfield. The class contains a method
HeightField.createTerrain(). This is the method that currently produces random height values and that should be replaced by
the fractal Diamonds and Squares generator. The terrain size is a constant in HeightField.h .
- You'll need the GLut environment. It consists of 3 files, GLut32.dll, GLut.lib, GLut.h. You have to copy these files into the
following folders (if you use Visual Studio):
- put the glut.h into folder: C:\Program Files\Microsoft Visual Studio\VC98\Include\GL
- put the glut.lib into folder: C:\Program Files\Microsoft Visual Studio\VC98\Lib
- put the glut.dll into the systems folder: C:\WINDOWS\SYSTEM32 (if possible, if you are not allowed to do so, extend your PATH).
- to include the libs for opengl into visual studio, you have to add the OpenGL32.lib GLut32.lib to the project-link-path. This is already done
in the project delivered.
The Visual Studio Project to show the heightfield is HERE
If everything went right, you should be able to compile the program, the result:
The GLut files are here
We will build a game using this terrain in the upcoming assignments, so don't faint on this one !