diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8133c2b06a3..0ca6f6c385e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,7 @@ add_subdirectory(libigl) add_subdirectory(hints) add_subdirectory(mcut) add_subdirectory(qoi) +add_subdirectory(libnoise) # Adding libnest2d project for bin packing... add_subdirectory(libnest2d) diff --git a/src/libnoise/CMakeLists.txt b/src/libnoise/CMakeLists.txt new file mode 100644 index 00000000000..5dee620e99b --- /dev/null +++ b/src/libnoise/CMakeLists.txt @@ -0,0 +1,38 @@ +project(libnoise) +cmake_minimum_required(VERSION 3.0) + +add_library(libnoise INTERFACE) + +# Define the source directory +set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") + +file(GLOB NOISE_SOURCES_LIST + "${SOURCE_DIR}/*.cpp" + "${SOURCE_DIR}/model/*.cpp" + "${SOURCE_DIR}/module/*.cpp") + +file(GLOB NOISE_HEADERS_LIST + "${SOURCE_DIR}/*.h" + "${SOURCE_DIR}/model/*.h" + "${SOURCE_DIR}/module/*.h") + +# Conditionally include win32 files if compiling on Windows +if(WIN32) + set(WIN32_DIR "${SOURCE_DIR}/win32") + file(GLOB WIN32_SOURCES "${WIN32_DIR}/*.cpp") + file(GLOB WIN32_HEADERS "${WIN32_DIR}/*.h") + list(APPEND NOISE_SOURCES_LIST ${WIN32_SOURCES}) + list(APPEND NOISE_HEADERS_LIST ${WIN32_HEADERS}) +endif() + +# Add the static library +add_library(libnoise_static STATIC ${NOISE_SOURCES_LIST} ${NOISE_HEADERS_LIST}) + +if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") + target_compile_definitions(libnoise_static PRIVATE _GNU_SOURCE) +endif() + +target_link_libraries(libnoise INTERFACE libnoise_static) +target_include_directories(libnoise INTERFACE ${SOURCE_DIR}) + +message(STATUS "libnoise using bundled version...") diff --git a/src/libnoise/INSTALL b/src/libnoise/INSTALL new file mode 100644 index 00000000000..d822a27fd82 --- /dev/null +++ b/src/libnoise/INSTALL @@ -0,0 +1,34 @@ +Installing libnoise: + +1. Make! + +CXXFLAGS='-O3 -fomit-frame-pointer ...options of choice...' make + +Using compiler optimizations for libnoise is *strongly recommended*. Using the +unoptimized library is roughly a fifth as fast as using -O3 on my test +computer. + +2. Install! + +The 'include' directory should be copied to your software include directory, +usually /usr/local/include, with an appropriate name. I use + + cp -R include /usr/local/include/noise + +Similarly, the *contents* of the 'lib' directory should go into your library +directory (usually /usr/local/lib). Once you've done that, run 'ldconfig', +then make a symlink from LIBDIR/libnoise.so to LIBDIR/libnoise.so.0. I use: + + cp lib/* /usr/local/lib + ldconfig + ln -s /usr/local/lib/libnoise.so.0 /usr/local/lib/libnoise.so + +At this point, you should be able to include libnoise in your projects using + + #include + +and + + g++ ...options... -lnoise + +At some point we'll automate this process. diff --git a/src/libnoise/Makefile b/src/libnoise/Makefile new file mode 100644 index 00000000000..cb1c7a08a54 --- /dev/null +++ b/src/libnoise/Makefile @@ -0,0 +1,23 @@ +.PHONY: all doc src include +all: doc src include lib +clean: cleandoc cleansrc cleaninclude cleanlib +install: installinclude installlib + +doc src include lib: + $(MAKE) -C $@ + +lib: include + +cleandoc: + $(MAKE) -C doc clean +cleansrc: + $(MAKE) -C src clean +cleaninclude: + $(MAKE) -C include clean +cleanlib: + $(MAKE) -C lib clean + +installinclude: + $(MAKE) -C include include +installlib: + $(MAKE) -C lib include diff --git a/src/libnoise/README.md b/src/libnoise/README.md new file mode 100644 index 00000000000..646c843b89c --- /dev/null +++ b/src/libnoise/README.md @@ -0,0 +1,8 @@ +This distribution of noise library is only meant for interfacing noise with OrcaSlicer. + +The noise source file was acquired from https://sourceforge.net/projects/libnoise/ version 1.0. + +No changes to the noise library were made except for deleting the 'doc' directory. + +Nick Johnson +2 December 2024 diff --git a/src/libnoise/include/Makefile b/src/libnoise/include/Makefile new file mode 100644 index 00000000000..eae5c747d18 --- /dev/null +++ b/src/libnoise/include/Makefile @@ -0,0 +1,14 @@ +.PHONY: all here clean +all: here model module + +here: + cp ../src/*.h . +model: + (mkdir $@ && cp ../src/model/*.h $@) +module: + (mkdir $@ && cp ../src/$@/*.h $@) + +clean: + -rm *.h + -rm -rf model + -rm -rf module diff --git a/src/libnoise/lib/Makefile b/src/libnoise/lib/Makefile new file mode 100644 index 00000000000..86affd7f3f1 --- /dev/null +++ b/src/libnoise/lib/Makefile @@ -0,0 +1,8 @@ +VPATH=../src/ + +.PHONY: all clean +all: libnoise.a libnoise.la libnoise.so.0.3 + -cp $? . + +clean: + -rm libnoise.* diff --git a/src/libnoise/libnoise.dsp b/src/libnoise/libnoise.dsp new file mode 100644 index 00000000000..89c364ab1a9 --- /dev/null +++ b/src/libnoise/libnoise.dsp @@ -0,0 +1,432 @@ +# Microsoft Developer Studio Project File - Name="libnoise" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=libnoise - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "libnoise.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "libnoise.mak" CFG="libnoise - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "libnoise - Win32 Release" (based on\ + "Win32 (x86) Dynamic-Link Library") +!MESSAGE "libnoise - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "libnoise - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "win32/Release" +# PROP Intermediate_Dir "win32/Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# SUBTRACT LINK32 /map + +!ELSEIF "$(CFG)" == "libnoise - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "win32/Debug" +# PROP Intermediate_Dir "win32/Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /map /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "libnoise - Win32 Release" +# Name "libnoise - Win32 Debug" +# Begin Group "modules" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\src\module\abs.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\abs.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\add.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\add.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\billow.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\billow.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\blend.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\blend.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\cache.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\cache.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\checkerboard.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\checkerboard.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\clamp.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\clamp.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\const.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\const.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\curve.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\curve.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\cylinders.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\cylinders.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\displace.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\displace.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\exponent.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\exponent.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\invert.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\invert.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\max.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\max.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\min.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\min.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\module.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\modulebase.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\modulebase.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\multiply.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\multiply.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\perlin.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\perlin.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\power.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\power.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\ridgedmulti.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\ridgedmulti.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\rotatepoint.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\rotatepoint.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\scalebias.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\scalebias.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\scalepoint.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\scalepoint.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\select.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\select.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\spheres.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\spheres.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\terrace.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\terrace.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\translatepoint.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\translatepoint.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\turbulence.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\turbulence.h +# End Source File +# Begin Source File + +SOURCE=.\src\module\voronoi.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\module\voronoi.h +# End Source File +# End Group +# Begin Group "models" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\src\model\cylinder.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\model\cylinder.h +# End Source File +# Begin Source File + +SOURCE=.\src\model\line.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\model\line.h +# End Source File +# Begin Source File + +SOURCE=.\src\model\model.h +# End Source File +# Begin Source File + +SOURCE=.\src\model\plane.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\model\plane.h +# End Source File +# Begin Source File + +SOURCE=.\src\model\sphere.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\model\sphere.h +# End Source File +# End Group +# Begin Group "win32" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\src\win32\dllmain.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\win32\libnoise.def +# End Source File +# Begin Source File + +SOURCE=.\src\win32\noise.rc +# End Source File +# End Group +# Begin Source File + +SOURCE=.\src\basictypes.h +# End Source File +# Begin Source File + +SOURCE=.\src\exception.h +# End Source File +# Begin Source File + +SOURCE=.\src\interp.h +# End Source File +# Begin Source File + +SOURCE=.\src\latlon.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\latlon.h +# End Source File +# Begin Source File + +SOURCE=.\src\mathconsts.h +# End Source File +# Begin Source File + +SOURCE=.\src\misc.h +# End Source File +# Begin Source File + +SOURCE=.\src\noise.h +# End Source File +# Begin Source File + +SOURCE=.\src\noisegen.cpp +# End Source File +# Begin Source File + +SOURCE=.\src\noisegen.h +# End Source File +# Begin Source File + +SOURCE=.\src\vectortable.h +# End Source File +# End Target +# End Project diff --git a/src/libnoise/libnoise.dsw b/src/libnoise/libnoise.dsw new file mode 100644 index 00000000000..9ef1804ed22 --- /dev/null +++ b/src/libnoise/libnoise.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 5.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "libnoise"=.\libnoise.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/src/libnoise/libnoise.ncb b/src/libnoise/libnoise.ncb new file mode 100644 index 00000000000..29bce143c65 Binary files /dev/null and b/src/libnoise/libnoise.ncb differ diff --git a/src/libnoise/libnoise.opt b/src/libnoise/libnoise.opt new file mode 100644 index 00000000000..669fdfe2bcb Binary files /dev/null and b/src/libnoise/libnoise.opt differ diff --git a/src/libnoise/libnoise.plg b/src/libnoise/libnoise.plg new file mode 100644 index 00000000000..52c34364e81 --- /dev/null +++ b/src/libnoise/libnoise.plg @@ -0,0 +1,136 @@ +--------------------Configuration: libnoise - Win32 Release-------------------- +Begining build with project "C:\dev\src\noise\libnoise.dsp", at root. +Active configuration is Win32 (x86) Dynamic-Link Library (based on Win32 (x86) Dynamic-Link Library) + +Project's tools are: + "32-bit C/C++ Compiler for 80x86" with flags "/nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /Fp"win32/Release/libnoise.pch" /YX /Fo"win32/Release/" /Fd"win32/Release/" /FD /c " + "OLE Type Library Maker" with flags "/nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 " + "Win32 Resource Compiler" with flags "/l 0x409 /fo"win32/Release/noise.res" /d "NDEBUG" " + "Browser Database Maker" with flags "/nologo /o"win32/Release/libnoise.bsc" " + "COFF Linker for 80x86" with flags "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /incremental:no /pdb:"win32/Release/libnoise.pdb" /machine:I386 /def:".\src\win32\libnoise.def" /out:"win32/Release/libnoise.dll" /implib:"win32/Release/libnoise.lib" " + "Custom Build" with flags "" + "" with flags "" + +Creating command line "rc.exe /l 0x409 /fo"win32/Release/noise.res" /i "src\win32" /d "NDEBUG" "C:\dev\src\noise\src\win32\noise.rc"" +Creating temp file "C:\DOCUME~1\jas\LOCALS~1\Temp\RSP2AB7.tmp" with contents +Creating command line "cl.exe @C:\DOCUME~1\jas\LOCALS~1\Temp\RSP2AB7.tmp" +Creating temp file "C:\DOCUME~1\jas\LOCALS~1\Temp\RSP2AB8.tmp" with contents +Creating command line "link.exe @C:\DOCUME~1\jas\LOCALS~1\Temp\RSP2AB8.tmp" +Compiling resources... +Compiling... +abs.cpp +add.cpp +billow.cpp +blend.cpp +cache.cpp +checkerboard.cpp +clamp.cpp +const.cpp +curve.cpp +cylinders.cpp +displace.cpp +exponent.cpp +invert.cpp +max.cpp +min.cpp +modulebase.cpp +multiply.cpp +perlin.cpp +power.cpp +ridgedmulti.cpp +rotatepoint.cpp +scalebias.cpp +scalepoint.cpp +select.cpp +spheres.cpp +terrace.cpp +translatepoint.cpp +turbulence.cpp +voronoi.cpp +cylinder.cpp +line.cpp +plane.cpp +sphere.cpp +dllmain.cpp +latlon.cpp +noisegen.cpp +Linking... + Creating library win32/Release/libnoise.lib and object win32/Release/libnoise.exp + + + +libnoise.dll - 0 error(s), 0 warning(s) diff --git a/src/libnoise/noise.aps b/src/libnoise/noise.aps new file mode 100644 index 00000000000..78625e2ebe3 Binary files /dev/null and b/src/libnoise/noise.aps differ diff --git a/src/libnoise/src/Makefile b/src/libnoise/src/Makefile new file mode 100644 index 00000000000..8df1a9556a7 --- /dev/null +++ b/src/libnoise/src/Makefile @@ -0,0 +1,56 @@ +LIBTOOL=libtool + +# defines source files and vpaths +include Sources + +DEPENDS=$(SOURCES:.cpp=.d) + +# What source objects are we building? +OBJECTS=$(SOURCES:.cpp=.o) + +.PHONY: all clean cleandeps cleanobjs cleanlib libnoise libnoise.so libnoise.so.0 + +# hooks for future makefiles being able to make multiple SOs, or older SOs +libnoise: libnoise.so libnoise.a libnoise.la +libnoise.so: libnoise.so.0 +libnoise.so.0: libnoise.so.0.3 + +# Real build targets +libnoise.so.0.3: $(OBJECTS) + $(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -shared -Wl,-soname=libnoise.so.0 -o $@ $(OBJECTS:.o=.lo) + +libnoise.a: $(OBJECTS) + $(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $(OBJECTS) +libnoise.la: $(OBJECTS) + $(LIBTOOL) --mode=link $(CXX) $(LDFLAGS) -o $@ $(OBJECTS:.o=.lo) + +clean: cleandeps cleanobjs cleanlib +cleandeps: + -rm $(DEPENDS) +cleanobjs: + -rm $(OBJECTS) + -rm $(OBJECTS:.o=.lo) #clean up after libtool + -rm -rf .libs model/.libs module/.libs +cleanlib: + -rm libnoise.so.0.3 + -rm libnoise.a + -rm libnoise.la + +# Utility rules +# Generates dependancy files: +%.d: %.cpp + @set -e; rm -f $@; \ + $(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +# C and C++ libtool (rather than raw CXX/CC) use +%.o %.lo: %.cpp + $(LIBTOOL) --mode=compile $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $(@:.lo=.o) + +%.o %.lo: %.c + $(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $(@:.lo=.o) + +# If dependancies have never been built this will produce a horde of +# "file not found" warnings and *then* build the deps. Very odd. +include $(DEPENDS) diff --git a/src/libnoise/src/Sources b/src/libnoise/src/Sources new file mode 100644 index 00000000000..73a9b3e6a8d --- /dev/null +++ b/src/libnoise/src/Sources @@ -0,0 +1,80 @@ +SOURCES=../src/latlon.cpp \ + ../src/noisegen.cpp \ + ../src/model/cylinder.cpp \ + ../src/model/line.cpp \ + ../src/model/plane.cpp \ + ../src/model/sphere.cpp \ + ../src/module/abs.cpp \ + ../src/module/add.cpp \ + ../src/module/billow.cpp \ + ../src/module/blend.cpp \ + ../src/module/cache.cpp \ + ../src/module/checkerboard.cpp \ + ../src/module/clamp.cpp \ + ../src/module/const.cpp \ + ../src/module/curve.cpp \ + ../src/module/cylinders.cpp \ + ../src/module/displace.cpp \ + ../src/module/exponent.cpp \ + ../src/module/invert.cpp \ + ../src/module/max.cpp \ + ../src/module/min.cpp \ + ../src/module/modulebase.cpp \ + ../src/module/multiply.cpp \ + ../src/module/perlin.cpp \ + ../src/module/power.cpp \ + ../src/module/ridgedmulti.cpp \ + ../src/module/rotatepoint.cpp \ + ../src/module/scalebias.cpp \ + ../src/module/scalepoint.cpp \ + ../src/module/select.cpp \ + ../src/module/spheres.cpp \ + ../src/module/terrace.cpp \ + ../src/module/translatepoint.cpp \ + ../src/module/turbulence.cpp \ + ../src/module/voronoi.cpp + +HEADERS=../src/basictypes.h \ + ../src/exception.h \ + ../src/interp.h \ + ../src/latlon.h \ + ../src/mathconsts.h \ + ../src/misc.h \ + ../src/noisegen.h \ + ../src/noise.h \ + ../src/vectortable.h \ + ../src/model/cylinder.h \ + ../src/model/model.h \ + ../src/model/sphere.h \ + ../src/model/line.h \ + ../src/model/plane.h \ + ../src/module/abs.h \ + ../src/module/add.h \ + ../src/module/billow.h \ + ../src/module/blend.h \ + ../src/module/cache.h \ + ../src/module/checkerboard.h \ + ../src/module/clamp.h \ + ../src/module/const.h \ + ../src/module/curve.h \ + ../src/module/cylinders.h \ + ../src/module/displace.h \ + ../src/module/exponent.h \ + ../src/module/invert.h \ + ../src/module/max.h \ + ../src/module/min.h \ + ../src/module/module.h \ + ../src/module/modulebase.h \ + ../src/module/multiply.h \ + ../src/module/perlin.h \ + ../src/module/power.h \ + ../src/module/ridgedmulti.h \ + ../src/module/rotatepoint.h \ + ../src/module/scalebias.h \ + ../src/module/scalepoint.h \ + ../src/module/select.h \ + ../src/module/spheres.h \ + ../src/module/terrace.h \ + ../src/module/translatepoint.h \ + ../src/module/turbulence.h \ + ../src/module/voronoi.h diff --git a/src/libnoise/src/basictypes.h b/src/libnoise/src/basictypes.h new file mode 100644 index 00000000000..6c5f9f0d5ac --- /dev/null +++ b/src/libnoise/src/basictypes.h @@ -0,0 +1,60 @@ +// basictypes.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_BASICTYPES_H +#define NOISE_BASICTYPES_H + +// You may need to modify these constants for your compiler or platform. + +namespace noise +{ + + /// @defgroup libnoise libnoise + /// @addtogroup libnoise + /// @{ + + /// Unsigned integer type. + typedef unsigned int uint; + + /// 32-bit unsigned integer type. + typedef unsigned int uint32; + + /// 16-bit unsigned integer type. + typedef unsigned short uint16; + + /// 8-bit unsigned integer type. + typedef unsigned char uint8; + + /// 32-bit signed integer type. + typedef int int32; + + /// 16-bit signed integer type. + typedef short int16; + + /// 8-bit signed integer type. + typedef char int8; + + /// @} + +} + +#endif diff --git a/src/libnoise/src/exception.h b/src/libnoise/src/exception.h new file mode 100644 index 00000000000..b760563c2b1 --- /dev/null +++ b/src/libnoise/src/exception.h @@ -0,0 +1,74 @@ +// exception.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_EXCEPTION_H +#define NOISE_EXCEPTION_H + +namespace noise +{ + + /// @addtogroup libnoise + /// @{ + + /// Abstract base class for libnoise exceptions + class Exception + { + }; + + /// Invalid parameter exception + /// + /// An invalid parameter was passed to a libnoise function or method. + class ExceptionInvalidParam: public Exception + { + }; + + /// No module exception + /// + /// Could not retrieve a source module from a noise module. + /// + /// @note If one or more required source modules were not connected to a + /// specific noise module, and its GetValue() method was called, that + /// method will raise a debug assertion instead of this exception. This + /// is done for performance reasons. + class ExceptionNoModule: public Exception + { + }; + + /// Out of memory exception + /// + /// There was not enough memory to perform an action. + class ExceptionOutOfMemory: public Exception + { + }; + + /// Unknown exception + /// + /// libnoise raised an unknown exception. + class ExceptionUnknown: public Exception + { + }; + + /// @} + +} + +#endif diff --git a/src/libnoise/src/interp.h b/src/libnoise/src/interp.h new file mode 100644 index 00000000000..a657cb169c4 --- /dev/null +++ b/src/libnoise/src/interp.h @@ -0,0 +1,112 @@ +// interp.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_INTERP_H +#define NOISE_INTERP_H + +namespace noise +{ + + /// @addtogroup libnoise + /// @{ + + /// Performs cubic interpolation between two values bound between two other + /// values. + /// + /// @param n0 The value before the first value. + /// @param n1 The first value. + /// @param n2 The second value. + /// @param n3 The value after the second value. + /// @param a The alpha value. + /// + /// @returns The interpolated value. + /// + /// The alpha value should range from 0.0 to 1.0. If the alpha value is + /// 0.0, this function returns @a n1. If the alpha value is 1.0, this + /// function returns @a n2. + inline double CubicInterp (double n0, double n1, double n2, double n3, + double a) + { + double p = (n3 - n2) - (n0 - n1); + double q = (n0 - n1) - p; + double r = n2 - n0; + double s = n1; + return p * a * a * a + q * a * a + r * a + s; + } + + /// Performs linear interpolation between two values. + /// + /// @param n0 The first value. + /// @param n1 The second value. + /// @param a The alpha value. + /// + /// @returns The interpolated value. + /// + /// The alpha value should range from 0.0 to 1.0. If the alpha value is + /// 0.0, this function returns @a n0. If the alpha value is 1.0, this + /// function returns @a n1. + inline double LinearInterp (double n0, double n1, double a) + { + return ((1.0 - a) * n0) + (a * n1); + } + + /// Maps a value onto a cubic S-curve. + /// + /// @param a The value to map onto a cubic S-curve. + /// + /// @returns The mapped value. + /// + /// @a a should range from 0.0 to 1.0. + /// + /// The derivitive of a cubic S-curve is zero at @a a = 0.0 and @a a = + /// 1.0 + inline double SCurve3 (double a) + { + return (a * a * (3.0 - 2.0 * a)); + } + + /// Maps a value onto a quintic S-curve. + /// + /// @param a The value to map onto a quintic S-curve. + /// + /// @returns The mapped value. + /// + /// @a a should range from 0.0 to 1.0. + /// + /// The first derivitive of a quintic S-curve is zero at @a a = 0.0 and + /// @a a = 1.0 + /// + /// The second derivitive of a quintic S-curve is zero at @a a = 0.0 and + /// @a a = 1.0 + inline double SCurve5 (double a) + { + double a3 = a * a * a; + double a4 = a3 * a; + double a5 = a4 * a; + return (6.0 * a5) - (15.0 * a4) + (10.0 * a3); + } + + // @} + +} + +#endif diff --git a/src/libnoise/src/latlon.cpp b/src/libnoise/src/latlon.cpp new file mode 100644 index 00000000000..7fe97c698db --- /dev/null +++ b/src/libnoise/src/latlon.cpp @@ -0,0 +1,34 @@ +// latlon.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "latlon.h" + +using namespace noise; + +void noise::LatLonToXYZ (double lat, double lon, double& x, double& y, + double& z) +{ + double r = cos (DEG_TO_RAD * lat); + x = r * cos (DEG_TO_RAD * lon); + y = sin (DEG_TO_RAD * lat); + z = r * sin (DEG_TO_RAD * lon); +} diff --git a/src/libnoise/src/latlon.h b/src/libnoise/src/latlon.h new file mode 100644 index 00000000000..5cdf85d4c68 --- /dev/null +++ b/src/libnoise/src/latlon.h @@ -0,0 +1,52 @@ +// latlon.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_LATLON_H +#define NOISE_LATLON_H + +#include +#include "mathconsts.h" + +namespace noise +{ + + /// @addtogroup libnoise + /// @{ + + /// Converts latitude/longitude coordinates on a unit sphere into 3D + /// Cartesian coordinates. + /// + /// @param lat The latitude, in degrees. + /// @param lon The longitude, in degrees. + /// @param x On exit, this parameter contains the @a x coordinate. + /// @param y On exit, this parameter contains the @a y coordinate. + /// @param z On exit, this parameter contains the @a z coordinate. + /// + /// @pre lat must range from @b -90 to @b +90. + /// @pre lon must range from @b -180 to @b +180. + void LatLonToXYZ (double lat, double lon, double& x, double& y, double& z); + + /// @} + +} + +#endif diff --git a/src/libnoise/src/mathconsts.h b/src/libnoise/src/mathconsts.h new file mode 100644 index 00000000000..70b3bd5e263 --- /dev/null +++ b/src/libnoise/src/mathconsts.h @@ -0,0 +1,54 @@ +// mathconsts.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MATHCONSTS_H +#define NOISE_MATHCONSTS_H + +// For whatever reason, I can't find the basic math consts in the MSVC version +// of math.h. + +namespace noise +{ + + /// @addtogroup libnoise + /// @{ + + /// Pi. + const double PI = 3.1415926535897932385; + + /// Square root of 2. + const double SQRT_2 = 1.4142135623730950488; + + /// Square root of 3. + const double SQRT_3 = 1.7320508075688772935; + + /// Converts an angle from degrees to radians. + const double DEG_TO_RAD = PI / 180.0; + + /// Converts an angle from radians to degrees. + const double RAD_TO_DEG = 1.0 / DEG_TO_RAD; + + /// @} + +} + +#endif diff --git a/src/libnoise/src/misc.h b/src/libnoise/src/misc.h new file mode 100644 index 00000000000..cfdb5364ff7 --- /dev/null +++ b/src/libnoise/src/misc.h @@ -0,0 +1,97 @@ +// misc.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MISC_H +#define NOISE_MISC_H + +namespace noise +{ + + /// Clamps a value onto a clamping range. + /// + /// @param value The value to clamp. + /// @param lowerBound The lower bound of the clamping range. + /// @param upperBound The upper bound of the clamping range. + /// + /// @returns + /// - @a value if @a value lies between @a lowerBound and @a upperBound. + /// - @a lowerBound if @a value is less than @a lowerBound. + /// - @a upperBound if @a value is greater than @a upperBound. + /// + /// This function does not modify any parameters. + inline int ClampValue (int value, int lowerBound, int upperBound) + { + if (value < lowerBound) { + return lowerBound; + } else if (value > upperBound) { + return upperBound; + } else { + return value; + } + } + + /// @addtogroup libnoise + /// @{ + + /// Returns the maximum of two values. + /// + /// @param a The first value. + /// @param b The second value. + /// + /// @returns The maximum of the two values. + template + T GetMax (const T& a, const T& b) + { + return (a > b? a: b); + } + + /// Returns the minimum of two values. + /// + /// @param a The first value. + /// @param b The second value. + /// + /// @returns The minimum of the two values. + template + T GetMin (const T& a, const T& b) + { + return (a < b? a: b); + } + + /// Swaps two values. + /// + /// @param a A variable containing the first value. + /// @param b A variable containing the second value. + /// + /// @post The values within the the two variables are swapped. + template + void SwapValues (T& a, T& b) + { + T c = a; + a = b; + b = c; + } + + /// @} + +} + +#endif diff --git a/src/libnoise/src/model/cylinder.cpp b/src/libnoise/src/model/cylinder.cpp new file mode 100644 index 00000000000..defded2978f --- /dev/null +++ b/src/libnoise/src/model/cylinder.cpp @@ -0,0 +1,47 @@ +// cylinder.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../mathconsts.h" +#include "cylinder.h" + +using namespace noise; +using namespace noise::model; + +Cylinder::Cylinder (): m_pModule (NULL) +{ +} + +Cylinder::Cylinder (const module::Module& module): + m_pModule (&module) +{ +} + +double Cylinder::GetValue (double angle, double height) const +{ + assert (m_pModule != NULL); + + double x, y, z; + x = cos (angle * DEG_TO_RAD); + y = height; + z = sin (angle * DEG_TO_RAD); + return m_pModule->GetValue (x, y, z); +} diff --git a/src/libnoise/src/model/cylinder.h b/src/libnoise/src/model/cylinder.h new file mode 100644 index 00000000000..627abb326dc --- /dev/null +++ b/src/libnoise/src/model/cylinder.h @@ -0,0 +1,131 @@ +// cylinder.h +// +// Copyright 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODEL_CYLINDER_H +#define NOISE_MODEL_CYLINDER_H + +#include +#include +#include +#include "../module/modulebase.h" + +namespace noise +{ + + namespace model + { + + /// @addtogroup libnoise + /// @{ + + /// @defgroup models Models + /// @addtogroup models + /// @{ + + /// Model that defines the surface of a cylinder. + /// + /// @image html modelcylinder.png + /// + /// This model returns an output value from a noise module given the + /// coordinates of an input value located on the surface of a cylinder. + /// + /// To generate an output value, pass the (angle, height) coordinates of + /// an input value to the GetValue() method. + /// + /// This model is useful for creating: + /// - seamless textures that can be mapped onto a cylinder + /// + /// This cylinder has a radius of 1.0 unit and has infinite height. It is + /// oriented along the @a y axis. Its center is located at the origin. + class Cylinder + { + + public: + + /// Constructor. + Cylinder (); + + /// Constructor + /// + /// @param module The noise module that is used to generate the output + /// values. + Cylinder (const module::Module& module); + + /// Returns the noise module that is used to generate the output + /// values. + /// + /// @returns A reference to the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + const module::Module& GetModule () const + { + assert (m_pModule != NULL); + return *m_pModule; + } + + /// Returns the output value from the noise module given the + /// (angle, height) coordinates of the specified input value located + /// on the surface of the cylinder. + /// + /// @param angle The angle around the cylinder's center, in degrees. + /// @param height The height along the @a y axis. + /// + /// @returns The output value from the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + /// + /// This output value is generated by the noise module passed to the + /// SetModule() method. + /// + /// This cylinder has a radius of 1.0 unit and has infinite height. + /// It is oriented along the @a y axis. Its center is located at the + /// origin. + double GetValue (double angle, double height) const; + + /// Sets the noise module that is used to generate the output values. + /// + /// @param module The noise module that is used to generate the output + /// values. + /// + /// This noise module must exist for the lifetime of this object, + /// until you pass a new noise module to this method. + void SetModule (const module::Module& module) + { + m_pModule = &module; + } + + private: + + /// A pointer to the noise module used to generate the output values. + const module::Module* m_pModule; + + }; + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/model/line.cpp b/src/libnoise/src/model/line.cpp new file mode 100644 index 00000000000..dab5e4f7cb7 --- /dev/null +++ b/src/libnoise/src/model/line.cpp @@ -0,0 +1,65 @@ +// line.cpp +// +// Copyright (C) 2004 Keith Davies +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#include "line.h" + +using namespace noise; +using namespace noise::model; + +Line::Line (): + + m_attenuate (true), + m_pModule (NULL), + m_x0 (0.0), + m_x1 (1.0), + m_y0 (0.0), + m_y1 (1.0), + m_z0 (0.0), + m_z1 (1.0) +{ +} + +Line::Line (const module::Module& module): + + m_attenuate (true), + m_pModule (&module), + m_x0 (0.0), + m_x1 (1.0), + m_y0 (0.0), + m_y1 (1.0), + m_z0 (0.0), + m_z1 (1.0) +{ +} + +double Line::GetValue (double p) const +{ + assert (m_pModule != NULL); + + double x = (m_x1 - m_x0) * p + m_x0; + double y = (m_y1 - m_y0) * p + m_y0; + double z = (m_z1 - m_z0) * p + m_z0; + double value = m_pModule->GetValue (x, y, z); + + if (m_attenuate) { + return p * (1.0 - p) * 4 * value; + } else { + return value; + } +} diff --git a/src/libnoise/src/model/line.h b/src/libnoise/src/model/line.h new file mode 100644 index 00000000000..cf3a8087bd7 --- /dev/null +++ b/src/libnoise/src/model/line.h @@ -0,0 +1,198 @@ +// line.h +// +// Copyright (C) 2004 Keith Davies +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#ifndef NOISE_MODEL_LINE_H +#define NOISE_MODEL_LINE_H + +#include +#include +#include +#include "../module/modulebase.h" + +namespace noise +{ + + namespace model + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup models + /// @{ + + /// Model that defines the displacement of a line segment. + /// + /// This model returns an output value from a noise module given the + /// one-dimensional coordinate of an input value located on a line + /// segment, which can be used as displacements. + /// + /// This class is useful for creating: + /// - roads and rivers + /// - disaffected college students + /// + /// To generate an output value, pass an input value between 0.0 and 1.0 + /// to the GetValue() method. 0.0 represents the start position of the + /// line segment and 1.0 represents the end position of the line segment. + class Line + { + + public: + + /// Constructor. + Line (); + + /// Constructor + /// + /// @param module The noise module that is used to generate the output + /// values. + Line (const module::Module& module); + + /// Returns a flag indicating whether the output value is to be + /// attenuated (moved toward 0.0) as the ends of the line segment are + /// approached by the input value. + /// + /// @returns + /// - @a true if the value is to be attenuated + /// - @a false if not. + bool GetAttenuate () const + { + return m_attenuate; + } + + /// Returns the noise module that is used to generate the output + /// values. + /// + /// @returns A reference to the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + const module::Module& GetModule () const + { + assert (m_pModule != NULL); + return *m_pModule; + } + + /// Returns the output value from the noise module given the + /// one-dimensional coordinate of the specified input value located + /// on the line segment. + /// + /// @param p The distance along the line segment (ranges from 0.0 + /// to 1.0) + /// + /// @returns The output value from the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + /// @pre The start and end points of the line segment were specified. + /// + /// The output value is generated by the noise module passed to the + /// SetModule() method. This value may be attenuated (moved toward + /// 0.0) as @a p approaches either end of the line segment; this is + /// the default behavior. + /// + /// If the value is not to be attenuated, @a p can safely range + /// outside the 0.0 to 1.0 range; the output value will be + /// extrapolated along the line that this segment is part of. + double GetValue (double p) const; + + /// Sets a flag indicating that the output value is to be attenuated + /// (moved toward 0.0) as the ends of the line segment are approached. + /// + /// @param att A flag that specifies whether the output value is to be + /// attenuated. + void SetAttenuate (bool att) + { + m_attenuate = att; + } + + /// Sets the position ( @a x, @a y, @a z ) of the end of the line + /// segment to choose values along. + /// + /// @param x x coordinate of the end position. + /// @param y y coordinate of the end position. + /// @param z z coordinate of the end position. + void SetEndPoint (double x, double y, double z) + { + m_x1 = x; + m_y1 = y; + m_z1 = z; + } + + /// Sets the noise module that is used to generate the output values. + /// + /// @param module The noise module that is used to generate the output + /// values. + /// + /// This noise module must exist for the lifetime of this object, + /// until you pass a new noise module to this method. + void SetModule (const module::Module& module) + { + m_pModule = &module; + } + + /// Sets the position ( @a x, @a y, @a z ) of the start of the line + /// segment to choose values along. + /// + /// @param x x coordinate of the start position. + /// @param y y coordinate of the start position. + /// @param z z coordinate of the start position. + void SetStartPoint (double x, double y, double z) + { + m_x0 = x; + m_y0 = y; + m_z0 = z; + } + + private: + + /// A flag that specifies whether the value is to be attenuated + /// (moved toward 0.0) as the ends of the line segment are approached. + bool m_attenuate; + + /// A pointer to the noise module used to generate the output values. + const module::Module* m_pModule; + + /// @a x coordinate of the start of the line segment. + double m_x0; + + /// @a x coordinate of the end of the line segment. + double m_x1; + + /// @a y coordinate of the start of the line segment. + double m_y0; + + /// @a y coordinate of the end of the line segment. + double m_y1; + + /// @a z coordinate of the start of the line segment. + double m_z0; + + /// @a z coordinate of the end of the line segment. + double m_z1; + + }; + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/model/model.h b/src/libnoise/src/model/model.h new file mode 100644 index 00000000000..e3ce92ce80e --- /dev/null +++ b/src/libnoise/src/model/model.h @@ -0,0 +1,31 @@ +// model.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODEL_H +#define NOISE_MODEL_H + +#include "cylinder.h" +#include "line.h" +#include "plane.h" +#include "sphere.h" + +#endif diff --git a/src/libnoise/src/model/plane.cpp b/src/libnoise/src/model/plane.cpp new file mode 100644 index 00000000000..c5fd02f7ee1 --- /dev/null +++ b/src/libnoise/src/model/plane.cpp @@ -0,0 +1,43 @@ +// plane.cpp +// +// Copyright (C) 2004 Owen Jacobson +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is ojacobson@lionsanctuary.net +// + +#include "plane.h" + +using namespace noise; +using namespace noise::model; + +Plane::Plane (): + m_pModule (NULL) +{ +} + +Plane::Plane (const module::Module& module) : + m_pModule( &module) +{ +} + +// Told you this was trivial. +double Plane::GetValue (double x, double z) const +{ + assert (m_pModule != NULL); + + return m_pModule->GetValue (x, 0, z); +} diff --git a/src/libnoise/src/model/plane.h b/src/libnoise/src/model/plane.h new file mode 100644 index 00000000000..fe08f9b3c8e --- /dev/null +++ b/src/libnoise/src/model/plane.h @@ -0,0 +1,121 @@ +// plane.h +// +// Copyright (C) 2004 Owen Jacobson +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is ojacobson@lionsanctuary.net +// + +#ifndef NOISE_MODEL_PLANE_H +#define NOISE_MODEL_PLANE_H + +#include +#include "../module/modulebase.h" + +namespace noise +{ + + namespace model + { + /// @addtogroup libnoise + /// @{ + + /// @addtogroup models + /// @{ + + /// Model that defines the surface of a plane. + /// + /// This model returns an output value from a noise module given the + /// coordinates of an input value located on the surface of an ( @a x, + /// @a z ) plane. + /// + /// To generate an output value, pass the ( @a x, @a z ) coordinates of + /// an input value to the GetValue() method. + /// + /// This model is useful for creating: + /// - two-dimensional textures + /// - terrain height maps for local areas + /// + /// This plane extends infinitely in both directions. + class Plane + { + + public: + + /// Constructor. + Plane (); + + /// Constructor + /// + /// @param module The noise module that is used to generate the output + /// values. + Plane (const module::Module& module); + + /// Returns the noise module that is used to generate the output + /// values. + /// + /// @returns A reference to the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + const module::Module& GetModule () const + { + assert (m_pModule != NULL); + return *m_pModule; + } + + /// Returns the output value from the noise module given the + /// ( @a x, @a z ) coordinates of the specified input value located + /// on the surface of the plane. + /// + /// @param x The @a x coordinate of the input value. + /// @param z The @a z coordinate of the input value. + /// + /// @returns The output value from the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + /// + /// This output value is generated by the noise module passed to the + /// SetModule() method. + double GetValue (double x, double z) const; + + /// Sets the noise module that is used to generate the output values. + /// + /// @param module The noise module that is used to generate the output + /// values. + /// + /// This noise module must exist for the lifetime of this object, + /// until you pass a new noise module to this method. + void SetModule (const module::Module& module) + { + m_pModule = &module; + } + + private: + + /// A pointer to the noise module used to generate the output values. + const module::Module* m_pModule; + + }; + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/model/sphere.cpp b/src/libnoise/src/model/sphere.cpp new file mode 100644 index 00000000000..77ead1c4458 --- /dev/null +++ b/src/libnoise/src/model/sphere.cpp @@ -0,0 +1,46 @@ +// sphere.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../latlon.h" +#include "sphere.h" + +using namespace noise; +using namespace noise::model; + +Sphere::Sphere (): + m_pModule (NULL) +{ +} + +Sphere::Sphere (const module::Module& module): + m_pModule (&module) +{ +} + +double Sphere::GetValue (double lat, double lon) const +{ + assert (m_pModule != NULL); + + double x, y, z; + LatLonToXYZ (lat, lon, x, y, z); + return m_pModule->GetValue (x, y, z); +} diff --git a/src/libnoise/src/model/sphere.h b/src/libnoise/src/model/sphere.h new file mode 100644 index 00000000000..63a2a51609b --- /dev/null +++ b/src/libnoise/src/model/sphere.h @@ -0,0 +1,131 @@ +// sphere.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODEL_SPHERE_H +#define NOISE_MODEL_SPHERE_H + +#include +#include "../module/modulebase.h" + +namespace noise +{ + + namespace model + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup models + /// @{ + + /// Model that defines the surface of a sphere. + /// + /// @image html modelsphere.png + /// + /// This model returns an output value from a noise module given the + /// coordinates of an input value located on the surface of a sphere. + /// + /// To generate an output value, pass the (latitude, longitude) + /// coordinates of an input value to the GetValue() method. + /// + /// This model is useful for creating: + /// - seamless textures that can be mapped onto a sphere + /// - terrain height maps for entire planets + /// + /// This sphere has a radius of 1.0 unit and its center is located at + /// the origin. + class Sphere + { + + public: + + /// Constructor. + Sphere (); + + /// Constructor + /// + /// @param module The noise module that is used to generate the output + /// values. + Sphere (const module::Module& module); + + /// Returns the noise module that is used to generate the output + /// values. + /// + /// @returns A reference to the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + const module::Module& GetModule () const + { + assert (m_pModule != NULL); + return *m_pModule; + } + + /// Returns the output value from the noise module given the + /// (latitude, longitude) coordinates of the specified input value + /// located on the surface of the sphere. + /// + /// @param lat The latitude of the input value, in degrees. + /// @param lon The longitude of the input value, in degrees. + /// + /// @returns The output value from the noise module. + /// + /// @pre A noise module was passed to the SetModule() method. + /// + /// This output value is generated by the noise module passed to the + /// SetModule() method. + /// + /// Use a negative latitude if the input value is located on the + /// southern hemisphere. + /// + /// Use a negative longitude if the input value is located on the + /// western hemisphere. + double GetValue (double lat, double lon) const; + + /// Sets the noise module that is used to generate the output values. + /// + /// @param module The noise module that is used to generate the output + /// values. + /// + /// This noise module must exist for the lifetime of this object, + /// until you pass a new noise module to this method. + void SetModule (const module::Module& module) + { + m_pModule = &module; + } + + private: + + /// A pointer to the noise module used to generate the output values. + const module::Module* m_pModule; + + }; + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/abs.cpp b/src/libnoise/src/module/abs.cpp new file mode 100644 index 00000000000..13a5d63f28d --- /dev/null +++ b/src/libnoise/src/module/abs.cpp @@ -0,0 +1,37 @@ +// abs.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "abs.h" + +using namespace noise::module; + +Abs::Abs (): + Module (GetSourceModuleCount ()) +{ +} + +double Abs::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + return fabs (m_pSourceModule[0]->GetValue (x, y, z)); +} diff --git a/src/libnoise/src/module/abs.h b/src/libnoise/src/module/abs.h new file mode 100644 index 00000000000..7efba39d661 --- /dev/null +++ b/src/libnoise/src/module/abs.h @@ -0,0 +1,76 @@ +// abs.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_ABS_H +#define NOISE_MODULE_ABS_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @defgroup modifiermodules Modifier Modules + /// @addtogroup modifiermodules + /// @{ + + /// Noise module that outputs the absolute value of the output value from + /// a source module. + /// + /// @image html moduleabs.png + /// + /// This noise module requires one source module. + class Abs: public Module + { + + public: + + /// Constructor. + Abs (); + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/add.cpp b/src/libnoise/src/module/add.cpp new file mode 100644 index 00000000000..1b011625668 --- /dev/null +++ b/src/libnoise/src/module/add.cpp @@ -0,0 +1,39 @@ +// add.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "add.h" + +using namespace noise::module; + +Add::Add (): + Module (GetSourceModuleCount ()) +{ +} + +double Add::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + + return m_pSourceModule[0]->GetValue (x, y, z) + + m_pSourceModule[1]->GetValue (x, y, z); +} diff --git a/src/libnoise/src/module/add.h b/src/libnoise/src/module/add.h new file mode 100644 index 00000000000..a7a2de6783d --- /dev/null +++ b/src/libnoise/src/module/add.h @@ -0,0 +1,77 @@ +// add.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_ADD_H +#define NOISE_MODULE_ADD_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @defgroup combinermodules Combiner Modules + /// @addtogroup combinermodules + /// @{ + + /// Noise module that outputs the sum of the two output values from two + /// source modules. + /// + /// @image html moduleadd.png + /// + /// This noise module requires two source modules. + class Add: public Module + { + + public: + + /// Constructor. + Add (); + + virtual int GetSourceModuleCount () const + { + return 2; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/billow.cpp b/src/libnoise/src/module/billow.cpp new file mode 100644 index 00000000000..8c3c0aba845 --- /dev/null +++ b/src/libnoise/src/module/billow.cpp @@ -0,0 +1,74 @@ +// billow.cpp +// +// Copyright (C) 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "billow.h" + +using namespace noise::module; + +Billow::Billow (): + Module (GetSourceModuleCount ()), + m_frequency (DEFAULT_BILLOW_FREQUENCY ), + m_lacunarity (DEFAULT_BILLOW_LACUNARITY ), + m_noiseQuality (DEFAULT_BILLOW_QUALITY ), + m_octaveCount (DEFAULT_BILLOW_OCTAVE_COUNT), + m_persistence (DEFAULT_BILLOW_PERSISTENCE ), + m_seed (DEFAULT_BILLOW_SEED) +{ +} + +double Billow::GetValue (double x, double y, double z) const +{ + double value = 0.0; + double signal = 0.0; + double curPersistence = 1.0; + double nx, ny, nz; + int seed; + + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + for (int curOctave = 0; curOctave < m_octaveCount; curOctave++) { + + // Make sure that these floating-point values have the same range as a 32- + // bit integer so that we can pass them to the coherent-noise functions. + nx = MakeInt32Range (x); + ny = MakeInt32Range (y); + nz = MakeInt32Range (z); + + // Get the coherent-noise value from the input value and add it to the + // final result. + seed = (m_seed + curOctave) & 0xffffffff; + signal = GradientCoherentNoise3D (nx, ny, nz, seed, m_noiseQuality); + signal = 2.0 * fabs (signal) - 1.0; + value += signal * curPersistence; + + // Prepare the next octave. + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + curPersistence *= m_persistence; + } + value += 0.5; + + return value; +} diff --git a/src/libnoise/src/module/billow.h b/src/libnoise/src/module/billow.h new file mode 100644 index 00000000000..f9ef09220b6 --- /dev/null +++ b/src/libnoise/src/module/billow.h @@ -0,0 +1,277 @@ +// billow.h +// +// Copyright (C) 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_BILLOW_H +#define NOISE_MODULE_BILLOW_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup generatormodules + /// @{ + + /// Default frequency for the noise::module::Billow noise module. + const double DEFAULT_BILLOW_FREQUENCY = 1.0; + + /// Default lacunarity for the the noise::module::Billow noise module. + const double DEFAULT_BILLOW_LACUNARITY = 2.0; + + /// Default number of octaves for the the noise::module::Billow noise + /// module. + const int DEFAULT_BILLOW_OCTAVE_COUNT = 6; + + /// Default persistence value for the the noise::module::Billow noise + /// module. + const double DEFAULT_BILLOW_PERSISTENCE = 0.5; + + /// Default noise quality for the the noise::module::Billow noise module. + const noise::NoiseQuality DEFAULT_BILLOW_QUALITY = QUALITY_STD; + + /// Default noise seed for the the noise::module::Billow noise module. + const int DEFAULT_BILLOW_SEED = 0; + + /// Maximum number of octaves for the the noise::module::Billow noise + /// module. + const int BILLOW_MAX_OCTAVE = 30; + + /// Noise module that outputs three-dimensional "billowy" noise. + /// + /// @image html modulebillow.png + /// + /// This noise module generates "billowy" noise suitable for clouds and + /// rocks. + /// + /// This noise module is nearly identical to noise::module::Perlin except + /// this noise module modifies each octave with an absolute-value + /// function. See the documentation of noise::module::Perlin for more + /// information. + class Billow: public Module + { + + public: + + /// Constructor. + /// + /// The default frequency is set to + /// noise::module::DEFAULT_BILLOW_FREQUENCY. + /// + /// The default lacunarity is set to + /// noise::module::DEFAULT_BILLOW_LACUNARITY. + /// + /// The default number of octaves is set to + /// noise::module::DEFAULT_BILLOW_OCTAVE_COUNT. + /// + /// The default persistence value is set to + /// noise::module::DEFAULT_BILLOW_PERSISTENCE. + /// + /// The default seed value is set to + /// noise::module::DEFAULT_BILLOW_SEED. + Billow (); + + /// Returns the frequency of the first octave. + /// + /// @returns The frequency of the first octave. + double GetFrequency () const + { + return m_frequency; + } + + /// Returns the lacunarity of the billowy noise. + /// + /// @returns The lacunarity of the billowy noise. + /// + /// The lacunarity is the frequency multiplier between successive + /// octaves. + double GetLacunarity () const + { + return m_lacunarity; + } + + /// Returns the quality of the billowy noise. + /// + /// @returns The quality of the billowy noise. + /// + /// See noise::NoiseQuality for definitions of the various + /// coherent-noise qualities. + noise::NoiseQuality GetNoiseQuality () const + { + return m_noiseQuality; + } + + /// Returns the number of octaves that generate the billowy noise. + /// + /// @returns The number of octaves that generate the billowy noise. + /// + /// The number of octaves controls the amount of detail in the billowy + /// noise. + int GetOctaveCount () const + { + return m_octaveCount; + } + + /// Returns the persistence value of the billowy noise. + /// + /// @returns The persistence value of the billowy noise. + /// + /// The persistence value controls the roughness of the billowy noise. + double GetPersistence () const + { + return m_persistence; + } + + /// Returns the seed value used by the billowy-noise function. + /// + /// @returns The seed value. + int GetSeed () const + { + return m_seed; + } + + virtual int GetSourceModuleCount () const + { + return 0; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the frequency of the first octave. + /// + /// @param frequency The frequency of the first octave. + void SetFrequency (double frequency) + { + m_frequency = frequency; + } + + /// Sets the lacunarity of the billowy noise. + /// + /// @param lacunarity The lacunarity of the billowy noise. + /// + /// The lacunarity is the frequency multiplier between successive + /// octaves. + /// + /// For best results, set the lacunarity to a number between 1.5 and + /// 3.5. + void SetLacunarity (double lacunarity) + { + m_lacunarity = lacunarity; + } + + /// Sets the quality of the billowy noise. + /// + /// @param noiseQuality The quality of the billowy noise. + /// + /// See noise::NoiseQuality for definitions of the various + /// coherent-noise qualities. + void SetNoiseQuality (noise::NoiseQuality noiseQuality) + { + m_noiseQuality = noiseQuality; + } + + /// Sets the number of octaves that generate the billowy noise. + /// + /// @param octaveCount The number of octaves that generate the billowy + /// noise. + /// + /// @pre The number of octaves ranges from 1 to + /// noise::module::BILLOW_MAX_OCTAVE. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// The number of octaves controls the amount of detail in the billowy + /// noise. + /// + /// The larger the number of octaves, the more time required to + /// calculate the billowy-noise value. + void SetOctaveCount (int octaveCount) + { + if (octaveCount < 1 || octaveCount > BILLOW_MAX_OCTAVE) { + throw noise::ExceptionInvalidParam (); + } + m_octaveCount = octaveCount; + } + + /// Sets the persistence value of the billowy noise. + /// + /// @param persistence The persistence value of the billowy noise. + /// + /// The persistence value controls the roughness of the billowy noise. + /// + /// For best results, set the persistence value to a number between + /// 0.0 and 1.0. + void SetPersistence (double persistence) + { + m_persistence = persistence; + } + + /// Sets the seed value used by the billowy-noise function. + /// + /// @param seed The seed value. + void SetSeed (int seed) + { + m_seed = seed; + } + + protected: + + /// Frequency of the first octave. + double m_frequency; + + /// Frequency multiplier between successive octaves. + double m_lacunarity; + + /// Quality of the billowy noise. + noise::NoiseQuality m_noiseQuality; + + /// Total number of octaves that generate the billowy noise. + int m_octaveCount; + + /// Persistence value of the billowy noise. + double m_persistence; + + /// Seed value used by the billowy-noise function. + int m_seed; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/blend.cpp b/src/libnoise/src/module/blend.cpp new file mode 100644 index 00000000000..8c8e08821da --- /dev/null +++ b/src/libnoise/src/module/blend.cpp @@ -0,0 +1,43 @@ +// blend.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "blend.h" +#include "../interp.h" + +using namespace noise::module; + +Blend::Blend (): + Module (GetSourceModuleCount ()) +{ +} + +double Blend::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + assert (m_pSourceModule[2] != NULL); + + double v0 = m_pSourceModule[0]->GetValue (x, y, z); + double v1 = m_pSourceModule[1]->GetValue (x, y, z); + double alpha = (m_pSourceModule[2]->GetValue (x, y, z) + 1.0) / 2.0; + return LinearInterp (v0, v1, alpha); +} diff --git a/src/libnoise/src/module/blend.h b/src/libnoise/src/module/blend.h new file mode 100644 index 00000000000..9d23c111a3a --- /dev/null +++ b/src/libnoise/src/module/blend.h @@ -0,0 +1,144 @@ +// blend.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_BLEND_H +#define NOISE_MODULE_BLEND_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @defgroup selectormodules Selector Modules + /// @addtogroup selectormodules + /// @{ + + /// Noise module that outputs a weighted blend of the output values from + /// two source modules given the output value supplied by a control module. + /// + /// @image html moduleblend.png + /// + /// Unlike most other noise modules, the index value assigned to a source + /// module determines its role in the blending operation: + /// - Source module 0 (upper left in the diagram) outputs one of the + /// values to blend. + /// - Source module 1 (lower left in the diagram) outputs one of the + /// values to blend. + /// - Source module 2 (bottom of the diagram) is known as the control + /// module. The control module determines the weight of the + /// blending operation. Negative values weigh the blend towards the + /// output value from the source module with an index value of 0. + /// Positive values weigh the blend towards the output value from the + /// source module with an index value of 1. + /// + /// An application can pass the control module to the SetControlModule() + /// method instead of the SetSourceModule() method. This may make the + /// application code easier to read. + /// + /// This noise module uses linear interpolation to perform the blending + /// operation. + /// + /// This noise module requires three source modules. + class Blend: public Module + { + + public: + + /// Constructor. + Blend (); + + /// Returns the control module. + /// + /// @returns A reference to the control module. + /// + /// @pre A control module has been added to this noise module via a + /// call to SetSourceModule() or SetControlModule(). + /// + /// @throw noise::ExceptionNoModule See the preconditions for more + /// information. + /// + /// The control module determines the weight of the blending + /// operation. Negative values weigh the blend towards the output + /// value from the source module with an index value of 0. Positive + /// values weigh the blend towards the output value from the source + /// module with an index value of 1. + const Module& GetControlModule () const + { + if (m_pSourceModule == NULL || m_pSourceModule[2] == NULL) { + throw noise::ExceptionNoModule (); + } + return *(m_pSourceModule[2]); + } + + virtual int GetSourceModuleCount () const + { + return 3; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the control module. + /// + /// @param controlModule The control module. + /// + /// The control module determines the weight of the blending + /// operation. Negative values weigh the blend towards the output + /// value from the source module with an index value of 0. Positive + /// values weigh the blend towards the output value from the source + /// module with an index value of 1. + /// + /// This method assigns the control module an index value of 2. + /// Passing the control module to this method produces the same + /// results as passing the control module to the SetSourceModule() + /// method while assigning that noise module an index value of 2. + /// + /// This control module must exist throughout the lifetime of this + /// noise module unless another control module replaces that control + /// module. + void SetControlModule (const Module& controlModule) + { + assert (m_pSourceModule != NULL); + m_pSourceModule[2] = &controlModule; + } + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/cache.cpp b/src/libnoise/src/module/cache.cpp new file mode 100644 index 00000000000..d88633507bc --- /dev/null +++ b/src/libnoise/src/module/cache.cpp @@ -0,0 +1,45 @@ +// cache.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "cache.h" + +using namespace noise::module; + +Cache::Cache (): + Module (GetSourceModuleCount ()), + m_isCached (false) +{ +} + +double Cache::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + if (!(m_isCached && x == m_xCache && y == m_yCache && z == m_zCache)) { + m_cachedValue = m_pSourceModule[0]->GetValue (x, y, z); + m_xCache = x; + m_yCache = y; + m_zCache = z; + } + m_isCached = true; + return m_cachedValue; +} diff --git a/src/libnoise/src/module/cache.h b/src/libnoise/src/module/cache.h new file mode 100644 index 00000000000..7d4d1bab937 --- /dev/null +++ b/src/libnoise/src/module/cache.h @@ -0,0 +1,118 @@ +// cache.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_CACHE_H +#define NOISE_MODULE_CACHE_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @defgroup miscmodules Miscellaneous Modules + /// @addtogroup miscmodules + /// @{ + + /// Noise module that caches the last output value generated by a source + /// module. + /// + /// If an application passes an input value to the GetValue() method that + /// differs from the previously passed-in input value, this noise module + /// instructs the source module to calculate the output value. This + /// value, as well as the ( @a x, @a y, @a z ) coordinates of the input + /// value, are stored (cached) in this noise module. + /// + /// If the application passes an input value to the GetValue() method + /// that is equal to the previously passed-in input value, this noise + /// module returns the cached output value without having the source + /// module recalculate the output value. + /// + /// If an application passes a new source module to the SetSourceModule() + /// method, the cache is invalidated. + /// + /// Caching a noise module is useful if it is used as a source module for + /// multiple noise modules. If a source module is not cached, the source + /// module will redundantly calculate the same output value once for each + /// noise module in which it is included. + /// + /// This noise module requires one source module. + class Cache: public Module + { + + public: + + /// Constructor. + Cache (); + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + virtual void SetSourceModule (int index, const Module& sourceModule) + { + Module::SetSourceModule (index, sourceModule); + m_isCached = false; + } + + protected: + + /// The cached output value at the cached input value. + mutable double m_cachedValue; + + /// Determines if a cached output value is stored in this noise + /// module. + mutable double m_isCached; + + /// @a x coordinate of the cached input value. + mutable double m_xCache; + + /// @a y coordinate of the cached input value. + mutable double m_yCache; + + /// @a z coordinate of the cached input value. + mutable double m_zCache; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/checkerboard.cpp b/src/libnoise/src/module/checkerboard.cpp new file mode 100644 index 00000000000..c71f343a7e3 --- /dev/null +++ b/src/libnoise/src/module/checkerboard.cpp @@ -0,0 +1,38 @@ +// checkerboard.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "checkerboard.h" + +using namespace noise::module; + +Checkerboard::Checkerboard (): + Module (GetSourceModuleCount ()) +{ +} + +double Checkerboard::GetValue (double x, double y, double z) const +{ + int ix = (int)(floor (MakeInt32Range (x))); + int iy = (int)(floor (MakeInt32Range (y))); + int iz = (int)(floor (MakeInt32Range (z))); + return (ix & 1 ^ iy & 1 ^ iz & 1)? -1.0: 1.0; +} diff --git a/src/libnoise/src/module/checkerboard.h b/src/libnoise/src/module/checkerboard.h new file mode 100644 index 00000000000..fcd663c4979 --- /dev/null +++ b/src/libnoise/src/module/checkerboard.h @@ -0,0 +1,81 @@ +// checkerboard.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_CHECKERBOARD_H +#define NOISE_MODULE_CHECKERBOARD_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup generatormodules + /// @{ + + /// Noise module that outputs a checkerboard pattern. + /// + /// @image html modulecheckerboard.png + /// + /// This noise module outputs unit-sized blocks of alternating values. + /// The values of these blocks alternate between -1.0 and +1.0. + /// + /// This noise module is not really useful by itself, but it is often used + /// for debugging purposes. + /// + /// This noise module does not require any source modules. + class Checkerboard: public Module + { + + public: + + /// Constructor. + Checkerboard (); + + virtual int GetSourceModuleCount () const + { + return 0; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/clamp.cpp b/src/libnoise/src/module/clamp.cpp new file mode 100644 index 00000000000..12ca4704d8e --- /dev/null +++ b/src/libnoise/src/module/clamp.cpp @@ -0,0 +1,54 @@ +// clamp.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "clamp.h" + +using namespace noise::module; + +Clamp::Clamp (): + Module (GetSourceModuleCount ()), + m_lowerBound (DEFAULT_CLAMP_LOWER_BOUND), + m_upperBound (DEFAULT_CLAMP_UPPER_BOUND) +{ +} + +double Clamp::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + double value = m_pSourceModule[0]->GetValue (x, y, z); + if (value < m_lowerBound) { + return m_lowerBound; + } else if (value > m_upperBound) { + return m_upperBound; + } else { + return value; + } +} + +void Clamp::SetBounds (double lowerBound, double upperBound) +{ + assert (lowerBound < upperBound); + + m_lowerBound = lowerBound; + m_upperBound = upperBound; +} diff --git a/src/libnoise/src/module/clamp.h b/src/libnoise/src/module/clamp.h new file mode 100644 index 00000000000..15ea8224904 --- /dev/null +++ b/src/libnoise/src/module/clamp.h @@ -0,0 +1,152 @@ +// clamp.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_CLAMP_H +#define NOISE_MODULE_CLAMP_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup modifiermodules + /// @{ + + /// Default lower bound of the clamping range for the noise::module::Clamp + /// noise module. + const double DEFAULT_CLAMP_LOWER_BOUND = -1.0; + + /// Default upper bound of the clamping range for the noise::module::Clamp + /// noise module. + const double DEFAULT_CLAMP_UPPER_BOUND = 1.0; + + /// Noise module that clamps the output value from a source module to a + /// range of values. + /// + /// @image html moduleclamp.png + /// + /// The range of values in which to clamp the output value is called the + /// clamping range. + /// + /// If the output value from the source module is less than the lower + /// bound of the clamping range, this noise module clamps that value to + /// the lower bound. If the output value from the source module is + /// greater than the upper bound of the clamping range, this noise module + /// clamps that value to the upper bound. + /// + /// To specify the upper and lower bounds of the clamping range, call the + /// SetBounds() method. + /// + /// This noise module requires one source module. + class Clamp: public Module + { + + public: + + /// Constructor. + /// + /// The default lower bound of the clamping range is set to + /// noise::module::DEFAULT_CLAMP_LOWER_BOUND. + /// + /// The default upper bound of the clamping range is set to + /// noise::module::DEFAULT_CLAMP_UPPER_BOUND. + Clamp (); + + /// Returns the lower bound of the clamping range. + /// + /// @returns The lower bound. + /// + /// If the output value from the source module is less than the lower + /// bound of the clamping range, this noise module clamps that value + /// to the lower bound. + double GetLowerBound () const + { + return m_lowerBound; + } + + virtual int GetSourceModuleCount () const + { + return 1; + } + + /// Returns the upper bound of the clamping range. + /// + /// @returns The upper bound. + /// + /// If the output value from the source module is greater than the + /// upper bound of the clamping range, this noise module clamps that + /// value to the upper bound. + double GetUpperBound () const + { + return m_upperBound; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the lower and upper bounds of the clamping range. + /// + /// @param lowerBound The lower bound. + /// @param upperBound The upper bound. + /// + /// @pre The lower bound must be less than or equal to the + /// upper bound. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// If the output value from the source module is less than the lower + /// bound of the clamping range, this noise module clamps that value + /// to the lower bound. If the output value from the source module + /// is greater than the upper bound of the clamping range, this noise + /// module clamps that value to the upper bound. + void SetBounds (double lowerBound, double upperBound); + + protected: + + /// Lower bound of the clamping range. + double m_lowerBound; + + /// Upper bound of the clamping range. + double m_upperBound; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/const.cpp b/src/libnoise/src/module/const.cpp new file mode 100644 index 00000000000..5b28717c808 --- /dev/null +++ b/src/libnoise/src/module/const.cpp @@ -0,0 +1,31 @@ +// const.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "const.h" + +using namespace noise::module; + +Const::Const (): + Module (GetSourceModuleCount ()), + m_constValue (DEFAULT_CONST_VALUE) +{ +} diff --git a/src/libnoise/src/module/const.h b/src/libnoise/src/module/const.h new file mode 100644 index 00000000000..ffc64d9e058 --- /dev/null +++ b/src/libnoise/src/module/const.h @@ -0,0 +1,111 @@ +// const.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_CONST_H +#define NOISE_MODULE_CONST_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @defgroup generatormodules Generator Modules + /// @addtogroup generatormodules + /// @{ + + /// Default constant value for the noise::module::Const noise module. + const double DEFAULT_CONST_VALUE = 0.0; + + /// Noise module that outputs a constant value. + /// + /// @image html moduleconst.png + /// + /// To specify the constant value, call the SetConstValue() method. + /// + /// This noise module is not useful by itself, but it is often used as a + /// source module for other noise modules. + /// + /// This noise module does not require any source modules. + class Const: public Module + { + + public: + + /// Constructor. + /// + /// The default constant value is set to + /// noise::module::DEFAULT_CONST_VALUE. + Const (); + + /// Returns the constant output value for this noise module. + /// + /// @returns The constant output value for this noise module. + double GetConstValue () const + { + return m_constValue; + } + + virtual int GetSourceModuleCount () const + { + return 0; + } + + virtual double GetValue (double x, double y, double z) const + { + return m_constValue; + } + + /// Sets the constant output value for this noise module. + /// + /// @param constValue The constant output value for this noise module. + void SetConstValue (double constValue) + { + m_constValue = constValue; + } + + protected: + + /// Constant value. + double m_constValue; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/curve.cpp b/src/libnoise/src/module/curve.cpp new file mode 100644 index 00000000000..f15c5dc668d --- /dev/null +++ b/src/libnoise/src/module/curve.cpp @@ -0,0 +1,143 @@ +// curve.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../interp.h" +#include "../misc.h" +#include "curve.h" + +using namespace noise::module; + +Curve::Curve (): + Module (GetSourceModuleCount ()), + m_pControlPoints (NULL) +{ + m_controlPointCount = 0; +} + +Curve::~Curve () +{ + delete[] m_pControlPoints; +} + +void Curve::AddControlPoint (double inputValue, double outputValue) +{ + // Find the insertion point for the new control point and insert the new + // point at that position. The control point array will remain sorted by + // input value. + int insertionPos = FindInsertionPos (inputValue); + InsertAtPos (insertionPos, inputValue, outputValue); +} + +void Curve::ClearAllControlPoints () +{ + delete[] m_pControlPoints; + m_pControlPoints = NULL; + m_controlPointCount = 0; +} + +int Curve::FindInsertionPos (double inputValue) +{ + int insertionPos; + for (insertionPos = 0; insertionPos < m_controlPointCount; insertionPos++) { + if (inputValue < m_pControlPoints[insertionPos].inputValue) { + // We found the array index in which to insert the new control point. + // Exit now. + break; + } else if (inputValue == m_pControlPoints[insertionPos].inputValue) { + // Each control point is required to contain a unique input value, so + // throw an exception. + throw noise::ExceptionInvalidParam (); + } + } + return insertionPos; +} + +double Curve::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_controlPointCount >= 4); + + // Get the output value from the source module. + double sourceModuleValue = m_pSourceModule[0]->GetValue (x, y, z); + + // Find the first element in the control point array that has an input value + // larger than the output value from the source module. + int indexPos; + for (indexPos = 0; indexPos < m_controlPointCount; indexPos++) { + if (sourceModuleValue < m_pControlPoints[indexPos].inputValue) { + break; + } + } + + // Find the four nearest control points so that we can perform cubic + // interpolation. + int index0 = ClampValue (indexPos - 2, 0, m_controlPointCount - 1); + int index1 = ClampValue (indexPos - 1, 0, m_controlPointCount - 1); + int index2 = ClampValue (indexPos , 0, m_controlPointCount - 1); + int index3 = ClampValue (indexPos + 1, 0, m_controlPointCount - 1); + + // If some control points are missing (which occurs if the value from the + // source module is greater than the largest input value or less than the + // smallest input value of the control point array), get the corresponding + // output value of the nearest control point and exit now. + if (index1 == index2) { + return m_pControlPoints[index1].outputValue; + } + + // Compute the alpha value used for cubic interpolation. + double input0 = m_pControlPoints[index1].inputValue; + double input1 = m_pControlPoints[index2].inputValue; + double alpha = (sourceModuleValue - input0) / (input1 - input0); + + // Now perform the cubic interpolation given the alpha value. + return CubicInterp ( + m_pControlPoints[index0].outputValue, + m_pControlPoints[index1].outputValue, + m_pControlPoints[index2].outputValue, + m_pControlPoints[index3].outputValue, + alpha); +} + +void Curve::InsertAtPos (int insertionPos, double inputValue, + double outputValue) +{ + // Make room for the new control point at the specified position within the + // control point array. The position is determined by the input value of + // the control point; the control points must be sorted by input value + // within that array. + ControlPoint* newControlPoints = new ControlPoint[m_controlPointCount + 1]; + for (int i = 0; i < m_controlPointCount; i++) { + if (i < insertionPos) { + newControlPoints[i] = m_pControlPoints[i]; + } else { + newControlPoints[i + 1] = m_pControlPoints[i]; + } + } + delete[] m_pControlPoints; + m_pControlPoints = newControlPoints; + ++m_controlPointCount; + + // Now that we've made room for the new control point within the array, add + // the new control point. + m_pControlPoints[insertionPos].inputValue = inputValue ; + m_pControlPoints[insertionPos].outputValue = outputValue; +} diff --git a/src/libnoise/src/module/curve.h b/src/libnoise/src/module/curve.h new file mode 100644 index 00000000000..dabf49b68fc --- /dev/null +++ b/src/libnoise/src/module/curve.h @@ -0,0 +1,197 @@ +// curve.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_CURVE_H +#define NOISE_MODULE_CURVE_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// This structure defines a control point. + /// + /// Control points are used for defining splines. + struct ControlPoint + { + + /// The input value. + double inputValue; + + /// The output value that is mapped from the input value. + double outputValue; + + }; + + /// @addtogroup modules + /// @{ + + /// @addtogroup modifiermodules + /// @{ + + /// Noise module that maps the output value from a source module onto an + /// arbitrary function curve. + /// + /// @image html modulecurve.png + /// + /// This noise module maps the output value from the source module onto an + /// application-defined curve. This curve is defined by a number of + /// control points; each control point has an input value + /// that maps to an output value. Refer to the following + /// illustration: + /// + /// @image html curve.png + /// + /// To add the control points to this curve, call the AddControlPoint() + /// method. + /// + /// Since this curve is a cubic spline, an application must add a minimum + /// of four control points to the curve. If this is not done, the + /// GetValue() method fails. Each control point can have any input and + /// output value, although no two control points can have the same input + /// value. There is no limit to the number of control points that can be + /// added to the curve. + /// + /// This noise module requires one source module. + class Curve: public Module + { + + public: + + /// Constructor. + Curve (); + + /// Destructor. + ~Curve (); + + /// Adds a control point to the curve. + /// + /// @param inputValue The input value stored in the control point. + /// @param outputValue The output value stored in the control point. + /// + /// @pre No two control points have the same input value. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// It does not matter which order these points are added. + void AddControlPoint (double inputValue, double outputValue); + + /// Deletes all the control points on the curve. + /// + /// @post All points on the curve are deleted. + void ClearAllControlPoints (); + + /// Returns a pointer to the array of control points on the curve. + /// + /// @returns A pointer to the array of control points. + /// + /// Before calling this method, call GetControlPointCount() to + /// determine the number of control points in this array. + /// + /// It is recommended that an application does not store this pointer + /// for later use since the pointer to the array may change if the + /// application calls another method of this object. + const ControlPoint* GetControlPointArray () const + { + return m_pControlPoints; + } + + /// Returns the number of control points on the curve. + /// + /// @returns The number of control points on the curve. + int GetControlPointCount () const + { + return m_controlPointCount; + } + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + protected: + + /// Determines the array index in which to insert the control point + /// into the internal control point array. + /// + /// @param inputValue The input value of the control point. + /// + /// @returns The array index in which to insert the control point. + /// + /// @pre No two control points have the same input value. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// By inserting the control point at the returned array index, this + /// class ensures that the control point array is sorted by input + /// value. The code that maps a value onto the curve requires a + /// sorted control point array. + int FindInsertionPos (double inputValue); + + /// Inserts the control point at the specified position in the + /// internal control point array. + /// + /// @param insertionPos The zero-based array position in which to + /// insert the control point. + /// @param inputValue The input value stored in the control point. + /// @param outputValue The output value stored in the control point. + /// + /// To make room for this new control point, this method reallocates + /// the control point array and shifts all control points occurring + /// after the insertion position up by one. + /// + /// Because the curve mapping algorithm used by this noise module + /// requires that all control points in the array must be sorted by + /// input value, the new control point should be inserted at the + /// position in which the order is still preserved. + void InsertAtPos (int insertionPos, double inputValue, + double outputValue); + + /// Number of control points on the curve. + int m_controlPointCount; + + /// Array that stores the control points. + ControlPoint* m_pControlPoints; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/cylinders.cpp b/src/libnoise/src/module/cylinders.cpp new file mode 100644 index 00000000000..f695d45d77d --- /dev/null +++ b/src/libnoise/src/module/cylinders.cpp @@ -0,0 +1,44 @@ +// cylinders.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../misc.h" +#include "cylinders.h" + +using namespace noise::module; + +Cylinders::Cylinders (): + Module (GetSourceModuleCount ()), + m_frequency (DEFAULT_CYLINDERS_FREQUENCY) +{ +} + +double Cylinders::GetValue (double x, double y, double z) const +{ + x *= m_frequency; + z *= m_frequency; + + double distFromCenter = sqrt (x * x + z * z); + double distFromSmallerSphere = distFromCenter - floor (distFromCenter); + double distFromLargerSphere = 1.0 - distFromSmallerSphere; + double nearestDist = GetMin (distFromSmallerSphere, distFromLargerSphere); + return 1.0 - (nearestDist * 4.0); // Puts it in the -1.0 to +1.0 range. +} diff --git a/src/libnoise/src/module/cylinders.h b/src/libnoise/src/module/cylinders.h new file mode 100644 index 00000000000..e290dc6233d --- /dev/null +++ b/src/libnoise/src/module/cylinders.h @@ -0,0 +1,129 @@ +// cylinders.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_CYLINDERS_H +#define NOISE_MODULE_CYLINDERS_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup generatormodules + /// @{ + + /// Default frequency value for the noise::module::Cylinders noise module. + const double DEFAULT_CYLINDERS_FREQUENCY = 1.0; + + /// Noise module that outputs concentric cylinders. + /// + /// @image html modulecylinders.png + /// + /// This noise module outputs concentric cylinders centered on the origin. + /// These cylinders are oriented along the @a y axis similar to the + /// concentric rings of a tree. Each cylinder extends infinitely along + /// the @a y axis. + /// + /// The first cylinder has a radius of 1.0. Each subsequent cylinder has + /// a radius that is 1.0 unit larger than the previous cylinder. + /// + /// The output value from this noise module is determined by the distance + /// between the input value and the the nearest cylinder surface. The + /// input values that are located on a cylinder surface are given the + /// output value 1.0 and the input values that are equidistant from two + /// cylinder surfaces are given the output value -1.0. + /// + /// An application can change the frequency of the concentric cylinders. + /// Increasing the frequency reduces the distances between cylinders. To + /// specify the frequency, call the SetFrequency() method. + /// + /// This noise module, modified with some low-frequency, low-power + /// turbulence, is useful for generating wood-like textures. + /// + /// This noise module does not require any source modules. + class Cylinders: public Module + { + + public: + + /// Constructor. + /// + /// The default frequency is set to + /// noise::module::DEFAULT_CYLINDERS_FREQUENCY. + Cylinders (); + + /// Returns the frequency of the concentric cylinders. + /// + /// @returns The frequency of the concentric cylinders. + /// + /// Increasing the frequency increases the density of the concentric + /// cylinders, reducing the distances between them. + double GetFrequency () const + { + return m_frequency; + } + + virtual int GetSourceModuleCount () const + { + return 0; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the frequenct of the concentric cylinders. + /// + /// @param frequency The frequency of the concentric cylinders. + /// + /// Increasing the frequency increases the density of the concentric + /// cylinders, reducing the distances between them. + void SetFrequency (double frequency) + { + m_frequency = frequency; + } + + protected: + + /// Frequency of the concentric cylinders. + double m_frequency; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/displace.cpp b/src/libnoise/src/module/displace.cpp new file mode 100644 index 00000000000..b1c77f3d65f --- /dev/null +++ b/src/libnoise/src/module/displace.cpp @@ -0,0 +1,48 @@ +// displace.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "displace.h" + +using namespace noise::module; + +Displace::Displace (): + Module (GetSourceModuleCount ()) +{ +} + +double Displace::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + assert (m_pSourceModule[2] != NULL); + assert (m_pSourceModule[3] != NULL); + + // Get the output values from the three displacement modules. Add each + // value to the corresponding coordinate in the input value. + double xDisplace = x + (m_pSourceModule[1]->GetValue (x, y, z)); + double yDisplace = y + (m_pSourceModule[2]->GetValue (x, y, z)); + double zDisplace = z + (m_pSourceModule[3]->GetValue (x, y, z)); + + // Retrieve the output value using the offsetted input value instead of + // the original input value. + return m_pSourceModule[0]->GetValue (xDisplace, yDisplace, zDisplace); +} diff --git a/src/libnoise/src/module/displace.h b/src/libnoise/src/module/displace.h new file mode 100644 index 00000000000..97f610af73c --- /dev/null +++ b/src/libnoise/src/module/displace.h @@ -0,0 +1,259 @@ +// displace.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_DISPLACE_H +#define NOISE_MODULE_DISPLACE_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @defgroup transformermodules Transformer Modules + /// @addtogroup transformermodules + /// @{ + + /// Noise module that uses three source modules to displace each + /// coordinate of the input value before returning the output value from + /// a source module. + /// + /// @image html moduledisplace.png + /// + /// Unlike most other noise modules, the index value assigned to a source + /// module determines its role in the displacement operation: + /// - Source module 0 (left in the diagram) outputs a value. + /// - Source module 1 (lower left in the diagram) specifies the offset to + /// apply to the @a x coordinate of the input value. + /// - Source module 2 (lower center in the diagram) specifies the + /// offset to apply to the @a y coordinate of the input value. + /// - Source module 3 (lower right in the diagram) specifies the offset + /// to apply to the @a z coordinate of the input value. + /// + /// The GetValue() method modifies the ( @a x, @a y, @a z ) coordinates of + /// the input value using the output values from the three displacement + /// modules before retrieving the output value from the source module. + /// + /// The noise::module::Turbulence noise module is a special case of the + /// displacement module; internally, there are three Perlin-noise modules + /// that perform the displacement operation. + /// + /// This noise module requires four source modules. + class Displace: public Module + { + + public: + + /// Constructor. + Displace (); + + virtual int GetSourceModuleCount () const + { + return 4; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Returns the @a x displacement module. + /// + /// @returns A reference to the @a x displacement module. + /// + /// @pre This displacement module has been added to this noise module + /// via a call to SetSourceModule() or SetXDisplaceModule(). + /// + /// @throw noise::ExceptionNoModule See the preconditions for more + /// information. + /// + /// The GetValue() method displaces the input value by adding the output + /// value from this displacement module to the @a x coordinate of the + /// input value before returning the output value from the source + /// module. + const Module& GetXDisplaceModule () const + { + if (m_pSourceModule == NULL || m_pSourceModule[1] == NULL) { + throw noise::ExceptionNoModule (); + } + return *(m_pSourceModule[1]); + } + + /// Returns the @a y displacement module. + /// + /// @returns A reference to the @a y displacement module. + /// + /// @pre This displacement module has been added to this noise module + /// via a call to SetSourceModule() or SetYDisplaceModule(). + /// + /// @throw noise::ExceptionNoModule See the preconditions for more + /// information. + /// + /// The GetValue() method displaces the input value by adding the output + /// value from this displacement module to the @a y coordinate of the + /// input value before returning the output value from the source + /// module. + const Module& GetYDisplaceModule () const + { + if (m_pSourceModule == NULL || m_pSourceModule[2] == NULL) { + throw noise::ExceptionNoModule (); + } + return *(m_pSourceModule[2]); + } + + /// Returns the @a z displacement module. + /// + /// @returns A reference to the @a z displacement module. + /// + /// @pre This displacement module has been added to this noise module + /// via a call to SetSourceModule() or SetZDisplaceModule(). + /// + /// @throw noise::ExceptionNoModule See the preconditions for more + /// information. + /// + /// The GetValue() method displaces the input value by adding the output + /// value from this displacement module to the @a z coordinate of the + /// input value before returning the output value from the source + /// module. + const Module& GetZDisplaceModule () const + { + if (m_pSourceModule == NULL || m_pSourceModule[3] == NULL) { + throw noise::ExceptionNoModule (); + } + return *(m_pSourceModule[3]); + } + + /// Sets the @a x, @a y, and @a z displacement modules. + /// + /// @param xDisplaceModule Displacement module that displaces the @a x + /// coordinate of the input value. + /// @param yDisplaceModule Displacement module that displaces the @a y + /// coordinate of the input value. + /// @param zDisplaceModule Displacement module that displaces the @a z + /// coordinate of the input value. + /// + /// The GetValue() method displaces the input value by adding the output + /// value from each of the displacement modules to the corresponding + /// coordinates of the input value before returning the output value + /// from the source module. + /// + /// This method assigns an index value of 1 to the @a x displacement + /// module, an index value of 2 to the @a y displacement module, and an + /// index value of 3 to the @a z displacement module. + /// + /// These displacement modules must exist throughout the lifetime of + /// this noise module unless another displacement module replaces it. + void SetDisplaceModules (const Module& xDisplaceModule, + const Module& yDisplaceModule, const Module& zDisplaceModule) + { + SetXDisplaceModule (xDisplaceModule); + SetYDisplaceModule (yDisplaceModule); + SetZDisplaceModule (zDisplaceModule); + } + + /// Sets the @a x displacement module. + /// + /// @param xDisplaceModule Displacement module that displaces the @a x + /// coordinate. + /// + /// The GetValue() method displaces the input value by adding the output + /// value from this displacement module to the @a x coordinate of the + /// input value before returning the output value from the source + /// module. + /// + /// This method assigns an index value of 1 to the @a x displacement + /// module. Passing this displacement module to this method produces + /// the same results as passing this displacement module to the + /// SetSourceModule() method while assigning it an index value of 1. + /// + /// This displacement module must exist throughout the lifetime of this + /// noise module unless another displacement module replaces it. + void SetXDisplaceModule (const Module& xDisplaceModule) + { + assert (m_pSourceModule != NULL); + m_pSourceModule[1] = &xDisplaceModule; + } + + /// Sets the @a y displacement module. + /// + /// @param yDisplaceModule Displacement module that displaces the @a y + /// coordinate. + /// + /// The GetValue() method displaces the input value by adding the output + /// value from this displacement module to the @a y coordinate of the + /// input value before returning the output value from the source + /// module. + /// + /// This method assigns an index value of 2 to the @a y displacement + /// module. Passing this displacement module to this method produces + /// the same results as passing this displacement module to the + /// SetSourceModule() method while assigning it an index value of 2. + /// + /// This displacement module must exist throughout the lifetime of this + /// noise module unless another displacement module replaces it. + void SetYDisplaceModule (const Module& yDisplaceModule) + { + assert (m_pSourceModule != NULL); + m_pSourceModule[2] = &yDisplaceModule; + } + + /// Sets the @a z displacement module. + /// + /// @param zDisplaceModule Displacement module that displaces the @a z + /// coordinate. + /// + /// The GetValue() method displaces the input value by adding the output + /// value from this displacement module to the @a z coordinate of the + /// input value before returning the output value from the source + /// module. + /// + /// This method assigns an index value of 3 to the @a z displacement + /// module. Passing this displacement module to this method produces + /// the same results as passing this displacement module to the + /// SetSourceModule() method while assigning it an index value of 3. + /// + /// This displacement module must exist throughout the lifetime of this + /// noise module unless another displacement module replaces it. + void SetZDisplaceModule (const Module& zDisplaceModule) + { + assert (m_pSourceModule != NULL); + m_pSourceModule[3] = &zDisplaceModule; + } + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/exponent.cpp b/src/libnoise/src/module/exponent.cpp new file mode 100644 index 00000000000..3b3ffc62b10 --- /dev/null +++ b/src/libnoise/src/module/exponent.cpp @@ -0,0 +1,39 @@ +// exponent.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "exponent.h" + +using namespace noise::module; + +Exponent::Exponent (): + Module (GetSourceModuleCount ()), + m_exponent (DEFAULT_EXPONENT) +{ +} + +double Exponent::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + double value = m_pSourceModule[0]->GetValue (x, y, z); + return (pow (fabs ((value + 1.0) / 2.0), m_exponent) * 2.0 - 1.0); +} diff --git a/src/libnoise/src/module/exponent.h b/src/libnoise/src/module/exponent.h new file mode 100644 index 00000000000..a87eb3fa4aa --- /dev/null +++ b/src/libnoise/src/module/exponent.h @@ -0,0 +1,119 @@ +// exponent.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_EXPONENT_H +#define NOISE_MODULE_EXPONENT_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup modifiermodules + /// @{ + + /// Default exponent for the noise::module::Exponent noise module. + const double DEFAULT_EXPONENT = 1.0; + + /// Noise module that maps the output value from a source module onto an + /// exponential curve. + /// + /// @image html moduleexponent.png + /// + /// Because most noise modules will output values that range from -1.0 to + /// +1.0, this noise module first normalizes this output value (the range + /// becomes 0.0 to 1.0), maps that value onto an exponential curve, then + /// rescales that value back to the original range. + /// + /// This noise module requires one source module. + class Exponent: public Module + { + + public: + + /// Constructor. + /// + /// The default exponent is set to noise::module::DEFAULT_EXPONENT. + Exponent (); + + /// Returns the exponent value to apply to the output value from the + /// source module. + /// + /// @returns The exponent value. + /// + /// Because most noise modules will output values that range from -1.0 + /// to +1.0, this noise module first normalizes this output value (the + /// range becomes 0.0 to 1.0), maps that value onto an exponential + /// curve, then rescales that value back to the original range. + double GetExponent () const + { + return m_exponent; + } + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the exponent value to apply to the output value from the + /// source module. + /// + /// @param exponent The exponent value. + /// + /// Because most noise modules will output values that range from -1.0 + /// to +1.0, this noise module first normalizes this output value (the + /// range becomes 0.0 to 1.0), maps that value onto an exponential + /// curve, then rescales that value back to the original range. + void SetExponent (double exponent) + { + m_exponent = exponent; + } + + protected: + + /// Exponent to apply to the output value from the source module. + double m_exponent; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/invert.cpp b/src/libnoise/src/module/invert.cpp new file mode 100644 index 00000000000..9b481919770 --- /dev/null +++ b/src/libnoise/src/module/invert.cpp @@ -0,0 +1,37 @@ +// invert.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "invert.h" + +using namespace noise::module; + +Invert::Invert (): + Module (GetSourceModuleCount ()) +{ +} + +double Invert::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + return -(m_pSourceModule[0]->GetValue (x, y, z)); +} diff --git a/src/libnoise/src/module/invert.h b/src/libnoise/src/module/invert.h new file mode 100644 index 00000000000..994dccf50ea --- /dev/null +++ b/src/libnoise/src/module/invert.h @@ -0,0 +1,75 @@ +// invert.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_INVERT_H +#define NOISE_MODULE_INVERT_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup modifiermodules + /// @{ + + /// Noise module that inverts the output value from a source module. + /// + /// @image html moduleinvert.png + /// + /// This noise module requires one source module. + class Invert: public Module + { + + public: + + /// Constructor. + Invert (); + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/max.cpp b/src/libnoise/src/module/max.cpp new file mode 100644 index 00000000000..2d295c204d6 --- /dev/null +++ b/src/libnoise/src/module/max.cpp @@ -0,0 +1,41 @@ +// max.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../misc.h" +#include "max.h" + +using namespace noise::module; + +Max::Max (): + Module (GetSourceModuleCount ()) +{ +} + +double Max::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + + double v0 = m_pSourceModule[0]->GetValue (x, y, z); + double v1 = m_pSourceModule[1]->GetValue (x, y, z); + return GetMax (v0, v1); +} diff --git a/src/libnoise/src/module/max.h b/src/libnoise/src/module/max.h new file mode 100644 index 00000000000..87b854e53ba --- /dev/null +++ b/src/libnoise/src/module/max.h @@ -0,0 +1,76 @@ +// max.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_MAX_H +#define NOISE_MODULE_MAX_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup combinermodules + /// @{ + + /// Noise module that outputs the larger of the two output values from two + /// source modules. + /// + /// @image html modulemax.png + /// + /// This noise module requires two source modules. + class Max: public Module + { + + public: + + /// Constructor. + Max (); + + virtual int GetSourceModuleCount () const + { + return 2; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/min.cpp b/src/libnoise/src/module/min.cpp new file mode 100644 index 00000000000..60cb5f576ed --- /dev/null +++ b/src/libnoise/src/module/min.cpp @@ -0,0 +1,41 @@ +// min.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../misc.h" +#include "min.h" + +using namespace noise::module; + +Min::Min (): + Module (GetSourceModuleCount ()) +{ +} + +double Min::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + + double v0 = m_pSourceModule[0]->GetValue (x, y, z); + double v1 = m_pSourceModule[1]->GetValue (x, y, z); + return GetMin (v0, v1); +} diff --git a/src/libnoise/src/module/min.h b/src/libnoise/src/module/min.h new file mode 100644 index 00000000000..76de943174e --- /dev/null +++ b/src/libnoise/src/module/min.h @@ -0,0 +1,76 @@ +// min.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_MIN_H +#define NOISE_MODULE_MIN_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup combinermodules + /// @{ + + /// Noise module that outputs the smaller of the two output values from + /// two source modules. + /// + /// @image html modulemin.png + /// + /// This noise module requires two source modules. + class Min: public Module + { + + public: + + /// Constructor. + Min (); + + virtual int GetSourceModuleCount () const + { + return 2; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/module.h b/src/libnoise/src/module/module.h new file mode 100644 index 00000000000..820df8b767f --- /dev/null +++ b/src/libnoise/src/module/module.h @@ -0,0 +1,55 @@ +// module.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_H +#define NOISE_MODULE_H + +#include "add.h" +#include "abs.h" +#include "billow.h" +#include "blend.h" +#include "cache.h" +#include "checkerboard.h" +#include "clamp.h" +#include "const.h" +#include "curve.h" +#include "cylinders.h" +#include "displace.h" +#include "exponent.h" +#include "invert.h" +#include "max.h" +#include "min.h" +#include "multiply.h" +#include "perlin.h" +#include "power.h" +#include "ridgedmulti.h" +#include "rotatepoint.h" +#include "scalebias.h" +#include "scalepoint.h" +#include "select.h" +#include "spheres.h" +#include "terrace.h" +#include "translatepoint.h" +#include "turbulence.h" +#include "voronoi.h" + +#endif diff --git a/src/libnoise/src/module/modulebase.cpp b/src/libnoise/src/module/modulebase.cpp new file mode 100644 index 00000000000..7805e193c77 --- /dev/null +++ b/src/libnoise/src/module/modulebase.cpp @@ -0,0 +1,46 @@ +// modulebase.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "modulebase.h" + +using namespace noise::module; + +Module::Module (int sourceModuleCount) +{ + m_pSourceModule = NULL; + + // Create an array of pointers to all source modules required by this + // noise module. Set these pointers to NULL. + if (sourceModuleCount > 0) { + m_pSourceModule = new const Module*[sourceModuleCount]; + for (int i = 0; i < sourceModuleCount; i++) { + m_pSourceModule[i] = NULL; + } + } else { + m_pSourceModule = NULL; + } +} + +Module::~Module () +{ + delete[] m_pSourceModule; +} diff --git a/src/libnoise/src/module/modulebase.h b/src/libnoise/src/module/modulebase.h new file mode 100644 index 00000000000..913945ea9e7 --- /dev/null +++ b/src/libnoise/src/module/modulebase.h @@ -0,0 +1,366 @@ +// modulebase.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULEBASE_H +#define NOISE_MODULEBASE_H + +#include +#include +#include +#include "../basictypes.h" +#include "../exception.h" +#include "../noisegen.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @defgroup modules Noise Modules + /// @addtogroup modules + /// @{ + + /// Abstract base class for noise modules. + /// + /// A noise module is an object that calculates and outputs a value + /// given a three-dimensional input value. + /// + /// Each type of noise module uses a specific method to calculate an + /// output value. Some of these methods include: + /// + /// - Calculating a value using a coherent-noise function or some other + /// mathematical function. + /// - Mathematically changing the output value from another noise module + /// in various ways. + /// - Combining the output values from two noise modules in various ways. + /// + /// An application can use the output values from these noise modules in + /// the following ways: + /// + /// - It can be used as an elevation value for a terrain height map + /// - It can be used as a grayscale (or an RGB-channel) value for a + /// procedural texture + /// - It can be used as a position value for controlling the movement of a + /// simulated lifeform. + /// + /// A noise module defines a near-infinite 3-dimensional texture. Each + /// position in this "texture" has a specific value. + /// + /// Combining noise modules + /// + /// Noise modules can be combined with other noise modules to generate + /// complex output values. A noise module that is used as a source of + /// output values for another noise module is called a source + /// module. Each of these source modules may be connected to other + /// source modules, and so on. + /// + /// There is no limit to the number of noise modules that can be connected + /// together in this way. However, each connected noise module increases + /// the time required to calculate an output value. + /// + /// Noise-module categories + /// + /// The noise module classes that are included in libnoise can be roughly + /// divided into five categories. + /// + /// Generator Modules + /// + /// A generator module outputs a value generated by a coherent-noise + /// function or some other mathematical function. + /// + /// Examples of generator modules include: + /// - noise::module::Const: Outputs a constant value. + /// - noise::module::Perlin: Outputs a value generated by a Perlin-noise + /// function. + /// - noise::module::Voronoi: Outputs a value generated by a Voronoi-cell + /// function. + /// + /// Modifier Modules + /// + /// A modifer module mathematically modifies the output value from a + /// source module. + /// + /// Examples of modifier modules include: + /// - noise::module::Curve: Maps the output value from the source module + /// onto an arbitrary function curve. + /// - noise::module::Invert: Inverts the output value from the source + /// module. + /// + /// Combiner Modules + /// + /// A combiner module mathematically combines the output values from two + /// or more source modules together. + /// + /// Examples of combiner modules include: + /// - noise::module::Add: Adds the two output values from two source + /// modules. + /// - noise::module::Max: Outputs the larger of the two output values from + /// two source modules. + /// + /// Selector Modules + /// + /// A selector module uses the output value from a control module + /// to specify how to combine the output values from its source modules. + /// + /// Examples of selector modules include: + /// - noise::module::Blend: Outputs a value that is linearly interpolated + /// between the output values from two source modules; the interpolation + /// weight is determined by the output value from the control module. + /// - noise::module::Select: Outputs the value selected from one of two + /// source modules chosen by the output value from a control module. + /// + /// Transformer Modules + /// + /// A transformer module applies a transformation to the coordinates of + /// the input value before retrieving the output value from the source + /// module. A transformer module does not modify the output value. + /// + /// Examples of transformer modules include: + /// - RotatePoint: Rotates the coordinates of the input value around the + /// origin before retrieving the output value from the source module. + /// - ScalePoint: Multiplies each coordinate of the input value by a + /// constant value before retrieving the output value from the source + /// module. + /// + /// Connecting source modules to a noise module + /// + /// An application connects a source module to a noise module by passing + /// the source module to the SetSourceModule() method. + /// + /// The application must also pass an index value to + /// SetSourceModule() as well. An index value is a numeric identifier for + /// that source module. Index values are consecutively numbered starting + /// at zero. + /// + /// To retrieve a reference to a source module, pass its index value to + /// the GetSourceModule() method. + /// + /// Each noise module requires the attachment of a certain number of + /// source modules before it can output a value. For example, the + /// noise::module::Add module requires two source modules, while the + /// noise::module::Perlin module requires none. Call the + /// GetSourceModuleCount() method to retrieve the number of source modules + /// required by that module. + /// + /// For non-selector modules, it usually does not matter which index value + /// an application assigns to a particular source module, but for selector + /// modules, the purpose of a source module is defined by its index value. + /// For example, consider the noise::module::Select noise module, which + /// requires three source modules. The control module is the source + /// module assigned an index value of 2. The control module determines + /// whether the noise module will output the value from the source module + /// assigned an index value of 0 or the output value from the source + /// module assigned an index value of 1. + /// + /// Generating output values with a noise module + /// + /// Once an application has connected all required source modules to a + /// noise module, the application can now begin to generate output values + /// with that noise module. + /// + /// To generate an output value, pass the ( @a x, @a y, @a z ) coordinates + /// of an input value to the GetValue() method. + /// + /// Using a noise module to generate terrain height maps or textures + /// + /// One way to generate a terrain height map or a texture is to first + /// allocate a 2-dimensional array of floating-point values. For each + /// array element, pass the array subscripts as @a x and @a y coordinates + /// to the GetValue() method (leaving the @a z coordinate set to zero) and + /// place the resulting output value into the array element. + /// + /// Creating your own noise modules + /// + /// Create a class that publicly derives from noise::module::Module. + /// + /// In the constructor, call the base class' constructor while passing the + /// return value from GetSourceModuleCount() to it. + /// + /// Override the GetSourceModuleCount() pure virtual method. From this + /// method, return the number of source modules required by your noise + /// module. + /// + /// Override the GetValue() pure virtual method. For generator modules, + /// calculate and output a value given the coordinates of the input value. + /// For other modules, retrieve the output values from each source module + /// referenced in the protected @a m_pSourceModule array, mathematically + /// combine those values, and return the combined value. + /// + /// When developing a noise module, you must ensure that your noise module + /// does not modify any source module or control module connected to it; a + /// noise module can only modify the output value from those source + /// modules. You must also ensure that if an application fails to connect + /// all required source modules via the SetSourceModule() method and then + /// attempts to call the GetValue() method, your module will raise an + /// assertion. + /// + /// It shouldn't be too difficult to create your own noise module. If you + /// still have some problems, take a look at the source code for + /// noise::module::Add, which is a very simple noise module. + class Module + { + + public: + + /// Constructor. + Module (int sourceModuleCount); + + /// Destructor. + virtual ~Module (); + + /// Returns a reference to a source module connected to this noise + /// module. + /// + /// @param index The index value assigned to the source module. + /// + /// @returns A reference to the source module. + /// + /// @pre The index value ranges from 0 to one less than the number of + /// source modules required by this noise module. + /// @pre A source module with the specified index value has been added + /// to this noise module via a call to SetSourceModule(). + /// + /// @throw noise::ExceptionNoModule See the preconditions for more + /// information. + /// + /// Each noise module requires the attachment of a certain number of + /// source modules before an application can call the GetValue() + /// method. + virtual const Module& GetSourceModule (int index) const + { + assert (m_pSourceModule != NULL); + + // The following fix was provided by Will Hawkins: + // + // m_pSourceModule[index] != NULL + // + // was incorrect; it should be: + // + // m_pSourceModule[index] == NULL + if (index >= GetSourceModuleCount () || index < 0 + || m_pSourceModule[index] == NULL) { + throw noise::ExceptionNoModule (); + } + return *(m_pSourceModule[index]); + } + + /// Returns the number of source modules required by this noise + /// module. + /// + /// @returns The number of source modules required by this noise + /// module. + virtual int GetSourceModuleCount () const = 0; + + /// Generates an output value given the coordinates of the specified + /// input value. + /// + /// @param x The @a x coordinate of the input value. + /// @param y The @a y coordinate of the input value. + /// @param z The @a z coordinate of the input value. + /// + /// @returns The output value. + /// + /// @pre All source modules required by this noise module have been + /// passed to the SetSourceModule() method. + /// + /// Before an application can call this method, it must first connect + /// all required source modules via the SetSourceModule() method. If + /// these source modules are not connected to this noise module, this + /// method raises a debug assertion. + /// + /// To determine the number of source modules required by this noise + /// module, call the GetSourceModuleCount() method. + virtual double GetValue (double x, double y, double z) const = 0; + + /// Connects a source module to this noise module. + /// + /// @param index An index value to assign to this source module. + /// @param sourceModule The source module to attach. + /// + /// @pre The index value ranges from 0 to one less than the number of + /// source modules required by this noise module. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// A noise module mathematically combines the output values from the + /// source modules to generate the value returned by GetValue(). + /// + /// The index value to assign a source module is a unique identifier + /// for that source module. If an index value has already been + /// assigned to a source module, this noise module replaces the old + /// source module with the new source module. + /// + /// Before an application can call the GetValue() method, it must + /// first connect all required source modules. To determine the + /// number of source modules required by this noise module, call the + /// GetSourceModuleCount() method. + /// + /// This source module must exist throughout the lifetime of this + /// noise module unless another source module replaces that source + /// module. + /// + /// A noise module does not modify a source module; it only modifies + /// its output values. + virtual void SetSourceModule (int index, const Module& sourceModule) + { + assert (m_pSourceModule != NULL); + if (index >= GetSourceModuleCount () || index < 0) { + throw noise::ExceptionInvalidParam (); + } + m_pSourceModule[index] = &sourceModule; + } + + protected: + + /// An array containing the pointers to each source module required by + /// this noise module. + const Module** m_pSourceModule; + + private: + + /// Assignment operator. + /// + /// This assignment operator does nothing and cannot be overridden. + /// This restriction is necessary because if this object was copied, + /// all source modules assigned to this noise module would need to be + /// copied as well. + const Module& operator= (const Module& m) + { + return *this; + } + + }; + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/multiply.cpp b/src/libnoise/src/module/multiply.cpp new file mode 100644 index 00000000000..592aac30d59 --- /dev/null +++ b/src/libnoise/src/module/multiply.cpp @@ -0,0 +1,39 @@ +// multiply.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "multiply.h" + +using namespace noise::module; + +Multiply::Multiply (): + Module (GetSourceModuleCount ()) +{ +} + +double Multiply::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + + return m_pSourceModule[0]->GetValue (x, y, z) + * m_pSourceModule[1]->GetValue (x, y, z); +} diff --git a/src/libnoise/src/module/multiply.h b/src/libnoise/src/module/multiply.h new file mode 100644 index 00000000000..e15a92dbdb2 --- /dev/null +++ b/src/libnoise/src/module/multiply.h @@ -0,0 +1,76 @@ +// multiply.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_MULTIPLY_H +#define NOISE_MODULE_MULTIPLY_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup combinermodules + /// @{ + + /// Noise module that outputs the product of the two output values from + /// two source modules. + /// + /// @image html modulemultiply.png + /// + /// This noise module requires two source modules. + class Multiply: public Module + { + + public: + + /// Constructor. + Multiply (); + + virtual int GetSourceModuleCount () const + { + return 2; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/perlin.cpp b/src/libnoise/src/module/perlin.cpp new file mode 100644 index 00000000000..f3effb5c2e8 --- /dev/null +++ b/src/libnoise/src/module/perlin.cpp @@ -0,0 +1,72 @@ +// perlin.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "perlin.h" + +using namespace noise::module; + +Perlin::Perlin (): + Module (GetSourceModuleCount ()), + m_frequency (DEFAULT_PERLIN_FREQUENCY ), + m_lacunarity (DEFAULT_PERLIN_LACUNARITY ), + m_noiseQuality (DEFAULT_PERLIN_QUALITY ), + m_octaveCount (DEFAULT_PERLIN_OCTAVE_COUNT), + m_persistence (DEFAULT_PERLIN_PERSISTENCE ), + m_seed (DEFAULT_PERLIN_SEED) +{ +} + +double Perlin::GetValue (double x, double y, double z) const +{ + double value = 0.0; + double signal = 0.0; + double curPersistence = 1.0; + double nx, ny, nz; + int seed; + + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + for (int curOctave = 0; curOctave < m_octaveCount; curOctave++) { + + // Make sure that these floating-point values have the same range as a 32- + // bit integer so that we can pass them to the coherent-noise functions. + nx = MakeInt32Range (x); + ny = MakeInt32Range (y); + nz = MakeInt32Range (z); + + // Get the coherent-noise value from the input value and add it to the + // final result. + seed = (m_seed + curOctave) & 0xffffffff; + signal = GradientCoherentNoise3D (nx, ny, nz, seed, m_noiseQuality); + value += signal * curPersistence; + + // Prepare the next octave. + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + curPersistence *= m_persistence; + } + + return value; +} diff --git a/src/libnoise/src/module/perlin.h b/src/libnoise/src/module/perlin.h new file mode 100644 index 00000000000..043c07333dc --- /dev/null +++ b/src/libnoise/src/module/perlin.h @@ -0,0 +1,359 @@ +// perlin.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_PERLIN_H +#define NOISE_MODULE_PERLIN_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup generatormodules + /// @{ + + /// Default frequency for the noise::module::Perlin noise module. + const double DEFAULT_PERLIN_FREQUENCY = 1.0; + + /// Default lacunarity for the noise::module::Perlin noise module. + const double DEFAULT_PERLIN_LACUNARITY = 2.0; + + /// Default number of octaves for the noise::module::Perlin noise module. + const int DEFAULT_PERLIN_OCTAVE_COUNT = 6; + + /// Default persistence value for the noise::module::Perlin noise module. + const double DEFAULT_PERLIN_PERSISTENCE = 0.5; + + /// Default noise quality for the noise::module::Perlin noise module. + const noise::NoiseQuality DEFAULT_PERLIN_QUALITY = QUALITY_STD; + + /// Default noise seed for the noise::module::Perlin noise module. + const int DEFAULT_PERLIN_SEED = 0; + + /// Maximum number of octaves for the noise::module::Perlin noise module. + const int PERLIN_MAX_OCTAVE = 30; + + /// Noise module that outputs 3-dimensional Perlin noise. + /// + /// @image html moduleperlin.png + /// + /// Perlin noise is the sum of several coherent-noise functions of + /// ever-increasing frequencies and ever-decreasing amplitudes. + /// + /// An important property of Perlin noise is that a small change in the + /// input value will produce a small change in the output value, while a + /// large change in the input value will produce a random change in the + /// output value. + /// + /// This noise module outputs Perlin-noise values that usually range from + /// -1.0 to +1.0, but there are no guarantees that all output values will + /// exist within that range. + /// + /// For a better description of Perlin noise, see the links in the + /// References and Acknowledgments section. + /// + /// This noise module does not require any source modules. + /// + /// Octaves + /// + /// The number of octaves control the amount of detail of the + /// Perlin noise. Adding more octaves increases the detail of the Perlin + /// noise, but with the drawback of increasing the calculation time. + /// + /// An octave is one of the coherent-noise functions in a series of + /// coherent-noise functions that are added together to form Perlin + /// noise. + /// + /// An application may specify the frequency of the first octave by + /// calling the SetFrequency() method. + /// + /// An application may specify the number of octaves that generate Perlin + /// noise by calling the SetOctaveCount() method. + /// + /// These coherent-noise functions are called octaves because each octave + /// has, by default, double the frequency of the previous octave. Musical + /// tones have this property as well; a musical C tone that is one octave + /// higher than the previous C tone has double its frequency. + /// + /// Frequency + /// + /// An application may specify the frequency of the first octave by + /// calling the SetFrequency() method. + /// + /// Persistence + /// + /// The persistence value controls the roughness of the Perlin + /// noise. Larger values produce rougher noise. + /// + /// The persistence value determines how quickly the amplitudes diminish + /// for successive octaves. The amplitude of the first octave is 1.0. + /// The amplitude of each subsequent octave is equal to the product of the + /// previous octave's amplitude and the persistence value. So a + /// persistence value of 0.5 sets the amplitude of the first octave to + /// 1.0; the second, 0.5; the third, 0.25; etc. + /// + /// An application may specify the persistence value by calling the + /// SetPersistence() method. + /// + /// Lacunarity + /// + /// The lacunarity specifies the frequency multipler between successive + /// octaves. + /// + /// The effect of modifying the lacunarity is subtle; you may need to play + /// with the lacunarity value to determine the effects. For best results, + /// set the lacunarity to a number between 1.5 and 3.5. + /// + /// References & acknowledgments + /// + /// The Noise Machine - + /// From the master, Ken Perlin himself. This page contains a + /// presentation that describes Perlin noise and some of its variants. + /// He won an Oscar for creating the Perlin noise algorithm! + /// + /// + /// Perlin Noise - Hugo Elias's webpage contains a very good + /// description of Perlin noise and describes its many applications. This + /// page gave me the inspiration to create libnoise in the first place. + /// Now that I know how to generate Perlin noise, I will never again use + /// cheesy subdivision algorithms to create terrain (unless I absolutely + /// need the speed.) + /// + /// The + /// Perlin noise math FAQ - A good page that describes Perlin noise in + /// plain English with only a minor amount of math. During development of + /// libnoise, I noticed that my coherent-noise function generated terrain + /// with some "regularity" to the terrain features. This page describes a + /// better coherent-noise function called gradient noise. This + /// version of noise::module::Perlin uses gradient coherent noise to + /// generate Perlin noise. + class Perlin: public Module + { + + public: + + /// Constructor. + /// + /// The default frequency is set to + /// noise::module::DEFAULT_PERLIN_FREQUENCY. + /// + /// The default lacunarity is set to + /// noise::module::DEFAULT_PERLIN_LACUNARITY. + /// + /// The default number of octaves is set to + /// noise::module::DEFAULT_PERLIN_OCTAVE_COUNT. + /// + /// The default persistence value is set to + /// noise::module::DEFAULT_PERLIN_PERSISTENCE. + /// + /// The default seed value is set to + /// noise::module::DEFAULT_PERLIN_SEED. + Perlin (); + + /// Returns the frequency of the first octave. + /// + /// @returns The frequency of the first octave. + double GetFrequency () const + { + return m_frequency; + } + + /// Returns the lacunarity of the Perlin noise. + /// + /// @returns The lacunarity of the Perlin noise. + /// + /// The lacunarity is the frequency multiplier between successive + /// octaves. + double GetLacunarity () const + { + return m_lacunarity; + } + + /// Returns the quality of the Perlin noise. + /// + /// @returns The quality of the Perlin noise. + /// + /// See noise::NoiseQuality for definitions of the various + /// coherent-noise qualities. + noise::NoiseQuality GetNoiseQuality () const + { + return m_noiseQuality; + } + + /// Returns the number of octaves that generate the Perlin noise. + /// + /// @returns The number of octaves that generate the Perlin noise. + /// + /// The number of octaves controls the amount of detail in the Perlin + /// noise. + int GetOctaveCount () const + { + return m_octaveCount; + } + + /// Returns the persistence value of the Perlin noise. + /// + /// @returns The persistence value of the Perlin noise. + /// + /// The persistence value controls the roughness of the Perlin noise. + double GetPersistence () const + { + return m_persistence; + } + + /// Returns the seed value used by the Perlin-noise function. + /// + /// @returns The seed value. + int GetSeed () const + { + return m_seed; + } + + virtual int GetSourceModuleCount () const + { + return 0; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the frequency of the first octave. + /// + /// @param frequency The frequency of the first octave. + void SetFrequency (double frequency) + { + m_frequency = frequency; + } + + /// Sets the lacunarity of the Perlin noise. + /// + /// @param lacunarity The lacunarity of the Perlin noise. + /// + /// The lacunarity is the frequency multiplier between successive + /// octaves. + /// + /// For best results, set the lacunarity to a number between 1.5 and + /// 3.5. + void SetLacunarity (double lacunarity) + { + m_lacunarity = lacunarity; + } + + /// Sets the quality of the Perlin noise. + /// + /// @param noiseQuality The quality of the Perlin noise. + /// + /// See noise::NoiseQuality for definitions of the various + /// coherent-noise qualities. + void SetNoiseQuality (noise::NoiseQuality noiseQuality) + { + m_noiseQuality = noiseQuality; + } + + /// Sets the number of octaves that generate the Perlin noise. + /// + /// @param octaveCount The number of octaves that generate the Perlin + /// noise. + /// + /// @pre The number of octaves ranges from 1 to + /// noise::module::PERLIN_MAX_OCTAVE. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// The number of octaves controls the amount of detail in the Perlin + /// noise. + /// + /// The larger the number of octaves, the more time required to + /// calculate the Perlin-noise value. + void SetOctaveCount (int octaveCount) + { + if (octaveCount < 1 || octaveCount > PERLIN_MAX_OCTAVE) { + throw noise::ExceptionInvalidParam (); + } + m_octaveCount = octaveCount; + } + + /// Sets the persistence value of the Perlin noise. + /// + /// @param persistence The persistence value of the Perlin noise. + /// + /// The persistence value controls the roughness of the Perlin noise. + /// + /// For best results, set the persistence to a number between 0.0 and + /// 1.0. + void SetPersistence (double persistence) + { + m_persistence = persistence; + } + + /// Sets the seed value used by the Perlin-noise function. + /// + /// @param seed The seed value. + void SetSeed (int seed) + { + m_seed = seed; + } + + protected: + + /// Frequency of the first octave. + double m_frequency; + + /// Frequency multiplier between successive octaves. + double m_lacunarity; + + /// Quality of the Perlin noise. + noise::NoiseQuality m_noiseQuality; + + /// Total number of octaves that generate the Perlin noise. + int m_octaveCount; + + /// Persistence of the Perlin noise. + double m_persistence; + + /// Seed value used by the Perlin-noise function. + int m_seed; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/power.cpp b/src/libnoise/src/module/power.cpp new file mode 100644 index 00000000000..393853b69b3 --- /dev/null +++ b/src/libnoise/src/module/power.cpp @@ -0,0 +1,38 @@ +// power.cpp +// +// Copyright (C) 2004 Owen Jacobson +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is angstrom@lionsanctuary.net +// + +#include "power.h" + +using namespace noise::module; + +Power::Power (): + Module (GetSourceModuleCount ()) +{ +} + +double Power::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + + return pow (m_pSourceModule[0]->GetValue (x, y, z), + m_pSourceModule[1]->GetValue (x, y, z)); +} diff --git a/src/libnoise/src/module/power.h b/src/libnoise/src/module/power.h new file mode 100644 index 00000000000..1b741117c3b --- /dev/null +++ b/src/libnoise/src/module/power.h @@ -0,0 +1,80 @@ +// power.h +// +// Copyright (C) 2004 Owen Jacobson +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is angstrom@lionsanctuary.net +// + +#ifndef NOISE_MODULE_POWER_H +#define NOISE_MODULE_POWER_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @defgroup combinermodules Combiner Modules + /// @addtogroup combinermodules + /// @{ + + /// Noise module that raises the output value from a first source module + /// to the power of the output value from a second source module. + /// + /// @image html modulepower.png + /// + /// The first source module must have an index value of 0. + /// + /// The second source module must have an index value of 1. + /// + /// This noise module requires two source modules. + class Power: public Module + { + + public: + + /// Constructor. + Power (); + + virtual int GetSourceModuleCount () const + { + return 2; + } + + virtual double GetValue (double x, double y, double z) const; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/ridgedmulti.cpp b/src/libnoise/src/module/ridgedmulti.cpp new file mode 100644 index 00000000000..5a81a903bf8 --- /dev/null +++ b/src/libnoise/src/module/ridgedmulti.cpp @@ -0,0 +1,114 @@ +// ridgedmulti.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "ridgedmulti.h" + +using namespace noise::module; + +RidgedMulti::RidgedMulti (): + Module (GetSourceModuleCount ()), + m_frequency (DEFAULT_RIDGED_FREQUENCY ), + m_lacunarity (DEFAULT_RIDGED_LACUNARITY ), + m_noiseQuality (DEFAULT_RIDGED_QUALITY ), + m_octaveCount (DEFAULT_RIDGED_OCTAVE_COUNT), + m_seed (DEFAULT_RIDGED_SEED) +{ + CalcSpectralWeights (); +} + +// Calculates the spectral weights for each octave. +void RidgedMulti::CalcSpectralWeights () +{ + // This exponent parameter should be user-defined; it may be exposed in a + // future version of libnoise. + double h = 1.0; + + double frequency = 1.0; + for (int i = 0; i < RIDGED_MAX_OCTAVE; i++) { + // Compute weight for each frequency. + m_pSpectralWeights[i] = pow (frequency, -h); + frequency *= m_lacunarity; + } +} + +// Multifractal code originally written by F. Kenton "Doc Mojo" Musgrave, +// 1998. Modified by jas for use with libnoise. +double RidgedMulti::GetValue (double x, double y, double z) const +{ + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + double signal = 0.0; + double value = 0.0; + double weight = 1.0; + + // These parameters should be user-defined; they may be exposed in a + // future version of libnoise. + double offset = 1.0; + double gain = 2.0; + + for (int curOctave = 0; curOctave < m_octaveCount; curOctave++) { + + // Make sure that these floating-point values have the same range as a 32- + // bit integer so that we can pass them to the coherent-noise functions. + double nx, ny, nz; + nx = MakeInt32Range (x); + ny = MakeInt32Range (y); + nz = MakeInt32Range (z); + + // Get the coherent-noise value. + int seed = (m_seed + curOctave) & 0x7fffffff; + signal = GradientCoherentNoise3D (nx, ny, nz, seed, m_noiseQuality); + + // Make the ridges. + signal = fabs (signal); + signal = offset - signal; + + // Square the signal to increase the sharpness of the ridges. + signal *= signal; + + // The weighting from the previous octave is applied to the signal. + // Larger values have higher weights, producing sharp points along the + // ridges. + signal *= weight; + + // Weight successive contributions by the previous signal. + weight = signal * gain; + if (weight > 1.0) { + weight = 1.0; + } + if (weight < 0.0) { + weight = 0.0; + } + + // Add the signal to the output value. + value += (signal * m_pSpectralWeights[curOctave]); + + // Go to the next octave. + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + } + + return (value * 1.25) - 1.0; +} diff --git a/src/libnoise/src/module/ridgedmulti.h b/src/libnoise/src/module/ridgedmulti.h new file mode 100644 index 00000000000..99617f91d53 --- /dev/null +++ b/src/libnoise/src/module/ridgedmulti.h @@ -0,0 +1,313 @@ +// ridgedmulti.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_RIDGEDMULTI_H +#define NOISE_MODULE_RIDGEDMULTI_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup generatormodules + /// @{ + + /// Default frequency for the noise::module::RidgedMulti noise module. + const double DEFAULT_RIDGED_FREQUENCY = 1.0; + + /// Default lacunarity for the noise::module::RidgedMulti noise module. + const double DEFAULT_RIDGED_LACUNARITY = 2.0; + + /// Default number of octaves for the noise::module::RidgedMulti noise + /// module. + const int DEFAULT_RIDGED_OCTAVE_COUNT = 6; + + /// Default noise quality for the noise::module::RidgedMulti noise + /// module. + const noise::NoiseQuality DEFAULT_RIDGED_QUALITY = QUALITY_STD; + + /// Default noise seed for the noise::module::RidgedMulti noise module. + const int DEFAULT_RIDGED_SEED = 0; + + /// Maximum number of octaves for the noise::module::RidgedMulti noise + /// module. + const int RIDGED_MAX_OCTAVE = 30; + + /// Noise module that outputs 3-dimensional ridged-multifractal noise. + /// + /// @image html moduleridgedmulti.png + /// + /// This noise module, heavily based on the Perlin-noise module, generates + /// ridged-multifractal noise. Ridged-multifractal noise is generated in + /// much of the same way as Perlin noise, except the output of each octave + /// is modified by an absolute-value function. Modifying the octave + /// values in this way produces ridge-like formations. + /// + /// Ridged-multifractal noise does not use a persistence value. This is + /// because the persistence values of the octaves are based on the values + /// generated from from previous octaves, creating a feedback loop (or + /// that's what it looks like after reading the code.) + /// + /// This noise module outputs ridged-multifractal-noise values that + /// usually range from -1.0 to +1.0, but there are no guarantees that all + /// output values will exist within that range. + /// + /// @note For ridged-multifractal noise generated with only one octave, + /// the output value ranges from -1.0 to 0.0. + /// + /// Ridged-multifractal noise is often used to generate craggy mountainous + /// terrain or marble-like textures. + /// + /// This noise module does not require any source modules. + /// + /// Octaves + /// + /// The number of octaves control the amount of detail of the + /// ridged-multifractal noise. Adding more octaves increases the detail + /// of the ridged-multifractal noise, but with the drawback of increasing + /// the calculation time. + /// + /// An application may specify the number of octaves that generate + /// ridged-multifractal noise by calling the SetOctaveCount() method. + /// + /// Frequency + /// + /// An application may specify the frequency of the first octave by + /// calling the SetFrequency() method. + /// + /// Lacunarity + /// + /// The lacunarity specifies the frequency multipler between successive + /// octaves. + /// + /// The effect of modifying the lacunarity is subtle; you may need to play + /// with the lacunarity value to determine the effects. For best results, + /// set the lacunarity to a number between 1.5 and 3.5. + /// + /// References & Acknowledgments + /// + /// F. + /// Kenton "Doc Mojo" Musgrave's texturing page - This page contains + /// links to source code that generates ridged-multfractal noise, among + /// other types of noise. The source file + /// fractal.c contains the code I used in my ridged-multifractal class + /// (see the @a RidgedMultifractal() function.) This code was written by F. + /// Kenton Musgrave, the person who created + /// MojoWorld. He is also one of + /// the authors in Texturing and Modeling: A Procedural Approach + /// (Morgan Kaufmann, 2002. ISBN 1-55860-848-6.) + class RidgedMulti: public Module + { + + public: + + /// Constructor. + /// + /// The default number of octaves is set to + /// noise::module::DEFAULT_RIDGED_OCTAVE_COUNT. + /// + /// The default frequency is set to + /// noise::module::DEFAULT_RIDGED_FREQUENCY. + /// + /// The default lacunarity is set to + /// noise::module::DEFAULT_RIDGED_LACUNARITY. + /// + /// The default seed value is set to + /// noise::module::DEFAULT_RIDGED_SEED. + RidgedMulti (); + + /// Returns the frequency of the first octave. + /// + /// @returns The frequency of the first octave. + double GetFrequency () const + { + return m_frequency; + } + + /// Returns the lacunarity of the ridged-multifractal noise. + /// + /// @returns The lacunarity of the ridged-multifractal noise. + /// + /// The lacunarity is the frequency multiplier between successive + /// octaves. + double GetLacunarity () const + { + return m_lacunarity; + } + + /// Returns the quality of the ridged-multifractal noise. + /// + /// @returns The quality of the ridged-multifractal noise. + /// + /// See noise::NoiseQuality for definitions of the various + /// coherent-noise qualities. + noise::NoiseQuality GetNoiseQuality () const + { + return m_noiseQuality; + } + + /// Returns the number of octaves that generate the + /// ridged-multifractal noise. + /// + /// @returns The number of octaves that generate the + /// ridged-multifractal noise. + /// + /// The number of octaves controls the amount of detail in the + /// ridged-multifractal noise. + int GetOctaveCount () const + { + return m_octaveCount; + } + + /// Returns the seed value used by the ridged-multifractal-noise + /// function. + /// + /// @returns The seed value. + int GetSeed () const + { + return m_seed; + } + + virtual int GetSourceModuleCount () const + { + return 0; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the frequency of the first octave. + /// + /// @param frequency The frequency of the first octave. + void SetFrequency (double frequency) + { + m_frequency = frequency; + } + + /// Sets the lacunarity of the ridged-multifractal noise. + /// + /// @param lacunarity The lacunarity of the ridged-multifractal noise. + /// + /// The lacunarity is the frequency multiplier between successive + /// octaves. + /// + /// For best results, set the lacunarity to a number between 1.5 and + /// 3.5. + void SetLacunarity (double lacunarity) + { + m_lacunarity = lacunarity; + CalcSpectralWeights (); + } + + /// Sets the quality of the ridged-multifractal noise. + /// + /// @param noiseQuality The quality of the ridged-multifractal noise. + /// + /// See noise::NoiseQuality for definitions of the various + /// coherent-noise qualities. + void SetNoiseQuality (noise::NoiseQuality noiseQuality) + { + m_noiseQuality = noiseQuality; + } + + /// Sets the number of octaves that generate the ridged-multifractal + /// noise. + /// + /// @param octaveCount The number of octaves that generate the + /// ridged-multifractal noise. + /// + /// @pre The number of octaves ranges from 1 to + /// noise::module::RIDGED_MAX_OCTAVE. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// The number of octaves controls the amount of detail in the + /// ridged-multifractal noise. + /// + /// The larger the number of octaves, the more time required to + /// calculate the ridged-multifractal-noise value. + void SetOctaveCount (int octaveCount) + { + if (octaveCount > RIDGED_MAX_OCTAVE) { + throw noise::ExceptionInvalidParam (); + } + m_octaveCount = octaveCount; + } + + /// Sets the seed value used by the ridged-multifractal-noise + /// function. + /// + /// @param seed The seed value. + void SetSeed (int seed) + { + m_seed = seed; + } + + protected: + + /// Calculates the spectral weights for each octave. + /// + /// This method is called when the lacunarity changes. + void CalcSpectralWeights (); + + /// Frequency of the first octave. + double m_frequency; + + /// Frequency multiplier between successive octaves. + double m_lacunarity; + + /// Quality of the ridged-multifractal noise. + noise::NoiseQuality m_noiseQuality; + + /// Total number of octaves that generate the ridged-multifractal + /// noise. + int m_octaveCount; + + /// Contains the spectral weights for each octave. + double m_pSpectralWeights[RIDGED_MAX_OCTAVE]; + + /// Seed value used by the ridged-multfractal-noise function. + int m_seed; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/rotatepoint.cpp b/src/libnoise/src/module/rotatepoint.cpp new file mode 100644 index 00000000000..dccac82e1e7 --- /dev/null +++ b/src/libnoise/src/module/rotatepoint.cpp @@ -0,0 +1,68 @@ +// rotatepoint.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../mathconsts.h" +#include "rotatepoint.h" + +using namespace noise::module; + +RotatePoint::RotatePoint (): + Module (GetSourceModuleCount ()) +{ + SetAngles (DEFAULT_ROTATE_X, DEFAULT_ROTATE_Y, DEFAULT_ROTATE_Z); +} + +double RotatePoint::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + double nx = (m_x1Matrix * x) + (m_y1Matrix * y) + (m_z1Matrix * z); + double ny = (m_x2Matrix * x) + (m_y2Matrix * y) + (m_z2Matrix * z); + double nz = (m_x3Matrix * x) + (m_y3Matrix * y) + (m_z3Matrix * z); + return m_pSourceModule[0]->GetValue (nx, ny, nz); +} + +void RotatePoint::SetAngles (double xAngle, double yAngle, + double zAngle) +{ + double xCos, yCos, zCos, xSin, ySin, zSin; + xCos = cos (xAngle * DEG_TO_RAD); + yCos = cos (yAngle * DEG_TO_RAD); + zCos = cos (zAngle * DEG_TO_RAD); + xSin = sin (xAngle * DEG_TO_RAD); + ySin = sin (yAngle * DEG_TO_RAD); + zSin = sin (zAngle * DEG_TO_RAD); + + m_x1Matrix = ySin * xSin * zSin + yCos * zCos; + m_y1Matrix = xCos * zSin; + m_z1Matrix = ySin * zCos - yCos * xSin * zSin; + m_x2Matrix = ySin * xSin * zCos - yCos * zSin; + m_y2Matrix = xCos * zCos; + m_z2Matrix = -yCos * xSin * zCos - ySin * zSin; + m_x3Matrix = -ySin * xCos; + m_y3Matrix = xSin; + m_z3Matrix = yCos * xCos; + + m_xAngle = xAngle; + m_yAngle = yAngle; + m_zAngle = zAngle; +} diff --git a/src/libnoise/src/module/rotatepoint.h b/src/libnoise/src/module/rotatepoint.h new file mode 100644 index 00000000000..34c8830b773 --- /dev/null +++ b/src/libnoise/src/module/rotatepoint.h @@ -0,0 +1,233 @@ +// rotatepoint.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_ROTATEPOINT_H +#define NOISE_MODULE_ROTATEPOINT_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup transformermodules + /// @{ + + /// Default @a x rotation angle for the noise::module::RotatePoint noise + /// module. + const double DEFAULT_ROTATE_X = 0.0; + + /// Default @a y rotation angle for the noise::module::RotatePoint noise + /// module. + const double DEFAULT_ROTATE_Y = 0.0; + + /// Default @a z rotation angle for the noise::module::RotatePoint noise + /// module. + const double DEFAULT_ROTATE_Z = 0.0; + + /// Noise module that rotates the input value around the origin before + /// returning the output value from a source module. + /// + /// @image html modulerotatepoint.png + /// + /// The GetValue() method rotates the coordinates of the input value + /// around the origin before returning the output value from the source + /// module. To set the rotation angles, call the SetAngles() method. To + /// set the rotation angle around the individual @a x, @a y, or @a z axes, + /// call the SetXAngle(), SetYAngle() or SetZAngle() methods, + /// respectively. + /// + /// The coordinate system of the input value is assumed to be + /// "left-handed" (@a x increases to the right, @a y increases upward, + /// and @a z increases inward.) + /// + /// This noise module requires one source module. + class RotatePoint: public Module + { + + public: + + /// Constructor. + /// + /// The default rotation angle around the @a x axis, in degrees, is + /// set to noise::module::DEFAULT_ROTATE_X. + /// + /// The default rotation angle around the @a y axis, in degrees, is + /// set to noise::module::DEFAULT_ROTATE_Y. + /// + /// The default rotation angle around the @a z axis, in degrees, is + /// set to noise::module::DEFAULT_ROTATE_Z. + RotatePoint (); + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Returns the rotation angle around the @a x axis to apply to the + /// input value. + /// + /// @returns The rotation angle around the @a x axis, in degrees. + double GetXAngle () const + { + return m_xAngle; + } + + /// Returns the rotation angle around the @a y axis to apply to the + /// input value. + /// + /// @returns The rotation angle around the @a y axis, in degrees. + double GetYAngle () const + { + return m_yAngle; + } + + /// Returns the rotation angle around the @a z axis to apply to the + /// input value. + /// + /// @returns The rotation angle around the @a z axis, in degrees. + double GetZAngle () const + { + return m_zAngle; + } + + /// Sets the rotation angles around all three axes to apply to the + /// input value. + /// + /// @param xAngle The rotation angle around the @a x axis, in degrees. + /// @param yAngle The rotation angle around the @a y axis, in degrees. + /// @param zAngle The rotation angle around the @a z axis, in degrees. + /// + /// The GetValue() method rotates the coordinates of the input value + /// around the origin before returning the output value from the + /// source module. + void SetAngles (double xAngle, double yAngle, double zAngle); + + /// Sets the rotation angle around the @a x axis to apply to the input + /// value. + /// + /// @param xAngle The rotation angle around the @a x axis, in degrees. + /// + /// The GetValue() method rotates the coordinates of the input value + /// around the origin before returning the output value from the + /// source module. + void SetXAngle (double xAngle) + { + SetAngles (xAngle, m_yAngle, m_zAngle); + } + + /// Sets the rotation angle around the @a y axis to apply to the input + /// value. + /// + /// @param yAngle The rotation angle around the @a y axis, in degrees. + /// + /// The GetValue() method rotates the coordinates of the input value + /// around the origin before returning the output value from the + /// source module. + void SetYAngle (double yAngle) + { + SetAngles (m_xAngle, yAngle, m_zAngle); + } + + /// Sets the rotation angle around the @a z axis to apply to the input + /// value. + /// + /// @param zAngle The rotation angle around the @a z axis, in degrees. + /// + /// The GetValue() method rotates the coordinates of the input value + /// around the origin before returning the output value from the + /// source module. + void SetZAngle (double zAngle) + { + SetAngles (m_xAngle, m_yAngle, zAngle); + } + + protected: + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_x1Matrix; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_x2Matrix; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_x3Matrix; + + /// @a x rotation angle applied to the input value, in degrees. + double m_xAngle; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_y1Matrix; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_y2Matrix; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_y3Matrix; + + /// @a y rotation angle applied to the input value, in degrees. + double m_yAngle; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_z1Matrix; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_z2Matrix; + + /// An entry within the 3x3 rotation matrix used for rotating the + /// input value. + double m_z3Matrix; + + /// @a z rotation angle applied to the input value, in degrees. + double m_zAngle; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/scalebias.cpp b/src/libnoise/src/module/scalebias.cpp new file mode 100644 index 00000000000..67ba8d9fa72 --- /dev/null +++ b/src/libnoise/src/module/scalebias.cpp @@ -0,0 +1,39 @@ +// scalebias.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "scalebias.h" + +using namespace noise::module; + +ScaleBias::ScaleBias (): + Module (GetSourceModuleCount ()), + m_bias (DEFAULT_BIAS ), + m_scale (DEFAULT_SCALE) +{ +} + +double ScaleBias::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + return m_pSourceModule[0]->GetValue (x, y, z) * m_scale + m_bias; +} diff --git a/src/libnoise/src/module/scalebias.h b/src/libnoise/src/module/scalebias.h new file mode 100644 index 00000000000..419efca23af --- /dev/null +++ b/src/libnoise/src/module/scalebias.h @@ -0,0 +1,151 @@ +// scalebias.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_SCALEBIAS_H +#define NOISE_MODULE_SCALEBIAS_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup modifiermodules + /// @{ + + /// Default bias for the noise::module::ScaleBias noise module. + const double DEFAULT_BIAS = 0.0; + + /// Default scale for the noise::module::ScaleBias noise module. + const double DEFAULT_SCALE = 1.0; + + /// Noise module that applies a scaling factor and a bias to the output + /// value from a source module. + /// + /// @image html modulescalebias.png + /// + /// The GetValue() method retrieves the output value from the source + /// module, multiplies it with a scaling factor, adds a bias to it, then + /// outputs the value. + /// + /// This noise module requires one source module. + class ScaleBias: public Module + { + + public: + + /// Constructor. + /// + /// The default bias is set to noise::module::DEFAULT_BIAS. + /// + /// The default scaling factor is set to noise::module::DEFAULT_SCALE. + ScaleBias (); + + /// Returns the bias to apply to the scaled output value from the + /// source module. + /// + /// @returns The bias to apply. + /// + /// The GetValue() method retrieves the output value from the source + /// module, multiplies it with the scaling factor, adds the bias to + /// it, then outputs the value. + double GetBias () const + { + return m_bias; + } + + /// Returns the scaling factor to apply to the output value from the + /// source module. + /// + /// @returns The scaling factor to apply. + /// + /// The GetValue() method retrieves the output value from the source + /// module, multiplies it with the scaling factor, adds the bias to + /// it, then outputs the value. + double GetScale () const + { + return m_scale; + } + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the bias to apply to the scaled output value from the source + /// module. + /// + /// @param bias The bias to apply. + /// + /// The GetValue() method retrieves the output value from the source + /// module, multiplies it with the scaling factor, adds the bias to + /// it, then outputs the value. + void SetBias (double bias) + { + m_bias = bias; + } + + /// Sets the scaling factor to apply to the output value from the + /// source module. + /// + /// @param scale The scaling factor to apply. + /// + /// The GetValue() method retrieves the output value from the source + /// module, multiplies it with the scaling factor, adds the bias to + /// it, then outputs the value. + void SetScale (double scale) + { + m_scale = scale; + } + + protected: + + /// Bias to apply to the scaled output value from the source module. + double m_bias; + + /// Scaling factor to apply to the output value from the source + /// module. + double m_scale; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/scalepoint.cpp b/src/libnoise/src/module/scalepoint.cpp new file mode 100644 index 00000000000..f0c9676e051 --- /dev/null +++ b/src/libnoise/src/module/scalepoint.cpp @@ -0,0 +1,41 @@ +// scalepoint.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "scalepoint.h" + +using namespace noise::module; + +ScalePoint::ScalePoint (): + Module (GetSourceModuleCount ()), + m_xScale (DEFAULT_SCALE_POINT_X), + m_yScale (DEFAULT_SCALE_POINT_Y), + m_zScale (DEFAULT_SCALE_POINT_Z) +{ +} + +double ScalePoint::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + return m_pSourceModule[0]->GetValue (x * m_xScale, y * m_yScale, + z * m_zScale); +} diff --git a/src/libnoise/src/module/scalepoint.h b/src/libnoise/src/module/scalepoint.h new file mode 100644 index 00000000000..cd11956a1a5 --- /dev/null +++ b/src/libnoise/src/module/scalepoint.h @@ -0,0 +1,212 @@ +// scalepoint.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_SCALEPOINT_H +#define NOISE_MODULE_SCALEPOINT_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup transformermodules + /// @{ + + /// Default scaling factor applied to the @a x coordinate for the + /// noise::module::ScalePoint noise module. + const double DEFAULT_SCALE_POINT_X = 1.0; + + /// Default scaling factor applied to the @a y coordinate for the + /// noise::module::ScalePoint noise module. + const double DEFAULT_SCALE_POINT_Y = 1.0; + + /// Default scaling factor applied to the @a z coordinate for the + /// noise::module::ScalePoint noise module. + const double DEFAULT_SCALE_POINT_Z = 1.0; + + /// Noise module that scales the coordinates of the input value before + /// returning the output value from a source module. + /// + /// @image html modulescalepoint.png + /// + /// The GetValue() method multiplies the ( @a x, @a y, @a z ) coordinates + /// of the input value with a scaling factor before returning the output + /// value from the source module. To set the scaling factor, call the + /// SetScale() method. To set the scaling factor to apply to the + /// individual @a x, @a y, or @a z coordinates, call the SetXScale(), + /// SetYScale() or SetZScale() methods, respectively. + /// + /// This noise module requires one source module. + class ScalePoint: public Module + { + + public: + + /// Constructor. + /// + /// The default scaling factor applied to the @a x coordinate is set + /// to noise::module::DEFAULT_SCALE_POINT_X. + /// + /// The default scaling factor applied to the @a y coordinate is set + /// to noise::module::DEFAULT_SCALE_POINT_Y. + /// + /// The default scaling factor applied to the @a z coordinate is set + /// to noise::module::DEFAULT_SCALE_POINT_Z. + ScalePoint (); + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Returns the scaling factor applied to the @a x coordinate of the + /// input value. + /// + /// @returns The scaling factor applied to the @a x coordinate. + double GetXScale () const + { + return m_xScale; + } + + /// Returns the scaling factor applied to the @a y coordinate of the + /// input value. + /// + /// @returns The scaling factor applied to the @a y coordinate. + double GetYScale () const + { + return m_yScale; + } + + /// Returns the scaling factor applied to the @a z coordinate of the + /// input value. + /// + /// @returns The scaling factor applied to the @a z coordinate. + double GetZScale () const + { + return m_zScale; + } + + /// Sets the scaling factor to apply to the input value. + /// + /// @param scale The scaling factor to apply. + /// + /// The GetValue() method multiplies the ( @a x, @a y, @a z ) + /// coordinates of the input value with a scaling factor before + /// returning the output value from the source module. + void SetScale (double scale) + { + m_xScale = scale; + m_yScale = scale; + m_zScale = scale; + } + + /// Sets the scaling factor to apply to the ( @a x, @a y, @a z ) + /// coordinates of the input value. + /// + /// @param xScale The scaling factor to apply to the @a x coordinate. + /// @param yScale The scaling factor to apply to the @a y coordinate. + /// @param zScale The scaling factor to apply to the @a z coordinate. + /// + /// The GetValue() method multiplies the ( @a x, @a y, @a z ) + /// coordinates of the input value with a scaling factor before + /// returning the output value from the source module. + void SetScale (double xScale, double yScale, double zScale) + { + m_xScale = xScale; + m_yScale = yScale; + m_zScale = zScale; + } + + /// Sets the scaling factor to apply to the @a x coordinate of the + /// input value. + /// + /// @param xScale The scaling factor to apply to the @a x coordinate. + /// + /// The GetValue() method multiplies the ( @a x, @a y, @a z ) + /// coordinates of the input value with a scaling factor before + /// returning the output value from the source module. + void SetXScale (double xScale) + { + m_xScale = xScale; + } + + /// Sets the scaling factor to apply to the @a y coordinate of the + /// input value. + /// + /// @param yScale The scaling factor to apply to the @a y coordinate. + /// + /// The GetValue() method multiplies the ( @a x, @a y, @a z ) + /// coordinates of the input value with a scaling factor before + /// returning the output value from the source module. + void SetYScale (double yScale) + { + m_yScale = yScale; + } + + /// Sets the scaling factor to apply to the @a z coordinate of the + /// input value. + /// + /// @param zScale The scaling factor to apply to the @a z coordinate. + /// + /// The GetValue() method multiplies the ( @a x, @a y, @a z ) + /// coordinates of the input value with a scaling factor before + /// returning the output value from the source module. + void SetZScale (double zScale) + { + m_zScale = zScale; + } + + protected: + + /// Scaling factor applied to the @a x coordinate of the input value. + double m_xScale; + + /// Scaling factor applied to the @a y coordinate of the input value. + double m_yScale; + + /// Scaling factor applied to the @a z coordinate of the input value. + double m_zScale; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/select.cpp b/src/libnoise/src/module/select.cpp new file mode 100644 index 00000000000..d59e6aa2ada --- /dev/null +++ b/src/libnoise/src/module/select.cpp @@ -0,0 +1,109 @@ +// select.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../interp.h" +#include "select.h" + +using namespace noise::module; + +Select::Select (): + Module (GetSourceModuleCount ()), + m_edgeFalloff (DEFAULT_SELECT_EDGE_FALLOFF), + m_lowerBound (DEFAULT_SELECT_LOWER_BOUND), + m_upperBound (DEFAULT_SELECT_UPPER_BOUND) +{ +} + +double Select::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_pSourceModule[1] != NULL); + assert (m_pSourceModule[2] != NULL); + + double controlValue = m_pSourceModule[2]->GetValue (x, y, z); + double alpha; + if (m_edgeFalloff > 0.0) { + if (controlValue < (m_lowerBound - m_edgeFalloff)) { + // The output value from the control module is below the selector + // threshold; return the output value from the first source module. + return m_pSourceModule[0]->GetValue (x, y, z); + + } else if (controlValue < (m_lowerBound + m_edgeFalloff)) { + // The output value from the control module is near the lower end of the + // selector threshold and within the smooth curve. Interpolate between + // the output values from the first and second source modules. + double lowerCurve = (m_lowerBound - m_edgeFalloff); + double upperCurve = (m_lowerBound + m_edgeFalloff); + alpha = SCurve3 ( + (controlValue - lowerCurve) / (upperCurve - lowerCurve)); + return LinearInterp (m_pSourceModule[0]->GetValue (x, y, z), + m_pSourceModule[1]->GetValue (x, y, z), + alpha); + + } else if (controlValue < (m_upperBound - m_edgeFalloff)) { + // The output value from the control module is within the selector + // threshold; return the output value from the second source module. + return m_pSourceModule[1]->GetValue (x, y, z); + + } else if (controlValue < (m_upperBound + m_edgeFalloff)) { + // The output value from the control module is near the upper end of the + // selector threshold and within the smooth curve. Interpolate between + // the output values from the first and second source modules. + double lowerCurve = (m_upperBound - m_edgeFalloff); + double upperCurve = (m_upperBound + m_edgeFalloff); + alpha = SCurve3 ( + (controlValue - lowerCurve) / (upperCurve - lowerCurve)); + return LinearInterp (m_pSourceModule[1]->GetValue (x, y, z), + m_pSourceModule[0]->GetValue (x, y, z), + alpha); + + } else { + // Output value from the control module is above the selector threshold; + // return the output value from the first source module. + return m_pSourceModule[0]->GetValue (x, y, z); + } + } else { + if (controlValue < m_lowerBound || controlValue > m_upperBound) { + return m_pSourceModule[0]->GetValue (x, y, z); + } else { + return m_pSourceModule[1]->GetValue (x, y, z); + } + } +} + +void Select::SetBounds (double lowerBound, double upperBound) +{ + assert (lowerBound < upperBound); + + m_lowerBound = lowerBound; + m_upperBound = upperBound; + + // Make sure that the edge falloff curves do not overlap. + SetEdgeFalloff (m_edgeFalloff); +} + +void Select::SetEdgeFalloff (double edgeFalloff) +{ + // Make sure that the edge falloff curves do not overlap. + double boundSize = m_upperBound - m_lowerBound; + m_edgeFalloff = (edgeFalloff > boundSize / 2)? boundSize / 2: edgeFalloff; +} diff --git a/src/libnoise/src/module/select.h b/src/libnoise/src/module/select.h new file mode 100644 index 00000000000..4e1dbd3fe90 --- /dev/null +++ b/src/libnoise/src/module/select.h @@ -0,0 +1,267 @@ +// select.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_SELECT_H +#define NOISE_MODULE_SELECT_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup selectormodules + /// @{ + + /// Default edge-falloff value for the noise::module::Select noise module. + const double DEFAULT_SELECT_EDGE_FALLOFF = 0.0; + + /// Default lower bound of the selection range for the + /// noise::module::Select noise module. + const double DEFAULT_SELECT_LOWER_BOUND = -1.0; + + /// Default upper bound of the selection range for the + /// noise::module::Select noise module. + const double DEFAULT_SELECT_UPPER_BOUND = 1.0; + + /// Noise module that outputs the value selected from one of two source + /// modules chosen by the output value from a control module. + /// + /// @image html moduleselect.png + /// + /// Unlike most other noise modules, the index value assigned to a source + /// module determines its role in the selection operation: + /// - Source module 0 (upper left in the diagram) outputs a value. + /// - Source module 1 (lower left in the diagram) outputs a value. + /// - Source module 2 (bottom of the diagram) is known as the control + /// module. The control module determines the value to select. If + /// the output value from the control module is within a range of values + /// known as the selection range, this noise module outputs the + /// value from the source module with an index value of 1. Otherwise, + /// this noise module outputs the value from the source module with an + /// index value of 0. + /// + /// To specify the bounds of the selection range, call the SetBounds() + /// method. + /// + /// An application can pass the control module to the SetControlModule() + /// method instead of the SetSourceModule() method. This may make the + /// application code easier to read. + /// + /// By default, there is an abrupt transition between the output values + /// from the two source modules at the selection-range boundary. To + /// smooth the transition, pass a non-zero value to the SetEdgeFalloff() + /// method. Higher values result in a smoother transition. + /// + /// This noise module requires three source modules. + class Select: public Module + { + + public: + + /// Constructor. + /// + /// The default falloff value at the edge transition is set to + /// noise::module::DEFAULT_SELECT_EDGE_FALLOFF. + /// + /// The default lower bound of the selection range is set to + /// noise::module::DEFAULT_SELECT_LOWER_BOUND. + /// + /// The default upper bound of the selection range is set to + /// noise::module::DEFAULT_SELECT_UPPER_BOUND. + Select (); + + /// Returns the control module. + /// + /// @returns A reference to the control module. + /// + /// @pre A control module has been added to this noise module via a + /// call to SetSourceModule() or SetControlModule(). + /// + /// @throw noise::ExceptionNoModule See the preconditions for more + /// information. + /// + /// The control module determines the output value to select. If the + /// output value from the control module is within a range of values + /// known as the selection range, the GetValue() method outputs + /// the value from the source module with an index value of 1. + /// Otherwise, this method outputs the value from the source module + /// with an index value of 0. + const Module& GetControlModule () const + { + if (m_pSourceModule == NULL || m_pSourceModule[2] == NULL) { + throw noise::ExceptionNoModule (); + } + return *(m_pSourceModule[2]); + } + + /// Returns the falloff value at the edge transition. + /// + /// @returns The falloff value at the edge transition. + /// + /// The falloff value is the width of the edge transition at either + /// edge of the selection range. + /// + /// By default, there is an abrupt transition between the output + /// values from the two source modules at the selection-range + /// boundary. + double GetEdgeFalloff () const + { + return m_edgeFalloff; + } + + /// Returns the lower bound of the selection range. + /// + /// @returns The lower bound of the selection range. + /// + /// If the output value from the control module is within the + /// selection range, the GetValue() method outputs the value from the + /// source module with an index value of 1. Otherwise, this method + /// outputs the value from the source module with an index value of 0. + double GetLowerBound () const + { + return m_lowerBound; + } + + virtual int GetSourceModuleCount () const + { + return 3; + } + + /// Returns the upper bound of the selection range. + /// + /// @returns The upper bound of the selection range. + /// + /// If the output value from the control module is within the + /// selection range, the GetValue() method outputs the value from the + /// source module with an index value of 1. Otherwise, this method + /// outputs the value from the source module with an index value of 0. + double GetUpperBound () const + { + return m_upperBound; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the lower and upper bounds of the selection range. + /// + /// @param lowerBound The lower bound. + /// @param upperBound The upper bound. + /// + /// @pre The lower bound must be less than or equal to the upper + /// bound. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// If the output value from the control module is within the + /// selection range, the GetValue() method outputs the value from the + /// source module with an index value of 1. Otherwise, this method + /// outputs the value from the source module with an index value of 0. + void SetBounds (double lowerBound, double upperBound); + + /// Sets the control module. + /// + /// @param controlModule The control module. + /// + /// The control module determines the output value to select. If the + /// output value from the control module is within a range of values + /// known as the selection range, the GetValue() method outputs + /// the value from the source module with an index value of 1. + /// Otherwise, this method outputs the value from the source module + /// with an index value of 0. + /// + /// This method assigns the control module an index value of 2. + /// Passing the control module to this method produces the same + /// results as passing the control module to the SetSourceModule() + /// method while assigning that noise module an index value of 2. + /// + /// This control module must exist throughout the lifetime of this + /// noise module unless another control module replaces that control + /// module. + void SetControlModule (const Module& controlModule) + { + assert (m_pSourceModule != NULL); + m_pSourceModule[2] = &controlModule; + } + + /// Sets the falloff value at the edge transition. + /// + /// @param edgeFalloff The falloff value at the edge transition. + /// + /// The falloff value is the width of the edge transition at either + /// edge of the selection range. + /// + /// By default, there is an abrupt transition between the values from + /// the two source modules at the boundaries of the selection range. + /// + /// For example, if the selection range is 0.5 to 0.8, and the edge + /// falloff value is 0.1, then the GetValue() method outputs: + /// - the output value from the source module with an index value of 0 + /// if the output value from the control module is less than 0.4 + /// ( = 0.5 - 0.1). + /// - a linear blend between the two output values from the two source + /// modules if the output value from the control module is between + /// 0.4 ( = 0.5 - 0.1) and 0.6 ( = 0.5 + 0.1). + /// - the output value from the source module with an index value of 1 + /// if the output value from the control module is between 0.6 + /// ( = 0.5 + 0.1) and 0.7 ( = 0.8 - 0.1). + /// - a linear blend between the output values from the two source + /// modules if the output value from the control module is between + /// 0.7 ( = 0.8 - 0.1 ) and 0.9 ( = 0.8 + 0.1). + /// - the output value from the source module with an index value of 0 + /// if the output value from the control module is greater than 0.9 + /// ( = 0.8 + 0.1). + void SetEdgeFalloff (double edgeFalloff); + + protected: + + /// Edge-falloff value. + double m_edgeFalloff; + + /// Lower bound of the selection range. + double m_lowerBound; + + /// Upper bound of the selection range. + double m_upperBound; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/spheres.cpp b/src/libnoise/src/module/spheres.cpp new file mode 100644 index 00000000000..4b625b6ff84 --- /dev/null +++ b/src/libnoise/src/module/spheres.cpp @@ -0,0 +1,45 @@ +// spheres.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../misc.h" +#include "spheres.h" + +using namespace noise::module; + +Spheres::Spheres (): + Module (GetSourceModuleCount ()), + m_frequency (DEFAULT_SPHERES_FREQUENCY) +{ +} + +double Spheres::GetValue (double x, double y, double z) const +{ + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + double distFromCenter = sqrt (x * x + y * y + z * z); + double distFromSmallerSphere = distFromCenter - floor (distFromCenter); + double distFromLargerSphere = 1.0 - distFromSmallerSphere; + double nearestDist = GetMin (distFromSmallerSphere, distFromLargerSphere); + return 1.0 - (nearestDist * 4.0); // Puts it in the -1.0 to +1.0 range. +} diff --git a/src/libnoise/src/module/spheres.h b/src/libnoise/src/module/spheres.h new file mode 100644 index 00000000000..059ac6c9e79 --- /dev/null +++ b/src/libnoise/src/module/spheres.h @@ -0,0 +1,127 @@ +// spheres.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_SPHERES_H +#define NOISE_MODULE_SPHERES_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup generatormodules + /// @{ + + /// Default frequency value for the noise::module::Spheres noise module. + const double DEFAULT_SPHERES_FREQUENCY = 1.0; + + /// Noise module that outputs concentric spheres. + /// + /// @image html modulespheres.png + /// + /// This noise module outputs concentric spheres centered on the origin + /// like the concentric rings of an onion. + /// + /// The first sphere has a radius of 1.0. Each subsequent sphere has a + /// radius that is 1.0 unit larger than the previous sphere. + /// + /// The output value from this noise module is determined by the distance + /// between the input value and the the nearest spherical surface. The + /// input values that are located on a spherical surface are given the + /// output value 1.0 and the input values that are equidistant from two + /// spherical surfaces are given the output value -1.0. + /// + /// An application can change the frequency of the concentric spheres. + /// Increasing the frequency reduces the distances between spheres. To + /// specify the frequency, call the SetFrequency() method. + /// + /// This noise module, modified with some low-frequency, low-power + /// turbulence, is useful for generating agate-like textures. + /// + /// This noise module does not require any source modules. + class Spheres: public Module + { + + public: + + /// Constructor. + /// + /// The default frequency is set to + /// noise::module::DEFAULT_SPHERES_FREQUENCY. + Spheres (); + + /// Returns the frequency of the concentric spheres. + /// + /// @returns The frequency of the concentric spheres. + /// + /// Increasing the frequency increases the density of the concentric + /// spheres, reducing the distances between them. + double GetFrequency () const + { + return m_frequency; + } + + virtual int GetSourceModuleCount () const + { + return 0; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the frequenct of the concentric spheres. + /// + /// @param frequency The frequency of the concentric spheres. + /// + /// Increasing the frequency increases the density of the concentric + /// spheres, reducing the distances between them. + void SetFrequency (double frequency) + { + m_frequency = frequency; + } + + protected: + + /// Frequency of the concentric spheres. + double m_frequency; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/terrace.cpp b/src/libnoise/src/module/terrace.cpp new file mode 100644 index 00000000000..cfecaab8055 --- /dev/null +++ b/src/libnoise/src/module/terrace.cpp @@ -0,0 +1,160 @@ +// terrace.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../interp.h" +#include "../misc.h" +#include "terrace.h" + +using namespace noise::module; + +using namespace noise; + +Terrace::Terrace (): + Module (GetSourceModuleCount ()), + m_controlPointCount (0), + m_invertTerraces (false), + m_pControlPoints (NULL) +{ +} + +Terrace::~Terrace () +{ + delete[] m_pControlPoints; +} + +void Terrace::AddControlPoint (double value) +{ + // Find the insertion point for the new control point and insert the new + // point at that position. The control point array will remain sorted by + // value. + int insertionPos = FindInsertionPos (value); + InsertAtPos (insertionPos, value); +} + +void Terrace::ClearAllControlPoints () +{ + delete[] m_pControlPoints; + m_pControlPoints = NULL; + m_controlPointCount = 0; +} + +int Terrace::FindInsertionPos (double value) +{ + int insertionPos; + for (insertionPos = 0; insertionPos < m_controlPointCount; insertionPos++) { + if (value < m_pControlPoints[insertionPos]) { + // We found the array index in which to insert the new control point. + // Exit now. + break; + } else if (value == m_pControlPoints[insertionPos]) { + // Each control point is required to contain a unique value, so throw + // an exception. + throw noise::ExceptionInvalidParam (); + } + } + return insertionPos; +} + +double Terrace::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + assert (m_controlPointCount >= 2); + + // Get the output value from the source module. + double sourceModuleValue = m_pSourceModule[0]->GetValue (x, y, z); + + // Find the first element in the control point array that has a value + // larger than the output value from the source module. + int indexPos; + for (indexPos = 0; indexPos < m_controlPointCount; indexPos++) { + if (sourceModuleValue < m_pControlPoints[indexPos]) { + break; + } + } + + // Find the two nearest control points so that we can map their values + // onto a quadratic curve. + int index0 = ClampValue (indexPos - 1, 0, m_controlPointCount - 1); + int index1 = ClampValue (indexPos , 0, m_controlPointCount - 1); + + // If some control points are missing (which occurs if the output value from + // the source module is greater than the largest value or less than the + // smallest value of the control point array), get the value of the nearest + // control point and exit now. + if (index0 == index1) { + return m_pControlPoints[index1]; + } + + // Compute the alpha value used for linear interpolation. + double value0 = m_pControlPoints[index0]; + double value1 = m_pControlPoints[index1]; + double alpha = (sourceModuleValue - value0) / (value1 - value0); + if (m_invertTerraces) { + alpha = 1.0 - alpha; + SwapValues (value0, value1); + } + + // Squaring the alpha produces the terrace effect. + alpha *= alpha; + + // Now perform the linear interpolation given the alpha value. + return LinearInterp (value0, value1, alpha); +} + +void Terrace::InsertAtPos (int insertionPos, double value) +{ + // Make room for the new control point at the specified position within + // the control point array. The position is determined by the value of + // the control point; the control points must be sorted by value within + // that array. + double* newControlPoints = new double[m_controlPointCount + 1]; + for (int i = 0; i < m_controlPointCount; i++) { + if (i < insertionPos) { + newControlPoints[i] = m_pControlPoints[i]; + } else { + newControlPoints[i + 1] = m_pControlPoints[i]; + } + } + delete[] m_pControlPoints; + m_pControlPoints = newControlPoints; + ++m_controlPointCount; + + // Now that we've made room for the new control point within the array, + // add the new control point. + m_pControlPoints[insertionPos] = value; +} + +void Terrace::MakeControlPoints (int controlPointCount) +{ + if (controlPointCount < 2) { + throw noise::ExceptionInvalidParam (); + } + + ClearAllControlPoints (); + + double terraceStep = 2.0 / ((double)controlPointCount - 1.0); + double curValue = -1.0; + for (int i = 0; i < (int)controlPointCount; i++) { + AddControlPoint (curValue); + curValue += terraceStep; + } +} diff --git a/src/libnoise/src/module/terrace.h b/src/libnoise/src/module/terrace.h new file mode 100644 index 00000000000..c1f665ab10b --- /dev/null +++ b/src/libnoise/src/module/terrace.h @@ -0,0 +1,242 @@ +// terrace.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_TERRACE_H +#define NOISE_MODULE_TERRACE_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup modifiermodules + /// @{ + + /// Noise module that maps the output value from a source module onto a + /// terrace-forming curve. + /// + /// @image html moduleterrace.png + /// + /// This noise module maps the output value from the source module onto a + /// terrace-forming curve. The start of this curve has a slope of zero; + /// its slope then smoothly increases. This curve also contains + /// control points which resets the slope to zero at that point, + /// producing a "terracing" effect. Refer to the following illustration: + /// + /// @image html terrace.png + /// + /// To add a control point to this noise module, call the + /// AddControlPoint() method. + /// + /// An application must add a minimum of two control points to the curve. + /// If this is not done, the GetValue() method fails. The control points + /// can have any value, although no two control points can have the same + /// value. There is no limit to the number of control points that can be + /// added to the curve. + /// + /// This noise module clamps the output value from the source module if + /// that value is less than the value of the lowest control point or + /// greater than the value of the highest control point. + /// + /// This noise module is often used to generate terrain features such as + /// your stereotypical desert canyon. + /// + /// This noise module requires one source module. + class Terrace: public Module + { + + public: + + /// Constructor. + Terrace (); + + /// Destructor. + ~Terrace (); + + /// Adds a control point to the terrace-forming curve. + /// + /// @param value The value of the control point to add. + /// + /// @pre No two control points have the same value. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// Two or more control points define the terrace-forming curve. The + /// start of this curve has a slope of zero; its slope then smoothly + /// increases. At the control points, its slope resets to zero. + /// + /// It does not matter which order these points are added. + void AddControlPoint (double value); + + /// Deletes all the control points on the terrace-forming curve. + /// + /// @post All control points on the terrace-forming curve are deleted. + void ClearAllControlPoints (); + + /// Returns a pointer to the array of control points on the + /// terrace-forming curve. + /// + /// @returns A pointer to the array of control points in this noise + /// module. + /// + /// Two or more control points define the terrace-forming curve. The + /// start of this curve has a slope of zero; its slope then smoothly + /// increases. At the control points, its slope resets to zero. + /// + /// Before calling this method, call GetControlPointCount() to + /// determine the number of control points in this array. + /// + /// It is recommended that an application does not store this pointer + /// for later use since the pointer to the array may change if the + /// application calls another method of this object. + const double* GetControlPointArray () const + { + return m_pControlPoints; + } + + /// Returns the number of control points on the terrace-forming curve. + /// + /// @returns The number of control points on the terrace-forming + /// curve. + int GetControlPointCount () const + { + return m_controlPointCount; + } + + virtual int GetSourceModuleCount () const + { + return 1; + } + + /// Enables or disables the inversion of the terrace-forming curve + /// between the control points. + /// + /// @param invert Specifies whether to invert the curve between the + /// control points. + void InvertTerraces (bool invert = true) + { + m_invertTerraces = invert; + } + + /// Determines if the terrace-forming curve between the control + /// points is inverted. + /// + /// @returns + /// - @a true if the curve between the control points is inverted. + /// - @a false if the curve between the control points is not + /// inverted. + bool IsTerracesInverted () const + { + return m_invertTerraces; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Creates a number of equally-spaced control points that range from + /// -1 to +1. + /// + /// @param controlPointCount The number of control points to generate. + /// + /// @pre The number of control points must be greater than or equal to + /// 2. + /// + /// @post The previous control points on the terrace-forming curve are + /// deleted. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// Two or more control points define the terrace-forming curve. The + /// start of this curve has a slope of zero; its slope then smoothly + /// increases. At the control points, its slope resets to zero. + void MakeControlPoints (int controlPointCount); + + protected: + + /// Determines the array index in which to insert the control point + /// into the internal control point array. + /// + /// @param value The value of the control point. + /// + /// @returns The array index in which to insert the control point. + /// + /// @pre No two control points have the same value. + /// + /// @throw noise::ExceptionInvalidParam An invalid parameter was + /// specified; see the preconditions for more information. + /// + /// By inserting the control point at the returned array index, this + /// class ensures that the control point array is sorted by value. + /// The code that maps a value onto the curve requires a sorted + /// control point array. + int FindInsertionPos (double value); + + /// Inserts the control point at the specified position in the + /// internal control point array. + /// + /// @param insertionPos The zero-based array position in which to + /// insert the control point. + /// @param value The value of the control point. + /// + /// To make room for this new control point, this method reallocates + /// the control point array and shifts all control points occurring + /// after the insertion position up by one. + /// + /// Because the curve mapping algorithm in this noise module requires + /// that all control points in the array be sorted by value, the new + /// control point should be inserted at the position in which the + /// order is still preserved. + void InsertAtPos (int insertionPos, double value); + + /// Number of control points stored in this noise module. + int m_controlPointCount; + + /// Determines if the terrace-forming curve between all control points + /// is inverted. + bool m_invertTerraces; + + /// Array that stores the control points. + double* m_pControlPoints; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/translatepoint.cpp b/src/libnoise/src/module/translatepoint.cpp new file mode 100644 index 00000000000..eecdf84ac40 --- /dev/null +++ b/src/libnoise/src/module/translatepoint.cpp @@ -0,0 +1,41 @@ +// translatepoint.cpp +// +// Copyright (C) 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "translatepoint.h" + +using namespace noise::module; + +TranslatePoint::TranslatePoint (): + Module (GetSourceModuleCount ()), + m_xTranslation (DEFAULT_TRANSLATE_POINT_X), + m_yTranslation (DEFAULT_TRANSLATE_POINT_Y), + m_zTranslation (DEFAULT_TRANSLATE_POINT_Z) +{ +} + +double TranslatePoint::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + return m_pSourceModule[0]->GetValue (x + m_xTranslation, y + m_yTranslation, + z + m_zTranslation); +} diff --git a/src/libnoise/src/module/translatepoint.h b/src/libnoise/src/module/translatepoint.h new file mode 100644 index 00000000000..46adac42cb3 --- /dev/null +++ b/src/libnoise/src/module/translatepoint.h @@ -0,0 +1,223 @@ +// translatepoint.h +// +// Copyright (C) 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_TRANSLATEPOINT_H +#define NOISE_MODULE_TRANSLATEPOINT_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup transformermodules + /// @{ + + /// Default translation factor applied to the @a x coordinate for the + /// noise::module::TranslatePoint noise module. + const double DEFAULT_TRANSLATE_POINT_X = 0.0; + + /// Default translation factor applied to the @a y coordinate for the + /// noise::module::TranslatePoint noise module. + const double DEFAULT_TRANSLATE_POINT_Y = 0.0; + + /// Default translation factor applied to the @a z coordinate for the + /// noise::module::TranslatePoint noise module. + const double DEFAULT_TRANSLATE_POINT_Z = 0.0; + + /// Noise module that moves the coordinates of the input value before + /// returning the output value from a source module. + /// + /// @image html moduletranslatepoint.png + /// + /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates of + /// the input value by a translation amount before returning the output + /// value from the source module. To set the translation amount, call + /// the SetTranslation() method. To set the translation amount to + /// apply to the individual @a x, @a y, or @a z coordinates, call the + /// SetXTranslation(), SetYTranslation() or SetZTranslation() methods, + /// respectively. + /// + /// This noise module requires one source module. + class TranslatePoint: public Module + { + + public: + + /// Constructor. + /// + /// The default translation amount to apply to the @a x coordinate is + /// set to noise::module::DEFAULT_TRANSLATE_POINT_X. + /// + /// The default translation amount to apply to the @a y coordinate is + /// set to noise::module::DEFAULT_TRANSLATE_POINT_Y. + /// + /// The default translation amount to apply to the @a z coordinate is + /// set to noise::module::DEFAULT_TRANSLATE_POINT_Z. + TranslatePoint (); + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Returns the translation amount to apply to the @a x coordinate of + /// the input value. + /// + /// @returns The translation amount to apply to the @a x coordinate. + double GetXTranslation () const + { + return m_xTranslation; + } + + /// Returns the translation amount to apply to the @a y coordinate of + /// the input value. + /// + /// @returns The translation amount to apply to the @a y coordinate. + double GetYTranslation () const + { + return m_yTranslation; + } + + /// Returns the translation amount to apply to the @a z coordinate of + /// the input value. + /// + /// @returns The translation amount to apply to the @a z coordinate. + double GetZTranslation () const + { + return m_zTranslation; + } + + /// Sets the translation amount to apply to the input value. + /// + /// @param translation The translation amount to apply. + /// + /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates + /// of the input value by a translation amount before returning the + /// output value from the source module + void SetTranslation (double translation) + { + m_xTranslation = translation; + m_yTranslation = translation; + m_zTranslation = translation; + } + + /// Sets the translation amounts to apply to the ( @a x, @a y, @a z ) + /// coordinates of the input value. + /// + /// @param xTranslation The translation amount to apply to the @a x + /// coordinate. + /// @param yTranslation The translation amount to apply to the @a y + /// coordinate. + /// @param zTranslation The translation amount to apply to the @a z + /// coordinate. + /// + /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates + /// of the input value by a translation amount before returning the + /// output value from the source module + void SetTranslation (double xTranslation, double yTranslation, + double zTranslation) + { + m_xTranslation = xTranslation; + m_yTranslation = yTranslation; + m_zTranslation = zTranslation; + } + + /// Sets the translation amount to apply to the @a x coordinate of the + /// input value. + /// + /// @param xTranslation The translation amount to apply to the @a x + /// coordinate. + /// + /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates + /// of the input value by a translation amount before returning the + /// output value from the source module + void SetXTranslation (double xTranslation) + { + m_xTranslation = xTranslation; + } + + /// Sets the translation amount to apply to the @a y coordinate of the + /// input value. + /// + /// @param yTranslation The translation amount to apply to the @a y + /// coordinate. + /// + /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates + /// of the input value by a translation amount before returning the + /// output value from the source module + void SetYTranslation (double yTranslation) + { + m_yTranslation = yTranslation; + } + + /// Sets the translation amount to apply to the @a z coordinate of the + /// input value. + /// + /// @param zTranslation The translation amount to apply to the @a z + /// coordinate. + /// + /// The GetValue() method moves the ( @a x, @a y, @a z ) coordinates + /// of the input value by a translation amount before returning the + /// output value from the source module + void SetZTranslation (double zTranslation) + { + m_zTranslation = zTranslation; + } + + protected: + + /// Translation amount applied to the @a x coordinate of the input + /// value. + double m_xTranslation; + + /// Translation amount applied to the @a y coordinate of the input + /// value. + double m_yTranslation; + + /// Translation amount applied to the @a z coordinate of the input + /// value. + double m_zTranslation; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/turbulence.cpp b/src/libnoise/src/module/turbulence.cpp new file mode 100644 index 00000000000..82a3ed94e2e --- /dev/null +++ b/src/libnoise/src/module/turbulence.cpp @@ -0,0 +1,91 @@ +// turbulence.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "turbulence.h" + +using namespace noise::module; + +Turbulence::Turbulence (): + Module (GetSourceModuleCount ()), + m_power (DEFAULT_TURBULENCE_POWER) +{ + SetSeed (DEFAULT_TURBULENCE_SEED); + SetFrequency (DEFAULT_TURBULENCE_FREQUENCY); + SetRoughness (DEFAULT_TURBULENCE_ROUGHNESS); +} + +double Turbulence::GetFrequency () const +{ + // Since each noise::module::Perlin noise module has the same frequency, it + // does not matter which module we use to retrieve the frequency. + return m_xDistortModule.GetFrequency (); +} + +int Turbulence::GetSeed () const +{ + return m_xDistortModule.GetSeed (); +} + +double Turbulence::GetValue (double x, double y, double z) const +{ + assert (m_pSourceModule[0] != NULL); + + // Get the values from the three noise::module::Perlin noise modules and + // add each value to each coordinate of the input value. There are also + // some offsets added to the coordinates of the input values. This prevents + // the distortion modules from returning zero if the (x, y, z) coordinates, + // when multiplied by the frequency, are near an integer boundary. This is + // due to a property of gradient coherent noise, which returns zero at + // integer boundaries. + double x0, y0, z0; + double x1, y1, z1; + double x2, y2, z2; + x0 = x + (12414.0 / 65536.0); + y0 = y + (65124.0 / 65536.0); + z0 = z + (31337.0 / 65536.0); + x1 = x + (26519.0 / 65536.0); + y1 = y + (18128.0 / 65536.0); + z1 = z + (60493.0 / 65536.0); + x2 = x + (53820.0 / 65536.0); + y2 = y + (11213.0 / 65536.0); + z2 = z + (44845.0 / 65536.0); + double xDistort = x + (m_xDistortModule.GetValue (x0, y0, z0) + * m_power); + double yDistort = y + (m_yDistortModule.GetValue (x1, y1, z1) + * m_power); + double zDistort = z + (m_zDistortModule.GetValue (x2, y2, z2) + * m_power); + + // Retrieve the output value at the offsetted input value instead of the + // original input value. + return m_pSourceModule[0]->GetValue (xDistort, yDistort, zDistort); +} + +void Turbulence::SetSeed (int seed) +{ + // Set the seed of each noise::module::Perlin noise modules. To prevent any + // sort of weird artifacting, use a slightly different seed for each noise + // module. + m_xDistortModule.SetSeed (seed ); + m_yDistortModule.SetSeed (seed + 1); + m_zDistortModule.SetSeed (seed + 2); +} diff --git a/src/libnoise/src/module/turbulence.h b/src/libnoise/src/module/turbulence.h new file mode 100644 index 00000000000..1561561a0eb --- /dev/null +++ b/src/libnoise/src/module/turbulence.h @@ -0,0 +1,269 @@ +// turbulence.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_TURBULENCE_H +#define NOISE_MODULE_TURBULENCE_H + +#include "perlin.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup transformermodules + /// @{ + + /// Default frequency for the noise::module::Turbulence noise module. + const double DEFAULT_TURBULENCE_FREQUENCY = DEFAULT_PERLIN_FREQUENCY; + + /// Default power for the noise::module::Turbulence noise module. + const double DEFAULT_TURBULENCE_POWER = 1.0; + + /// Default roughness for the noise::module::Turbulence noise module. + const int DEFAULT_TURBULENCE_ROUGHNESS = 3; + + /// Default noise seed for the noise::module::Turbulence noise module. + const int DEFAULT_TURBULENCE_SEED = DEFAULT_PERLIN_SEED; + + /// Noise module that randomly displaces the input value before + /// returning the output value from a source module. + /// + /// @image html moduleturbulence.png + /// + /// @a Turbulence is the pseudo-random displacement of the input value. + /// The GetValue() method randomly displaces the ( @a x, @a y, @a z ) + /// coordinates of the input value before retrieving the output value from + /// the source module. To control the turbulence, an application can + /// modify its frequency, its power, and its roughness. + /// + /// The frequency of the turbulence determines how rapidly the + /// displacement amount changes. To specify the frequency, call the + /// SetFrequency() method. + /// + /// The power of the turbulence determines the scaling factor that is + /// applied to the displacement amount. To specify the power, call the + /// SetPower() method. + /// + /// The roughness of the turbulence determines the roughness of the + /// changes to the displacement amount. Low values smoothly change the + /// displacement amount. High values roughly change the displacement + /// amount, which produces more "kinky" changes. To specify the + /// roughness, call the SetRoughness() method. + /// + /// Use of this noise module may require some trial and error. Assuming + /// that you are using a generator module as the source module, you + /// should first: + /// - Set the frequency to the same frequency as the source module. + /// - Set the power to the reciprocal of the frequency. + /// + /// From these initial frequency and power values, modify these values + /// until this noise module produce the desired changes in your terrain or + /// texture. For example: + /// - Low frequency (1/8 initial frequency) and low power (1/8 initial + /// power) produces very minor, almost unnoticeable changes. + /// - Low frequency (1/8 initial frequency) and high power (8 times + /// initial power) produces "ropey" lava-like terrain or marble-like + /// textures. + /// - High frequency (8 times initial frequency) and low power (1/8 + /// initial power) produces a noisy version of the initial terrain or + /// texture. + /// - High frequency (8 times initial frequency) and high power (8 times + /// initial power) produces nearly pure noise, which isn't entirely + /// useful. + /// + /// Displacing the input values result in more realistic terrain and + /// textures. If you are generating elevations for terrain height maps, + /// you can use this noise module to produce more realistic mountain + /// ranges or terrain features that look like flowing lava rock. If you + /// are generating values for textures, you can use this noise module to + /// produce realistic marble-like or "oily" textures. + /// + /// Internally, there are three noise::module::Perlin noise modules + /// that displace the input value; one for the @a x, one for the @a y, + /// and one for the @a z coordinate. + /// + /// This noise module requires one source module. + class Turbulence: public Module + { + + public: + + /// Constructor. + /// + /// The default frequency is set to + /// noise::module::DEFAULT_TURBULENCE_FREQUENCY. + /// + /// The default power is set to + /// noise::module::DEFAULT_TURBULENCE_POWER. + /// + /// The default roughness is set to + /// noise::module::DEFAULT_TURBULENCE_ROUGHNESS. + /// + /// The default seed value is set to + /// noise::module::DEFAULT_TURBULENCE_SEED. + Turbulence (); + + /// Returns the frequency of the turbulence. + /// + /// @returns The frequency of the turbulence. + /// + /// The frequency of the turbulence determines how rapidly the + /// displacement amount changes. + double GetFrequency () const; + + /// Returns the power of the turbulence. + /// + /// @returns The power of the turbulence. + /// + /// The power of the turbulence determines the scaling factor that is + /// applied to the displacement amount. + double GetPower () const + { + return m_power; + } + + /// Returns the roughness of the turbulence. + /// + /// @returns The roughness of the turbulence. + /// + /// The roughness of the turbulence determines the roughness of the + /// changes to the displacement amount. Low values smoothly change + /// the displacement amount. High values roughly change the + /// displacement amount, which produces more "kinky" changes. + int GetRoughnessCount () const + { + return m_xDistortModule.GetOctaveCount (); + } + + /// Returns the seed value of the internal Perlin-noise modules that + /// are used to displace the input values. + /// + /// @returns The seed value. + /// + /// Internally, there are three noise::module::Perlin noise modules + /// that displace the input value; one for the @a x, one for the @a y, + /// and one for the @a z coordinate. + int GetSeed () const; + + virtual int GetSourceModuleCount () const + { + return 1; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the frequency of the turbulence. + /// + /// @param frequency The frequency of the turbulence. + /// + /// The frequency of the turbulence determines how rapidly the + /// displacement amount changes. + void SetFrequency (double frequency) + { + // Set the frequency of each Perlin-noise module. + m_xDistortModule.SetFrequency (frequency); + m_yDistortModule.SetFrequency (frequency); + m_zDistortModule.SetFrequency (frequency); + } + + /// Sets the power of the turbulence. + /// + /// @param power The power of the turbulence. + /// + /// The power of the turbulence determines the scaling factor that is + /// applied to the displacement amount. + void SetPower (double power) + { + m_power = power; + } + + /// Sets the roughness of the turbulence. + /// + /// @param roughness The roughness of the turbulence. + /// + /// The roughness of the turbulence determines the roughness of the + /// changes to the displacement amount. Low values smoothly change + /// the displacement amount. High values roughly change the + /// displacement amount, which produces more "kinky" changes. + /// + /// Internally, there are three noise::module::Perlin noise modules + /// that displace the input value; one for the @a x, one for the @a y, + /// and one for the @a z coordinate. The roughness value is equal to + /// the number of octaves used by the noise::module::Perlin noise + /// modules. + void SetRoughness (int roughness) + { + // Set the octave count for each Perlin-noise module. + m_xDistortModule.SetOctaveCount (roughness); + m_yDistortModule.SetOctaveCount (roughness); + m_zDistortModule.SetOctaveCount (roughness); + } + + /// Sets the seed value of the internal noise modules that are used to + /// displace the input values. + /// + /// @param seed The seed value. + /// + /// Internally, there are three noise::module::Perlin noise modules + /// that displace the input value; one for the @a x, one for the @a y, + /// and one for the @a z coordinate. This noise module assigns the + /// following seed values to the noise::module::Perlin noise modules: + /// - It assigns the seed value (@a seed + 0) to the @a x noise module. + /// - It assigns the seed value (@a seed + 1) to the @a y noise module. + /// - It assigns the seed value (@a seed + 2) to the @a z noise module. + void SetSeed (int seed); + + protected: + + /// The power (scale) of the displacement. + double m_power; + + /// Noise module that displaces the @a x coordinate. + Perlin m_xDistortModule; + + /// Noise module that displaces the @a y coordinate. + Perlin m_yDistortModule; + + /// Noise module that displaces the @a z coordinate. + Perlin m_zDistortModule; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/module/voronoi.cpp b/src/libnoise/src/module/voronoi.cpp new file mode 100644 index 00000000000..759e2a93c9b --- /dev/null +++ b/src/libnoise/src/module/voronoi.cpp @@ -0,0 +1,101 @@ +// voronoi.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "../mathconsts.h" +#include "voronoi.h" + +using namespace noise::module; + +Voronoi::Voronoi (): + Module (GetSourceModuleCount ()), + m_displacement (DEFAULT_VORONOI_DISPLACEMENT), + m_enableDistance (false ), + m_frequency (DEFAULT_VORONOI_FREQUENCY ), + m_seed (DEFAULT_VORONOI_SEED ) +{ +} + +double Voronoi::GetValue (double x, double y, double z) const +{ + // This method could be more efficient by caching the seed values. Fix + // later. + + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + + int xInt = (x > 0.0? (int)x: (int)x - 1); + int yInt = (y > 0.0? (int)y: (int)y - 1); + int zInt = (z > 0.0? (int)z: (int)z - 1); + + double minDist = 2147483647.0; + double xCandidate = 0; + double yCandidate = 0; + double zCandidate = 0; + + // Inside each unit cube, there is a seed point at a random position. Go + // through each of the nearby cubes until we find a cube with a seed point + // that is closest to the specified position. + for (int zCur = zInt - 2; zCur <= zInt + 2; zCur++) { + for (int yCur = yInt - 2; yCur <= yInt + 2; yCur++) { + for (int xCur = xInt - 2; xCur <= xInt + 2; xCur++) { + + // Calculate the position and distance to the seed point inside of + // this unit cube. + double xPos = xCur + ValueNoise3D (xCur, yCur, zCur, m_seed ); + double yPos = yCur + ValueNoise3D (xCur, yCur, zCur, m_seed + 1); + double zPos = zCur + ValueNoise3D (xCur, yCur, zCur, m_seed + 2); + double xDist = xPos - x; + double yDist = yPos - y; + double zDist = zPos - z; + double dist = xDist * xDist + yDist * yDist + zDist * zDist; + + if (dist < minDist) { + // This seed point is closer to any others found so far, so record + // this seed point. + minDist = dist; + xCandidate = xPos; + yCandidate = yPos; + zCandidate = zPos; + } + } + } + } + + double value; + if (m_enableDistance) { + // Determine the distance to the nearest seed point. + double xDist = xCandidate - x; + double yDist = yCandidate - y; + double zDist = zCandidate - z; + value = (sqrt (xDist * xDist + yDist * yDist + zDist * zDist) + ) * SQRT_3 - 1.0; + } else { + value = 0.0; + } + + // Return the calculated distance with the displacement value applied. + return value + (m_displacement * (double)ValueNoise3D ( + (int)(floor (xCandidate)), + (int)(floor (yCandidate)), + (int)(floor (zCandidate)))); +} diff --git a/src/libnoise/src/module/voronoi.h b/src/libnoise/src/module/voronoi.h new file mode 100644 index 00000000000..16a8783bbfa --- /dev/null +++ b/src/libnoise/src/module/voronoi.h @@ -0,0 +1,246 @@ +// voronoi.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_MODULE_VORONOI_H +#define NOISE_MODULE_VORONOI_H + +#include "modulebase.h" + +namespace noise +{ + + namespace module + { + + /// @addtogroup libnoise + /// @{ + + /// @addtogroup modules + /// @{ + + /// @addtogroup generatormodules + /// @{ + + /// Default displacement to apply to each cell for the + /// noise::module::Voronoi noise module. + const double DEFAULT_VORONOI_DISPLACEMENT = 1.0; + + /// Default frequency of the seed points for the noise::module::Voronoi + /// noise module. + const double DEFAULT_VORONOI_FREQUENCY = 1.0; + + /// Default seed of the noise function for the noise::module::Voronoi + /// noise module. + const int DEFAULT_VORONOI_SEED = 0; + + /// Noise module that outputs Voronoi cells. + /// + /// @image html modulevoronoi.png + /// + /// In mathematics, a Voronoi cell is a region containing all the + /// points that are closer to a specific seed point than to any + /// other seed point. These cells mesh with one another, producing + /// polygon-like formations. + /// + /// By default, this noise module randomly places a seed point within + /// each unit cube. By modifying the frequency of the seed points, + /// an application can change the distance between seed points. The + /// higher the frequency, the closer together this noise module places + /// the seed points, which reduces the size of the cells. To specify the + /// frequency of the cells, call the SetFrequency() method. + /// + /// This noise module assigns each Voronoi cell with a random constant + /// value from a coherent-noise function. The displacement value + /// controls the range of random values to assign to each cell. The + /// range of random values is +/- the displacement value. Call the + /// SetDisplacement() method to specify the displacement value. + /// + /// To modify the random positions of the seed points, call the SetSeed() + /// method. + /// + /// This noise module can optionally add the distance from the nearest + /// seed to the output value. To enable this feature, call the + /// EnableDistance() method. This causes the points in the Voronoi cells + /// to increase in value the further away that point is from the nearest + /// seed point. + /// + /// Voronoi cells are often used to generate cracked-mud terrain + /// formations or crystal-like textures + /// + /// This noise module requires no source modules. + class Voronoi: public Module + { + + public: + + /// Constructor. + /// + /// The default displacement value is set to + /// noise::module::DEFAULT_VORONOI_DISPLACEMENT. + /// + /// The default frequency is set to + /// noise::module::DEFAULT_VORONOI_FREQUENCY. + /// + /// The default seed value is set to + /// noise::module::DEFAULT_VORONOI_SEED. + Voronoi (); + + /// Enables or disables applying the distance from the nearest seed + /// point to the output value. + /// + /// @param enable Specifies whether to apply the distance to the + /// output value or not. + /// + /// Applying the distance from the nearest seed point to the output + /// value causes the points in the Voronoi cells to increase in value + /// the further away that point is from the nearest seed point. + /// Setting this value to @a true (and setting the displacement to a + /// near-zero value) causes this noise module to generate cracked mud + /// formations. + void EnableDistance (bool enable = true) + { + m_enableDistance = enable; + } + + /// Returns the displacement value of the Voronoi cells. + /// + /// @returns The displacement value of the Voronoi cells. + /// + /// This noise module assigns each Voronoi cell with a random constant + /// value from a coherent-noise function. The displacement + /// value controls the range of random values to assign to each + /// cell. The range of random values is +/- the displacement value. + double GetDisplacement () const + { + return m_displacement; + } + + /// Returns the frequency of the seed points. + /// + /// @returns The frequency of the seed points. + /// + /// The frequency determines the size of the Voronoi cells and the + /// distance between these cells. + double GetFrequency () const + { + return m_frequency; + } + + virtual int GetSourceModuleCount () const + { + return 0; + } + + /// Returns the seed value used by the Voronoi cells + /// + /// @returns The seed value. + /// + /// The positions of the seed values are calculated by a + /// coherent-noise function. By modifying the seed value, the output + /// of that function changes. + int GetSeed () const + { + return m_seed; + } + + /// Determines if the distance from the nearest seed point is applied + /// to the output value. + /// + /// @returns + /// - @a true if the distance is applied to the output value. + /// - @a false if not. + /// + /// Applying the distance from the nearest seed point to the output + /// value causes the points in the Voronoi cells to increase in value + /// the further away that point is from the nearest seed point. + bool IsDistanceEnabled () const + { + return m_enableDistance; + } + + virtual double GetValue (double x, double y, double z) const; + + /// Sets the displacement value of the Voronoi cells. + /// + /// @param displacement The displacement value of the Voronoi cells. + /// + /// This noise module assigns each Voronoi cell with a random constant + /// value from a coherent-noise function. The displacement + /// value controls the range of random values to assign to each + /// cell. The range of random values is +/- the displacement value. + void SetDisplacement (double displacement) + { + m_displacement = displacement; + } + + /// Sets the frequency of the seed points. + /// + /// @param frequency The frequency of the seed points. + /// + /// The frequency determines the size of the Voronoi cells and the + /// distance between these cells. + void SetFrequency (double frequency) + { + m_frequency = frequency; + } + + /// Sets the seed value used by the Voronoi cells + /// + /// @param seed The seed value. + /// + /// The positions of the seed values are calculated by a + /// coherent-noise function. By modifying the seed value, the output + /// of that function changes. + void SetSeed (int seed) + { + m_seed = seed; + } + + protected: + + /// Scale of the random displacement to apply to each Voronoi cell. + double m_displacement; + + /// Determines if the distance from the nearest seed point is applied to + /// the output value. + bool m_enableDistance; + + /// Frequency of the seed points. + double m_frequency; + + /// Seed value used by the coherent-noise function to determine the + /// positions of the seed points. + int m_seed; + + }; + + /// @} + + /// @} + + /// @} + + } + +} + +#endif diff --git a/src/libnoise/src/noise.h b/src/libnoise/src/noise.h new file mode 100644 index 00000000000..39aa75f762b --- /dev/null +++ b/src/libnoise/src/noise.h @@ -0,0 +1,74 @@ +// noise.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_H +#define NOISE_H + +/// @mainpage libnoise +/// +/// @section intro Introduction +/// +/// libnoise is a portable C++ library that is used to generate coherent +/// noise, a type of smoothly-changing noise. libnoise can generate Perlin +/// noise, ridged multifractal noise, and other types of coherent noise. +/// +/// Coherent noise is often used by graphics programmers to generate +/// natural-looking textures, planetary terrain, and other things. It can +/// also be used to move critters in a realistic way. +/// +/// libnoise is known to compile using the following compilers on the +/// following platforms: +/// - Microsoft Visual C++ 5.0 under Microsoft Windows 2000 Service Pack 4 +/// - gcc 3.3.4 under Gentoo Linux 10.0 (x86) +/// +/// It is not known if libnoise will compile on 64-bit platforms, although +/// there is a good change that it will. +/// +/// @section noise Noise Modules +/// +/// In libnoise, coherent-noise generators are encapsulated in classes called +/// noise modules. There are many different types of noise modules. +/// Some noise modules can combine or modify the outputs of other noise +/// modules in various ways; you can join these modules together to generate +/// very complex coherent noise. +/// +/// A noise module receives a 3-dimensional input value from the application, +/// computes the noise value given that input value, and returns the resulting +/// value back to the application. +/// +/// If the application passes the same input value to a noise module, the +/// noise module returns the same output value. +/// +/// All noise modules are derived from the noise::module::Module abstract +/// base class. +/// +/// @section contact Contact +/// +/// Contact jas for questions about libnoise. The spam-resistant email +/// address is jlbezigvins@gmzigail.com (For great email, take off every +/// zig.) + +#include "module/module.h" +#include "model/model.h" +#include "misc.h" + +#endif diff --git a/src/libnoise/src/noisegen.cpp b/src/libnoise/src/noisegen.cpp new file mode 100644 index 00000000000..fa9250b90fc --- /dev/null +++ b/src/libnoise/src/noisegen.cpp @@ -0,0 +1,220 @@ +// noisegen.cpp +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include "noisegen.h" +#include "interp.h" +#include "vectortable.h" + +using namespace noise; + +// Specifies the version of the coherent-noise functions to use. +// - Set to 2 to use the current version. +// - Set to 1 to use the flawed version from the original version of libnoise. +// If your application requires coherent-noise values that were generated by +// an earlier version of libnoise, change this constant to the appropriate +// value and recompile libnoise. +#define NOISE_VERSION 2 + +// These constants control certain parameters that all coherent-noise +// functions require. +#if (NOISE_VERSION == 1) +// Constants used by the original version of libnoise. +// Because X_NOISE_GEN is not relatively prime to the other values, and +// Z_NOISE_GEN is close to 256 (the number of random gradient vectors), +// patterns show up in high-frequency coherent noise. +const int X_NOISE_GEN = 1; +const int Y_NOISE_GEN = 31337; +const int Z_NOISE_GEN = 263; +const int SEED_NOISE_GEN = 1013; +const int SHIFT_NOISE_GEN = 13; +#else +// Constants used by the current version of libnoise. +const int X_NOISE_GEN = 1619; +const int Y_NOISE_GEN = 31337; +const int Z_NOISE_GEN = 6971; +const int SEED_NOISE_GEN = 1013; +const int SHIFT_NOISE_GEN = 8; +#endif + +double noise::GradientCoherentNoise3D (double x, double y, double z, int seed, + NoiseQuality noiseQuality) +{ + // Create a unit-length cube aligned along an integer boundary. This cube + // surrounds the input point. + int x0 = (x > 0.0? (int)x: (int)x - 1); + int x1 = x0 + 1; + int y0 = (y > 0.0? (int)y: (int)y - 1); + int y1 = y0 + 1; + int z0 = (z > 0.0? (int)z: (int)z - 1); + int z1 = z0 + 1; + + // Map the difference between the coordinates of the input value and the + // coordinates of the cube's outer-lower-left vertex onto an S-curve. + double xs = 0, ys = 0, zs = 0; + switch (noiseQuality) { + case QUALITY_FAST: + xs = (x - (double)x0); + ys = (y - (double)y0); + zs = (z - (double)z0); + break; + case QUALITY_STD: + xs = SCurve3 (x - (double)x0); + ys = SCurve3 (y - (double)y0); + zs = SCurve3 (z - (double)z0); + break; + case QUALITY_BEST: + xs = SCurve5 (x - (double)x0); + ys = SCurve5 (y - (double)y0); + zs = SCurve5 (z - (double)z0); + break; + } + + // Now calculate the noise values at each vertex of the cube. To generate + // the coherent-noise value at the input point, interpolate these eight + // noise values using the S-curve value as the interpolant (trilinear + // interpolation.) + double n0, n1, ix0, ix1, iy0, iy1; + n0 = GradientNoise3D (x, y, z, x0, y0, z0, seed); + n1 = GradientNoise3D (x, y, z, x1, y0, z0, seed); + ix0 = LinearInterp (n0, n1, xs); + n0 = GradientNoise3D (x, y, z, x0, y1, z0, seed); + n1 = GradientNoise3D (x, y, z, x1, y1, z0, seed); + ix1 = LinearInterp (n0, n1, xs); + iy0 = LinearInterp (ix0, ix1, ys); + n0 = GradientNoise3D (x, y, z, x0, y0, z1, seed); + n1 = GradientNoise3D (x, y, z, x1, y0, z1, seed); + ix0 = LinearInterp (n0, n1, xs); + n0 = GradientNoise3D (x, y, z, x0, y1, z1, seed); + n1 = GradientNoise3D (x, y, z, x1, y1, z1, seed); + ix1 = LinearInterp (n0, n1, xs); + iy1 = LinearInterp (ix0, ix1, ys); + + return LinearInterp (iy0, iy1, zs); +} + +double noise::GradientNoise3D (double fx, double fy, double fz, int ix, + int iy, int iz, int seed) +{ + // Randomly generate a gradient vector given the integer coordinates of the + // input value. This implementation generates a random number and uses it + // as an index into a normalized-vector lookup table. + int vectorIndex = ( + X_NOISE_GEN * ix + + Y_NOISE_GEN * iy + + Z_NOISE_GEN * iz + + SEED_NOISE_GEN * seed) + & 0xffffffff; + vectorIndex ^= (vectorIndex >> SHIFT_NOISE_GEN); + vectorIndex &= 0xff; + + double xvGradient = g_randomVectors[(vectorIndex << 2) ]; + double yvGradient = g_randomVectors[(vectorIndex << 2) + 1]; + double zvGradient = g_randomVectors[(vectorIndex << 2) + 2]; + + // Set up us another vector equal to the distance between the two vectors + // passed to this function. + double xvPoint = (fx - (double)ix); + double yvPoint = (fy - (double)iy); + double zvPoint = (fz - (double)iz); + + // Now compute the dot product of the gradient vector with the distance + // vector. The resulting value is gradient noise. Apply a scaling value + // so that this noise value ranges from -1.0 to 1.0. + return ((xvGradient * xvPoint) + + (yvGradient * yvPoint) + + (zvGradient * zvPoint)) * 2.12; +} + +int noise::IntValueNoise3D (int x, int y, int z, int seed) +{ + // All constants are primes and must remain prime in order for this noise + // function to work correctly. + int n = ( + X_NOISE_GEN * x + + Y_NOISE_GEN * y + + Z_NOISE_GEN * z + + SEED_NOISE_GEN * seed) + & 0x7fffffff; + n = (n >> 13) ^ n; + return (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; +} + +double noise::ValueCoherentNoise3D (double x, double y, double z, int seed, + NoiseQuality noiseQuality) +{ + // Create a unit-length cube aligned along an integer boundary. This cube + // surrounds the input point. + int x0 = (x > 0.0? (int)x: (int)x - 1); + int x1 = x0 + 1; + int y0 = (y > 0.0? (int)y: (int)y - 1); + int y1 = y0 + 1; + int z0 = (z > 0.0? (int)z: (int)z - 1); + int z1 = z0 + 1; + + // Map the difference between the coordinates of the input value and the + // coordinates of the cube's outer-lower-left vertex onto an S-curve. + double xs = 0, ys = 0, zs = 0; + switch (noiseQuality) { + case QUALITY_FAST: + xs = (x - (double)x0); + ys = (y - (double)y0); + zs = (z - (double)z0); + break; + case QUALITY_STD: + xs = SCurve3 (x - (double)x0); + ys = SCurve3 (y - (double)y0); + zs = SCurve3 (z - (double)z0); + break; + case QUALITY_BEST: + xs = SCurve5 (x - (double)x0); + ys = SCurve5 (y - (double)y0); + zs = SCurve5 (z - (double)z0); + break; + } + + // Now calculate the noise values at each vertex of the cube. To generate + // the coherent-noise value at the input point, interpolate these eight + // noise values using the S-curve value as the interpolant (trilinear + // interpolation.) + double n0, n1, ix0, ix1, iy0, iy1; + n0 = ValueNoise3D (x0, y0, z0, seed); + n1 = ValueNoise3D (x1, y0, z0, seed); + ix0 = LinearInterp (n0, n1, xs); + n0 = ValueNoise3D (x0, y1, z0, seed); + n1 = ValueNoise3D (x1, y1, z0, seed); + ix1 = LinearInterp (n0, n1, xs); + iy0 = LinearInterp (ix0, ix1, ys); + n0 = ValueNoise3D (x0, y0, z1, seed); + n1 = ValueNoise3D (x1, y0, z1, seed); + ix0 = LinearInterp (n0, n1, xs); + n0 = ValueNoise3D (x0, y1, z1, seed); + n1 = ValueNoise3D (x1, y1, z1, seed); + ix1 = LinearInterp (n0, n1, xs); + iy1 = LinearInterp (ix0, ix1, ys); + return LinearInterp (iy0, iy1, zs); +} + +double noise::ValueNoise3D (int x, int y, int z, int seed) +{ + return 1.0 - ((double)IntValueNoise3D (x, y, z, seed) / 1073741824.0); +} + diff --git a/src/libnoise/src/noisegen.h b/src/libnoise/src/noisegen.h new file mode 100644 index 00000000000..192ece9fce9 --- /dev/null +++ b/src/libnoise/src/noisegen.h @@ -0,0 +1,208 @@ +// noisegen.h +// +// Copyright (C) 2003, 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#ifndef NOISE_NOISEGEN_H +#define NOISE_NOISEGEN_H + +#include +#include "basictypes.h" + +namespace noise +{ + + /// @addtogroup libnoise + /// @{ + + /// Enumerates the noise quality. + enum NoiseQuality + { + + /// Generates coherent noise quickly. When a coherent-noise function with + /// this quality setting is used to generate a bump-map image, there are + /// noticeable "creasing" artifacts in the resulting image. This is + /// because the derivative of that function is discontinuous at integer + /// boundaries. + QUALITY_FAST = 0, + + /// Generates standard-quality coherent noise. When a coherent-noise + /// function with this quality setting is used to generate a bump-map + /// image, there are some minor "creasing" artifacts in the resulting + /// image. This is because the second derivative of that function is + /// discontinuous at integer boundaries. + QUALITY_STD = 1, + + /// Generates the best-quality coherent noise. When a coherent-noise + /// function with this quality setting is used to generate a bump-map + /// image, there are no "creasing" artifacts in the resulting image. This + /// is because the first and second derivatives of that function are + /// continuous at integer boundaries. + QUALITY_BEST = 2 + + }; + + /// Generates a gradient-coherent-noise value from the coordinates of a + /// three-dimensional input value. + /// + /// @param x The @a x coordinate of the input value. + /// @param y The @a y coordinate of the input value. + /// @param z The @a z coordinate of the input value. + /// @param seed The random number seed. + /// @param noiseQuality The quality of the coherent-noise. + /// + /// @returns The generated gradient-coherent-noise value. + /// + /// The return value ranges from -1.0 to +1.0. + /// + /// For an explanation of the difference between gradient noise and + /// value noise, see the comments for the GradientNoise3D() function. + double GradientCoherentNoise3D (double x, double y, double z, int seed = 0, + NoiseQuality noiseQuality = QUALITY_STD); + + /// Generates a gradient-noise value from the coordinates of a + /// three-dimensional input value and the integer coordinates of a + /// nearby three-dimensional value. + /// + /// @param fx The floating-point @a x coordinate of the input value. + /// @param fy The floating-point @a y coordinate of the input value. + /// @param fz The floating-point @a z coordinate of the input value. + /// @param ix The integer @a x coordinate of a nearby value. + /// @param iy The integer @a y coordinate of a nearby value. + /// @param iz The integer @a z coordinate of a nearby value. + /// @param seed The random number seed. + /// + /// @returns The generated gradient-noise value. + /// + /// @pre The difference between @a fx and @a ix must be less than or equal + /// to one. + /// + /// @pre The difference between @a fy and @a iy must be less than or equal + /// to one. + /// + /// @pre The difference between @a fz and @a iz must be less than or equal + /// to one. + /// + /// A gradient-noise function generates better-quality noise than a + /// value-noise function. Most noise modules use gradient noise for + /// this reason, although it takes much longer to calculate. + /// + /// The return value ranges from -1.0 to +1.0. + /// + /// This function generates a gradient-noise value by performing the + /// following steps: + /// - It first calculates a random normalized vector based on the + /// nearby integer value passed to this function. + /// - It then calculates a new value by adding this vector to the + /// nearby integer value passed to this function. + /// - It then calculates the dot product of the above-generated value + /// and the floating-point input value passed to this function. + /// + /// A noise function differs from a random-number generator because it + /// always returns the same output value if the same input value is passed + /// to it. + double GradientNoise3D (double fx, double fy, double fz, int ix, int iy, + int iz, int seed = 0); + + /// Generates an integer-noise value from the coordinates of a + /// three-dimensional input value. + /// + /// @param x The integer @a x coordinate of the input value. + /// @param y The integer @a y coordinate of the input value. + /// @param z The integer @a z coordinate of the input value. + /// @param seed A random number seed. + /// + /// @returns The generated integer-noise value. + /// + /// The return value ranges from 0 to 2147483647. + /// + /// A noise function differs from a random-number generator because it + /// always returns the same output value if the same input value is passed + /// to it. + int IntValueNoise3D (int x, int y, int z, int seed = 0); + + /// Modifies a floating-point value so that it can be stored in a + /// noise::int32 variable. + /// + /// @param n A floating-point number. + /// + /// @returns The modified floating-point number. + /// + /// This function does not modify @a n. + /// + /// In libnoise, the noise-generating algorithms are all integer-based; + /// they use variables of type noise::int32. Before calling a noise + /// function, pass the @a x, @a y, and @a z coordinates to this function to + /// ensure that these coordinates can be cast to a noise::int32 value. + /// + /// Although you could do a straight cast from double to noise::int32, the + /// resulting value may differ between platforms. By using this function, + /// you ensure that the resulting value is identical between platforms. + inline double MakeInt32Range (double n) + { + if (n >= 1073741824.0) { + return (2.0 * fmod (n, 1073741824.0)) - 1073741824.0; + } else if (n <= -1073741824.0) { + return (2.0 * fmod (n, 1073741824.0)) + 1073741824.0; + } else { + return n; + } + } + + /// Generates a value-coherent-noise value from the coordinates of a + /// three-dimensional input value. + /// + /// @param x The @a x coordinate of the input value. + /// @param y The @a y coordinate of the input value. + /// @param z The @a z coordinate of the input value. + /// @param seed The random number seed. + /// @param noiseQuality The quality of the coherent-noise. + /// + /// @returns The generated value-coherent-noise value. + /// + /// The return value ranges from -1.0 to +1.0. + /// + /// For an explanation of the difference between gradient noise and + /// value noise, see the comments for the GradientNoise3D() function. + double ValueCoherentNoise3D (double x, double y, double z, int seed = 0, + NoiseQuality noiseQuality = QUALITY_STD); + + /// Generates a value-noise value from the coordinates of a + /// three-dimensional input value. + /// + /// @param x The @a x coordinate of the input value. + /// @param y The @a y coordinate of the input value. + /// @param z The @a z coordinate of the input value. + /// @param seed A random number seed. + /// + /// @returns The generated value-noise value. + /// + /// The return value ranges from -1.0 to +1.0. + /// + /// A noise function differs from a random-number generator because it + /// always returns the same output value if the same input value is passed + /// to it. + double ValueNoise3D (int x, int y, int z, int seed = 0); + + /// @} + +} + +#endif diff --git a/src/libnoise/src/vectortable.h b/src/libnoise/src/vectortable.h new file mode 100644 index 00000000000..cc25429a76e --- /dev/null +++ b/src/libnoise/src/vectortable.h @@ -0,0 +1,290 @@ +// vectortable.h +// +// Written by Jason Bevins. Actually it's the output of a program written +// by me. I'm not going to copyright a bunch of random numbers (although +// you could probably do so in the States, the way things are going down +// there :-) +// +// This file is in the public domain. +// + +#ifndef NOISE_VECTORTABLE_H +#define NOISE_VECTORTABLE_H + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +namespace noise +{ + + // A table of 256 random normalized vectors. Each row is an (x, y, z, 0) + // coordinate. The 0 is used as padding so we can use bit shifts to index + // any row in the table. These vectors have an even statistical + // distribution, which improves the quality of the coherent noise + // generated by these vectors. For more information, see "GPU Gems", + // Chapter 5 - Implementing Improved Perlin Noise by Ken Perlin, + // specifically page 76. + double g_randomVectors[256 * 4] = + { + -0.763874, -0.596439, -0.246489, 0.0, + 0.396055, 0.904518, -0.158073, 0.0, + -0.499004, -0.8665, -0.0131631, 0.0, + 0.468724, -0.824756, 0.316346, 0.0, + 0.829598, 0.43195, 0.353816, 0.0, + -0.454473, 0.629497, -0.630228, 0.0, + -0.162349, -0.869962, -0.465628, 0.0, + 0.932805, 0.253451, 0.256198, 0.0, + -0.345419, 0.927299, -0.144227, 0.0, + -0.715026, -0.293698, -0.634413, 0.0, + -0.245997, 0.717467, -0.651711, 0.0, + -0.967409, -0.250435, -0.037451, 0.0, + 0.901729, 0.397108, -0.170852, 0.0, + 0.892657, -0.0720622, -0.444938, 0.0, + 0.0260084, -0.0361701, 0.999007, 0.0, + 0.949107, -0.19486, 0.247439, 0.0, + 0.471803, -0.807064, -0.355036, 0.0, + 0.879737, 0.141845, 0.453809, 0.0, + 0.570747, 0.696415, 0.435033, 0.0, + -0.141751, -0.988233, -0.0574584, 0.0, + -0.58219, -0.0303005, 0.812488, 0.0, + -0.60922, 0.239482, -0.755975, 0.0, + 0.299394, -0.197066, -0.933557, 0.0, + -0.851615, -0.220702, -0.47544, 0.0, + 0.848886, 0.341829, -0.403169, 0.0, + -0.156129, -0.687241, 0.709453, 0.0, + -0.665651, 0.626724, 0.405124, 0.0, + 0.595914, -0.674582, 0.43569, 0.0, + 0.171025, -0.509292, 0.843428, 0.0, + 0.78605, 0.536414, -0.307222, 0.0, + 0.18905, -0.791613, 0.581042, 0.0, + -0.294916, 0.844994, 0.446105, 0.0, + 0.342031, -0.58736, -0.7335, 0.0, + 0.57155, 0.7869, 0.232635, 0.0, + 0.885026, -0.408223, 0.223791, 0.0, + -0.789518, 0.571645, 0.223347, 0.0, + 0.774571, 0.31566, 0.548087, 0.0, + -0.79695, -0.0433603, -0.602487, 0.0, + -0.142425, -0.473249, -0.869339, 0.0, + -0.0698838, 0.170442, 0.982886, 0.0, + 0.687815, -0.484748, 0.540306, 0.0, + 0.543703, -0.534446, -0.647112, 0.0, + 0.97186, 0.184391, -0.146588, 0.0, + 0.707084, 0.485713, -0.513921, 0.0, + 0.942302, 0.331945, 0.043348, 0.0, + 0.499084, 0.599922, 0.625307, 0.0, + -0.289203, 0.211107, 0.9337, 0.0, + 0.412433, -0.71667, -0.56239, 0.0, + 0.87721, -0.082816, 0.47291, 0.0, + -0.420685, -0.214278, 0.881538, 0.0, + 0.752558, -0.0391579, 0.657361, 0.0, + 0.0765725, -0.996789, 0.0234082, 0.0, + -0.544312, -0.309435, -0.779727, 0.0, + -0.455358, -0.415572, 0.787368, 0.0, + -0.874586, 0.483746, 0.0330131, 0.0, + 0.245172, -0.0838623, 0.965846, 0.0, + 0.382293, -0.432813, 0.81641, 0.0, + -0.287735, -0.905514, 0.311853, 0.0, + -0.667704, 0.704955, -0.239186, 0.0, + 0.717885, -0.464002, -0.518983, 0.0, + 0.976342, -0.214895, 0.0240053, 0.0, + -0.0733096, -0.921136, 0.382276, 0.0, + -0.986284, 0.151224, -0.0661379, 0.0, + -0.899319, -0.429671, 0.0812908, 0.0, + 0.652102, -0.724625, 0.222893, 0.0, + 0.203761, 0.458023, -0.865272, 0.0, + -0.030396, 0.698724, -0.714745, 0.0, + -0.460232, 0.839138, 0.289887, 0.0, + -0.0898602, 0.837894, 0.538386, 0.0, + -0.731595, 0.0793784, 0.677102, 0.0, + -0.447236, -0.788397, 0.422386, 0.0, + 0.186481, 0.645855, -0.740335, 0.0, + -0.259006, 0.935463, 0.240467, 0.0, + 0.445839, 0.819655, -0.359712, 0.0, + 0.349962, 0.755022, -0.554499, 0.0, + -0.997078, -0.0359577, 0.0673977, 0.0, + -0.431163, -0.147516, -0.890133, 0.0, + 0.299648, -0.63914, 0.708316, 0.0, + 0.397043, 0.566526, -0.722084, 0.0, + -0.502489, 0.438308, -0.745246, 0.0, + 0.0687235, 0.354097, 0.93268, 0.0, + -0.0476651, -0.462597, 0.885286, 0.0, + -0.221934, 0.900739, -0.373383, 0.0, + -0.956107, -0.225676, 0.186893, 0.0, + -0.187627, 0.391487, -0.900852, 0.0, + -0.224209, -0.315405, 0.92209, 0.0, + -0.730807, -0.537068, 0.421283, 0.0, + -0.0353135, -0.816748, 0.575913, 0.0, + -0.941391, 0.176991, -0.287153, 0.0, + -0.154174, 0.390458, 0.90762, 0.0, + -0.283847, 0.533842, 0.796519, 0.0, + -0.482737, -0.850448, 0.209052, 0.0, + -0.649175, 0.477748, 0.591886, 0.0, + 0.885373, -0.405387, -0.227543, 0.0, + -0.147261, 0.181623, -0.972279, 0.0, + 0.0959236, -0.115847, -0.988624, 0.0, + -0.89724, -0.191348, 0.397928, 0.0, + 0.903553, -0.428461, -0.00350461, 0.0, + 0.849072, -0.295807, -0.437693, 0.0, + 0.65551, 0.741754, -0.141804, 0.0, + 0.61598, -0.178669, 0.767232, 0.0, + 0.0112967, 0.932256, -0.361623, 0.0, + -0.793031, 0.258012, 0.551845, 0.0, + 0.421933, 0.454311, 0.784585, 0.0, + -0.319993, 0.0401618, -0.946568, 0.0, + -0.81571, 0.551307, -0.175151, 0.0, + -0.377644, 0.00322313, 0.925945, 0.0, + 0.129759, -0.666581, -0.734052, 0.0, + 0.601901, -0.654237, -0.457919, 0.0, + -0.927463, -0.0343576, -0.372334, 0.0, + -0.438663, -0.868301, -0.231578, 0.0, + -0.648845, -0.749138, -0.133387, 0.0, + 0.507393, -0.588294, 0.629653, 0.0, + 0.726958, 0.623665, 0.287358, 0.0, + 0.411159, 0.367614, -0.834151, 0.0, + 0.806333, 0.585117, -0.0864016, 0.0, + 0.263935, -0.880876, 0.392932, 0.0, + 0.421546, -0.201336, 0.884174, 0.0, + -0.683198, -0.569557, -0.456996, 0.0, + -0.117116, -0.0406654, -0.992285, 0.0, + -0.643679, -0.109196, -0.757465, 0.0, + -0.561559, -0.62989, 0.536554, 0.0, + 0.0628422, 0.104677, -0.992519, 0.0, + 0.480759, -0.2867, -0.828658, 0.0, + -0.228559, -0.228965, -0.946222, 0.0, + -0.10194, -0.65706, -0.746914, 0.0, + 0.0689193, -0.678236, 0.731605, 0.0, + 0.401019, -0.754026, 0.52022, 0.0, + -0.742141, 0.547083, -0.387203, 0.0, + -0.00210603, -0.796417, -0.604745, 0.0, + 0.296725, -0.409909, -0.862513, 0.0, + -0.260932, -0.798201, 0.542945, 0.0, + -0.641628, 0.742379, 0.192838, 0.0, + -0.186009, -0.101514, 0.97729, 0.0, + 0.106711, -0.962067, 0.251079, 0.0, + -0.743499, 0.30988, -0.592607, 0.0, + -0.795853, -0.605066, -0.0226607, 0.0, + -0.828661, -0.419471, -0.370628, 0.0, + 0.0847218, -0.489815, -0.8677, 0.0, + -0.381405, 0.788019, -0.483276, 0.0, + 0.282042, -0.953394, 0.107205, 0.0, + 0.530774, 0.847413, 0.0130696, 0.0, + 0.0515397, 0.922524, 0.382484, 0.0, + -0.631467, -0.709046, 0.313852, 0.0, + 0.688248, 0.517273, 0.508668, 0.0, + 0.646689, -0.333782, -0.685845, 0.0, + -0.932528, -0.247532, -0.262906, 0.0, + 0.630609, 0.68757, -0.359973, 0.0, + 0.577805, -0.394189, 0.714673, 0.0, + -0.887833, -0.437301, -0.14325, 0.0, + 0.690982, 0.174003, 0.701617, 0.0, + -0.866701, 0.0118182, 0.498689, 0.0, + -0.482876, 0.727143, 0.487949, 0.0, + -0.577567, 0.682593, -0.447752, 0.0, + 0.373768, 0.0982991, 0.922299, 0.0, + 0.170744, 0.964243, -0.202687, 0.0, + 0.993654, -0.035791, -0.106632, 0.0, + 0.587065, 0.4143, -0.695493, 0.0, + -0.396509, 0.26509, -0.878924, 0.0, + -0.0866853, 0.83553, -0.542563, 0.0, + 0.923193, 0.133398, -0.360443, 0.0, + 0.00379108, -0.258618, 0.965972, 0.0, + 0.239144, 0.245154, -0.939526, 0.0, + 0.758731, -0.555871, 0.33961, 0.0, + 0.295355, 0.309513, 0.903862, 0.0, + 0.0531222, -0.91003, -0.411124, 0.0, + 0.270452, 0.0229439, -0.96246, 0.0, + 0.563634, 0.0324352, 0.825387, 0.0, + 0.156326, 0.147392, 0.976646, 0.0, + -0.0410141, 0.981824, 0.185309, 0.0, + -0.385562, -0.576343, -0.720535, 0.0, + 0.388281, 0.904441, 0.176702, 0.0, + 0.945561, -0.192859, -0.262146, 0.0, + 0.844504, 0.520193, 0.127325, 0.0, + 0.0330893, 0.999121, -0.0257505, 0.0, + -0.592616, -0.482475, -0.644999, 0.0, + 0.539471, 0.631024, -0.557476, 0.0, + 0.655851, -0.027319, -0.754396, 0.0, + 0.274465, 0.887659, 0.369772, 0.0, + -0.123419, 0.975177, -0.183842, 0.0, + -0.223429, 0.708045, 0.66989, 0.0, + -0.908654, 0.196302, 0.368528, 0.0, + -0.95759, -0.00863708, 0.288005, 0.0, + 0.960535, 0.030592, 0.276472, 0.0, + -0.413146, 0.907537, 0.0754161, 0.0, + -0.847992, 0.350849, -0.397259, 0.0, + 0.614736, 0.395841, 0.68221, 0.0, + -0.503504, -0.666128, -0.550234, 0.0, + -0.268833, -0.738524, -0.618314, 0.0, + 0.792737, -0.60001, -0.107502, 0.0, + -0.637582, 0.508144, -0.579032, 0.0, + 0.750105, 0.282165, -0.598101, 0.0, + -0.351199, -0.392294, -0.850155, 0.0, + 0.250126, -0.960993, -0.118025, 0.0, + -0.732341, 0.680909, -0.0063274, 0.0, + -0.760674, -0.141009, 0.633634, 0.0, + 0.222823, -0.304012, 0.926243, 0.0, + 0.209178, 0.505671, 0.836984, 0.0, + 0.757914, -0.56629, -0.323857, 0.0, + -0.782926, -0.339196, 0.52151, 0.0, + -0.462952, 0.585565, 0.665424, 0.0, + 0.61879, 0.194119, -0.761194, 0.0, + 0.741388, -0.276743, 0.611357, 0.0, + 0.707571, 0.702621, 0.0752872, 0.0, + 0.156562, 0.819977, 0.550569, 0.0, + -0.793606, 0.440216, 0.42, 0.0, + 0.234547, 0.885309, -0.401517, 0.0, + 0.132598, 0.80115, -0.58359, 0.0, + -0.377899, -0.639179, 0.669808, 0.0, + -0.865993, -0.396465, 0.304748, 0.0, + -0.624815, -0.44283, 0.643046, 0.0, + -0.485705, 0.825614, -0.287146, 0.0, + -0.971788, 0.175535, 0.157529, 0.0, + -0.456027, 0.392629, 0.798675, 0.0, + -0.0104443, 0.521623, -0.853112, 0.0, + -0.660575, -0.74519, 0.091282, 0.0, + -0.0157698, -0.307475, -0.951425, 0.0, + -0.603467, -0.250192, 0.757121, 0.0, + 0.506876, 0.25006, 0.824952, 0.0, + 0.255404, 0.966794, 0.00884498, 0.0, + 0.466764, -0.874228, -0.133625, 0.0, + 0.475077, -0.0682351, -0.877295, 0.0, + -0.224967, -0.938972, -0.260233, 0.0, + -0.377929, -0.814757, -0.439705, 0.0, + -0.305847, 0.542333, -0.782517, 0.0, + 0.26658, -0.902905, -0.337191, 0.0, + 0.0275773, 0.322158, -0.946284, 0.0, + 0.0185422, 0.716349, 0.697496, 0.0, + -0.20483, 0.978416, 0.0273371, 0.0, + -0.898276, 0.373969, 0.230752, 0.0, + -0.00909378, 0.546594, 0.837349, 0.0, + 0.6602, -0.751089, 0.000959236, 0.0, + 0.855301, -0.303056, 0.420259, 0.0, + 0.797138, 0.0623013, -0.600574, 0.0, + 0.48947, -0.866813, 0.0951509, 0.0, + 0.251142, 0.674531, 0.694216, 0.0, + -0.578422, -0.737373, -0.348867, 0.0, + -0.254689, -0.514807, 0.818601, 0.0, + 0.374972, 0.761612, 0.528529, 0.0, + 0.640303, -0.734271, -0.225517, 0.0, + -0.638076, 0.285527, 0.715075, 0.0, + 0.772956, -0.15984, -0.613995, 0.0, + 0.798217, -0.590628, 0.118356, 0.0, + -0.986276, -0.0578337, -0.154644, 0.0, + -0.312988, -0.94549, 0.0899272, 0.0, + -0.497338, 0.178325, 0.849032, 0.0, + -0.101136, -0.981014, 0.165477, 0.0, + -0.521688, 0.0553434, -0.851339, 0.0, + -0.786182, -0.583814, 0.202678, 0.0, + -0.565191, 0.821858, -0.0714658, 0.0, + 0.437895, 0.152598, -0.885981, 0.0, + -0.92394, 0.353436, -0.14635, 0.0, + 0.212189, -0.815162, -0.538969, 0.0, + -0.859262, 0.143405, -0.491024, 0.0, + 0.991353, 0.112814, 0.0670273, 0.0, + 0.0337884, -0.979891, -0.196654, 0.0 + }; + +} + +#endif + +#endif diff --git a/src/libnoise/src/win32/dllmain.cpp b/src/libnoise/src/win32/dllmain.cpp new file mode 100644 index 00000000000..8acda06a12b --- /dev/null +++ b/src/libnoise/src/win32/dllmain.cpp @@ -0,0 +1,28 @@ +// dllmain.cpp +// +// Copyright (C) 2004 Jason Bevins +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or (at +// your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License (COPYING.txt) for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// The developer's email is jlbezigvins@gmzigail.com (for great email, take +// off every 'zig'.) +// + +#include + +BOOL WINAPI DllMain (HINSTANCE hInst, ULONG reason, LPVOID lpReserved) +{ + return TRUE; +} diff --git a/src/libnoise/src/win32/libnoise.def b/src/libnoise/src/win32/libnoise.def new file mode 100644 index 00000000000..4028a887699 --- /dev/null +++ b/src/libnoise/src/win32/libnoise.def @@ -0,0 +1,154 @@ +LIBRARY libnoise + +EXPORTS + ?LatLonToXYZ@noise@@YAXNNAAN00@Z @ 1 + ?GradientNoise3D@noise@@YANNNNHHHH@Z @ 2 + ?IntValueNoise3D@noise@@YAHHHHH@Z @ 3 + ?ValueNoise3D@noise@@YANHHHH@Z @ 6 + ??0Add@module@noise@@QAE@XZ @ 9 + ?GetValue@Add@module@noise@@UBENNNN@Z @ 10 + ?GetSourceModule@Module@module@noise@@UBEABV123@H@Z @ 11 + ?SetSourceModule@Module@module@noise@@UAEXHABV123@@Z @ 12 + ?GetSourceModuleCount@Add@module@noise@@UBEHXZ @ 13 + ??0Blend@module@noise@@QAE@XZ @ 14 + ?GetValue@Blend@module@noise@@UBENNNN@Z @ 15 + ?GetSourceModuleCount@Blend@module@noise@@UBEHXZ @ 16 + ??0Cache@module@noise@@QAE@XZ @ 17 + ?GetValue@Cache@module@noise@@UBENNNN@Z @ 18 + ?GetSourceModuleCount@Cache@module@noise@@UBEHXZ @ 19 + ?SetSourceModule@Cache@module@noise@@UAEXHABVModule@23@@Z @ 20 + ??0Checkerboard@module@noise@@QAE@XZ @ 21 + ?GetValue@Checkerboard@module@noise@@UBENNNN@Z @ 22 + ?GetSourceModuleCount@Checkerboard@module@noise@@UBEHXZ @ 24 + ??0Clamp@module@noise@@QAE@XZ @ 25 + ?GetValue@Clamp@module@noise@@UBENNNN@Z @ 26 + ?SetBounds@Clamp@module@noise@@QAEXNN@Z @ 27 + ?GetSourceModuleCount@Clamp@module@noise@@UBEHXZ @ 28 + ??0Const@module@noise@@QAE@XZ @ 29 + ?GetSourceModuleCount@Const@module@noise@@UBEHXZ @ 30 + ?GetValue@Const@module@noise@@UBENNNN@Z @ 31 + ??0Curve@module@noise@@QAE@XZ @ 32 + ?AddControlPoint@Curve@module@noise@@QAEXNN@Z @ 34 + ?ClearAllControlPoints@Curve@module@noise@@QAEXXZ @ 35 + ?FindInsertionPos@Curve@module@noise@@IAEHN@Z @ 36 + ?GetValue@Curve@module@noise@@UBENNNN@Z @ 37 + ?InsertAtPos@Curve@module@noise@@IAEXHNN@Z @ 38 + ?GetSourceModuleCount@Curve@module@noise@@UBEHXZ @ 42 + ??0Cylinders@module@noise@@QAE@XZ @ 43 + ?GetValue@Cylinders@module@noise@@UBENNNN@Z @ 44 + ?GetSourceModuleCount@Cylinders@module@noise@@UBEHXZ @ 46 + ??0Displace@module@noise@@QAE@XZ @ 47 + ?GetValue@Displace@module@noise@@UBENNNN@Z @ 48 + ?GetSourceModuleCount@Displace@module@noise@@UBEHXZ @ 49 + ??0Exponent@module@noise@@QAE@XZ @ 50 + ?GetValue@Exponent@module@noise@@UBENNNN@Z @ 51 + ?GetSourceModuleCount@Exponent@module@noise@@UBEHXZ @ 52 + ??0Invert@module@noise@@QAE@XZ @ 53 + ?GetValue@Invert@module@noise@@UBENNNN@Z @ 54 + ?GetSourceModuleCount@Invert@module@noise@@UBEHXZ @ 55 + ??0Max@module@noise@@QAE@XZ @ 56 + ?GetValue@Max@module@noise@@UBENNNN@Z @ 57 + ?GetSourceModuleCount@Max@module@noise@@UBEHXZ @ 59 + ??0Min@module@noise@@QAE@XZ @ 60 + ?GetValue@Min@module@noise@@UBENNNN@Z @ 61 + ?GetSourceModuleCount@Min@module@noise@@UBEHXZ @ 62 + ??0Module@module@noise@@QAE@H@Z @ 63 + ??0Multiply@module@noise@@QAE@XZ @ 64 + ?GetValue@Multiply@module@noise@@UBENNNN@Z @ 65 + ?GetSourceModuleCount@Multiply@module@noise@@UBEHXZ @ 66 + ??0Perlin@module@noise@@QAE@XZ @ 67 + ?GetValue@Perlin@module@noise@@UBENNNN@Z @ 68 + ?GetSourceModuleCount@Perlin@module@noise@@UBEHXZ @ 69 + ??0Power@module@noise@@QAE@XZ @ 70 + ?GetValue@Power@module@noise@@UBENNNN@Z @ 71 + ?GetSourceModuleCount@Power@module@noise@@UBEHXZ @ 72 + ??0RidgedMulti@module@noise@@QAE@XZ @ 73 + ?GetValue@RidgedMulti@module@noise@@UBENNNN@Z @ 74 + ?GetSourceModuleCount@RidgedMulti@module@noise@@UBEHXZ @ 75 + ??0RotatePoint@module@noise@@QAE@XZ @ 76 + ?GetValue@RotatePoint@module@noise@@UBENNNN@Z @ 77 + ?SetAngles@RotatePoint@module@noise@@QAEXNNN@Z @ 78 + ?GetSourceModuleCount@RotatePoint@module@noise@@UBEHXZ @ 79 + ??0ScaleBias@module@noise@@QAE@XZ @ 80 + ?GetValue@ScaleBias@module@noise@@UBENNNN@Z @ 81 + ?GetSourceModuleCount@ScaleBias@module@noise@@UBEHXZ @ 82 + ??0ScalePoint@module@noise@@QAE@XZ @ 83 + ?GetValue@ScalePoint@module@noise@@UBENNNN@Z @ 84 + ?GetSourceModuleCount@ScalePoint@module@noise@@UBEHXZ @ 85 + ??0Select@module@noise@@QAE@XZ @ 86 + ?GetValue@Select@module@noise@@UBENNNN@Z @ 87 + ?SetBounds@Select@module@noise@@QAEXNN@Z @ 88 + ?SetEdgeFalloff@Select@module@noise@@QAEXN@Z @ 89 + ?GetSourceModuleCount@Select@module@noise@@UBEHXZ @ 90 + ??0Spheres@module@noise@@QAE@XZ @ 91 + ?GetValue@Spheres@module@noise@@UBENNNN@Z @ 92 + ?GetSourceModuleCount@Spheres@module@noise@@UBEHXZ @ 93 + ??0Terrace@module@noise@@QAE@XZ @ 94 + ?FindInsertionPos@Terrace@module@noise@@IAEHN@Z @ 98 + ?GetValue@Terrace@module@noise@@UBENNNN@Z @ 99 + ?InsertAtPos@Terrace@module@noise@@IAEXHN@Z @ 100 + ?GetSourceModuleCount@Terrace@module@noise@@UBEHXZ @ 103 + ??0Turbulence@module@noise@@QAE@XZ @ 104 + ?GetFrequency@Turbulence@module@noise@@QBENXZ @ 105 + ?GetSeed@Turbulence@module@noise@@QBEHXZ @ 106 + ?GetValue@Turbulence@module@noise@@UBENNNN@Z @ 107 + ?SetSeed@Turbulence@module@noise@@QAEXH@Z @ 109 + ?GetSourceModuleCount@Turbulence@module@noise@@UBEHXZ @ 115 + ??0Voronoi@module@noise@@QAE@XZ @ 116 + ?GetValue@Voronoi@module@noise@@UBENNNN@Z @ 117 + ?GetSourceModuleCount@Voronoi@module@noise@@UBEHXZ @ 118 + ??0Abs@module@noise@@QAE@XZ @ 119 + ?GetValue@Abs@module@noise@@UBENNNN@Z @ 120 + ?GetSourceModuleCount@Abs@module@noise@@UBEHXZ @ 121 + ??0Line@model@noise@@QAE@XZ @ 122 + ?GetValue@Line@model@noise@@QBENN@Z @ 123 + ??0Plane@model@noise@@QAE@XZ @ 124 + ?GetValue@Plane@model@noise@@QBENNN@Z @ 125 + ??0Sphere@model@noise@@QAE@XZ @ 126 + ?GetValue@Sphere@model@noise@@QBENNN@Z @ 127 + ??0Cylinder@model@noise@@QAE@XZ @ 128 + ?GetValue@Cylinder@model@noise@@QBENNN@Z @ 129 + ??_7Add@module@noise@@6B@ @ 130 + ??_7Blend@module@noise@@6B@ @ 131 + ??_7Cache@module@noise@@6B@ @ 132 + ??_7Checkerboard@module@noise@@6B@ @ 133 + ??_7Clamp@module@noise@@6B@ @ 134 + ??_7Const@module@noise@@6B@ @ 135 + ??_7Curve@module@noise@@6B@ @ 136 + ??_7Module@module@noise@@6B@ @ 137 + ??_7Cylinders@module@noise@@6B@ @ 138 + ??_7Displace@module@noise@@6B@ @ 139 + ??_7Exponent@module@noise@@6B@ @ 140 + ??_7Invert@module@noise@@6B@ @ 141 + ??_7Max@module@noise@@6B@ @ 142 + ??_7Min@module@noise@@6B@ @ 143 + ??_7Multiply@module@noise@@6B@ @ 144 + ??_7Perlin@module@noise@@6B@ @ 145 + ??_7Power@module@noise@@6B@ @ 146 + ??_7RidgedMulti@module@noise@@6B@ @ 147 + ??_7RotatePoint@module@noise@@6B@ @ 148 + ??_7ScaleBias@module@noise@@6B@ @ 149 + ??_7ScalePoint@module@noise@@6B@ @ 150 + ??_7Select@module@noise@@6B@ @ 151 + ??_7Spheres@module@noise@@6B@ @ 152 + ??_7Terrace@module@noise@@6B@ @ 153 + ??_7Turbulence@module@noise@@6B@ @ 154 + ??_7Voronoi@module@noise@@6B@ @ 155 + ??_7Abs@module@noise@@6B@ @ 156 + ??0Billow@module@noise@@QAE@XZ @ 159 + ?GetValue@Billow@module@noise@@UBENNNN@Z @ 160 + ?GetSourceModuleCount@Billow@module@noise@@UBEHXZ @ 161 + ??_7Billow@module@noise@@6B@ @ 163 + ?CalcSpectralWeights@RidgedMulti@module@noise@@IAEXXZ @ 164 + ??0TranslatePoint@module@noise@@QAE@XZ @ 166 + ?GetValue@TranslatePoint@module@noise@@UBENNNN@Z @ 167 + ?GetSourceModuleCount@TranslatePoint@module@noise@@UBEHXZ @ 168 + ??_7TranslatePoint@module@noise@@6B@ @ 169 + ?AddControlPoint@Terrace@module@noise@@QAEXN@Z @ 170 + ?ClearAllControlPoints@Terrace@module@noise@@QAEXXZ @ 171 + ?MakeControlPoints@Terrace@module@noise@@QAEXH@Z @ 172 + ?GradientCoherentNoise3D@noise@@YANNNNHW4NoiseQuality@1@@Z @ 173 + ?ValueCoherentNoise3D@noise@@YANNNNHW4NoiseQuality@1@@Z @ 174 + ??1Terrace@module@noise@@UAE@XZ @ 175 + ??1Curve@module@noise@@UAE@XZ @ 176 + ??1Module@module@noise@@UAE@XZ @ 177 diff --git a/src/libnoise/src/win32/noise.aps b/src/libnoise/src/win32/noise.aps new file mode 100644 index 00000000000..ee7906dc889 Binary files /dev/null and b/src/libnoise/src/win32/noise.aps differ diff --git a/src/libnoise/src/win32/noise.rc b/src/libnoise/src/win32/noise.rc new file mode 100644 index 00000000000..c516ab09267 --- /dev/null +++ b/src/libnoise/src/win32/noise.rc @@ -0,0 +1,106 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION 1,0,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "Licensed under the GNU LGPL\0" + VALUE "CompanyName", "\0" + VALUE "FileDescription", "Library for generating coherent noise\0" + VALUE "FileVersion", "1.0.0\0" + VALUE "InternalName", "libnoise\0" + VALUE "LegalCopyright", "Copyright © 2004, 2007 Jason Bevins\0" + VALUE "OriginalFilename", "libnoise.dll\0" + VALUE "ProductName", "libnoise\0" + VALUE "ProductVersion", "1.0.0\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // !_MAC + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/src/libnoise/src/win32/resource.h b/src/libnoise/src/win32/resource.h new file mode 100644 index 00000000000..a136694a0b2 --- /dev/null +++ b/src/libnoise/src/win32/resource.h @@ -0,0 +1,15 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by noise.rc +// + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 9dae196b325..3a24297a73f 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -578,6 +578,7 @@ target_link_libraries(libslic3r JPEG::JPEG qoi opencv_world + libnoise ) if(NOT WIN32) diff --git a/src/libslic3r/LayerRegion.cpp b/src/libslic3r/LayerRegion.cpp index ef5d325f56d..60ba2721e35 100644 --- a/src/libslic3r/LayerRegion.cpp +++ b/src/libslic3r/LayerRegion.cpp @@ -87,6 +87,7 @@ void LayerRegion::make_perimeters(const SurfaceCollection &slices, const LayerRe &slices, &compatible_regions, this->layer()->height, + this->layer()->slice_z, this->flow(frPerimeter), ®ion_config, &this->layer()->object()->config(), diff --git a/src/libslic3r/PerimeterGenerator.cpp b/src/libslic3r/PerimeterGenerator.cpp index 5c142db4715..1b6224c29fd 100644 --- a/src/libslic3r/PerimeterGenerator.cpp +++ b/src/libslic3r/PerimeterGenerator.cpp @@ -23,6 +23,7 @@ #include "libslic3r/AABBTreeLines.hpp" #include "Print.hpp" #include "Algorithm/LineSplit.hpp" +#include "noise.h" static const int overhang_sampling_number = 6; static const double narrow_loop_length_threshold = 10; static const double min_degree_gap = 0.1; @@ -45,6 +46,14 @@ static double random_value() { return dist(gen); } +class UniformNoise: public noise::module::Module { + public: + UniformNoise(): Module (GetSourceModuleCount ()) {}; + + virtual int GetSourceModuleCount() const { return 0; } + virtual double GetValue(double x, double y, double z) const { return random_value() * 2 - 1; } +}; + // Hierarchy of perimeters. class PerimeterGeneratorLoop { public: @@ -67,9 +76,39 @@ class PerimeterGeneratorLoop { bool is_internal_contour() const; }; +static std::unique_ptr get_noise_module(const FuzzySkinConfig& cfg) { + if (cfg.noise_type == NoiseType::Perlin) { + auto perlin_noise = noise::module::Perlin(); + perlin_noise.SetFrequency(1 / cfg.noise_scale); + perlin_noise.SetOctaveCount(cfg.noise_octaves); + perlin_noise.SetPersistence(cfg.noise_persistence); + return std::make_unique(perlin_noise); + } else if (cfg.noise_type == NoiseType::Billow) { + auto billow_noise = noise::module::Billow(); + billow_noise.SetFrequency(1 / cfg.noise_scale); + billow_noise.SetOctaveCount(cfg.noise_octaves); + billow_noise.SetPersistence(cfg.noise_persistence); + return std::make_unique(billow_noise); + } else if (cfg.noise_type == NoiseType::RidgedMulti) { + auto ridged_multi_noise = noise::module::RidgedMulti(); + ridged_multi_noise.SetFrequency(1 / cfg.noise_scale); + ridged_multi_noise.SetOctaveCount(cfg.noise_octaves); + return std::make_unique(ridged_multi_noise); + } else if (cfg.noise_type == NoiseType::Voronoi) { + auto voronoi_noise = noise::module::Voronoi(); + voronoi_noise.SetFrequency(1 / cfg.noise_scale); + voronoi_noise.SetDisplacement(1.0); + return std::make_unique(voronoi_noise); + } else { + return std::make_unique(); + } +} + // Thanks Cura developers for this function. -static void fuzzy_polyline(Points& poly, bool closed, const FuzzySkinConfig& cfg) +static void fuzzy_polyline(Points& poly, bool closed, coordf_t slice_z, const FuzzySkinConfig& cfg) { + std::unique_ptr noise = get_noise_module(cfg); + const double min_dist_between_points = cfg.point_distance * 3. / 4.; // hardcoded: the point distance may vary between 3/4 and 5/4 the supplied value const double range_random_point_dist = cfg.point_distance / 2.; double dist_left_over = random_value() * (min_dist_between_points / 2.); // the distance to be traversed on the line before making the first new point @@ -91,8 +130,9 @@ static void fuzzy_polyline(Points& poly, bool closed, const FuzzySkinConfig& cfg for (; p0pa_dist < p0p1_size; p0pa_dist += min_dist_between_points + random_value() * range_random_point_dist) { - double r = random_value() * (cfg.thickness * 2.) - cfg.thickness; - out.emplace_back(*p0 + (p0p1 * (p0pa_dist / p0p1_size) + perp(p0p1).cast().normalized() * r).cast()); + Point pa = *p0 + (p0p1 * (p0pa_dist / p0p1_size)).cast(); + double r = noise->GetValue(unscale_(pa.x()), unscale_(pa.y()), slice_z) * cfg.thickness; + out.emplace_back(pa + (perp(p0p1).cast().normalized() * r).cast()); } dist_left_over = p0pa_dist - p0p1_size; p0 = &p1; @@ -109,8 +149,10 @@ static void fuzzy_polyline(Points& poly, bool closed, const FuzzySkinConfig& cfg } // Thanks Cura developers for this function. -static void fuzzy_extrusion_line(std::vector& ext_lines, const FuzzySkinConfig& cfg) +static void fuzzy_extrusion_line(std::vector& ext_lines, coordf_t slice_z, const FuzzySkinConfig& cfg) { + std::unique_ptr noise = get_noise_module(cfg); + const double min_dist_between_points = cfg.point_distance * 3. / 4.; // hardcoded: the point distance may vary between 3/4 and 5/4 the supplied value const double range_random_point_dist = cfg.point_distance / 2.; double dist_left_over = random_value() * (min_dist_between_points / 2.); // the distance to be traversed on the line before making the first new point @@ -129,8 +171,9 @@ static void fuzzy_extrusion_line(std::vector& ext_li double p0p1_size = p0p1.norm(); double p0pa_dist = dist_left_over; for (; p0pa_dist < p0p1_size; p0pa_dist += min_dist_between_points + random_value() * range_random_point_dist) { - double r = random_value() * (cfg.thickness * 2.) - cfg.thickness; - out.emplace_back(p0->p + (p0p1 * (p0pa_dist / p0p1_size) + perp(p0p1).cast().normalized() * r).cast(), p1.w, p1.perimeter_index); + Point pa = p0->p + (p0p1 * (p0pa_dist / p0p1_size)).cast(); + double r = noise->GetValue(unscale_(pa.x()), unscale_(pa.y()), slice_z) * cfg.thickness; + out.emplace_back(pa + (perp(p0p1).cast().normalized() * r).cast(), p1.w, p1.perimeter_index); } dist_left_over = p0pa_dist - p0p1_size; p0 = &p1; @@ -545,7 +588,7 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime } fuzzified = loop.polygon; - fuzzy_polyline(fuzzified.points, true, config); + fuzzy_polyline(fuzzified.points, true, perimeter_generator.slice_z, config); return &fuzzified; } @@ -590,16 +633,17 @@ static ExtrusionEntityCollection traverse_loops(const PerimeterGenerator &perime // Fuzzy splitted polygon if (std::all_of(splitted.begin(), splitted.end(), [](const Algorithm::SplitLineJunction& j) { return j.clipped; })) { // The entire polygon is fuzzified - fuzzy_polyline(fuzzified.points, true, r.first); + fuzzy_polyline(fuzzified.points, true, perimeter_generator.slice_z, r.first); } else { Points segment; segment.reserve(splitted.size()); fuzzified.points.clear(); - const auto fuzzy_current_segment = [&segment, &fuzzified, &r]() { + const auto slice_z = perimeter_generator.slice_z; + const auto fuzzy_current_segment = [&segment, &fuzzified, &r, slice_z]() { fuzzified.points.push_back(segment.front()); const auto back = segment.back(); - fuzzy_polyline(segment, false, r.first); + fuzzy_polyline(segment, false, slice_z, r.first); fuzzified.points.insert(fuzzified.points.end(), segment.begin(), segment.end()); fuzzified.points.push_back(back); segment.clear(); @@ -964,6 +1008,8 @@ static void smooth_overhang_level(ExtrusionPaths &paths) static ExtrusionEntityCollection traverse_extrusions(const PerimeterGenerator& perimeter_generator, Arachne::PerimeterOrder::PerimeterExtrusions& pg_extrusions, bool &steep_overhang_contour, bool &steep_overhang_hole) { + const auto slice_z = perimeter_generator.slice_z; + // Detect steep overhangs bool overhangs_reverse = perimeter_generator.config->overhang_reverse && perimeter_generator.layer_id % 2 == 1; // Only calculate overhang degree on even (from GUI POV) layers @@ -983,7 +1029,7 @@ static ExtrusionEntityCollection traverse_extrusions(const PerimeterGenerator& p const auto& config = regions.begin()->first; const bool fuzzify = should_fuzzify(config, perimeter_generator.layer_id, extrusion.inset_idx, is_contour); if (fuzzify) - fuzzy_extrusion_line(extrusion.junctions, config); + fuzzy_extrusion_line(extrusion.junctions, slice_z, config); } else { // Find all affective regions std::vector> fuzzified_regions; @@ -1005,17 +1051,17 @@ static ExtrusionEntityCollection traverse_extrusions(const PerimeterGenerator& p // Fuzzy splitted extrusion if (std::all_of(splitted.begin(), splitted.end(), [](const Algorithm::SplitLineJunction& j) { return j.clipped; })) { // The entire polygon is fuzzified - fuzzy_extrusion_line(extrusion.junctions, r.first); + fuzzy_extrusion_line(extrusion.junctions, slice_z, r.first); } else { const auto current_ext = extrusion.junctions; std::vector segment; segment.reserve(current_ext.size()); extrusion.junctions.clear(); - const auto fuzzy_current_segment = [&segment, &extrusion, &r]() { + const auto fuzzy_current_segment = [&segment, &extrusion, &r, slice_z]() { extrusion.junctions.push_back(segment.front()); const auto back = segment.back(); - fuzzy_extrusion_line(segment, r.first); + fuzzy_extrusion_line(segment, slice_z, r.first); extrusion.junctions.insert(extrusion.junctions.end(), segment.begin(), segment.end()); extrusion.junctions.push_back(back); segment.clear(); @@ -1852,7 +1898,11 @@ static void group_region_by_fuzzify(PerimeterGenerator& g) region_config.fuzzy_skin, scaled(region_config.fuzzy_skin_thickness.value), scaled(region_config.fuzzy_skin_point_distance.value), - region_config.fuzzy_skin_first_layer + region_config.fuzzy_skin_first_layer, + region_config.fuzzy_skin_noise_type, + region_config.fuzzy_skin_scale, + region_config.fuzzy_skin_octaves, + region_config.fuzzy_skin_persistence }; auto& surfaces = regions[cfg]; for (const auto& surface : region->slices.surfaces) { diff --git a/src/libslic3r/PerimeterGenerator.hpp b/src/libslic3r/PerimeterGenerator.hpp index 733920e3106..0b79cc40c29 100644 --- a/src/libslic3r/PerimeterGenerator.hpp +++ b/src/libslic3r/PerimeterGenerator.hpp @@ -16,10 +16,21 @@ struct FuzzySkinConfig coord_t thickness; coord_t point_distance; bool fuzzy_first_layer; + NoiseType noise_type; + double noise_scale; + int noise_octaves; + double noise_persistence; bool operator==(const FuzzySkinConfig& r) const { - return type == r.type && thickness == r.thickness && point_distance == r.point_distance && fuzzy_first_layer == r.fuzzy_first_layer; + return type == r.type + && thickness == r.thickness + && point_distance == r.point_distance + && fuzzy_first_layer == r.fuzzy_first_layer + && noise_type == r.noise_type + && noise_scale == r.noise_scale + && noise_octaves == r.noise_octaves + && noise_persistence == r.noise_persistence; } bool operator!=(const FuzzySkinConfig& r) const { return !(*this == r); } @@ -35,6 +46,10 @@ template<> struct hash boost::hash_combine(seed, std::hash{}(c.thickness)); boost::hash_combine(seed, std::hash{}(c.point_distance)); boost::hash_combine(seed, std::hash{}(c.fuzzy_first_layer)); + boost::hash_combine(seed, std::hash{}(c.noise_type)); + boost::hash_combine(seed, std::hash{}(c.noise_scale)); + boost::hash_combine(seed, std::hash{}(c.noise_octaves)); + boost::hash_combine(seed, std::hash{}(c.noise_persistence)); return seed; } }; @@ -51,6 +66,7 @@ class PerimeterGenerator { const ExPolygons *lower_slices; double layer_height; int layer_id; + coordf_t slice_z; Flow perimeter_flow; Flow ext_perimeter_flow; Flow overhang_flow; @@ -83,6 +99,7 @@ class PerimeterGenerator { const SurfaceCollection* slices, const LayerRegionPtrs *compatible_regions, double layer_height, + coordf_t slice_z, Flow flow, const PrintRegionConfig* config, const PrintObjectConfig* object_config, @@ -98,7 +115,7 @@ class PerimeterGenerator { //BBS ExPolygons* fill_no_overlap) : slices(slices), compatible_regions(compatible_regions), upper_slices(nullptr), lower_slices(nullptr), layer_height(layer_height), - layer_id(-1), perimeter_flow(flow), ext_perimeter_flow(flow), + slice_z(slice_z), layer_id(-1), perimeter_flow(flow), ext_perimeter_flow(flow), overhang_flow(flow), solid_infill_flow(flow), config(config), object_config(object_config), print_config(print_config), m_spiral_vase(spiral_mode), diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 1ed6d07ad87..7311498b350 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -769,7 +769,7 @@ static std::vector s_Preset_print_options { "minimum_sparse_infill_area", "reduce_infill_retraction","internal_solid_infill_pattern","gap_fill_target", "ironing_type", "ironing_pattern", "ironing_flow", "ironing_speed", "ironing_spacing", "ironing_angle", "max_travel_detour_distance", - "fuzzy_skin", "fuzzy_skin_thickness", "fuzzy_skin_point_distance", "fuzzy_skin_first_layer", + "fuzzy_skin", "fuzzy_skin_thickness", "fuzzy_skin_point_distance", "fuzzy_skin_first_layer", "fuzzy_skin_noise_type", "fuzzy_skin_scale", "fuzzy_skin_octaves", "fuzzy_skin_persistence", "max_volumetric_extrusion_rate_slope", "max_volumetric_extrusion_rate_slope_segment_length","extrusion_rate_smoothing_external_perimeter_only", "inner_wall_speed", "outer_wall_speed", "sparse_infill_speed", "internal_solid_infill_speed", "top_surface_speed", "support_speed", "support_object_xy_distance", "support_interface_speed", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index e922af9c5d8..c92c73b9354 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -123,6 +123,15 @@ static t_config_enum_values s_keys_map_FuzzySkinType { }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(FuzzySkinType) +static t_config_enum_values s_keys_map_NoiseType { + { "classic", int(NoiseType::Classic) }, + { "perlin", int(NoiseType::Perlin) }, + { "billow", int(NoiseType::Billow) }, + { "ridgedmulti", int(NoiseType::RidgedMulti) }, + { "voronoi", int(NoiseType::Voronoi) } +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(NoiseType) + static t_config_enum_values s_keys_map_InfillPattern { { "concentric", ipConcentric }, { "zig-zag", ipRectilinear }, @@ -2629,6 +2638,57 @@ void PrintConfigDef::init_fff_params() def->mode = comSimple; def->set_default_value(new ConfigOptionBool(0)); + def = this->add("fuzzy_skin_noise_type", coEnum); + def->label = L("Fuzzy skin noise type"); + def->category = L("Others"); + def->tooltip = L("Noise type to use for fuzzy skin generation.\n" + "Classic: Classic uniform random noise.\n" + "Perlin: Perlin noise, which gives a more consistent texture.\n" + "Billow: Similar to perlin noise, but clumpier.\n" + "Ridged Multifractal: Ridged noise with sharp, jagged features. Creates marble-like textures.\n" + "Voronoi: Divides the surface into voronoi cells, and displaces each one by a random amount. Creates a patchwork texture."); + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("classic"); + def->enum_values.push_back("perlin"); + def->enum_values.push_back("billow"); + def->enum_values.push_back("ridgedmulti"); + def->enum_values.push_back("voronoi"); + def->enum_labels.push_back(L("Classic")); + def->enum_labels.push_back(L("Perlin")); + def->enum_labels.push_back(L("Billow")); + def->enum_labels.push_back(L("Ridged Multifractal")); + def->enum_labels.push_back(L("Voronoi")); + def->mode = comSimple; + def->set_default_value(new ConfigOptionEnum(NoiseType::Classic)); + + def = this->add("fuzzy_skin_scale", coFloat); + def->label = L("Fuzzy skin feature size"); + def->category = L("Others"); + def->tooltip = L("The base size of the coherent noise features, in mm. Higher values will result in larger features."); + def->sidetext = L("mm"); + def->min = 0.1; + def->max = 500; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(1.0)); + + def = this->add("fuzzy_skin_octaves", coInt); + def->label = L("Fuzzy Skin Noise Octaves"); + def->category = L("Others"); + def->tooltip = L("The number of octaves of coherent noise to use. Higher values increase the detail of the noise, but also increase computation time."); + def->min = 1; + def->max = 10; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionInt(4)); + + def = this->add("fuzzy_skin_persistence", coFloat); + def->label = L("Fuzzy skin noise persistence"); + def->category = L("Others"); + def->tooltip = L("The decay rate for higher octaves of the coherent noise. Lower values will result in smoother noise."); + def->min = 0.01; + def->max = 1; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloat(0.5)); + def = this->add("filter_out_gap_fill", coFloat); def->label = L("Filter out tiny gaps"); def->category = L("Layers and Perimeters"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index e406e4f3c2e..fa594a4cdde 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -41,6 +41,14 @@ enum class FuzzySkinType { AllWalls, }; +enum class NoiseType { + Classic, + Perlin, + Billow, + RidgedMulti, + Voronoi, +}; + enum PrintHostType { htPrusaLink, htPrusaConnect, htOctoPrint, htDuet, htFlashAir, htAstroBox, htRepetier, htMKS, htESP3D, htCrealityPrint, htObico, htFlashforge, htSimplyPrint }; @@ -402,6 +410,7 @@ static std::string get_bed_temp_1st_layer_key(const BedType type) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(PrinterTechnology) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(GCodeFlavor) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(FuzzySkinType) +CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(NoiseType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(InfillPattern) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(IroningType) CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(SlicingMode) @@ -916,6 +925,10 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloat, fuzzy_skin_thickness)) ((ConfigOptionFloat, fuzzy_skin_point_distance)) ((ConfigOptionBool, fuzzy_skin_first_layer)) + ((ConfigOptionEnum, fuzzy_skin_noise_type)) + ((ConfigOptionFloat, fuzzy_skin_scale)) + ((ConfigOptionInt, fuzzy_skin_octaves)) + ((ConfigOptionFloat, fuzzy_skin_persistence)) ((ConfigOptionFloat, gap_infill_speed)) ((ConfigOptionInt, sparse_infill_filament)) ((ConfigOptionFloatOrPercent, sparse_infill_line_width)) diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 01d7e242c97..a2d479e61b2 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -1116,6 +1116,10 @@ bool PrintObject::invalidate_state_by_config_options( || opt_key == "fuzzy_skin_thickness" || opt_key == "fuzzy_skin_point_distance" || opt_key == "fuzzy_skin_first_layer" + || opt_key == "fuzzy_skin_noise_type" + || opt_key == "fuzzy_skin_scale" + || opt_key == "fuzzy_skin_octaves" + || opt_key == "fuzzy_skin_persistence" || opt_key == "detect_overhang_wall" || opt_key == "overhang_reverse" || opt_key == "overhang_reverse_internal_only" diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 10d3f376480..2275982f542 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -616,7 +616,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SLIC3R_GUI_SOURCES}) encoding_check(libslic3r_gui) -target_link_libraries(libslic3r_gui libslic3r cereal::cereal imgui imguizmo minilzo GLEW::GLEW OpenGL::GL hidapi ${wxWidgets_LIBRARIES} glfw libcurl OpenSSL::SSL OpenSSL::Crypto) +target_link_libraries(libslic3r_gui libslic3r cereal::cereal imgui imguizmo minilzo GLEW::GLEW OpenGL::GL hidapi ${wxWidgets_LIBRARIES} glfw libcurl OpenSSL::SSL OpenSSL::Crypto libnoise_static) if (MSVC) target_link_libraries(libslic3r_gui Setupapi.lib) diff --git a/src/slic3r/GUI/ConfigManipulation.cpp b/src/slic3r/GUI/ConfigManipulation.cpp index 600cb30c0fc..a572a88c6d2 100644 --- a/src/slic3r/GUI/ConfigManipulation.cpp +++ b/src/slic3r/GUI/ConfigManipulation.cpp @@ -707,9 +707,14 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig *config, co toggle_line("support_interface_not_for_body",config->opt_int("support_interface_filament")&&!config->opt_int("support_filament")); bool has_fuzzy_skin = (config->opt_enum("fuzzy_skin") != FuzzySkinType::None); - for (auto el : { "fuzzy_skin_thickness", "fuzzy_skin_point_distance", "fuzzy_skin_first_layer"}) + for (auto el : { "fuzzy_skin_thickness", "fuzzy_skin_point_distance", "fuzzy_skin_first_layer", "fuzzy_skin_noise_type"}) toggle_line(el, has_fuzzy_skin); + NoiseType fuzzy_skin_noise_type = config->opt_enum("fuzzy_skin_noise_type"); + toggle_line("fuzzy_skin_scale", has_fuzzy_skin && fuzzy_skin_noise_type != NoiseType::Classic); + toggle_line("fuzzy_skin_octaves", has_fuzzy_skin && fuzzy_skin_noise_type != NoiseType::Classic && fuzzy_skin_noise_type != NoiseType::Voronoi); + toggle_line("fuzzy_skin_persistence", has_fuzzy_skin && (fuzzy_skin_noise_type == NoiseType::Perlin || fuzzy_skin_noise_type == NoiseType::Billow)); + bool have_arachne = config->opt_enum("wall_generator") == PerimeterGeneratorType::Arachne; for (auto el : { "wall_transition_length", "wall_transition_filter_deviation", "wall_transition_angle", "min_feature_size", "min_length_factor", "min_bead_width", "wall_distribution_count", "initial_layer_min_bead_width"}) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index b86e2b75e13..a7d441bd216 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2347,8 +2347,12 @@ page = add_options_page(L("Others"), "custom-gcode_other"); // ORCA: icon only v optgroup->append_single_option_line("timelapse_type", "Timelapse"); optgroup->append_single_option_line("fuzzy_skin"); + optgroup->append_single_option_line("fuzzy_skin_noise_type"); optgroup->append_single_option_line("fuzzy_skin_point_distance"); optgroup->append_single_option_line("fuzzy_skin_thickness"); + optgroup->append_single_option_line("fuzzy_skin_scale"); + optgroup->append_single_option_line("fuzzy_skin_octaves"); + optgroup->append_single_option_line("fuzzy_skin_persistence"); optgroup->append_single_option_line("fuzzy_skin_first_layer"); optgroup = page->new_optgroup(L("G-code output"), L"param_gcode");