noise2d.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _NOISE2D_H_ 25#define _NOISE2D_H_ 26 27 28#ifndef _PLATFORM_H_ 29#include "platform/platform.h" 30#endif 31#ifndef _MMATH_H_ 32#include "math/mMath.h" 33#endif 34#ifndef _MRANDOM_H_ 35#include "math/mRandom.h" 36#endif 37 38class Noise2D 39{ 40private: 41 enum Constants { 42 SIZE = 0x100, 43 SIZE_MASK = 0x0ff 44 }; 45 S32 mPermutation[SIZE + SIZE + 2]; 46 F32 mGradient[SIZE + SIZE + 2][2]; 47 48 U32 mSeed; 49 50 MRandom mRandom; 51 52 F32 lerp(F32 t, F32 a, F32 b); 53 F32 curve(F32 t); 54 void setup(F32 t, S32 &b0, S32 &b1, F32 &r0, F32 &r1); 55 F32 dot(const F32 *q, F32 rx, F32 ry); 56 void normalize(F32 v[2]); 57 58public: 59 Noise2D(); 60 ~Noise2D(); 61 62 void setSeed(U32 seed); 63 U32 getSeed(); 64 65 F32 getValue(F32 u, F32 v, S32 interval); 66 67 /// @name Noise 68 /// These functions actually generate 69 /// noise values into the passed in destination 70 /// array. 71 /// 72 /// Note that the output values of these functions 73 /// are from -1.0 to 1.0. 74 /// 75 /// fBm - Fractal Brownian Motion - A simple noise generation 76 /// algorithm, it tends to generate either flowing rounded 77 /// hills or rounded mountainous shapes. 78 /// @{ 79 void fBm( Vector<F32> *dst, U32 size, U32 interval, F32 h, F32 octave=5.0f); 80 81 /// rigidMultiFractal 82 /// Creates ridged mountains with a high frequency detail. 83 void rigidMultiFractal( Vector<F32> *dst, Vector<F32> *signal, U32 size, U32 interval, F32 h, F32 octave=5.0f); 84 /// @} 85 86 bool erodeHydraulic(Vector<F32> *src, Vector<F32> *dst, U32 iterations, U32 size ); 87 bool erodeThermal(Vector<F32> *src, Vector<F32> *dst, F32 slope, F32 materialLoss, U32 iterations, U32 size, U32 squareSize, F32 maxHeight ); 88 89 F32 turbulence(F32 x, F32 y, F32 freq); 90 91 void getMinMax( Vector<F32> *src, F32 *maxNoise, F32 *minNoise, U32 size ); 92}; 93 94 95 96#endif // _NOISE2D_H_ 97