libnoise logo

A portable, open-source, coherent noise-generating library for C++


noisegen.h

00001 // noisegen.h
00002 //
00003 // Copyright (C) 2003, 2004 Jason Bevins
00004 //
00005 // This library is free software; you can redistribute it and/or modify it
00006 // under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation; either version 2.1 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful, but WITHOUT
00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00013 // License (COPYING.txt) for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this library; if not, write to the Free Software Foundation,
00017 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 // The developer's email is jlbezigvins@gmzigail.com (for great email, take
00020 // off every 'zig'.)
00021 //
00022 
00023 #ifndef NOISE_NOISEGEN_H
00024 #define NOISE_NOISEGEN_H
00025 
00026 #include <math.h>
00027 #include "basictypes.h"
00028 
00029 namespace noise
00030 {
00031 
00034 
00036   enum NoiseQuality
00037   {
00038 
00044     QUALITY_FAST = 0,
00045 
00051     QUALITY_STD = 1,
00052 
00058     QUALITY_BEST = 2
00059 
00060   };
00061 
00077   double GradientCoherentNoise3D (double x, double y, double z, int seed = 0,
00078     NoiseQuality noiseQuality = QUALITY_STD);
00079 
00121   double GradientNoise3D (double fx, double fy, double fz, int ix, int iy,
00122     int iz, int seed = 0);
00123 
00139   int IntValueNoise3D (int x, int y, int z, int seed = 0);
00140 
00158   inline double MakeInt32Range (double n)
00159   {
00160     if (n >= 1073741824.0) {
00161       return (2.0 * fmod (n, 1073741824.0)) - 1073741824.0;
00162     } else if (n <= -1073741824.0) {
00163       return (2.0 * fmod (n, 1073741824.0)) + 1073741824.0;
00164     } else {
00165       return n;
00166     }
00167   }
00168 
00184   double ValueCoherentNoise3D (double x, double y, double z, int seed = 0,
00185     NoiseQuality noiseQuality = QUALITY_STD);
00186 
00202   double ValueNoise3D (int x, int y, int z, int seed = 0);
00203 
00205 
00206 }
00207 
00208 #endif