 |
 |
|
 | |
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);
Parameters:
-
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.
|