RigsofRods
Soft-body Physics Simulation
Perlin.h
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 
24 Based on the perlin noise code from Claes Johanson thesis:
25 http://graphics.cs.lth.se/theses/projects/projgrid/
26 --------------------------------------------------------------------------------
27 */
28 
29 #ifndef _Hydrax_Noise_Perlin_H_
30 #define _Hydrax_Noise_Perlin_H_
31 
32 #include "Noise.h"
33 
36 
39 
40 #define n_bits 5
41 #define n_size (1<<(n_bits-1))
42 #define n_size_m1 (n_size - 1)
43 #define n_size_sq (n_size*n_size)
44 #define n_size_sq_m1 (n_size_sq - 1)
45 
46 #define n_packsize 4
47 
48 #define np_bits (n_bits+n_packsize-1)
49 #define np_size (1<<(np_bits-1))
50 #define np_size_m1 (np_size-1)
51 #define np_size_sq (np_size*np_size)
52 #define np_size_sq_m1 (np_size_sq-1)
53 
54 #define n_dec_bits 12
55 #define n_dec_magn 4096
56 #define n_dec_magn_m1 4095
57 
58 #define max_octaves 32
59 
60 #define noise_frames 256
61 #define noise_frames_m1 (noise_frames-1)
62 
63 #define noise_decimalbits 15
64 #define noise_magnitude (1<<(noise_decimalbits-1))
65 
66 #define scale_decimalbits 15
67 #define scale_magnitude (1<<(scale_decimalbits-1))
68 
69 namespace Hydrax{ namespace Noise
70 {
73  class Perlin : public Noise
74  {
75  public:
78  struct Options
79  {
81  int Octaves;
83  float Scale;
85  float Falloff;
87  float Animspeed;
89  float Timemulti;
90 
94  float GPU_Strength;
103  Ogre::Vector3 GPU_LODParameters;
104 
108  : Octaves(8)
109  , Scale(0.085f)
110  , Falloff(0.49f)
111  , Animspeed(1.4f)
112  , Timemulti(1.27f)
113  , GPU_Strength(2.0f)
114  , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
115  {
116  }
117 
125  Options(const int &_Octaves,
126  const float &_Scale,
127  const float &_Falloff,
128  const float &_Animspeed,
129  const float &_Timemulti)
130  : Octaves(_Octaves)
131  , Scale(_Scale)
132  , Falloff(_Falloff)
133  , Animspeed(_Animspeed)
134  , Timemulti(_Timemulti)
135  , GPU_Strength(2.0f)
136  , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
137  {
138  }
139 
149  Options(const int &_Octaves,
150  const float &_Scale,
151  const float &_Falloff,
152  const float &_Animspeed,
153  const float &_Timemulti,
154  const float &_GPU_Strength,
155  const Ogre::Vector3 &_GPU_LODParameters)
156  : Octaves(_Octaves)
157  , Scale(_Scale)
158  , Falloff(_Falloff)
159  , Animspeed(_Animspeed)
160  , Timemulti(_Timemulti)
161  , GPU_Strength(_GPU_Strength)
162  , GPU_LODParameters(_GPU_LODParameters)
163  {
164  }
165  };
166 
169  Perlin();
170 
174  Perlin(const Options &Options);
175 
178  ~Perlin();
179 
182  void create();
183 
186  void remove();
187 
193 
197  void update(const Ogre::Real &timeSinceLastFrame);
198 
202  void saveCfg(Ogre::String &Data);
203 
207  bool loadCfg(Ogre::ConfigFile &CfgFile);
208 
215  float getValue(const float &x, const float &y);
216 
221  void setOptions(const Options &Options);
222 
226  inline const Options& getOptions() const
227  {
228  return mOptions;
229  }
230 
231  private:
234  void _initNoise();
235 
238  void _calculeNoise();
239 
243 
250  int _readTexelLinearDual(const int &u, const int &v, const int &o);
251 
257  float _getHeigthDual(float u, float v);
258 
266  int _mapSample(const int &u, const int &v, const int &upsamplepower, const int &octave);
267 
272  int *r_noise;
273  float magnitude;
274 
276  double time;
277 
280 
283  };
284 }}
285 
288 
289 #endif
Hydrax::Noise::Perlin::getValue
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition: Perlin.cpp:403
Hydrax::Noise::Perlin::o_noise
int o_noise[n_size_sq *max_octaves]
Definition: Perlin.h:270
Hydrax::Noise::Perlin::noise
int noise[n_size_sq *noise_frames]
Perlin noise variables.
Definition: Perlin.h:269
Hydrax::Noise::Perlin::r_noise
int * r_noise
Definition: Perlin.h:272
n_size_sq
#define n_size_sq
Definition: Perlin.h:43
Hydrax::Noise::Perlin::remove
void remove()
Remove.
Definition: Perlin.cpp:74
y
float y
Definition: (ValueTypes) quaternion.h:6
Hydrax::Noise::Perlin::getOptions
const Options & getOptions() const
Get current Perlin noise options.
Definition: Perlin.h:226
Hydrax::Noise::Perlin::Options::Octaves
int Octaves
Octaves.
Definition: Perlin.h:81
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::Noise::Perlin::_getHeigthDual
float _getHeigthDual(float u, float v)
Read texel linear.
Definition: Perlin.cpp:547
Hydrax::Noise::Perlin::Options::Falloff
float Falloff
Falloff.
Definition: Perlin.h:85
Hydrax::Noise::Perlin::createGPUNormalMapResources
bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition: Perlin.cpp:126
n_packsize
#define n_packsize
Definition: Perlin.h:46
Hydrax::Noise::Perlin::Options::Options
Options(const int &_Octaves, const float &_Scale, const float &_Falloff, const float &_Animspeed, const float &_Timemulti)
Constructor.
Definition: Perlin.h:125
Hydrax::GPUNormalMapManager
Class to manager GPU normal maps.
Definition: GPUNormalMapManager.h:45
Hydrax::Noise::Perlin::saveCfg
void saveCfg(Ogre::String &Data)
Save config.
Definition: Perlin.cpp:335
Noise.h
Hydrax::Noise::Perlin::Options::Options
Options(const int &_Octaves, const float &_Scale, const float &_Falloff, const float &_Animspeed, const float &_Timemulti, const float &_GPU_Strength, const Ogre::Vector3 &_GPU_LODParameters)
Constructor.
Definition: Perlin.h:149
Hydrax::Noise::Perlin::magnitude
float magnitude
Definition: Perlin.h:273
Hydrax::Noise::Perlin::Options::GPU_Strength
float GPU_Strength
GPU Normal map generator parameters Only if GPU normal map generation is active.
Definition: Perlin.h:95
Hydrax::Noise::Perlin::_initNoise
void _initNoise()
Initialize noise.
Definition: Perlin.cpp:408
Hydrax::Noise::Perlin::Options::Timemulti
float Timemulti
Timemulti.
Definition: Perlin.h:89
Hydrax::Noise::Noise
Base noise class, Override it for create different ways of create water noise.
Definition: Noise.h:42
Hydrax::Noise::Perlin::_calculeNoise
void _calculeNoise()
Calcule noise.
Definition: Perlin.cpp:447
Hydrax::Noise::Perlin::time
double time
Elapsed time.
Definition: Perlin.h:276
noise_frames
#define noise_frames
Definition: Perlin.h:60
Hydrax::Noise::Perlin::_mapSample
int _mapSample(const int &u, const int &v, const int &upsamplepower, const int &octave)
Map sample.
Definition: Perlin.cpp:569
Hydrax::Noise::Perlin::mGPUNormalMapManager
GPUNormalMapManager * mGPUNormalMapManager
GPUNormalMapManager pointer.
Definition: Perlin.h:279
Hydrax::Noise::Perlin::Options::Animspeed
float Animspeed
Animspeed.
Definition: Perlin.h:87
Hydrax::Noise::Perlin::_updateGPUNormalMapResources
void _updateGPUNormalMapResources()
Update gpu normal map resources.
Definition: Perlin.cpp:378
Hydrax::Noise::Perlin::update
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: Perlin.cpp:367
Hydrax::Noise::Perlin::Options::Options
Options()
Default constructor.
Definition: Perlin.h:107
Hydrax::Noise::Perlin::Perlin
Perlin()
Default constructor.
Definition: Perlin.cpp:37
np_size_sq
#define np_size_sq
Definition: Perlin.h:51
Hydrax::Noise::Perlin::mOptions
Options mOptions
Perlin noise options.
Definition: Perlin.h:282
Hydrax::Noise::Perlin::_readTexelLinearDual
int _readTexelLinearDual(const int &u, const int &v, const int &o)
Read texel linear dual.
Definition: Perlin.cpp:526
Hydrax::Noise::Perlin::loadCfg
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition: Perlin.cpp:348
Hydrax::Noise::Perlin::Options::GPU_LODParameters
Ogre::Vector3 GPU_LODParameters
LOD Parameters, in order to obtain a smooth normal map we need to decrease the detail level when the ...
Definition: Perlin.h:103
Hydrax::Noise::Perlin::Options::Scale
float Scale
Scale.
Definition: Perlin.h:83
Hydrax::Noise::Perlin::Options
Struct wich contains Perlin noise module options.
Definition: Perlin.h:78
Ogre
Definition: ExtinguishableFireAffector.cpp:35
Hydrax::Noise::Perlin::p_noise
int p_noise[np_size_sq *(max_octaves >>(n_packsize-1))]
Definition: Perlin.h:271
Hydrax::Noise::Perlin::create
void create()
Create.
Definition: Perlin.cpp:63
Hydrax::Noise::Perlin::setOptions
void setOptions(const Options &Options)
Set/Update perlin noise options.
Definition: Perlin.cpp:91
max_octaves
#define max_octaves
Definition: Perlin.h:58
Hydrax::Noise::Perlin::~Perlin
~Perlin()
Destructor.
Definition: Perlin.cpp:56
Hydrax::Noise::Perlin
Perlin noise module class.
Definition: Perlin.h:73
x
float x
Definition: (ValueTypes) quaternion.h:5