Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
FFT.h
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/copyleft/lesser.txt.
22--------------------------------------------------------------------------------
23*/
24
25#ifndef _Hydrax_Noise_FFT_H_
26#define _Hydrax_Noise_FFT_H_
27
28
29
30#include "Noise.h"
31
32#include <complex>
33
36
39
40namespace Hydrax{ namespace Noise
41{
44 class FFT : public Noise
45 {
46 public:
49 struct Options
50 {
56 float Scale;
58 Ogre::Vector2 WindDirection;
62 float KwPower;
64 float Amplitude;
65
78 Ogre::Vector3 GPU_LODParameters;
79
83 : Resolution(128)
84 , PhysicalResolution(32.0f)
85 , Scale(0.25f)
86 , WindDirection(Ogre::Vector2(4,5))
88 , KwPower(6.0f)
89 , Amplitude(1.0f)
90 , GPU_Strength(2.0f)
91 , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
92 {
93 }
94
104 Options(const int& _Resolution,
105 const float& _PhysicalResolution,
106 const float& _Scale,
107 const Ogre::Vector2& _WindDirection,
108 const float& _AnimationSpeed,
109 const float& _KwPower,
110 const float& _Amplitude)
111 : Resolution(_Resolution)
112 , PhysicalResolution(_PhysicalResolution)
113 , Scale(_Scale)
114 , WindDirection(_WindDirection)
115 , AnimationSpeed(_AnimationSpeed)
116 , KwPower(_KwPower)
117 , Amplitude(_Amplitude)
118 , GPU_Strength(2.0f)
119 , GPU_LODParameters(Ogre::Vector3(0.5f, 50, 150000))
120 {
121 }
122
134 Options(const int& _Resolution,
135 const float& _PhysicalResolution,
136 const float& _Scale,
137 const Ogre::Vector2& _WindDirection,
138 const float& _AnimationSpeed,
139 const float& _KwPower,
140 const float& _Amplitude,
141 const float &_GPU_Strength,
142 const Ogre::Vector3 &_GPU_LODParameters)
143 : Resolution(_Resolution)
144 , PhysicalResolution(_PhysicalResolution)
145 , Scale(_Scale)
146 , WindDirection(_WindDirection)
147 , AnimationSpeed(_AnimationSpeed)
148 , KwPower(_KwPower)
149 , Amplitude(_Amplitude)
150 , GPU_Strength(_GPU_Strength)
151 , GPU_LODParameters(_GPU_LODParameters)
152 {
153 }
154 };
155
158 FFT();
159
163 FFT(const Options &Options);
164
167 ~FFT();
168
171 void create();
172
178
181 void remove();
182
186 void update(const Ogre::Real &timeSinceLastFrame);
187
191 void saveCfg(Ogre::String &Data);
192
196 bool loadCfg(Ogre::ConfigFile &CfgFile);
197
203 float getValue(const float &x, const float &y);
204
208 void setOptions(const Options &Options);
209
213 inline const Options& getOptions() const
214 {
215 return mOptions;
216 }
217
218 private:
221 void _initNoise();
222
226 void _calculeNoise(const float &delta);
227
230 void _executeInverseFFT();
231
235 void _normalizeFFTData(const float& scale);
236
243 const float _getPhillipsSpectrum(const Ogre::Vector2& waveVector, const Ogre::Vector2& wind, const float& kwPower_ = 2.0f) const;
244
248 const float _getGaussianRandomFloat() const;
249
253
257 float *re, *img;
260
262 std::complex<float> *initialWaves;
264 std::complex<float> *currentWaves;
268 float time;
269
272
275 };
276}}
277
280
281#endif
Class to manager GPU normal maps.
FFT noise module class.
Definition FFT.h:45
std::complex< float > * initialWaves
the data which is referred as h0{x,t), that is, the data of the simulation at the time 0.
Definition FFT.h:262
void _calculeNoise(const float &delta)
Calcule noise.
Definition FFT.cpp:469
void _initNoise()
Initialize noise.
Definition FFT.cpp:433
void setOptions(const Options &Options)
Set/Update fft noise options.
Definition FFT.cpp:125
float time
Current time.
Definition FFT.h:268
float * angularFrequencies
the angular frequencies
Definition FFT.h:266
Options mOptions
Perlin noise options.
Definition FFT.h:274
void _executeInverseFFT()
Execute inverse fast fourier transform.
Definition FFT.cpp:547
void _normalizeFFTData(const float &scale)
Normalize fft data.
Definition FFT.cpp:714
float * re
Pointers to resolution*resolution float size arrays.
Definition FFT.h:257
const Options & getOptions() const
Get current FFT noise options.
Definition FFT.h:213
const float _getPhillipsSpectrum(const Ogre::Vector2 &waveVector, const Ogre::Vector2 &wind, const float &kwPower_=2.0f) const
Get the Philipps Spectrum, used to create the amplitudes and phases.
Definition FFT.cpp:525
FFT()
Default constructor.
Definition FFT.cpp:37
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition FFT.cpp:404
void saveCfg(Ogre::String &Data)
Save config.
Definition FFT.cpp:391
const float _getGaussianRandomFloat() const
Get a Gaussian random number with mean 0 and standard deviation 1, using Box - muller transform.
Definition FFT.cpp:506
float * img
Definition FFT.h:257
void remove()
Remove.
Definition FFT.cpp:85
int resolution
FFT resolution.
Definition FFT.h:255
bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition FFT.cpp:175
GPUNormalMapManager * mGPUNormalMapManager
GPUNormalMapManager pointer.
Definition FFT.h:271
void _updateGPUNormalMapResources()
Update gpu normal map resources.
Definition FFT.cpp:371
float maximalValue
The minimal value of the result data of the fft transformation.
Definition FFT.h:259
void create()
Create.
Definition FFT.cpp:73
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition FFT.cpp:757
std::complex< float > * currentWaves
the data of the simulation at time t, which is formed using the data at time 0 and the angular freque...
Definition FFT.h:264
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition FFT.cpp:423
~FFT()
Destructor.
Definition FFT.cpp:66
Base noise class, Override it for create different ways of create water noise.
Definition Noise.h:43
Struct wich contains fft noise module options.
Definition FFT.h:50
Ogre::Vector3 GPU_LODParameters
LOD Parameters, in order to obtain a smooth normal map we need to decrease the detail level when the ...
Definition FFT.h:78
float GPU_Strength
GPU Normal map generator parameters Only if GPU normal map generation is active.
Definition FFT.h:70
float Amplitude
Noise amplitude.
Definition FFT.h:64
float KwPower
KwPower.
Definition FFT.h:62
int Resolution
Noise resolution (2^n)
Definition FFT.h:52
Options(const int &_Resolution, const float &_PhysicalResolution, const float &_Scale, const Ogre::Vector2 &_WindDirection, const float &_AnimationSpeed, const float &_KwPower, const float &_Amplitude)
User constructor.
Definition FFT.h:104
Ogre::Vector2 WindDirection
Wind direction.
Definition FFT.h:58
float Scale
Noise scale.
Definition FFT.h:56
Options()
Default constructor.
Definition FFT.h:82
float AnimationSpeed
Animation speed.
Definition FFT.h:60
float PhysicalResolution
Physical resolution.
Definition FFT.h:54
Options(const int &_Resolution, const float &_PhysicalResolution, const float &_Scale, const Ogre::Vector2 &_WindDirection, const float &_AnimationSpeed, const float &_KwPower, const float &_Amplitude, const float &_GPU_Strength, const Ogre::Vector3 &_GPU_LODParameters)
User constructor.
Definition FFT.h:134