00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 #ifndef base_noise_Perlin_hpp 00023 #define base_noise_Perlin_hpp 00024 00025 #include "util/type/util_type.hpp" 00026 #include "../vecmath/Vector3.hpp" 00027 00028 namespace se_core { 00029 class _SeCoreExport Perlin { 00030 public: 00031 Perlin(); 00032 Perlin(const unsigned int seed); 00033 void defaultPermutations(); 00034 void shufflePermutations(const unsigned int seed); 00035 00036 float noise( float x, 00037 const unsigned int frequency, 00038 const bool tile ); 00039 float noise( float x, float y, 00040 const unsigned int frequencyX, const unsigned int frequencyY, 00041 const bool tileX, const bool tileY ); 00042 float noise( float x, float y, float z, 00043 const unsigned int frequencyX, const unsigned int frequencyY, const unsigned int frequencyZ, 00044 const bool tileX, const bool tileY, const bool tileZ ); 00045 float noise( float x, float y, float z, float w, 00046 const unsigned int frequencyX, const unsigned int frequencyY, 00047 const unsigned int frequencyZ, const unsigned int frequencyW, 00048 const bool tileX, const bool tileY, const bool tileZ, const bool tileW ); 00049 00050 float noise( const Vector3& v, const unsigned int freq, bool tile); 00051 00052 protected: 00053 static int floor( const float x ) { return ((int)(x) - ((x) < 0 && (x) != (int)(x))); } 00054 static int tileMod( const int index, const unsigned int frequency ); 00055 static float fade( const float t ) { return t * t * t * (t * (t * 6 - 15) + 10); } 00056 static float lerp( const float t, const float a, const float b ) { return a + t * (b - a); } 00057 static int abs( int v) { return (v < 0) ? -v : v; } 00058 static float abs( float v) { return (v < 0) ? -v : v; } 00059 00060 static float gradient( const int hash, const float x ); 00061 static float gradient( const int hash, const float x, const float y ); 00062 static float gradient( const int hash, const float x, const float y, const float z ); 00063 static float gradient( const int hash, const float x, const float y, const float z, const float w ); 00064 00065 private: 00066 unsigned char permutations_[512]; 00067 static const unsigned char defaultPermutations_[256]; 00068 }; 00069 } 00070 00071 #endif
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.