1 /**************************************************************************/ 2 /* Copyright 2009 Tim Day */ 3 /* */ 4 /* This file is part of Fracplanet */ 5 /* */ 6 /* Fracplanet is free software: you can redistribute it and/or modify */ 7 /* it under the terms of the GNU General Public License as published by */ 8 /* the Free Software Foundation, either version 3 of the License, or */ 9 /* (at your option) any later version. */ 10 /* */ 11 /* Fracplanet is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public License */ 17 /* along with Fracplanet. If not, see <http://www.gnu.org/licenses/>. */ 18 /**************************************************************************/ 19 20 /*! \file 21 \brief Interface to Noise class. 22 */ 23 24 #ifndef _noise_h_ 25 #define _noise_h_ 26 27 #include "common.h" 28 #include "xyz.h" 29 30 //! Perlin noise generator. 31 class Noise 32 { 33 public: 34 35 //! Constructor. 36 Noise(uint seed); 37 38 //! Destructor. 39 ~Noise(); 40 41 //! Return noise value at a point. 42 float operator()(const XYZ& p) const; 43 44 protected: 45 46 //! Number of table entries. 47 enum {N=256}; 48 49 int _p[2*N+2]; 50 XYZ _g[2*N+2]; 51 }; 52 53 //! Multiscale noise generator. 54 class MultiscaleNoise 55 { 56 public: 57 58 //! Constructor. 59 MultiscaleNoise(uint seed,uint terms,float decay); 60 61 //! Destructor. 62 ~MultiscaleNoise(); 63 64 //! Return noise value at a point. 65 float operator()(const XYZ& p) const; 66 67 private: 68 69 //! Number of terms 70 const uint _terms; 71 72 //! Noise functions for each frequency. 73 boost::scoped_array<boost::scoped_ptr<const Noise> > _noise; 74 75 //! Amplitude for each frequency. 76 boost::scoped_array<float> _amplitude; 77 }; 78 79 #endif 80