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

#include <PerlinNoiseAlgorithm.h>

Inheritance diagram for APNature::PerlinNoiseAlgorithm:
APNature::TerrainAlgorithm

Public Member Functions

 PerlinNoiseAlgorithm (int width, int height)
 
float GetNoise (float x, float y)
 
float * GenerateNoiseTexture (float frequencyX, float frequencyY)
 
float * GenerateCloudsTexture (std::size_t octaveCount, float persistence)
 
- 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
 

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

PerlinNoiseAlgorithm::PerlinNoiseAlgorithm ( int  width,
int  height 
)

Initializes the attributes and generates the gradient and permutations tables.

Parameters
[in]widthSize of the terrain surface to generate in X-axis.
[in]heightSize of the terrain surface to generate in Y-axis.

Member Function Documentation

float * PerlinNoiseAlgorithm::GenerateCloudsTexture ( std::size_t  octaveCount,
float  persistence 
)

Generates multiple noise surfaces at different frequencies and sums them up together with different weights given by persistence. Deallocation of the noise surface is automatic after the instance is deleted. If the method is called repeatedly, previous result is rewritten. Less surfaces result in a rough terrain with a small elevation differences, more surfaces result in smoother terrain with higher elevation differences.

[Based] on a theory from Ken Perlin's talk which can be found at http://www.noisemachine.com/talk1/21.html , with some parts inspired by algorithm at http://devmag.org.za/2009/04/25/perlin-noise/ (e.g. faster squaring (<<) in case base is always 2)

Parameters
[in]octaveCountNumber of noise surfaces which are summed up together.
[in]persistenceProperty similar to fractal dimension - the higher the persistence is, the more rough the terrain is and vice versa.
Returns
Generated noise surface in one-dimensional array of size [width * height] if allocation succeded, NULL otherwise.
float * PerlinNoiseAlgorithm::GenerateNoiseTexture ( float  frequencyX,
float  frequencyY 
)

Generates a new single noise texture of a given dimensions with points sampled at given frequencies. Deallocation of the noise texture is user's resposibility.

Parameters
[in]frequencyXFrequency at which is noise sampled in X-axis.
[in]frequencyYFrequency at which is noise sampled in Y-axis.
Returns
Pointer to the newly generated noise surface in one-dimensional array of size [width * height] if allocation succeded, NULL otherwise.
float PerlinNoiseAlgorithm::GetNoise ( float  x,
float  y 
)

Returns the value of perlin noise function in two dimensions for the point located at the given coordinates.

[Adapted], modified and clarified version of function noise2() from original implementation by Ken Perlin which can be found at http://www.mrl.nyu.edu/~perlin/doc/oscar.html#noise

Parameters
[in]xLocation of the point on the X-axis.
[in]yLocation of the point on the Y-axis.
Returns
Intensity value of the perlin noise function for the point at the given two-dimensional coordinates.

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