[Plib-cvs] plib/src/sg sgPerlinNoise.cxx,NONE,1.1 Makefile.am,1.6,1.7 sg.h,1.44,1.45
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-08-24 23:22:16
|
Update of /cvsroot/plib/plib/src/sg In directory usw-pr-cvs1:/tmp/cvs-serv5373/plib/src/sg Modified Files: Makefile.am sg.h Added Files: sgPerlinNoise.cxx Log Message: Added Perlin Noise functions - plus documentation. --- NEW FILE: sgPerlinNoise.cxx --- /* sgPerlinNoise This is a class to implement coherent noise over 1, 2, or 3 dimensions. The implementation is based on the Ken Perlin's noise function and borrows heavily from Matt Zucker's implementation. */ #include <stdio.h> #include <time.h> #include <math.h> #include "sg.h" static unsigned int *permTable = NULL ; [...255 lines suppressed...] { int i ; for ( i = 0 ; i < SG_PERLIN_NOISE_WRAP_INDEX ; i++ ) { sgSetVec3 ( gradTable [ i ], randFloat(), randFloat(), randFloat() ) ; sgNormalizeVec3 ( gradTable [ i ] ) ; } for ( i = 0 ; i < SG_PERLIN_NOISE_WRAP_INDEX + 2 ; i++ ) { gradTable [ SG_PERLIN_NOISE_WRAP_INDEX + i ][ 0 ] = gradTable [ i ][ 0 ] ; gradTable [ SG_PERLIN_NOISE_WRAP_INDEX + i ][ 1 ] = gradTable [ i ][ 1 ] ; gradTable [ SG_PERLIN_NOISE_WRAP_INDEX + i ][ 2 ] = gradTable [ i ][ 2 ] ; } initPermTable () ; } Index: Makefile.am =================================================================== RCS file: /cvsroot/plib/plib/src/sg/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.am 18 Dec 2001 04:06:04 -0000 1.6 +++ Makefile.am 24 Aug 2002 23:22:13 -0000 1.7 @@ -2,7 +2,9 @@ include_HEADERS = sg.h -libplibsg_a_SOURCES = sg.cxx sgd.cxx sgIsect.cxx sgdIsect.cxx +libplibsg_a_SOURCES = sg.cxx sgd.cxx \ + sgIsect.cxx sgdIsect.cxx \ + sgPerlinNoise.cxx INCLUDES = -I$(top_srcdir)/src/util Index: sg.h =================================================================== RCS file: /cvsroot/plib/plib/src/sg/sg.h,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- sg.h 11 Aug 2002 19:52:07 -0000 1.44 +++ sg.h 24 Aug 2002 23:22:13 -0000 1.45 @@ -574,6 +574,10 @@ extern void sgVectorProductVec3 ( sgVec3 dst, const sgVec3 a, const sgVec3 b ) ; +inline SGfloat sgLerp ( const SGfloat a, const SGfloat b, const SGfloat f ) +{ + return a + f * ( b - a ) ; +} inline void sgLerpVec4 ( sgVec4 dst, const sgVec4 a, const sgVec4 b, const SGfloat f ) { @@ -2795,6 +2799,86 @@ [...66 lines suppressed...] + sgVec3 gradTable [ SG_PERLIN_NOISE_WRAP_INDEX * 2 + 2 ] ; + +public: + + sgPerlinNoise_3D () ; + + void regenerate () ; + + SGfloat getNoise ( sgVec3 pos ) ; + SGfloat getNoise ( SGfloat x, SGfloat y, SGfloat z ) + { + sgVec3 p ; + sgSetVec3 ( p, x, y, z ) ; + return getNoise ( p ) ; + } +} ; + #endif |