/******************************************************************************
 * $Id: gfx_noise.cc,v 1.2 2006/07/23 02:04:39 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Static class wrapper around underlying noise library.
 *//*
 * LEGAL:	COPYRIGHT (C) 2006 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 ******************************************************************************/

#define GFX_NOISE_CC 1
#include "gfx.hh"
#include "gfx_stream.hh"
#include "gfx_noise.hh"

// libnoise
#include "noise.hh"

namespace gfx {

int PerlinNoise::mSeed			= 1234;
fp	PerlinNoise::mFreq			= 0.0042;
fp	PerlinNoise::mLacunarity	= 1.0;
int	PerlinNoise::mOctaves		= 3;
fp	PerlinNoise::mPersistence	= 0.9;

// libnoise
static noise::module::Perlin sLibnoisePerlin;

/*****************************************************************************
 * Set noise parameters.  This affects Calc().
 *****************************************************************************/
void
PerlinNoise::Set( int seed, fp freq, fp lacunarity, int octaves )
{
	mSeed		= seed;
	mFreq		= freq;
	mLacunarity	= lacunarity;
	mOctaves	= octaves;

	sLibnoisePerlin.SetSeed( mSeed );
	sLibnoisePerlin.SetFrequency( mFreq );
  //sLibnoisePerlin.SetPersistence( mPersistence );
	sLibnoisePerlin.SetLacunarity( mLacunarity );
	sLibnoisePerlin.SetOctaveCount( mOctaves );
  //sLibnoisePerlin.SetNoiseQuality( mQuality );
}

/*****************************************************************************
 * Calculate 3D noise value.
 *****************************************************************************/
fp
PerlinNoise::Calc( const Vector3& vec )
{
	return sLibnoisePerlin.GetValue( vec.x, vec.y, vec.z );
}

} // namespace gfx
