VRML Shockwave 3D
Home Books Applications Tools Docs Models Textures

Please send me your comments
Tutorials List

Terrain Tutorial



A TGA Library
A Simple TGA Library
TGA lib Source

Height Maps
Height Maps from Images

Computing Normals
Simulating Lighting
Implementation Details
Screen Shots

Source Code

Artificial Terrain Generation
The Fault Algorithm
Implementation Details
Two Simple Variations
The Circles Algorithm

Mid Point Displacement
The MPD Algorithm

Particle Deposition

Matrix filters
API details

Source (Linux and Win32)

[Previous: Matrix Filters] [Next]

Terrain Tutorial

Smoothing - API Details

Three functions are provided in terrain.cpp (see the source code) for this effect. The first one resets the filter to the identity filter, i.e. a matrix full of zeroes with a single 1.0 value at the center. Applying this matrix is the same as lefting the terrain untouched.

void terrainResetFilter();

There is a function to set a filter. This function receives a 5x5 matrix as a 25 floats array.

void terrainSetFilter(float *newFilter);

newFilter - The array with the matrix coefficients

In the implementation provided the final height of a grid point after applying the matrix is divided by the sum of the matrix components. Therefore the following two matrices produce the same result:

	m = [ 1/9   1/9   1/9
	      1/9   1/9   1/9
	      1/9   1/9   1/9];
	m = [ 1     1     1
	      1     1     1
	      1     1     1];

Note: The example above uses 3x3 matrices for simplification purposes. The function expects to receive an array with 25 floats, i.e. a 5x5 matrix.

Finally the function terrainApplyFilter will apply the matrix previously defined to all the terrain grid points.

int terrainApplyFilter();

The application provided in the source code includes a window where you can enter the matrix components and try your own filters. Please let me know if you get interesting results.

[Previous: Matrix Filters] [Next]

Site designed and maintained by António Ramires Fernandes
Your comments, suggestions and references to further material are welcome!

Lighthouse 3D privacy statement