mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Syncing uppdev
git-svn-id: svn://ultimatepp.org/upp/trunk@599 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
a907bee20e
commit
a8f5eddbab
13 changed files with 625 additions and 125 deletions
61
uppdev/CtrlLibTest/PerlinNoise.h
Normal file
61
uppdev/CtrlLibTest/PerlinNoise.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef _CtrlLibTest_PerlinNoise_h_
|
||||
#define _CtrlLibTest_PerlinNoise_h_
|
||||
|
||||
#include <Core/Core.h>
|
||||
using namespace Upp;
|
||||
|
||||
struct PerlinNoise
|
||||
{
|
||||
public:
|
||||
PerlinNoise() : octaves(2), persistence(0.5f) {}
|
||||
|
||||
PerlinNoise &Octaves(int _octaves) { octaves = minmax(_octaves, 2, 31); return *this; }
|
||||
PerlinNoise &Persistence(float _pers) { persistence = _pers; return *this; }
|
||||
|
||||
virtual float Noise(int x, int y) const;
|
||||
float SmoothNoise1(int x, int y) const;
|
||||
float InterpolatedNoise1(float x, float y) const;
|
||||
float CosineInterpolate(float a, float b, float x) const;
|
||||
|
||||
float PerlinNoise2D(int x, int y) const;
|
||||
float PerlinNoise2D(float x, float y) const;
|
||||
float PerlinNoise3D(int x, int y, int z, int offset = 0x151) const
|
||||
{ return PerlinNoise2D(x + offset*z, y + offset*z); }
|
||||
float PerlinNoise3D(float x, float y, int z, int offset = 0x151) const
|
||||
{ return PerlinNoise2D(x + offset*z, y + offset*z); }
|
||||
protected:
|
||||
int octaves;
|
||||
float persistence;
|
||||
};
|
||||
|
||||
class PerlinNoiseCache : private PerlinNoise, public Moveable<PerlinNoiseCache>
|
||||
{
|
||||
public:
|
||||
PerlinNoiseCache() { Clear(); }
|
||||
void Cache(int cx, int cy);
|
||||
|
||||
PerlinNoiseCache &Octaves(int _octaves) { octaves = minmax(_octaves, 2, 31); return *this; }
|
||||
PerlinNoiseCache &Persistence(float _pers) { persistence = max(0.0f, _pers); return *this; }
|
||||
|
||||
Image AsImage() const;
|
||||
void Clear();
|
||||
|
||||
Size GetXY() const { return sz; }
|
||||
|
||||
float Get(int x, int y) const { ASSERT(~cache); return cache[(x % sz.cx) + sz.cx * (y % sz.cy)]; }
|
||||
float Get(int x, int y, int z) const;
|
||||
float Get(float x, float y, int z) const;
|
||||
virtual float operator()(int x, int y, int z) const { return Get(x, y, z); }
|
||||
virtual float operator()(float x, float y, int z) const { return Get(x, y, z); }
|
||||
|
||||
private:
|
||||
Size sz;
|
||||
Buffer<float> cache;
|
||||
Buffer<float> noise;
|
||||
|
||||
void InitNoise();
|
||||
void DeinitNoise() { noise.Clear(); }
|
||||
virtual float Noise(int x, int y) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue