vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
APNature::MidpointDisplacementAlgorithm Class Reference

#include <MidpointDisplacementAlgorithm.h>

Inheritance diagram for APNature::MidpointDisplacementAlgorithm:
APNature::TerrainAlgorithm

Public Member Functions

 MidpointDisplacementAlgorithm (int width, int height, float cornerValueFrom, float cornerValueTo)
 
void RandomizeSurfaceCorners (float cornerValueFrom, float cornerValueTo)
 
float * GenerateSurfaceByMidpointDisplacement (int x1, int y1, int x2, int y2, int level)
 
- Public Member Functions inherited from APNature::TerrainAlgorithm
 TerrainAlgorithm (int width, int height)
 
 ~TerrainAlgorithm ()
 
unsigned int PointIndex (int x, int y) const
 
float GetLowestValue () const
 
float GetHighestValue () const
 

Static Public Attributes

static const int InitialLevel = 1
 

Additional Inherited Members

- Protected Member Functions inherited from APNature::TerrainAlgorithm
float * Allocate (int width, int height)
 
void Release ()
 
void Zero ()
 
void Flatten (float height)
 
float GetPointHeight (int x, int y) const
 
void SetPointHeight (int x, int y, float height)
 
- Protected Attributes inherited from APNature::TerrainAlgorithm
float * _terrain
 
int _width
 
int _height
 

Constructor & Destructor Documentation

MidpointDisplacementAlgorithm::MidpointDisplacementAlgorithm ( int  width,
int  height,
float  cornerValueFrom,
float  cornerValueTo 
)

Initializes the attributes, allocates the memory for the terrain data and sets the corner values.

Parameters
[in]widthSize of the terrain surface to generate in X-axis.
[in]heightSize of the terrain surface to generate in Y-axis.
[in]cornerValueFromLower boundary of the interval from which the pseudo-random values are generated.
[in]cornerValueToUpper boundary of the interval from which the pseudo-random values are generated.

Member Function Documentation

float * MidpointDisplacementAlgorithm::GenerateSurfaceByMidpointDisplacement ( int  x1,
int  y1,
int  x2,
int  y2,
int  level 
)

Core of the algorithm - method that is applied to the points which lie in a rectangle given by two corner points and subsequently divides the rectangle in four approximately large rectangles and calls itself upon them. Recursion stops when the smaller rectangle contains no more points.

[Based] on the midpoint displacement algorithm, described e.g. in Modern Computer Graphics, p.278

Parameters
[in]northWestNorth-West corner of the rectangle in which the computation takes place.
[in]southeEastSouth-East corner of the rectangle in which the computation takes place.
Returns
Terrain surface data stored in one-dimensional array.
void MidpointDisplacementAlgorithm::RandomizeSurfaceCorners ( float  cornerValueFrom,
float  cornerValueTo 
)

Randomizes the corners of the terrain surface. To each of the four corners a new pseudo-radom value from the given interval will be assigned. Positive values only.

Parameters
[in]cornerValueFromLower boundary of the interval from which the pseudo-random values are generated.
[in]cornerValueToUpper boundary of the interval from which the pseudo-random values are generated.

Member Data Documentation

const int MidpointDisplacementAlgorithm::InitialLevel = 1
static

The documentation for this class was generated from the following files: