├── .gitignore ├── AUTHORS.md ├── CMakeLists.txt ├── HISTORY.md ├── LICENSE.md ├── README.md ├── cmake └── Modules │ └── FindLibNoise.cmake ├── doc ├── CMakeLists.txt ├── Doxyfile.in ├── README.md ├── htmldata │ ├── background.png │ ├── doxygen.css │ ├── libnoise.png │ ├── templatefooter.html │ └── templateheader.html └── img │ ├── curve.png │ ├── gradientcolor.png │ ├── modelcylinder.png │ ├── modelsphere.png │ ├── moduleabs.png │ ├── moduleadd.png │ ├── modulebillow.png │ ├── moduleblend.png │ ├── modulecheckerboard.png │ ├── moduleclamp.png │ ├── moduleconst.png │ ├── modulecurve.png │ ├── modulecylinders.png │ ├── moduledisplace.png │ ├── moduleexponent.png │ ├── moduleinvert.png │ ├── modulemax.png │ ├── modulemin.png │ ├── modulemultiply.png │ ├── moduleperlin.png │ ├── modulepower.png │ ├── moduleridgedmulti.png │ ├── modulerotatepoint.png │ ├── modulescalebias.png │ ├── modulescalepoint.png │ ├── moduleselect.png │ ├── modulespheres.png │ ├── moduleterrace.png │ ├── moduletranslatepoint.png │ ├── moduleturbulence.png │ ├── modulevoronoi.png │ └── terrace.png ├── examples ├── CMakeLists.txt ├── COPYING.txt ├── complexplanet.cpp ├── readme.txt ├── texturegranite.cpp ├── texturejade.cpp ├── texturesky.cpp ├── textureslime.cpp ├── texturewood.cpp └── worms.cpp ├── noiseutils ├── CMakeLists.txt ├── COPYING.txt ├── noiseutils.cpp ├── noiseutils.h └── readme.txt └── src ├── CMakeLists.txt ├── latlon.cpp ├── model ├── cylinder.cpp ├── line.cpp ├── plane.cpp └── sphere.cpp ├── module ├── 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 ├── noise ├── basictypes.h ├── exception.h ├── interp.h ├── latlon.h ├── mathconsts.h ├── misc.h ├── model │ ├── cylinder.h │ ├── line.h │ ├── model.h │ ├── plane.h │ └── sphere.h ├── module │ ├── abs.h │ ├── add.h │ ├── billow.h │ ├── blend.h │ ├── cache.h │ ├── checkerboard.h │ ├── clamp.h │ ├── const.h │ ├── curve.h │ ├── cylinders.h │ ├── displace.h │ ├── exponent.h │ ├── invert.h │ ├── max.h │ ├── min.h │ ├── module.h │ ├── modulebase.h │ ├── multiply.h │ ├── perlin.h │ ├── power.h │ ├── ridgedmulti.h │ ├── rotatepoint.h │ ├── scalebias.h │ ├── scalepoint.h │ ├── select.h │ ├── spheres.h │ ├── terrace.h │ ├── translatepoint.h │ ├── turbulence.h │ └── voronoi.h ├── noise.h ├── noisegen.h └── vectortable.h ├── noisegen.cpp └── win32 ├── dllmain.cpp ├── noise.aps ├── noise.rc └── resource.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries 2 | build/ 3 | 4 | # Generated cmake files 5 | CMakeFiles/ 6 | Makefile 7 | cmake_install.cmake 8 | doc/CMakeFiles/ 9 | doc/Makefile 10 | doc/cmake_install.cmake 11 | src/CMakeFiles/ 12 | src/Makefile 13 | src/cmake_install.cmake 14 | CMakeCache.txt 15 | install_manifest.txt 16 | 17 | # Output files 18 | src/libnoise.a 19 | src/libnoise.dylib 20 | 21 | # Output Documentation 22 | doc/Doxyfile 23 | doc/html 24 | 25 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | Authors: 2 | * Jason Bevins (for great email, take off every 'zig'.) 3 | 4 | contributor: 5 | * Joachim Schiele , wrote the cmake system 6 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # http://www.linux-magazin.de/Heft-Abo/Ausgaben/2007/02/Mal-ausspannen 2 | 3 | cmake_minimum_required(VERSION 3.0) 4 | 5 | set(LIBNOISE_VERSION "1.0.0-cmake") 6 | 7 | #---------------------------------------- 8 | # Provide an option for the user to select (default given; otherwhise pass -Doption=ON to cmake) 9 | option(BUILD_WALL "Build with all warnings enabled" OFF) 10 | option(BUILD_SPEED_OPTIMIZED "Build with optimization for speed (only in release build)" ON) 11 | option(BUILD_SHARED_LIBS "Build shared libraries for libnoise" ON) 12 | option(BUILD_LIBNOISE_DOCUMENTATION "Create doxygen documentation for developers" OFF) 13 | option(BUILD_LIBNOISE_UTILS "Build utility functions for use with libnoise" ON) 14 | option(BUILD_LIBNOISE_EXAMPLES "Build libnoise examples" ON) 15 | 16 | #---------------------------------------- 17 | # enable all warnings 18 | # usually the library implementor needs to take care of those warnings and not the user of the lib 19 | if (BUILD_WALL) 20 | if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") 21 | message(STATUS "GNU - using build with all warnings enabled") 22 | add_compile_options(-Wall -ansi -pedantic) 23 | elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") 24 | message(STATUS "MSVC - using build with all warnings enabled") 25 | add_compile_options(/Wall) 26 | endif() 27 | endif() 28 | 29 | #---------------------------------------- 30 | # enable optimized compile settings 31 | # This cmake build by default (if not in developer mode; hence release build) will build with `-O3` 32 | if (BUILD_SPEED_OPTIMIZED AND CMAKE_BUILD_TYPE EQUAL "Release") 33 | if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") 34 | message(STATUS "GNU - using compiler optimization for speed") 35 | add_compile_options(-O3) 36 | elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") 37 | message(STATUS "MSVC - using compiler optimization for speed") 38 | add_compile_options(/Ox) 39 | endif() 40 | endif() 41 | 42 | #---------------------------------------- 43 | # src 44 | add_subdirectory(src) 45 | 46 | #---------------------------------------- 47 | # docs 48 | if(BUILD_LIBNOISE_DOCUMENTATION) 49 | add_subdirectory(doc) 50 | endif() 51 | 52 | #---------------------------------------- 53 | # noiseutils 54 | if (BUILD_LIBNOISE_UTILS) 55 | add_subdirectory(noiseutils) 56 | endif() 57 | 58 | #---------------------------------------- 59 | # examples 60 | if (BUILD_LIBNOISE_EXAMPLES AND BUILD_LIBNOISE_UTILS) 61 | add_subdirectory(examples) # examples also depend on noiseutils 62 | elseif (BUILD_LIBNOISE_EXAMPLES) 63 | message(STATUS "examples depend on noiseutils - \ 64 | fix: pass option -DBUILD_SHARED_LIBS=ON to cmake") 65 | endif() 66 | 67 | 68 | #---------------------------------------- 69 | # unused variables passed by vcpkg 70 | message(STATUS "CMAKE_INSTALL_BINDIR : " ${CMAKE_INSTALL_BINDIR}) 71 | message(STATUS "CMAKE_INSTALL_LIBDIR : " ${CMAKE_INSTALL_LIBDIR}) -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | 2010-11-29 2 | * fixed some doxygen specific issue, thanks to Max Bolingbroke. now libnoise compiles in: 3 | - gentoo linux (according to me: 32 and 64 bit runtimes) 4 | - mac os x, using macports (according to Max Bolingbroke) 5 | 6 | 2009-11-29 7 | * there is some license problem: the library uses the LGPL 2.1 and the examples (on the download page use GPL v2) 8 | but the zip file with example sources included uses also LGPL 2.1 license?! 9 | * basic doxygen support is there 10 | * wrote 'make install' step using cmake 11 | * WARNING: src/win32/ is not used at all, maybe someone has to test this with win32 ... 12 | and i removed thse win32 files from the distribution, maybe someone want's to have them back? 13 | * changed the library #include "noise.h" instead of "noise/noise.h" 14 | there is no /include directory anymore since one must use src/ as include path now 15 | which will the be searched for "noise.h" now 16 | * cmake: created a CMakeList.txt which builds the .so and .a file 17 | * removed static Makefiles and libtool but keep compatibility to existing projects working 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > My personal fork was to use this alongside a native plugin for the Unity game engine. It is still licensed under the LGPL as before. Primarily, I made some modifications to allow compiling to a Windows x64 DLL. 2 | 3 | libnoise 4 | ======== 5 | 6 | This is a fork of libnoise which includes noiseutils in the building and installing process. 7 | It also contains FindLibNoise.cmake 8 | 9 | > This is a fork of libnoise which changes the build system from static Makefiles to cmake. 10 | 11 | A portable, open-source, coherent noise-generating library for C++ 12 | 13 | libnoise is a portable C++ library that is used to generate coherent noise, a type of smoothly-changing noise. 14 | libnoise can generate Perlin noise, ridged multifractal noise, and other types of coherent-noise. 15 | 16 | Coherent noise is often used by graphics programmers to generate natural-looking textures, planetary terrain, 17 | and other things. The mountain scene shown above was rendered in Terragen with a terrain file generated by libnoise. 18 | You can also view some other examples of what libnoise can do. 19 | 20 | In libnoise, coherent-noise generators are encapsulated in classes called noise modules. 21 | There are many different types of noise modules. Some noise modules can combine or modify the outputs 22 | of other noise modules in various ways; you can join these modules together to generate very complex coherent noise. 23 | 24 | Compiling 25 | --------- 26 | 27 | cmake supports 'out of source' builds by default, to use it do this: 28 | 29 | ```shell 30 | mkdir build 31 | cd build 32 | cmake .. 33 | make 34 | ``` 35 | 36 | this should create everything into the `build/` directory 37 | 38 | Installing 39 | ---------- 40 | 41 | this is covered by cmake: 42 | 43 | ```shell 44 | make install 45 | ``` 46 | 47 | Usage 48 | ----- 49 | 50 | If you want to use this library, there are two ways of doing this (see examples for further details): 51 | 52 | * Linker 53 | 54 | 1. you need to supply the library `-lnoise` to the linker 55 | 2. the includes to the compile with `-I /usr/include/noise` 56 | 57 | * CMake 58 | 59 | use the provided FindLibNoise.cmake 60 | 61 | A comment on performance 62 | ------------------------ 63 | 64 | Using compiler optimizations for libnoise is *strongly recommended*. Using the 65 | unoptimized library is roughly a fifth as fast as using -O3 on my test 66 | computer. 67 | 68 | This cmake build by default (if not in developer mode; hence release build) will build with `-O3` 69 | 70 | see: 71 | CMAKE_BUILD_TYPE 72 | 73 | Type of build (Debug, Release, ...) 74 | 75 | If you want to disable optimizations, pass the following to the cmake arguments: 76 | ```"-DBUILD_SPEED_OPTIMIZED=OFF"``` 77 | 78 | -------------------------------------------------------------------------------- /cmake/Modules/FindLibNoise.cmake: -------------------------------------------------------------------------------- 1 | # Locate libnoise. 2 | # This module defines 3 | # LIBNOISE_LIBRARIES 4 | # LIBNOISE_FOUND, if false, do not try to link to libnoise 5 | # LIBNOISE_INCLUDE_DIR, where to find the headers 6 | 7 | FIND_PATH(LIBNOISE_INCLUDE_DIR noise.h 8 | $ENV{LIBNOISE_DIR} 9 | NO_DEFAULT_PATH 10 | PATH_SUFFIXES include 11 | ) 12 | 13 | FIND_PATH(LIBNOISE_INCLUDE_DIR "noise.h" 14 | PATHS 15 | ${CMAKE_SOURCE_DIR}/include 16 | ~/Library/Frameworks/noise/Headers 17 | /Library/Frameworks/noise/Headers 18 | /usr/local/include/noise 19 | /usr/local/include/noise 20 | /usr/local/include 21 | /usr/include/noise 22 | /usr/include/noise 23 | /usr/include 24 | /sw/include/noise 25 | /sw/include/noise 26 | /sw/include # Fink 27 | /opt/local/include/noise 28 | /opt/local/include/noise 29 | /opt/local/include # DarwinPorts 30 | /opt/csw/include/noise 31 | /opt/csw/include/noise 32 | /opt/csw/include # Blastwave 33 | /opt/include/noise 34 | /opt/include/noise 35 | /opt/include 36 | PATH_SUFFIXES noise 37 | ) 38 | 39 | FIND_LIBRARY(LIBNOISE_LIBRARIES 40 | NAMES libnoise noise libnoiseutils noiseutils 41 | PATHS 42 | $ENV{LIBNOISE_DIR} 43 | NO_DEFAULT_PATH 44 | PATH_SUFFIXES lib64 lib so 45 | ) 46 | 47 | FIND_LIBRARY(LIBNOISE_LIBRARIES 48 | NAMES libnoise noise libnoiseutils noiseutils 49 | PATHS 50 | ${CMAKE_SOURCE_DIR}/lib 51 | ~/Library/Frameworks 52 | /Library/Frameworks 53 | /usr/local 54 | /usr 55 | /sw 56 | /opt/local 57 | /opt/csw 58 | /opt 59 | /usr/freeware 60 | PATH_SUFFIXES lib64 lib so 61 | ) 62 | 63 | message("LIBNOISE_INCLUDE_DIR: ${LIBNOISE_INCLUDE_DIR}") 64 | 65 | SET(LIBNOISE_FOUND "NO") 66 | IF(LIBNOISE_LIBRARY AND LIBNOISE_INCLUDE_DIR) 67 | SET(LIBNOISE_FOUND "YES") 68 | ENDIF(LIBNOISE_LIBRARY AND LIBNOISE_INCLUDE_DIR) 69 | 70 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # many thanks go to Philippe Poilbarbe for writing the code this file is based on 2 | # http://www.cmake.org/pipermail/cmake/2006-August/010794.html 3 | # 4 | # much later i also found this: 5 | # http://tobias.rautenkranz.ch/cmake/doxygen/ 6 | # but it is hard to understand... 7 | 8 | find_package(Doxygen) 9 | 10 | if(DOXYGEN_FOUND) 11 | set(DOXYGEN_LANGUAGE "English" CACHE STRING "Language used by doxygen") 12 | mark_as_advanced(DOXYGEN_LANGUAGE) 13 | 14 | # you could also set the version with this, see Doxygen.in 15 | # there you will find a line like this: 16 | # PROJECT_NUMBER = @LIBNOISE_VERSION@ 17 | # @LIBNOISE_VERSION@ is then replaced by our global LIBNOISE_VERSION 18 | # 19 | # for instance you could uncomment the next 3 lines and change the version for testing 20 | # SET(LIBNOISE_VERSION 21 | # "1.2.3-foo500" 22 | # ) 23 | 24 | # doxygen can reference external images with IMAGE_PATH, this is how we set it dynamically 25 | set( CMAKE_DOXYGEN_IMAGE_PATH 26 | "${CMAKE_CURRENT_SOURCE_DIR}/img" 27 | ) 28 | 29 | # doxygen searches for source code (defined in FILE_PATTERNS, for example: *.cpp *.h) 30 | # with DOXYGEN_SOURCE_DIR we fill a list of directories and later we write it into 31 | # the Doxyfile with a REGEX REPLACE (see below) 32 | set( DOXYGEN_SOURCE_DIR 33 | "${CMAKE_SOURCE_DIR}/src" 34 | ) 35 | 36 | set(DOXYGEN_OUTPUT_DIR html) 37 | string(REGEX REPLACE ";" " " CMAKE_DOXYGEN_INPUT_LIST "${DOXYGEN_SOURCE_DIR}") 38 | 39 | configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) 40 | set(HTML_TARGET "html" ) 41 | 42 | add_custom_target(${HTML_TARGET} ALL 43 | ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 44 | DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) 45 | 46 | install( DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html/" DESTINATION "/usr/share/doc/libnoise-${LIBNOISE_VERSION}" ) 47 | 48 | else(DOXYGEN_FOUND) 49 | message (FATAL_ERROR "doxygen binary couldn't be found") 50 | endif(DOXYGEN_FOUND) -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | Building doco 2 | ------------- 3 | 4 | Run doxygen from this directory. 5 | 6 | Copy the following files from the htmldata into the html subdirectory: 7 | 8 | * background.png 9 | * doxygen.css 10 | * libnoise.png 11 | 12 | The HTML documentation contains custom headers and footers that require 13 | certain image files to exist in the html subdirectory. I don't know how to 14 | get doxygen to copy these files automagically. 15 | 16 | -- jas 17 | -------------------------------------------------------------------------------- /doc/htmldata/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/htmldata/background.png -------------------------------------------------------------------------------- /doc/htmldata/doxygen.css: -------------------------------------------------------------------------------- 1 | body 2 | { 3 | background-color: #99cccc; 4 | background-image: url(background.png); 5 | display: block; 6 | font-family: verdana,helvetica,sans-serif; 7 | font-size: 10pt; 8 | margin-left: auto; 9 | margin-right: auto; 10 | max-width: 70em; 11 | } 12 | 13 | img 14 | { 15 | background-color: white; 16 | border-style: none; 17 | } 18 | 19 | span.header 20 | { 21 | font-weight: bold; 22 | } 23 | 24 | table.layout 25 | { 26 | border-collapse: collapse; 27 | border-style: none; 28 | border-width: 0px; 29 | margin: 0px; 30 | padding: 0px; 31 | width: 100%; 32 | } 33 | 34 | td.header 35 | { 36 | background-color: white; 37 | background-repeat: no-repeat; 38 | padding: 6pt; 39 | vertical-align: top; 40 | } 41 | 42 | td.sidebar 43 | { 44 | background-color: #99cccc; 45 | border-color: #669999; 46 | border-style: none; 47 | border-width: 0px; 48 | padding: 3pt; 49 | vertical-align: top; 50 | width: 18em; 51 | font-size: 8pt; 52 | } 53 | 54 | td.sidebar a:hover 55 | { 56 | color: red; 57 | } 58 | 59 | td.content 60 | { 61 | background-color: white; 62 | vertical-align: top; 63 | padding: 6pt; 64 | } 65 | 66 | td.footer 67 | { 68 | background-color: white; 69 | vertical-align: bottom; 70 | } 71 | 72 | ul.toc 73 | { 74 | padding-left: 1em; 75 | } 76 | 77 | td.content img 78 | { 79 | padding: 4pt; 80 | } 81 | 82 | div.fragment 83 | { 84 | background-color: #ddeeee; 85 | border-color: #996666; 86 | border-style: dashed; 87 | border-width: 1px; 88 | font-family: monospace; 89 | padding: 8pt; 90 | margin: 8pt; 91 | margin-left: 24pt; 92 | } 93 | 94 | td { 95 | font-size: 10pt; 96 | } 97 | 98 | 99 | 100 | 101 | 102 | caption 103 | { 104 | font-weight: bold 105 | } 106 | 107 | a.qindex 108 | { 109 | } 110 | 111 | a.qindexRef 112 | { 113 | } 114 | 115 | a.el 116 | { 117 | text-decoration: none; 118 | font-weight: bold 119 | } 120 | 121 | a.elRef 122 | { 123 | font-weight: bold 124 | } 125 | 126 | a.code 127 | { 128 | text-decoration: none; 129 | font-weight: normal; 130 | color: #4444ee 131 | } 132 | 133 | a.codeRef 134 | { 135 | font-weight: normal; 136 | color: #4444ee 137 | } 138 | 139 | dl.el 140 | { 141 | margin-left: -1cm 142 | } 143 | 144 | div.ah 145 | { 146 | background-color: black; 147 | font-weight: bold; 148 | color: #ffffff; 149 | margin-bottom: 3px; 150 | margin-top: 3px 151 | } 152 | 153 | div.groupHeader 154 | { 155 | margin-left: 16px; 156 | margin-top: 12px; 157 | margin-bottom: 6px; 158 | font-weight: bold 159 | } 160 | 161 | div.groupText 162 | { 163 | margin-left: 16px; 164 | font-style: italic; 165 | } 166 | 167 | td.indexkey 168 | { 169 | background-color: #ddeeee; 170 | font-weight: bold; 171 | padding-right: 10px; 172 | padding-top: 2px; 173 | padding-left: 10px; 174 | padding-bottom: 2px; 175 | margin-left: 0px; 176 | margin-right: 0px; 177 | margin-top: 2px; 178 | margin-bottom: 2px 179 | } 180 | 181 | td.indexvalue 182 | { 183 | background-color: #ddeeee; 184 | font-style: italic; 185 | padding-right: 10px; 186 | padding-top: 2px; 187 | padding-left: 10px; 188 | padding-bottom: 2px; 189 | margin-left: 0px; 190 | margin-right: 0px; 191 | margin-top: 2px; 192 | margin-bottom: 2px 193 | } 194 | 195 | td.md 196 | { 197 | background-color: #ddeeee; 198 | font-weight: bold; 199 | } 200 | 201 | td.mdname1 202 | { 203 | background-color: #ddeeee; 204 | font-weight: bold; 205 | color: #602020; 206 | } 207 | 208 | td.mdname 209 | { 210 | background-color: #ddeeee; 211 | font-weight: bold; 212 | color: #602020; 213 | width: 600px; 214 | } 215 | 216 | span.keyword 217 | { 218 | color: #008000 219 | } 220 | 221 | span.keywordtype 222 | { 223 | color: #604020 224 | } 225 | 226 | span.keywordflow 227 | { 228 | color: #e08000 229 | } 230 | 231 | span.comment 232 | { 233 | color: #800000 234 | } 235 | 236 | span.preprocessor 237 | { 238 | color: #806020 239 | } 240 | 241 | span.stringliteral 242 | { 243 | color: #002080 244 | } 245 | 246 | span.charliteral 247 | { 248 | color: #008080 249 | } 250 | -------------------------------------------------------------------------------- /doc/htmldata/libnoise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/htmldata/libnoise.png -------------------------------------------------------------------------------- /doc/htmldata/templatefooter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

8 | © 2003-2005 Jason Bevins 9 |

10 |

11 | Doxygen logo 12 |
13 | The libnoise source documentation was generated by doxygen 1.3.9.1 14 |

15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/htmldata/templateheader.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | libnoise: Documentation 6 | 7 | 8 | 9 | 10 | 11 | 12 | 86 | 95 | 96 | 97 |
87 |

88 | libnoise logo 89 |

90 |

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

93 |
94 |
98 | 99 | 100 | -------------------------------------------------------------------------------- /doc/img/curve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/curve.png -------------------------------------------------------------------------------- /doc/img/gradientcolor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/gradientcolor.png -------------------------------------------------------------------------------- /doc/img/modelcylinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modelcylinder.png -------------------------------------------------------------------------------- /doc/img/modelsphere.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modelsphere.png -------------------------------------------------------------------------------- /doc/img/moduleabs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleabs.png -------------------------------------------------------------------------------- /doc/img/moduleadd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleadd.png -------------------------------------------------------------------------------- /doc/img/modulebillow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulebillow.png -------------------------------------------------------------------------------- /doc/img/moduleblend.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleblend.png -------------------------------------------------------------------------------- /doc/img/modulecheckerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulecheckerboard.png -------------------------------------------------------------------------------- /doc/img/moduleclamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleclamp.png -------------------------------------------------------------------------------- /doc/img/moduleconst.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleconst.png -------------------------------------------------------------------------------- /doc/img/modulecurve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulecurve.png -------------------------------------------------------------------------------- /doc/img/modulecylinders.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulecylinders.png -------------------------------------------------------------------------------- /doc/img/moduledisplace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduledisplace.png -------------------------------------------------------------------------------- /doc/img/moduleexponent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleexponent.png -------------------------------------------------------------------------------- /doc/img/moduleinvert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleinvert.png -------------------------------------------------------------------------------- /doc/img/modulemax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulemax.png -------------------------------------------------------------------------------- /doc/img/modulemin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulemin.png -------------------------------------------------------------------------------- /doc/img/modulemultiply.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulemultiply.png -------------------------------------------------------------------------------- /doc/img/moduleperlin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleperlin.png -------------------------------------------------------------------------------- /doc/img/modulepower.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulepower.png -------------------------------------------------------------------------------- /doc/img/moduleridgedmulti.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleridgedmulti.png -------------------------------------------------------------------------------- /doc/img/modulerotatepoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulerotatepoint.png -------------------------------------------------------------------------------- /doc/img/modulescalebias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulescalebias.png -------------------------------------------------------------------------------- /doc/img/modulescalepoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulescalepoint.png -------------------------------------------------------------------------------- /doc/img/moduleselect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleselect.png -------------------------------------------------------------------------------- /doc/img/modulespheres.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulespheres.png -------------------------------------------------------------------------------- /doc/img/moduleterrace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleterrace.png -------------------------------------------------------------------------------- /doc/img/moduletranslatepoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduletranslatepoint.png -------------------------------------------------------------------------------- /doc/img/moduleturbulence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/moduleturbulence.png -------------------------------------------------------------------------------- /doc/img/modulevoronoi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/modulevoronoi.png -------------------------------------------------------------------------------- /doc/img/terrace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/doc/img/terrace.png -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET(PROJECT_NAME examples) 2 | 3 | add_executable(complexplanet complexplanet.cpp) 4 | ADD_DEFINITIONS( "-I${PROJECT_SOURCE_DIR}/src" ) 5 | ADD_DEFINITIONS( "-I${PROJECT_SOURCE_DIR}/noiseutils" ) 6 | target_link_libraries(complexplanet noiseutils-static noise-static) 7 | -------------------------------------------------------------------------------- /examples/readme.txt: -------------------------------------------------------------------------------- 1 | libnoise examples - differences between 0.9.0 and 0.9.0.1 2 | 3 | - Since the noiseutils library is part of the noise namespace, these 4 | examples now use that namespace. 5 | -------------------------------------------------------------------------------- /examples/texturegranite.cpp: -------------------------------------------------------------------------------- 1 | // texturegranite.cpp 2 | // 3 | // This program uses the libnoise library to generate texture maps consisting 4 | // of granite. 5 | // 6 | // Copyright (C) 2004 Jason Bevins 7 | // 8 | // This program is free software; you can redistribute it and/or modify it 9 | // under the terms of the GNU General Public License as published by the Free 10 | // Software Foundation; either version 2 of the License, or (at your option) 11 | // any later version. 12 | // 13 | // This program is distributed in the hope that it will be useful, but WITHOUT 14 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 | // (COPYING.txt) for more details. 17 | // 18 | // You should have received a copy of the GNU General Public License along 19 | // with this program; if not, write to the Free Software Foundation, Inc., 59 20 | // Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | // 22 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 23 | // off every 'zig'.) 24 | // 25 | 26 | #include 27 | 28 | #include "noiseutils.h" 29 | 30 | using namespace noise; 31 | 32 | // Height of the texture. 33 | const int TEXTURE_HEIGHT = 256; 34 | 35 | // Creates the color gradients for the texture. 36 | void CreateTextureColor (utils::RendererImage& renderer); 37 | 38 | // Given a noise module, this function renders a flat square texture map and 39 | // writes it to a Windows bitmap (*.bmp) file. Because the texture map is 40 | // square, its width is equal to its height. The texture map can be seamless 41 | // (tileable) or non-seamless. 42 | void CreatePlanarTexture (const module::Module& noiseModule, bool seamless, 43 | int height, const char* filename); 44 | 45 | // Given a noise module, this function renders a spherical texture map and 46 | // writes it to a Windows bitmap (*.bmp) file. The texture map's width is 47 | // double its height. 48 | void CreateSphericalTexture (const module::Module& noiseModule, int height, 49 | const char* filename); 50 | 51 | // Given a noise map, this function renders a texture map and writes it to a 52 | // Windows bitmap (*.bmp) file. 53 | void RenderTexture (const utils::NoiseMap& noiseMap, 54 | const char* filename); 55 | 56 | int main () 57 | { 58 | // Primary granite texture. This generates the "roughness" of the texture 59 | // when lit by a light source. 60 | module::Billow primaryGranite; 61 | primaryGranite.SetSeed (0); 62 | primaryGranite.SetFrequency (8.0); 63 | primaryGranite.SetPersistence (0.625); 64 | primaryGranite.SetLacunarity (2.18359375); 65 | primaryGranite.SetOctaveCount (6); 66 | primaryGranite.SetNoiseQuality (QUALITY_STD); 67 | 68 | // Use Voronoi polygons to produce the small grains for the granite texture. 69 | module::Voronoi baseGrains; 70 | baseGrains.SetSeed (1); 71 | baseGrains.SetFrequency (16.0); 72 | baseGrains.EnableDistance (true); 73 | 74 | // Scale the small grain values so that they may be added to the base 75 | // granite texture. Voronoi polygons normally generate pits, so apply a 76 | // negative scaling factor to produce bumps instead. 77 | module::ScaleBias scaledGrains; 78 | scaledGrains.SetSourceModule (0, baseGrains); 79 | scaledGrains.SetScale (-0.5); 80 | scaledGrains.SetBias (0.0); 81 | 82 | // Combine the primary granite texture with the small grain texture. 83 | module::Add combinedGranite; 84 | combinedGranite.SetSourceModule (0, primaryGranite); 85 | combinedGranite.SetSourceModule (1, scaledGrains); 86 | 87 | // Finally, perturb the granite texture to add realism. 88 | module::Turbulence finalGranite; 89 | finalGranite.SetSourceModule (0, combinedGranite); 90 | finalGranite.SetSeed (2); 91 | finalGranite.SetFrequency (4.0); 92 | finalGranite.SetPower (1.0 / 8.0); 93 | finalGranite.SetRoughness (6); 94 | 95 | // Given the granite noise module, create a non-seamless texture map, a 96 | // seamless texture map, and a spherical texture map. 97 | CreatePlanarTexture (finalGranite, false, TEXTURE_HEIGHT, 98 | "textureplane.bmp"); 99 | CreatePlanarTexture (finalGranite, true, TEXTURE_HEIGHT, 100 | "textureseamless.bmp"); 101 | CreateSphericalTexture (finalGranite, TEXTURE_HEIGHT, 102 | "texturesphere.bmp"); 103 | 104 | return 0; 105 | } 106 | 107 | void CreateTextureColor (utils::RendererImage& renderer) 108 | { 109 | // Create a gray granite palette. Black and pink appear at either ends of 110 | // the palette; those colors provide the charactistic black and pink flecks 111 | // in granite. 112 | renderer.ClearGradient (); 113 | renderer.AddGradientPoint (-1.0000, utils::Color ( 0, 0, 0, 255)); 114 | renderer.AddGradientPoint (-0.9375, utils::Color ( 0, 0, 0, 255)); 115 | renderer.AddGradientPoint (-0.8750, utils::Color (216, 216, 242, 255)); 116 | renderer.AddGradientPoint ( 0.0000, utils::Color (191, 191, 191, 255)); 117 | renderer.AddGradientPoint ( 0.5000, utils::Color (210, 116, 125, 255)); 118 | renderer.AddGradientPoint ( 0.7500, utils::Color (210, 113, 98, 255)); 119 | renderer.AddGradientPoint ( 1.0000, utils::Color (255, 176, 192, 255)); 120 | } 121 | 122 | void CreatePlanarTexture (const module::Module& noiseModule, bool seamless, 123 | int height, const char* filename) 124 | { 125 | // Map the output values from the noise module onto a plane. This will 126 | // create a two-dimensional noise map which can be rendered as a flat 127 | // texture map. 128 | utils::NoiseMapBuilderPlane plane; 129 | utils::NoiseMap noiseMap; 130 | plane.SetBounds (-1.0, 1.0, -1.0, 1.0); 131 | plane.SetDestSize (height, height); 132 | plane.SetSourceModule (noiseModule); 133 | plane.SetDestNoiseMap (noiseMap); 134 | plane.EnableSeamless (seamless); 135 | plane.Build (); 136 | 137 | RenderTexture (noiseMap, filename); 138 | } 139 | 140 | void CreateSphericalTexture (const module::Module& noiseModule, int height, 141 | const char* filename) 142 | { 143 | // Map the output values from the noise module onto a sphere. This will 144 | // create a two-dimensional noise map which can be rendered as a spherical 145 | // texture map. 146 | utils::NoiseMapBuilderSphere sphere; 147 | utils::NoiseMap noiseMap; 148 | sphere.SetBounds (-90.0, 90.0, -180.0, 180.0); // degrees 149 | sphere.SetDestSize (height * 2, height); 150 | sphere.SetSourceModule (noiseModule); 151 | sphere.SetDestNoiseMap (noiseMap); 152 | sphere.Build (); 153 | 154 | RenderTexture (noiseMap, filename); 155 | } 156 | 157 | void RenderTexture (const utils::NoiseMap& noiseMap, const char* filename) 158 | { 159 | // Create the color gradients for the texture. 160 | utils::RendererImage textureRenderer; 161 | CreateTextureColor (textureRenderer); 162 | 163 | // Set up us the texture renderer and pass the noise map to it. 164 | utils::Image destTexture; 165 | textureRenderer.SetSourceNoiseMap (noiseMap); 166 | textureRenderer.SetDestImage (destTexture); 167 | textureRenderer.EnableLight (true); 168 | textureRenderer.SetLightAzimuth (135.0); 169 | textureRenderer.SetLightElev (60.0); 170 | textureRenderer.SetLightContrast (2.0); 171 | textureRenderer.SetLightColor (utils::Color (255, 255, 255, 0)); 172 | 173 | // Render the texture. 174 | textureRenderer.Render (); 175 | 176 | // Write the texture as a Windows bitmap file (*.bmp). 177 | utils::WriterBMP textureWriter; 178 | textureWriter.SetSourceImage (destTexture); 179 | textureWriter.SetDestFilename (filename); 180 | textureWriter.WriteDestFile (); 181 | } 182 | -------------------------------------------------------------------------------- /noiseutils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PROJECT_NAME libnoiseutils) 2 | set(LIB_NAME noiseutils) 3 | message(STATUS "\n\n#############################################") 4 | message(STATUS "# building project ${PROJECT_NAME}") 5 | 6 | set(libSrcs ${libSrcs} noiseutils.cpp) 7 | 8 | 9 | if(BUILD_SHARED_LIBS) 10 | #---------------------------------------- 11 | # build dynamic lib 12 | set(TARGET_NAME "${LIB_NAME}") 13 | add_library(${TARGET_NAME} SHARED ${libSrcs}) 14 | 15 | if(WIN32) 16 | #set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES CACHE BOOL "Export all symbols") 17 | set_target_properties(${TARGET_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1) 18 | endif() 19 | 20 | set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${LIBNOISE_VERSION}) 21 | target_link_libraries(${TARGET_NAME} noise) 22 | target_include_directories(${TARGET_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src) 23 | 24 | # install dynamic libraries (.dll or .so) into /bin 25 | install(TARGETS ${TARGET_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") 26 | endif() 27 | 28 | #---------------------------------------- 29 | # build static lib (it's good practice to include a lib file for the dll) 30 | set(TARGET_NAME "${LIB_NAME}-static") 31 | add_library(${TARGET_NAME} STATIC ${libSrcs}) 32 | set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${LIBNOISE_VERSION}) 33 | target_link_libraries(${TARGET_NAME} noise-static) 34 | target_include_directories(${TARGET_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src) 35 | # install static libraries (.lib) into /lib 36 | install(TARGETS ${TARGET_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") 37 | #---------------------------------------- 38 | 39 | # install include files into /include 40 | install( FILES "${PROJECT_SOURCE_DIR}/noiseutils/noiseutils.h" 41 | DESTINATION "${CMAKE_INSTALL_PREFIX}/include/noise" ) -------------------------------------------------------------------------------- /noiseutils/readme.txt: -------------------------------------------------------------------------------- 1 | noiseutils library - differences between 0.9.0 and 0.9.0.1 2 | 3 | - Added the noiseutils classes to the noise::utils namespace. 4 | 5 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PROJECT_NAME libnoise) 2 | set(LIB_NAME noise) 3 | message(STATUS "\n\n#############################################") 4 | message(STATUS "# building project ${PROJECT_NAME}") 5 | 6 | include_directories(noise) 7 | 8 | set(libSrcs ${libSrcs} 9 | noisegen.cpp 10 | latlon.cpp 11 | 12 | model/line.cpp 13 | model/plane.cpp 14 | model/sphere.cpp 15 | model/cylinder.cpp 16 | 17 | module/abs.cpp 18 | module/add.cpp 19 | module/billow.cpp 20 | module/blend.cpp 21 | module/cache.cpp 22 | module/checkerboard.cpp 23 | module/clamp.cpp 24 | module/const.cpp 25 | module/curve.cpp 26 | module/cylinders.cpp 27 | module/displace.cpp 28 | module/exponent.cpp 29 | module/invert.cpp 30 | module/max.cpp 31 | module/min.cpp 32 | module/modulebase.cpp 33 | module/multiply.cpp 34 | module/perlin.cpp 35 | module/power.cpp 36 | module/ridgedmulti.cpp 37 | module/rotatepoint.cpp 38 | module/scalebias.cpp 39 | module/scalepoint.cpp 40 | module/select.cpp 41 | module/spheres.cpp 42 | module/terrace.cpp 43 | module/translatepoint.cpp 44 | module/turbulence.cpp 45 | module/voronoi.cpp 46 | ) 47 | 48 | # Users of your library should be able to choose static library or shared library to build. 49 | # Do not specify a library type explicitly unless necessary. 50 | if(BUILD_SHARED_LIBS) 51 | #---------------------------------------- 52 | # build dynamic lib 53 | set(TARGET_NAME "${LIB_NAME}") 54 | if (WIN32) 55 | message(STATUS "build ${TARGET_NAME}: shared | platform: win32 (x86) & win64 (x64)") 56 | add_library(${TARGET_NAME} SHARED ${libSrcs} win32/dllmain.cpp) 57 | set_target_properties(${TARGET_NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1) 58 | else() 59 | message(STATUS "build ${TARGET_NAME}: shared | platform: others") 60 | add_library(${TARGET_NAME} SHARED ${libSrcs}) 61 | endif() 62 | set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${LIBNOISE_VERSION}) 63 | target_include_directories(${TARGET_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src) 64 | target_compile_definitions(${TARGET_NAME} PRIVATE NOISE_BUILD_DLL) 65 | install(TARGETS ${TARGET_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") 66 | endif() 67 | 68 | #---------------------------------------- 69 | # build static lib (it's good practice to include a lib file for the dll) 70 | set(TARGET_NAME "${LIB_NAME}-static") 71 | message(STATUS "build ${TARGET_NAME}") 72 | add_library(${TARGET_NAME} STATIC ${libSrcs}) 73 | set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${LIBNOISE_VERSION}) 74 | target_include_directories(${TARGET_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src) 75 | target_compile_definitions(${TARGET_NAME} PUBLIC NOISE_STATIC) 76 | # install static libraries (.lib) into /lib 77 | install(TARGETS ${TARGET_NAME} DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") 78 | #---------------------------------------- 79 | 80 | # install include files into /include 81 | install( DIRECTORY "${PROJECT_SOURCE_DIR}/src/noise" 82 | DESTINATION "${CMAKE_INSTALL_PREFIX}/include" ) -------------------------------------------------------------------------------- /src/latlon.cpp: -------------------------------------------------------------------------------- 1 | // latlon.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "noise/latlon.h" 24 | 25 | using namespace noise; 26 | 27 | void noise::LatLonToXYZ (double lat, double lon, double& x, double& y, 28 | double& z) 29 | { 30 | double r = cos (DEG_TO_RAD * lat); 31 | x = r * cos (DEG_TO_RAD * lon); 32 | y = sin (DEG_TO_RAD * lat); 33 | z = r * sin (DEG_TO_RAD * lon); 34 | } 35 | -------------------------------------------------------------------------------- /src/model/cylinder.cpp: -------------------------------------------------------------------------------- 1 | // cylinder.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "mathconsts.h" 24 | #include "model/cylinder.h" 25 | 26 | using namespace noise; 27 | using namespace noise::model; 28 | 29 | Cylinder::Cylinder (): m_pModule (NULL) 30 | { 31 | } 32 | 33 | Cylinder::Cylinder (const module::Module& module): 34 | m_pModule (&module) 35 | { 36 | } 37 | 38 | double Cylinder::GetValue (double angle, double height) const 39 | { 40 | assert (m_pModule != NULL); 41 | 42 | double x, y, z; 43 | x = cos (angle * DEG_TO_RAD); 44 | y = height; 45 | z = sin (angle * DEG_TO_RAD); 46 | return m_pModule->GetValue (x, y, z); 47 | } 48 | -------------------------------------------------------------------------------- /src/model/line.cpp: -------------------------------------------------------------------------------- 1 | // line.cpp 2 | // 3 | // Copyright (C) 2004 Keith Davies 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | 20 | #include "model/line.h" 21 | 22 | using namespace noise; 23 | using namespace noise::model; 24 | 25 | Line::Line (): 26 | 27 | m_attenuate (true), 28 | m_pModule (NULL), 29 | m_x0 (0.0), 30 | m_x1 (1.0), 31 | m_y0 (0.0), 32 | m_y1 (1.0), 33 | m_z0 (0.0), 34 | m_z1 (1.0) 35 | { 36 | } 37 | 38 | Line::Line (const module::Module& module): 39 | 40 | m_attenuate (true), 41 | m_pModule (&module), 42 | m_x0 (0.0), 43 | m_x1 (1.0), 44 | m_y0 (0.0), 45 | m_y1 (1.0), 46 | m_z0 (0.0), 47 | m_z1 (1.0) 48 | { 49 | } 50 | 51 | double Line::GetValue (double p) const 52 | { 53 | assert (m_pModule != NULL); 54 | 55 | double x = (m_x1 - m_x0) * p + m_x0; 56 | double y = (m_y1 - m_y0) * p + m_y0; 57 | double z = (m_z1 - m_z0) * p + m_z0; 58 | double value = m_pModule->GetValue (x, y, z); 59 | 60 | if (m_attenuate) { 61 | return p * (1.0 - p) * 4 * value; 62 | } else { 63 | return value; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/model/plane.cpp: -------------------------------------------------------------------------------- 1 | // plane.cpp 2 | // 3 | // Copyright (C) 2004 Owen Jacobson 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is ojacobson@lionsanctuary.net 20 | // 21 | 22 | #include "model/plane.h" 23 | 24 | using namespace noise; 25 | using namespace noise::model; 26 | 27 | Plane::Plane (): 28 | m_pModule (NULL) 29 | { 30 | } 31 | 32 | Plane::Plane (const module::Module& module) : 33 | m_pModule( &module) 34 | { 35 | } 36 | 37 | // Told you this was trivial. 38 | double Plane::GetValue (double x, double z) const 39 | { 40 | assert (m_pModule != NULL); 41 | 42 | return m_pModule->GetValue (x, 0, z); 43 | } 44 | -------------------------------------------------------------------------------- /src/model/sphere.cpp: -------------------------------------------------------------------------------- 1 | // sphere.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "latlon.h" 24 | #include "model/sphere.h" 25 | using namespace noise; 26 | using namespace noise::model; 27 | 28 | Sphere::Sphere (): 29 | m_pModule (NULL) 30 | { 31 | } 32 | 33 | Sphere::Sphere (const module::Module& module): 34 | m_pModule (&module) 35 | { 36 | } 37 | 38 | double Sphere::GetValue (double lat, double lon) const 39 | { 40 | assert (m_pModule != NULL); 41 | 42 | double x, y, z; 43 | LatLonToXYZ (lat, lon, x, y, z); 44 | return m_pModule->GetValue (x, y, z); 45 | } 46 | -------------------------------------------------------------------------------- /src/module/abs.cpp: -------------------------------------------------------------------------------- 1 | // abs.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/abs.h" 24 | 25 | using namespace noise::module; 26 | 27 | Abs::Abs (): 28 | Module (GetSourceModuleCount ()) 29 | { 30 | } 31 | 32 | double Abs::GetValue (double x, double y, double z) const 33 | { 34 | assert (m_pSourceModule[0] != NULL); 35 | 36 | return fabs (m_pSourceModule[0]->GetValue (x, y, z)); 37 | } 38 | -------------------------------------------------------------------------------- /src/module/add.cpp: -------------------------------------------------------------------------------- 1 | // add.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/add.h" 24 | 25 | using namespace noise::module; 26 | 27 | Add::Add (): 28 | Module (GetSourceModuleCount ()) 29 | { 30 | } 31 | 32 | double Add::GetValue (double x, double y, double z) const 33 | { 34 | assert (m_pSourceModule[0] != NULL); 35 | assert (m_pSourceModule[1] != NULL); 36 | 37 | return m_pSourceModule[0]->GetValue (x, y, z) 38 | + m_pSourceModule[1]->GetValue (x, y, z); 39 | } 40 | -------------------------------------------------------------------------------- /src/module/billow.cpp: -------------------------------------------------------------------------------- 1 | // billow.cpp 2 | // 3 | // Copyright (C) 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/billow.h" 24 | 25 | using namespace noise::module; 26 | 27 | Billow::Billow (): 28 | Module (GetSourceModuleCount ()), 29 | m_frequency (DEFAULT_BILLOW_FREQUENCY ), 30 | m_lacunarity (DEFAULT_BILLOW_LACUNARITY ), 31 | m_noiseQuality (DEFAULT_BILLOW_QUALITY ), 32 | m_octaveCount (DEFAULT_BILLOW_OCTAVE_COUNT), 33 | m_persistence (DEFAULT_BILLOW_PERSISTENCE ), 34 | m_seed (DEFAULT_BILLOW_SEED) 35 | { 36 | } 37 | 38 | double Billow::GetValue (double x, double y, double z) const 39 | { 40 | double value = 0.0; 41 | double signal = 0.0; 42 | double curPersistence = 1.0; 43 | double nx, ny, nz; 44 | int seed; 45 | 46 | x *= m_frequency; 47 | y *= m_frequency; 48 | z *= m_frequency; 49 | 50 | for (int curOctave = 0; curOctave < m_octaveCount; curOctave++) { 51 | 52 | // Make sure that these floating-point values have the same range as a 32- 53 | // bit integer so that we can pass them to the coherent-noise functions. 54 | nx = MakeInt32Range (x); 55 | ny = MakeInt32Range (y); 56 | nz = MakeInt32Range (z); 57 | 58 | // Get the coherent-noise value from the input value and add it to the 59 | // final result. 60 | seed = (m_seed + curOctave) & 0xffffffff; 61 | signal = GradientCoherentNoise3D (nx, ny, nz, seed, m_noiseQuality); 62 | signal = 2.0 * fabs (signal) - 1.0; 63 | value += signal * curPersistence; 64 | 65 | // Prepare the next octave. 66 | x *= m_lacunarity; 67 | y *= m_lacunarity; 68 | z *= m_lacunarity; 69 | curPersistence *= m_persistence; 70 | } 71 | value += 0.5; 72 | 73 | return value; 74 | } 75 | -------------------------------------------------------------------------------- /src/module/blend.cpp: -------------------------------------------------------------------------------- 1 | // blend.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/blend.h" 24 | #include "interp.h" 25 | 26 | using namespace noise::module; 27 | 28 | Blend::Blend (): 29 | Module (GetSourceModuleCount ()) 30 | { 31 | } 32 | 33 | double Blend::GetValue (double x, double y, double z) const 34 | { 35 | assert (m_pSourceModule[0] != NULL); 36 | assert (m_pSourceModule[1] != NULL); 37 | assert (m_pSourceModule[2] != NULL); 38 | 39 | double v0 = m_pSourceModule[0]->GetValue (x, y, z); 40 | double v1 = m_pSourceModule[1]->GetValue (x, y, z); 41 | double alpha = (m_pSourceModule[2]->GetValue (x, y, z) + 1.0) / 2.0; 42 | return LinearInterp (v0, v1, alpha); 43 | } 44 | -------------------------------------------------------------------------------- /src/module/cache.cpp: -------------------------------------------------------------------------------- 1 | // cache.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/cache.h" 24 | 25 | using namespace noise::module; 26 | 27 | Cache::Cache (): 28 | Module (GetSourceModuleCount ()), 29 | m_isCached (false) 30 | { 31 | } 32 | 33 | double Cache::GetValue (double x, double y, double z) const 34 | { 35 | assert (m_pSourceModule[0] != NULL); 36 | 37 | if (!(m_isCached && x == m_xCache && y == m_yCache && z == m_zCache)) { 38 | m_cachedValue = m_pSourceModule[0]->GetValue (x, y, z); 39 | m_xCache = x; 40 | m_yCache = y; 41 | m_zCache = z; 42 | } 43 | m_isCached = true; 44 | return m_cachedValue; 45 | } 46 | -------------------------------------------------------------------------------- /src/module/checkerboard.cpp: -------------------------------------------------------------------------------- 1 | // checkerboard.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/checkerboard.h" 24 | 25 | using namespace noise::module; 26 | 27 | Checkerboard::Checkerboard (): 28 | Module (GetSourceModuleCount ()) 29 | { 30 | } 31 | 32 | double Checkerboard::GetValue (double x, double y, double z) const 33 | { 34 | int ix = (int)(floor (MakeInt32Range (x))); 35 | int iy = (int)(floor (MakeInt32Range (y))); 36 | int iz = (int)(floor (MakeInt32Range (z))); 37 | return (ix & 1 ^ iy & 1 ^ iz & 1)? -1.0: 1.0; 38 | } 39 | -------------------------------------------------------------------------------- /src/module/clamp.cpp: -------------------------------------------------------------------------------- 1 | // clamp.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/clamp.h" 24 | 25 | using namespace noise::module; 26 | 27 | Clamp::Clamp (): 28 | Module (GetSourceModuleCount ()), 29 | m_lowerBound (DEFAULT_CLAMP_LOWER_BOUND), 30 | m_upperBound (DEFAULT_CLAMP_UPPER_BOUND) 31 | { 32 | } 33 | 34 | double Clamp::GetValue (double x, double y, double z) const 35 | { 36 | assert (m_pSourceModule[0] != NULL); 37 | 38 | double value = m_pSourceModule[0]->GetValue (x, y, z); 39 | if (value < m_lowerBound) { 40 | return m_lowerBound; 41 | } else if (value > m_upperBound) { 42 | return m_upperBound; 43 | } else { 44 | return value; 45 | } 46 | } 47 | 48 | void Clamp::SetBounds (double lowerBound, double upperBound) 49 | { 50 | assert (lowerBound < upperBound); 51 | 52 | m_lowerBound = lowerBound; 53 | m_upperBound = upperBound; 54 | } 55 | -------------------------------------------------------------------------------- /src/module/const.cpp: -------------------------------------------------------------------------------- 1 | // const.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/const.h" 24 | 25 | using namespace noise::module; 26 | 27 | Const::Const (): 28 | Module (GetSourceModuleCount ()), 29 | m_constValue (DEFAULT_CONST_VALUE) 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /src/module/curve.cpp: -------------------------------------------------------------------------------- 1 | // curve.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "interp.h" 24 | #include "misc.h" 25 | #include "module/curve.h" 26 | 27 | using namespace noise::module; 28 | 29 | Curve::Curve (): 30 | Module (GetSourceModuleCount ()), 31 | m_pControlPoints (NULL) 32 | { 33 | m_controlPointCount = 0; 34 | } 35 | 36 | Curve::~Curve () 37 | { 38 | delete[] m_pControlPoints; 39 | } 40 | 41 | void Curve::AddControlPoint (double inputValue, double outputValue) 42 | { 43 | // Find the insertion point for the new control point and insert the new 44 | // point at that position. The control point array will remain sorted by 45 | // input value. 46 | int insertionPos = FindInsertionPos (inputValue); 47 | InsertAtPos (insertionPos, inputValue, outputValue); 48 | } 49 | 50 | void Curve::ClearAllControlPoints () 51 | { 52 | delete[] m_pControlPoints; 53 | m_pControlPoints = NULL; 54 | m_controlPointCount = 0; 55 | } 56 | 57 | int Curve::FindInsertionPos (double inputValue) 58 | { 59 | int insertionPos; 60 | for (insertionPos = 0; insertionPos < m_controlPointCount; insertionPos++) { 61 | if (inputValue < m_pControlPoints[insertionPos].inputValue) { 62 | // We found the array index in which to insert the new control point. 63 | // Exit now. 64 | break; 65 | } else if (inputValue == m_pControlPoints[insertionPos].inputValue) { 66 | // Each control point is required to contain a unique input value, so 67 | // throw an exception. 68 | throw noise::ExceptionInvalidParam (); 69 | } 70 | } 71 | return insertionPos; 72 | } 73 | 74 | double Curve::GetValue (double x, double y, double z) const 75 | { 76 | assert (m_pSourceModule[0] != NULL); 77 | assert (m_controlPointCount >= 4); 78 | 79 | // Get the output value from the source module. 80 | double sourceModuleValue = m_pSourceModule[0]->GetValue (x, y, z); 81 | 82 | // Find the first element in the control point array that has an input value 83 | // larger than the output value from the source module. 84 | int indexPos; 85 | for (indexPos = 0; indexPos < m_controlPointCount; indexPos++) { 86 | if (sourceModuleValue < m_pControlPoints[indexPos].inputValue) { 87 | break; 88 | } 89 | } 90 | 91 | // Find the four nearest control points so that we can perform cubic 92 | // interpolation. 93 | int index0 = ClampValue (indexPos - 2, 0, m_controlPointCount - 1); 94 | int index1 = ClampValue (indexPos - 1, 0, m_controlPointCount - 1); 95 | int index2 = ClampValue (indexPos , 0, m_controlPointCount - 1); 96 | int index3 = ClampValue (indexPos + 1, 0, m_controlPointCount - 1); 97 | 98 | // If some control points are missing (which occurs if the value from the 99 | // source module is greater than the largest input value or less than the 100 | // smallest input value of the control point array), get the corresponding 101 | // output value of the nearest control point and exit now. 102 | if (index1 == index2) { 103 | return m_pControlPoints[index1].outputValue; 104 | } 105 | 106 | // Compute the alpha value used for cubic interpolation. 107 | double input0 = m_pControlPoints[index1].inputValue; 108 | double input1 = m_pControlPoints[index2].inputValue; 109 | double alpha = (sourceModuleValue - input0) / (input1 - input0); 110 | 111 | // Now perform the cubic interpolation given the alpha value. 112 | return CubicInterp ( 113 | m_pControlPoints[index0].outputValue, 114 | m_pControlPoints[index1].outputValue, 115 | m_pControlPoints[index2].outputValue, 116 | m_pControlPoints[index3].outputValue, 117 | alpha); 118 | } 119 | 120 | void Curve::InsertAtPos (int insertionPos, double inputValue, 121 | double outputValue) 122 | { 123 | // Make room for the new control point at the specified position within the 124 | // control point array. The position is determined by the input value of 125 | // the control point; the control points must be sorted by input value 126 | // within that array. 127 | ControlPoint* newControlPoints = new ControlPoint[m_controlPointCount + 1]; 128 | for (int i = 0; i < m_controlPointCount; i++) { 129 | if (i < insertionPos) { 130 | newControlPoints[i] = m_pControlPoints[i]; 131 | } else { 132 | newControlPoints[i + 1] = m_pControlPoints[i]; 133 | } 134 | } 135 | delete[] m_pControlPoints; 136 | m_pControlPoints = newControlPoints; 137 | ++m_controlPointCount; 138 | 139 | // Now that we've made room for the new control point within the array, add 140 | // the new control point. 141 | m_pControlPoints[insertionPos].inputValue = inputValue ; 142 | m_pControlPoints[insertionPos].outputValue = outputValue; 143 | } 144 | -------------------------------------------------------------------------------- /src/module/cylinders.cpp: -------------------------------------------------------------------------------- 1 | // cylinders.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "misc.h" 24 | #include "module/cylinders.h" 25 | 26 | using namespace noise::module; 27 | 28 | Cylinders::Cylinders (): 29 | Module (GetSourceModuleCount ()), 30 | m_frequency (DEFAULT_CYLINDERS_FREQUENCY) 31 | { 32 | } 33 | 34 | double Cylinders::GetValue (double x, double y, double z) const 35 | { 36 | x *= m_frequency; 37 | z *= m_frequency; 38 | 39 | double distFromCenter = sqrt (x * x + z * z); 40 | double distFromSmallerSphere = distFromCenter - floor (distFromCenter); 41 | double distFromLargerSphere = 1.0 - distFromSmallerSphere; 42 | double nearestDist = GetMin (distFromSmallerSphere, distFromLargerSphere); 43 | return 1.0 - (nearestDist * 4.0); // Puts it in the -1.0 to +1.0 range. 44 | } 45 | -------------------------------------------------------------------------------- /src/module/displace.cpp: -------------------------------------------------------------------------------- 1 | // displace.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/displace.h" 24 | 25 | using namespace noise::module; 26 | 27 | Displace::Displace (): 28 | Module (GetSourceModuleCount ()) 29 | { 30 | } 31 | 32 | double Displace::GetValue (double x, double y, double z) const 33 | { 34 | assert (m_pSourceModule[0] != NULL); 35 | assert (m_pSourceModule[1] != NULL); 36 | assert (m_pSourceModule[2] != NULL); 37 | assert (m_pSourceModule[3] != NULL); 38 | 39 | // Get the output values from the three displacement modules. Add each 40 | // value to the corresponding coordinate in the input value. 41 | double xDisplace = x + (m_pSourceModule[1]->GetValue (x, y, z)); 42 | double yDisplace = y + (m_pSourceModule[2]->GetValue (x, y, z)); 43 | double zDisplace = z + (m_pSourceModule[3]->GetValue (x, y, z)); 44 | 45 | // Retrieve the output value using the offsetted input value instead of 46 | // the original input value. 47 | return m_pSourceModule[0]->GetValue (xDisplace, yDisplace, zDisplace); 48 | } 49 | -------------------------------------------------------------------------------- /src/module/exponent.cpp: -------------------------------------------------------------------------------- 1 | // exponent.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/exponent.h" 24 | 25 | using namespace noise::module; 26 | 27 | Exponent::Exponent (): 28 | Module (GetSourceModuleCount ()), 29 | m_exponent (DEFAULT_EXPONENT) 30 | { 31 | } 32 | 33 | double Exponent::GetValue (double x, double y, double z) const 34 | { 35 | assert (m_pSourceModule[0] != NULL); 36 | 37 | double value = m_pSourceModule[0]->GetValue (x, y, z); 38 | return (pow (fabs ((value + 1.0) / 2.0), m_exponent) * 2.0 - 1.0); 39 | } 40 | -------------------------------------------------------------------------------- /src/module/invert.cpp: -------------------------------------------------------------------------------- 1 | // invert.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/invert.h" 24 | 25 | using namespace noise::module; 26 | 27 | Invert::Invert (): 28 | Module (GetSourceModuleCount ()) 29 | { 30 | } 31 | 32 | double Invert::GetValue (double x, double y, double z) const 33 | { 34 | assert (m_pSourceModule[0] != NULL); 35 | 36 | return -(m_pSourceModule[0]->GetValue (x, y, z)); 37 | } 38 | -------------------------------------------------------------------------------- /src/module/max.cpp: -------------------------------------------------------------------------------- 1 | // max.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "misc.h" 24 | #include "module/max.h" 25 | 26 | using namespace noise::module; 27 | 28 | Max::Max (): 29 | Module (GetSourceModuleCount ()) 30 | { 31 | } 32 | 33 | double Max::GetValue (double x, double y, double z) const 34 | { 35 | assert (m_pSourceModule[0] != NULL); 36 | assert (m_pSourceModule[1] != NULL); 37 | 38 | double v0 = m_pSourceModule[0]->GetValue (x, y, z); 39 | double v1 = m_pSourceModule[1]->GetValue (x, y, z); 40 | return GetMax (v0, v1); 41 | } 42 | -------------------------------------------------------------------------------- /src/module/min.cpp: -------------------------------------------------------------------------------- 1 | // min.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "misc.h" 24 | #include "module/min.h" 25 | 26 | using namespace noise::module; 27 | 28 | Min::Min (): 29 | Module (GetSourceModuleCount ()) 30 | { 31 | } 32 | 33 | double Min::GetValue (double x, double y, double z) const 34 | { 35 | assert (m_pSourceModule[0] != NULL); 36 | assert (m_pSourceModule[1] != NULL); 37 | 38 | double v0 = m_pSourceModule[0]->GetValue (x, y, z); 39 | double v1 = m_pSourceModule[1]->GetValue (x, y, z); 40 | return GetMin (v0, v1); 41 | } 42 | -------------------------------------------------------------------------------- /src/module/modulebase.cpp: -------------------------------------------------------------------------------- 1 | // modulebase.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/modulebase.h" 24 | 25 | using namespace noise::module; 26 | 27 | Module::Module (int sourceModuleCount) 28 | { 29 | m_pSourceModule = NULL; 30 | 31 | // Create an array of pointers to all source modules required by this 32 | // noise module. Set these pointers to NULL. 33 | if (sourceModuleCount > 0) { 34 | m_pSourceModule = new const Module*[sourceModuleCount]; 35 | for (int i = 0; i < sourceModuleCount; i++) { 36 | m_pSourceModule[i] = NULL; 37 | } 38 | } else { 39 | m_pSourceModule = NULL; 40 | } 41 | } 42 | 43 | Module::~Module () 44 | { 45 | delete[] m_pSourceModule; 46 | } 47 | -------------------------------------------------------------------------------- /src/module/multiply.cpp: -------------------------------------------------------------------------------- 1 | // multiply.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/multiply.h" 24 | 25 | using namespace noise::module; 26 | 27 | Multiply::Multiply (): 28 | Module (GetSourceModuleCount ()) 29 | { 30 | } 31 | 32 | double Multiply::GetValue (double x, double y, double z) const 33 | { 34 | assert (m_pSourceModule[0] != NULL); 35 | assert (m_pSourceModule[1] != NULL); 36 | 37 | return m_pSourceModule[0]->GetValue (x, y, z) 38 | * m_pSourceModule[1]->GetValue (x, y, z); 39 | } 40 | -------------------------------------------------------------------------------- /src/module/perlin.cpp: -------------------------------------------------------------------------------- 1 | // perlin.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/perlin.h" 24 | 25 | using namespace noise::module; 26 | 27 | Perlin::Perlin (): 28 | Module (GetSourceModuleCount ()), 29 | m_frequency (DEFAULT_PERLIN_FREQUENCY ), 30 | m_lacunarity (DEFAULT_PERLIN_LACUNARITY ), 31 | m_noiseQuality (DEFAULT_PERLIN_QUALITY ), 32 | m_octaveCount (DEFAULT_PERLIN_OCTAVE_COUNT), 33 | m_persistence (DEFAULT_PERLIN_PERSISTENCE ), 34 | m_seed (DEFAULT_PERLIN_SEED) 35 | { 36 | } 37 | 38 | double Perlin::GetValue (double x, double y, double z) const 39 | { 40 | double value = 0.0; 41 | double signal = 0.0; 42 | double curPersistence = 1.0; 43 | double nx, ny, nz; 44 | int seed; 45 | 46 | x *= m_frequency; 47 | y *= m_frequency; 48 | z *= m_frequency; 49 | 50 | for (int curOctave = 0; curOctave < m_octaveCount; curOctave++) { 51 | 52 | // Make sure that these floating-point values have the same range as a 32- 53 | // bit integer so that we can pass them to the coherent-noise functions. 54 | nx = MakeInt32Range (x); 55 | ny = MakeInt32Range (y); 56 | nz = MakeInt32Range (z); 57 | 58 | // Get the coherent-noise value from the input value and add it to the 59 | // final result. 60 | seed = (m_seed + curOctave) & 0xffffffff; 61 | signal = GradientCoherentNoise3D (nx, ny, nz, seed, m_noiseQuality); 62 | value += signal * curPersistence; 63 | 64 | // Prepare the next octave. 65 | x *= m_lacunarity; 66 | y *= m_lacunarity; 67 | z *= m_lacunarity; 68 | curPersistence *= m_persistence; 69 | } 70 | 71 | return value; 72 | } 73 | -------------------------------------------------------------------------------- /src/module/power.cpp: -------------------------------------------------------------------------------- 1 | // power.cpp 2 | // 3 | // Copyright (C) 2004 Owen Jacobson 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is angstrom@lionsanctuary.net 20 | // 21 | 22 | #include "module/power.h" 23 | 24 | using namespace noise::module; 25 | 26 | Power::Power (): 27 | Module (GetSourceModuleCount ()) 28 | { 29 | } 30 | 31 | double Power::GetValue (double x, double y, double z) const 32 | { 33 | assert (m_pSourceModule[0] != NULL); 34 | assert (m_pSourceModule[1] != NULL); 35 | 36 | return pow (m_pSourceModule[0]->GetValue (x, y, z), 37 | m_pSourceModule[1]->GetValue (x, y, z)); 38 | } 39 | -------------------------------------------------------------------------------- /src/module/ridgedmulti.cpp: -------------------------------------------------------------------------------- 1 | // ridgedmulti.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/ridgedmulti.h" 24 | 25 | using namespace noise::module; 26 | 27 | RidgedMulti::RidgedMulti (): 28 | Module (GetSourceModuleCount ()), 29 | m_frequency (DEFAULT_RIDGED_FREQUENCY ), 30 | m_lacunarity (DEFAULT_RIDGED_LACUNARITY ), 31 | m_noiseQuality (DEFAULT_RIDGED_QUALITY ), 32 | m_octaveCount (DEFAULT_RIDGED_OCTAVE_COUNT), 33 | m_seed (DEFAULT_RIDGED_SEED) 34 | { 35 | CalcSpectralWeights (); 36 | } 37 | 38 | // Calculates the spectral weights for each octave. 39 | void RidgedMulti::CalcSpectralWeights () 40 | { 41 | // This exponent parameter should be user-defined; it may be exposed in a 42 | // future version of libnoise. 43 | double h = 1.0; 44 | 45 | double frequency = 1.0; 46 | for (int i = 0; i < RIDGED_MAX_OCTAVE; i++) { 47 | // Compute weight for each frequency. 48 | m_pSpectralWeights[i] = pow (frequency, -h); 49 | frequency *= m_lacunarity; 50 | } 51 | } 52 | 53 | // Multifractal code originally written by F. Kenton "Doc Mojo" Musgrave, 54 | // 1998. Modified by jas for use with libnoise. 55 | double RidgedMulti::GetValue (double x, double y, double z) const 56 | { 57 | x *= m_frequency; 58 | y *= m_frequency; 59 | z *= m_frequency; 60 | 61 | double signal = 0.0; 62 | double value = 0.0; 63 | double weight = 1.0; 64 | 65 | // These parameters should be user-defined; they may be exposed in a 66 | // future version of libnoise. 67 | double offset = 1.0; 68 | double gain = 2.0; 69 | 70 | for (int curOctave = 0; curOctave < m_octaveCount; curOctave++) { 71 | 72 | // Make sure that these floating-point values have the same range as a 32- 73 | // bit integer so that we can pass them to the coherent-noise functions. 74 | double nx, ny, nz; 75 | nx = MakeInt32Range (x); 76 | ny = MakeInt32Range (y); 77 | nz = MakeInt32Range (z); 78 | 79 | // Get the coherent-noise value. 80 | int seed = (m_seed + curOctave) & 0x7fffffff; 81 | signal = GradientCoherentNoise3D (nx, ny, nz, seed, m_noiseQuality); 82 | 83 | // Make the ridges. 84 | signal = fabs (signal); 85 | signal = offset - signal; 86 | 87 | // Square the signal to increase the sharpness of the ridges. 88 | signal *= signal; 89 | 90 | // The weighting from the previous octave is applied to the signal. 91 | // Larger values have higher weights, producing sharp points along the 92 | // ridges. 93 | signal *= weight; 94 | 95 | // Weight successive contributions by the previous signal. 96 | weight = signal * gain; 97 | if (weight > 1.0) { 98 | weight = 1.0; 99 | } 100 | if (weight < 0.0) { 101 | weight = 0.0; 102 | } 103 | 104 | // Add the signal to the output value. 105 | value += (signal * m_pSpectralWeights[curOctave]); 106 | 107 | // Go to the next octave. 108 | x *= m_lacunarity; 109 | y *= m_lacunarity; 110 | z *= m_lacunarity; 111 | } 112 | 113 | return (value * 1.25) - 1.0; 114 | } 115 | -------------------------------------------------------------------------------- /src/module/rotatepoint.cpp: -------------------------------------------------------------------------------- 1 | // rotatepoint.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "mathconsts.h" 24 | #include "module/rotatepoint.h" 25 | 26 | using namespace noise::module; 27 | 28 | RotatePoint::RotatePoint (): 29 | Module (GetSourceModuleCount ()) 30 | { 31 | SetAngles (DEFAULT_ROTATE_X, DEFAULT_ROTATE_Y, DEFAULT_ROTATE_Z); 32 | } 33 | 34 | double RotatePoint::GetValue (double x, double y, double z) const 35 | { 36 | assert (m_pSourceModule[0] != NULL); 37 | 38 | double nx = (m_x1Matrix * x) + (m_y1Matrix * y) + (m_z1Matrix * z); 39 | double ny = (m_x2Matrix * x) + (m_y2Matrix * y) + (m_z2Matrix * z); 40 | double nz = (m_x3Matrix * x) + (m_y3Matrix * y) + (m_z3Matrix * z); 41 | return m_pSourceModule[0]->GetValue (nx, ny, nz); 42 | } 43 | 44 | void RotatePoint::SetAngles (double xAngle, double yAngle, 45 | double zAngle) 46 | { 47 | double xCos, yCos, zCos, xSin, ySin, zSin; 48 | xCos = cos (xAngle * DEG_TO_RAD); 49 | yCos = cos (yAngle * DEG_TO_RAD); 50 | zCos = cos (zAngle * DEG_TO_RAD); 51 | xSin = sin (xAngle * DEG_TO_RAD); 52 | ySin = sin (yAngle * DEG_TO_RAD); 53 | zSin = sin (zAngle * DEG_TO_RAD); 54 | 55 | m_x1Matrix = ySin * xSin * zSin + yCos * zCos; 56 | m_y1Matrix = xCos * zSin; 57 | m_z1Matrix = ySin * zCos - yCos * xSin * zSin; 58 | m_x2Matrix = ySin * xSin * zCos - yCos * zSin; 59 | m_y2Matrix = xCos * zCos; 60 | m_z2Matrix = -yCos * xSin * zCos - ySin * zSin; 61 | m_x3Matrix = -ySin * xCos; 62 | m_y3Matrix = xSin; 63 | m_z3Matrix = yCos * xCos; 64 | 65 | m_xAngle = xAngle; 66 | m_yAngle = yAngle; 67 | m_zAngle = zAngle; 68 | } 69 | -------------------------------------------------------------------------------- /src/module/scalebias.cpp: -------------------------------------------------------------------------------- 1 | // scalebias.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/scalebias.h" 24 | 25 | using namespace noise::module; 26 | 27 | ScaleBias::ScaleBias (): 28 | Module (GetSourceModuleCount ()), 29 | m_bias (DEFAULT_BIAS ), 30 | m_scale (DEFAULT_SCALE) 31 | { 32 | } 33 | 34 | double ScaleBias::GetValue (double x, double y, double z) const 35 | { 36 | assert (m_pSourceModule[0] != NULL); 37 | 38 | return m_pSourceModule[0]->GetValue (x, y, z) * m_scale + m_bias; 39 | } 40 | -------------------------------------------------------------------------------- /src/module/scalepoint.cpp: -------------------------------------------------------------------------------- 1 | // scalepoint.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/scalepoint.h" 24 | 25 | using namespace noise::module; 26 | 27 | ScalePoint::ScalePoint (): 28 | Module (GetSourceModuleCount ()), 29 | m_xScale (DEFAULT_SCALE_POINT_X), 30 | m_yScale (DEFAULT_SCALE_POINT_Y), 31 | m_zScale (DEFAULT_SCALE_POINT_Z) 32 | { 33 | } 34 | 35 | double ScalePoint::GetValue (double x, double y, double z) const 36 | { 37 | assert (m_pSourceModule[0] != NULL); 38 | 39 | return m_pSourceModule[0]->GetValue (x * m_xScale, y * m_yScale, 40 | z * m_zScale); 41 | } 42 | -------------------------------------------------------------------------------- /src/module/select.cpp: -------------------------------------------------------------------------------- 1 | // select.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "interp.h" 24 | #include "module/select.h" 25 | 26 | using namespace noise::module; 27 | 28 | Select::Select (): 29 | Module (GetSourceModuleCount ()), 30 | m_edgeFalloff (DEFAULT_SELECT_EDGE_FALLOFF), 31 | m_lowerBound (DEFAULT_SELECT_LOWER_BOUND), 32 | m_upperBound (DEFAULT_SELECT_UPPER_BOUND) 33 | { 34 | } 35 | 36 | double Select::GetValue (double x, double y, double z) const 37 | { 38 | assert (m_pSourceModule[0] != NULL); 39 | assert (m_pSourceModule[1] != NULL); 40 | assert (m_pSourceModule[2] != NULL); 41 | 42 | double controlValue = m_pSourceModule[2]->GetValue (x, y, z); 43 | double alpha; 44 | if (m_edgeFalloff > 0.0) { 45 | if (controlValue < (m_lowerBound - m_edgeFalloff)) { 46 | // The output value from the control module is below the selector 47 | // threshold; return the output value from the first source module. 48 | return m_pSourceModule[0]->GetValue (x, y, z); 49 | 50 | } else if (controlValue < (m_lowerBound + m_edgeFalloff)) { 51 | // The output value from the control module is near the lower end of the 52 | // selector threshold and within the smooth curve. Interpolate between 53 | // the output values from the first and second source modules. 54 | double lowerCurve = (m_lowerBound - m_edgeFalloff); 55 | double upperCurve = (m_lowerBound + m_edgeFalloff); 56 | alpha = SCurve3 ( 57 | (controlValue - lowerCurve) / (upperCurve - lowerCurve)); 58 | return LinearInterp (m_pSourceModule[0]->GetValue (x, y, z), 59 | m_pSourceModule[1]->GetValue (x, y, z), 60 | alpha); 61 | 62 | } else if (controlValue < (m_upperBound - m_edgeFalloff)) { 63 | // The output value from the control module is within the selector 64 | // threshold; return the output value from the second source module. 65 | return m_pSourceModule[1]->GetValue (x, y, z); 66 | 67 | } else if (controlValue < (m_upperBound + m_edgeFalloff)) { 68 | // The output value from the control module is near the upper end of the 69 | // selector threshold and within the smooth curve. Interpolate between 70 | // the output values from the first and second source modules. 71 | double lowerCurve = (m_upperBound - m_edgeFalloff); 72 | double upperCurve = (m_upperBound + m_edgeFalloff); 73 | alpha = SCurve3 ( 74 | (controlValue - lowerCurve) / (upperCurve - lowerCurve)); 75 | return LinearInterp (m_pSourceModule[1]->GetValue (x, y, z), 76 | m_pSourceModule[0]->GetValue (x, y, z), 77 | alpha); 78 | 79 | } else { 80 | // Output value from the control module is above the selector threshold; 81 | // return the output value from the first source module. 82 | return m_pSourceModule[0]->GetValue (x, y, z); 83 | } 84 | } else { 85 | if (controlValue < m_lowerBound || controlValue > m_upperBound) { 86 | return m_pSourceModule[0]->GetValue (x, y, z); 87 | } else { 88 | return m_pSourceModule[1]->GetValue (x, y, z); 89 | } 90 | } 91 | } 92 | 93 | void Select::SetBounds (double lowerBound, double upperBound) 94 | { 95 | assert (lowerBound < upperBound); 96 | 97 | m_lowerBound = lowerBound; 98 | m_upperBound = upperBound; 99 | 100 | // Make sure that the edge falloff curves do not overlap. 101 | SetEdgeFalloff (m_edgeFalloff); 102 | } 103 | 104 | void Select::SetEdgeFalloff (double edgeFalloff) 105 | { 106 | // Make sure that the edge falloff curves do not overlap. 107 | double boundSize = m_upperBound - m_lowerBound; 108 | m_edgeFalloff = (edgeFalloff > boundSize / 2)? boundSize / 2: edgeFalloff; 109 | } 110 | -------------------------------------------------------------------------------- /src/module/spheres.cpp: -------------------------------------------------------------------------------- 1 | // spheres.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "misc.h" 24 | #include "module/spheres.h" 25 | 26 | using namespace noise::module; 27 | 28 | Spheres::Spheres (): 29 | Module (GetSourceModuleCount ()), 30 | m_frequency (DEFAULT_SPHERES_FREQUENCY) 31 | { 32 | } 33 | 34 | double Spheres::GetValue (double x, double y, double z) const 35 | { 36 | x *= m_frequency; 37 | y *= m_frequency; 38 | z *= m_frequency; 39 | 40 | double distFromCenter = sqrt (x * x + y * y + z * z); 41 | double distFromSmallerSphere = distFromCenter - floor (distFromCenter); 42 | double distFromLargerSphere = 1.0 - distFromSmallerSphere; 43 | double nearestDist = GetMin (distFromSmallerSphere, distFromLargerSphere); 44 | return 1.0 - (nearestDist * 4.0); // Puts it in the -1.0 to +1.0 range. 45 | } 46 | -------------------------------------------------------------------------------- /src/module/terrace.cpp: -------------------------------------------------------------------------------- 1 | // terrace.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "interp.h" 24 | #include "misc.h" 25 | #include "module/terrace.h" 26 | 27 | using namespace noise::module; 28 | 29 | using namespace noise; 30 | 31 | Terrace::Terrace (): 32 | Module (GetSourceModuleCount ()), 33 | m_controlPointCount (0), 34 | m_invertTerraces (false), 35 | m_pControlPoints (NULL) 36 | { 37 | } 38 | 39 | Terrace::~Terrace () 40 | { 41 | delete[] m_pControlPoints; 42 | } 43 | 44 | void Terrace::AddControlPoint (double value) 45 | { 46 | // Find the insertion point for the new control point and insert the new 47 | // point at that position. The control point array will remain sorted by 48 | // value. 49 | int insertionPos = FindInsertionPos (value); 50 | InsertAtPos (insertionPos, value); 51 | } 52 | 53 | void Terrace::ClearAllControlPoints () 54 | { 55 | delete[] m_pControlPoints; 56 | m_pControlPoints = NULL; 57 | m_controlPointCount = 0; 58 | } 59 | 60 | int Terrace::FindInsertionPos (double value) 61 | { 62 | int insertionPos; 63 | for (insertionPos = 0; insertionPos < m_controlPointCount; insertionPos++) { 64 | if (value < m_pControlPoints[insertionPos]) { 65 | // We found the array index in which to insert the new control point. 66 | // Exit now. 67 | break; 68 | } else if (value == m_pControlPoints[insertionPos]) { 69 | // Each control point is required to contain a unique value, so throw 70 | // an exception. 71 | throw noise::ExceptionInvalidParam (); 72 | } 73 | } 74 | return insertionPos; 75 | } 76 | 77 | double Terrace::GetValue (double x, double y, double z) const 78 | { 79 | assert (m_pSourceModule[0] != NULL); 80 | assert (m_controlPointCount >= 2); 81 | 82 | // Get the output value from the source module. 83 | double sourceModuleValue = m_pSourceModule[0]->GetValue (x, y, z); 84 | 85 | // Find the first element in the control point array that has a value 86 | // larger than the output value from the source module. 87 | int indexPos; 88 | for (indexPos = 0; indexPos < m_controlPointCount; indexPos++) { 89 | if (sourceModuleValue < m_pControlPoints[indexPos]) { 90 | break; 91 | } 92 | } 93 | 94 | // Find the two nearest control points so that we can map their values 95 | // onto a quadratic curve. 96 | int index0 = ClampValue (indexPos - 1, 0, m_controlPointCount - 1); 97 | int index1 = ClampValue (indexPos , 0, m_controlPointCount - 1); 98 | 99 | // If some control points are missing (which occurs if the output value from 100 | // the source module is greater than the largest value or less than the 101 | // smallest value of the control point array), get the value of the nearest 102 | // control point and exit now. 103 | if (index0 == index1) { 104 | return m_pControlPoints[index1]; 105 | } 106 | 107 | // Compute the alpha value used for linear interpolation. 108 | double value0 = m_pControlPoints[index0]; 109 | double value1 = m_pControlPoints[index1]; 110 | double alpha = (sourceModuleValue - value0) / (value1 - value0); 111 | if (m_invertTerraces) { 112 | alpha = 1.0 - alpha; 113 | SwapValues (value0, value1); 114 | } 115 | 116 | // Squaring the alpha produces the terrace effect. 117 | alpha *= alpha; 118 | 119 | // Now perform the linear interpolation given the alpha value. 120 | return LinearInterp (value0, value1, alpha); 121 | } 122 | 123 | void Terrace::InsertAtPos (int insertionPos, double value) 124 | { 125 | // Make room for the new control point at the specified position within 126 | // the control point array. The position is determined by the value of 127 | // the control point; the control points must be sorted by value within 128 | // that array. 129 | double* newControlPoints = new double[m_controlPointCount + 1]; 130 | for (int i = 0; i < m_controlPointCount; i++) { 131 | if (i < insertionPos) { 132 | newControlPoints[i] = m_pControlPoints[i]; 133 | } else { 134 | newControlPoints[i + 1] = m_pControlPoints[i]; 135 | } 136 | } 137 | delete[] m_pControlPoints; 138 | m_pControlPoints = newControlPoints; 139 | ++m_controlPointCount; 140 | 141 | // Now that we've made room for the new control point within the array, 142 | // add the new control point. 143 | m_pControlPoints[insertionPos] = value; 144 | } 145 | 146 | void Terrace::MakeControlPoints (int controlPointCount) 147 | { 148 | if (controlPointCount < 2) { 149 | throw noise::ExceptionInvalidParam (); 150 | } 151 | 152 | ClearAllControlPoints (); 153 | 154 | double terraceStep = 2.0 / ((double)controlPointCount - 1.0); 155 | double curValue = -1.0; 156 | for (int i = 0; i < (int)controlPointCount; i++) { 157 | AddControlPoint (curValue); 158 | curValue += terraceStep; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/module/translatepoint.cpp: -------------------------------------------------------------------------------- 1 | // translatepoint.cpp 2 | // 3 | // Copyright (C) 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/translatepoint.h" 24 | 25 | using namespace noise::module; 26 | 27 | TranslatePoint::TranslatePoint (): 28 | Module (GetSourceModuleCount ()), 29 | m_xTranslation (DEFAULT_TRANSLATE_POINT_X), 30 | m_yTranslation (DEFAULT_TRANSLATE_POINT_Y), 31 | m_zTranslation (DEFAULT_TRANSLATE_POINT_Z) 32 | { 33 | } 34 | 35 | double TranslatePoint::GetValue (double x, double y, double z) const 36 | { 37 | assert (m_pSourceModule[0] != NULL); 38 | 39 | return m_pSourceModule[0]->GetValue (x + m_xTranslation, y + m_yTranslation, 40 | z + m_zTranslation); 41 | } 42 | -------------------------------------------------------------------------------- /src/module/turbulence.cpp: -------------------------------------------------------------------------------- 1 | // turbulence.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "module/turbulence.h" 24 | 25 | using namespace noise::module; 26 | 27 | Turbulence::Turbulence (): 28 | Module (GetSourceModuleCount ()), 29 | m_power (DEFAULT_TURBULENCE_POWER) 30 | { 31 | SetSeed (DEFAULT_TURBULENCE_SEED); 32 | SetFrequency (DEFAULT_TURBULENCE_FREQUENCY); 33 | SetRoughness (DEFAULT_TURBULENCE_ROUGHNESS); 34 | } 35 | 36 | double Turbulence::GetFrequency () const 37 | { 38 | // Since each noise::module::Perlin noise module has the same frequency, it 39 | // does not matter which module we use to retrieve the frequency. 40 | return m_xDistortModule.GetFrequency (); 41 | } 42 | 43 | int Turbulence::GetSeed () const 44 | { 45 | return m_xDistortModule.GetSeed (); 46 | } 47 | 48 | double Turbulence::GetValue (double x, double y, double z) const 49 | { 50 | assert (m_pSourceModule[0] != NULL); 51 | 52 | // Get the values from the three noise::module::Perlin noise modules and 53 | // add each value to each coordinate of the input value. There are also 54 | // some offsets added to the coordinates of the input values. This prevents 55 | // the distortion modules from returning zero if the (x, y, z) coordinates, 56 | // when multiplied by the frequency, are near an integer boundary. This is 57 | // due to a property of gradient coherent noise, which returns zero at 58 | // integer boundaries. 59 | double x0, y0, z0; 60 | double x1, y1, z1; 61 | double x2, y2, z2; 62 | x0 = x + (12414.0 / 65536.0); 63 | y0 = y + (65124.0 / 65536.0); 64 | z0 = z + (31337.0 / 65536.0); 65 | x1 = x + (26519.0 / 65536.0); 66 | y1 = y + (18128.0 / 65536.0); 67 | z1 = z + (60493.0 / 65536.0); 68 | x2 = x + (53820.0 / 65536.0); 69 | y2 = y + (11213.0 / 65536.0); 70 | z2 = z + (44845.0 / 65536.0); 71 | double xDistort = x + (m_xDistortModule.GetValue (x0, y0, z0) 72 | * m_power); 73 | double yDistort = y + (m_yDistortModule.GetValue (x1, y1, z1) 74 | * m_power); 75 | double zDistort = z + (m_zDistortModule.GetValue (x2, y2, z2) 76 | * m_power); 77 | 78 | // Retrieve the output value at the offsetted input value instead of the 79 | // original input value. 80 | return m_pSourceModule[0]->GetValue (xDistort, yDistort, zDistort); 81 | } 82 | 83 | void Turbulence::SetSeed (int seed) 84 | { 85 | // Set the seed of each noise::module::Perlin noise modules. To prevent any 86 | // sort of weird artifacting, use a slightly different seed for each noise 87 | // module. 88 | m_xDistortModule.SetSeed (seed ); 89 | m_yDistortModule.SetSeed (seed + 1); 90 | m_zDistortModule.SetSeed (seed + 2); 91 | } 92 | -------------------------------------------------------------------------------- /src/module/voronoi.cpp: -------------------------------------------------------------------------------- 1 | // voronoi.cpp 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include "mathconsts.h" 24 | #include "module/voronoi.h" 25 | 26 | using namespace noise::module; 27 | 28 | Voronoi::Voronoi (): 29 | Module (GetSourceModuleCount ()), 30 | m_displacement (DEFAULT_VORONOI_DISPLACEMENT), 31 | m_enableDistance (false ), 32 | m_frequency (DEFAULT_VORONOI_FREQUENCY ), 33 | m_seed (DEFAULT_VORONOI_SEED ) 34 | { 35 | } 36 | 37 | double Voronoi::GetValue (double x, double y, double z) const 38 | { 39 | // This method could be more efficient by caching the seed values. Fix 40 | // later. 41 | 42 | x *= m_frequency; 43 | y *= m_frequency; 44 | z *= m_frequency; 45 | 46 | int xInt = (x > 0.0? (int)x: (int)x - 1); 47 | int yInt = (y > 0.0? (int)y: (int)y - 1); 48 | int zInt = (z > 0.0? (int)z: (int)z - 1); 49 | 50 | double minDist = 2147483647.0; 51 | double xCandidate = 0; 52 | double yCandidate = 0; 53 | double zCandidate = 0; 54 | 55 | // Inside each unit cube, there is a seed point at a random position. Go 56 | // through each of the nearby cubes until we find a cube with a seed point 57 | // that is closest to the specified position. 58 | for (int zCur = zInt - 2; zCur <= zInt + 2; zCur++) { 59 | for (int yCur = yInt - 2; yCur <= yInt + 2; yCur++) { 60 | for (int xCur = xInt - 2; xCur <= xInt + 2; xCur++) { 61 | 62 | // Calculate the position and distance to the seed point inside of 63 | // this unit cube. 64 | double xPos = xCur + ValueNoise3D (xCur, yCur, zCur, m_seed ); 65 | double yPos = yCur + ValueNoise3D (xCur, yCur, zCur, m_seed + 1); 66 | double zPos = zCur + ValueNoise3D (xCur, yCur, zCur, m_seed + 2); 67 | double xDist = xPos - x; 68 | double yDist = yPos - y; 69 | double zDist = zPos - z; 70 | double dist = xDist * xDist + yDist * yDist + zDist * zDist; 71 | 72 | if (dist < minDist) { 73 | // This seed point is closer to any others found so far, so record 74 | // this seed point. 75 | minDist = dist; 76 | xCandidate = xPos; 77 | yCandidate = yPos; 78 | zCandidate = zPos; 79 | } 80 | } 81 | } 82 | } 83 | 84 | double value; 85 | if (m_enableDistance) { 86 | // Determine the distance to the nearest seed point. 87 | double xDist = xCandidate - x; 88 | double yDist = yCandidate - y; 89 | double zDist = zCandidate - z; 90 | value = (sqrt (xDist * xDist + yDist * yDist + zDist * zDist) 91 | ) * SQRT_3 - 1.0; 92 | } else { 93 | value = 0.0; 94 | } 95 | 96 | // Return the calculated distance with the displacement value applied. 97 | return value + (m_displacement * (double)ValueNoise3D ( 98 | (int)(floor (xCandidate)), 99 | (int)(floor (yCandidate)), 100 | (int)(floor (zCandidate)))); 101 | } 102 | -------------------------------------------------------------------------------- /src/noise/basictypes.h: -------------------------------------------------------------------------------- 1 | // basictypes.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_BASICTYPES_H 24 | #define NOISE_BASICTYPES_H 25 | 26 | // You may need to modify these constants for your compiler or platform. 27 | 28 | namespace noise 29 | { 30 | 31 | /// @defgroup libnoise libnoise 32 | /// @addtogroup libnoise 33 | /// @{ 34 | 35 | /// Unsigned integer type. 36 | typedef unsigned int uint; 37 | 38 | /// 32-bit unsigned integer type. 39 | typedef unsigned int uint32; 40 | 41 | /// 16-bit unsigned integer type. 42 | typedef unsigned short uint16; 43 | 44 | /// 8-bit unsigned integer type. 45 | typedef unsigned char uint8; 46 | 47 | /// 32-bit signed integer type. 48 | typedef int int32; 49 | 50 | /// 16-bit signed integer type. 51 | typedef short int16; 52 | 53 | /// 8-bit signed integer type. 54 | typedef char int8; 55 | 56 | /// @} 57 | 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/noise/exception.h: -------------------------------------------------------------------------------- 1 | // exception.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_EXCEPTION_H 24 | #define NOISE_EXCEPTION_H 25 | 26 | namespace noise 27 | { 28 | 29 | /// @addtogroup libnoise 30 | /// @{ 31 | 32 | /// Abstract base class for libnoise exceptions 33 | class Exception 34 | { 35 | }; 36 | 37 | /// Invalid parameter exception 38 | /// 39 | /// An invalid parameter was passed to a libnoise function or method. 40 | class ExceptionInvalidParam: public Exception 41 | { 42 | }; 43 | 44 | /// No module exception 45 | /// 46 | /// Could not retrieve a source module from a noise module. 47 | /// 48 | /// @note If one or more required source modules were not connected to a 49 | /// specific noise module, and its GetValue() method was called, that 50 | /// method will raise a debug assertion instead of this exception. This 51 | /// is done for performance reasons. 52 | class ExceptionNoModule: public Exception 53 | { 54 | }; 55 | 56 | /// Out of memory exception 57 | /// 58 | /// There was not enough memory to perform an action. 59 | class ExceptionOutOfMemory: public Exception 60 | { 61 | }; 62 | 63 | /// Unknown exception 64 | /// 65 | /// libnoise raised an unknown exception. 66 | class ExceptionUnknown: public Exception 67 | { 68 | }; 69 | 70 | /// @} 71 | 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/noise/interp.h: -------------------------------------------------------------------------------- 1 | // interp.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_INTERP_H 24 | #define NOISE_INTERP_H 25 | 26 | namespace noise 27 | { 28 | 29 | /// @addtogroup libnoise 30 | /// @{ 31 | 32 | /// Performs cubic interpolation between two values bound between two other 33 | /// values. 34 | /// 35 | /// @param n0 The value before the first value. 36 | /// @param n1 The first value. 37 | /// @param n2 The second value. 38 | /// @param n3 The value after the second value. 39 | /// @param a The alpha value. 40 | /// 41 | /// @returns The interpolated value. 42 | /// 43 | /// The alpha value should range from 0.0 to 1.0. If the alpha value is 44 | /// 0.0, this function returns @a n1. If the alpha value is 1.0, this 45 | /// function returns @a n2. 46 | inline double CubicInterp (double n0, double n1, double n2, double n3, 47 | double a) 48 | { 49 | double p = (n3 - n2) - (n0 - n1); 50 | double q = (n0 - n1) - p; 51 | double r = n2 - n0; 52 | double s = n1; 53 | return p * a * a * a + q * a * a + r * a + s; 54 | } 55 | 56 | /// Performs linear interpolation between two values. 57 | /// 58 | /// @param n0 The first value. 59 | /// @param n1 The second value. 60 | /// @param a The alpha value. 61 | /// 62 | /// @returns The interpolated value. 63 | /// 64 | /// The alpha value should range from 0.0 to 1.0. If the alpha value is 65 | /// 0.0, this function returns @a n0. If the alpha value is 1.0, this 66 | /// function returns @a n1. 67 | inline double LinearInterp (double n0, double n1, double a) 68 | { 69 | return ((1.0 - a) * n0) + (a * n1); 70 | } 71 | 72 | /// Maps a value onto a cubic S-curve. 73 | /// 74 | /// @param a The value to map onto a cubic S-curve. 75 | /// 76 | /// @returns The mapped value. 77 | /// 78 | /// @a a should range from 0.0 to 1.0. 79 | /// 80 | /// The derivitive of a cubic S-curve is zero at @a a = 0.0 and @a a = 81 | /// 1.0 82 | inline double SCurve3 (double a) 83 | { 84 | return (a * a * (3.0 - 2.0 * a)); 85 | } 86 | 87 | /// Maps a value onto a quintic S-curve. 88 | /// 89 | /// @param a The value to map onto a quintic S-curve. 90 | /// 91 | /// @returns The mapped value. 92 | /// 93 | /// @a a should range from 0.0 to 1.0. 94 | /// 95 | /// The first derivitive of a quintic S-curve is zero at @a a = 0.0 and 96 | /// @a a = 1.0 97 | /// 98 | /// The second derivitive of a quintic S-curve is zero at @a a = 0.0 and 99 | /// @a a = 1.0 100 | inline double SCurve5 (double a) 101 | { 102 | double a3 = a * a * a; 103 | double a4 = a3 * a; 104 | double a5 = a4 * a; 105 | return (6.0 * a5) - (15.0 * a4) + (10.0 * a3); 106 | } 107 | 108 | // @} 109 | 110 | } 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /src/noise/latlon.h: -------------------------------------------------------------------------------- 1 | // latlon.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_LATLON_H 24 | #define NOISE_LATLON_H 25 | 26 | #include 27 | #include "mathconsts.h" 28 | 29 | namespace noise 30 | { 31 | 32 | /// @addtogroup libnoise 33 | /// @{ 34 | 35 | /// Converts latitude/longitude coordinates on a unit sphere into 3D 36 | /// Cartesian coordinates. 37 | /// 38 | /// @param lat The latitude, in degrees. 39 | /// @param lon The longitude, in degrees. 40 | /// @param x On exit, this parameter contains the @a x coordinate. 41 | /// @param y On exit, this parameter contains the @a y coordinate. 42 | /// @param z On exit, this parameter contains the @a z coordinate. 43 | /// 44 | /// @pre lat must range from @b -90 to @b +90. 45 | /// @pre lon must range from @b -180 to @b +180. 46 | void LatLonToXYZ (double lat, double lon, double& x, double& y, double& z); 47 | 48 | /// @} 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/noise/mathconsts.h: -------------------------------------------------------------------------------- 1 | // mathconsts.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MATHCONSTS_H 24 | #define NOISE_MATHCONSTS_H 25 | 26 | // For whatever reason, I can't find the basic math consts in the MSVC version 27 | // of math.h. 28 | 29 | namespace noise 30 | { 31 | 32 | /// @addtogroup libnoise 33 | /// @{ 34 | 35 | /// Pi. 36 | const double PI = 3.1415926535897932385; 37 | 38 | /// Square root of 2. 39 | const double SQRT_2 = 1.4142135623730950488; 40 | 41 | /// Square root of 3. 42 | const double SQRT_3 = 1.7320508075688772935; 43 | 44 | /// Converts an angle from degrees to radians. 45 | const double DEG_TO_RAD = PI / 180.0; 46 | 47 | /// Converts an angle from radians to degrees. 48 | const double RAD_TO_DEG = 1.0 / DEG_TO_RAD; 49 | 50 | /// @} 51 | 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/noise/misc.h: -------------------------------------------------------------------------------- 1 | // misc.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MISC_H 24 | #define NOISE_MISC_H 25 | 26 | namespace noise 27 | { 28 | 29 | /// Clamps a value onto a clamping range. 30 | /// 31 | /// @param value The value to clamp. 32 | /// @param lowerBound The lower bound of the clamping range. 33 | /// @param upperBound The upper bound of the clamping range. 34 | /// 35 | /// @returns 36 | /// - @a value if @a value lies between @a lowerBound and @a upperBound. 37 | /// - @a lowerBound if @a value is less than @a lowerBound. 38 | /// - @a upperBound if @a value is greater than @a upperBound. 39 | /// 40 | /// This function does not modify any parameters. 41 | inline int ClampValue (int value, int lowerBound, int upperBound) 42 | { 43 | if (value < lowerBound) { 44 | return lowerBound; 45 | } else if (value > upperBound) { 46 | return upperBound; 47 | } else { 48 | return value; 49 | } 50 | } 51 | 52 | /// @addtogroup libnoise 53 | /// @{ 54 | 55 | /// Returns the maximum of two values. 56 | /// 57 | /// @param a The first value. 58 | /// @param b The second value. 59 | /// 60 | /// @returns The maximum of the two values. 61 | template 62 | T GetMax (const T& a, const T& b) 63 | { 64 | return (a > b? a: b); 65 | } 66 | 67 | /// Returns the minimum of two values. 68 | /// 69 | /// @param a The first value. 70 | /// @param b The second value. 71 | /// 72 | /// @returns The minimum of the two values. 73 | template 74 | T GetMin (const T& a, const T& b) 75 | { 76 | return (a < b? a: b); 77 | } 78 | 79 | /// Swaps two values. 80 | /// 81 | /// @param a A variable containing the first value. 82 | /// @param b A variable containing the second value. 83 | /// 84 | /// @post The values within the the two variables are swapped. 85 | template 86 | void SwapValues (T& a, T& b) 87 | { 88 | T c = a; 89 | a = b; 90 | b = c; 91 | } 92 | 93 | /// @} 94 | 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /src/noise/model/cylinder.h: -------------------------------------------------------------------------------- 1 | // cylinder.h 2 | // 3 | // Copyright 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODEL_CYLINDER_H 24 | #define NOISE_MODEL_CYLINDER_H 25 | 26 | #include 27 | #include 28 | #include 29 | #include "../module/modulebase.h" 30 | 31 | namespace noise 32 | { 33 | 34 | namespace model 35 | { 36 | 37 | /// @addtogroup libnoise 38 | /// @{ 39 | 40 | /// @defgroup models Models 41 | /// @addtogroup models 42 | /// @{ 43 | 44 | /// Model that defines the surface of a cylinder. 45 | /// 46 | /// @image html modelcylinder.png 47 | /// 48 | /// This model returns an output value from a noise module given the 49 | /// coordinates of an input value located on the surface of a cylinder. 50 | /// 51 | /// To generate an output value, pass the (angle, height) coordinates of 52 | /// an input value to the GetValue() method. 53 | /// 54 | /// This model is useful for creating: 55 | /// - seamless textures that can be mapped onto a cylinder 56 | /// 57 | /// This cylinder has a radius of 1.0 unit and has infinite height. It is 58 | /// oriented along the @a y axis. Its center is located at the origin. 59 | class NOISE_EXPORT Cylinder 60 | { 61 | 62 | public: 63 | 64 | /// Constructor. 65 | Cylinder (); 66 | 67 | /// Constructor 68 | /// 69 | /// @param module The noise module that is used to generate the output 70 | /// values. 71 | Cylinder (const module::Module& module); 72 | 73 | /// Returns the noise module that is used to generate the output 74 | /// values. 75 | /// 76 | /// @returns A reference to the noise module. 77 | /// 78 | /// @pre A noise module was passed to the SetModule() method. 79 | const module::Module& GetModule () const 80 | { 81 | assert (m_pModule != NULL); 82 | return *m_pModule; 83 | } 84 | 85 | /// Returns the output value from the noise module given the 86 | /// (angle, height) coordinates of the specified input value located 87 | /// on the surface of the cylinder. 88 | /// 89 | /// @param angle The angle around the cylinder's center, in degrees. 90 | /// @param height The height along the @a y axis. 91 | /// 92 | /// @returns The output value from the noise module. 93 | /// 94 | /// @pre A noise module was passed to the SetModule() method. 95 | /// 96 | /// This output value is generated by the noise module passed to the 97 | /// SetModule() method. 98 | /// 99 | /// This cylinder has a radius of 1.0 unit and has infinite height. 100 | /// It is oriented along the @a y axis. Its center is located at the 101 | /// origin. 102 | double GetValue (double angle, double height) const; 103 | 104 | /// Sets the noise module that is used to generate the output values. 105 | /// 106 | /// @param module The noise module that is used to generate the output 107 | /// values. 108 | /// 109 | /// This noise module must exist for the lifetime of this object, 110 | /// until you pass a new noise module to this method. 111 | void SetModule (const module::Module& module) 112 | { 113 | m_pModule = &module; 114 | } 115 | 116 | private: 117 | 118 | /// A pointer to the noise module used to generate the output values. 119 | const module::Module* m_pModule; 120 | 121 | }; 122 | 123 | /// @} 124 | 125 | /// @} 126 | 127 | } 128 | 129 | } 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /src/noise/model/line.h: -------------------------------------------------------------------------------- 1 | // line.h 2 | // 3 | // Copyright (C) 2004 Keith Davies 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | 20 | #ifndef NOISE_MODEL_LINE_H 21 | #define NOISE_MODEL_LINE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include "../module/modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace model 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup models 38 | /// @{ 39 | 40 | /// Model that defines the displacement of a line segment. 41 | /// 42 | /// This model returns an output value from a noise module given the 43 | /// one-dimensional coordinate of an input value located on a line 44 | /// segment, which can be used as displacements. 45 | /// 46 | /// This class is useful for creating: 47 | /// - roads and rivers 48 | /// - disaffected college students 49 | /// 50 | /// To generate an output value, pass an input value between 0.0 and 1.0 51 | /// to the GetValue() method. 0.0 represents the start position of the 52 | /// line segment and 1.0 represents the end position of the line segment. 53 | class NOISE_EXPORT Line 54 | { 55 | 56 | public: 57 | 58 | /// Constructor. 59 | Line (); 60 | 61 | /// Constructor 62 | /// 63 | /// @param module The noise module that is used to generate the output 64 | /// values. 65 | Line (const module::Module& module); 66 | 67 | /// Returns a flag indicating whether the output value is to be 68 | /// attenuated (moved toward 0.0) as the ends of the line segment are 69 | /// approached by the input value. 70 | /// 71 | /// @returns 72 | /// - @a true if the value is to be attenuated 73 | /// - @a false if not. 74 | bool GetAttenuate () const 75 | { 76 | return m_attenuate; 77 | } 78 | 79 | /// Returns the noise module that is used to generate the output 80 | /// values. 81 | /// 82 | /// @returns A reference to the noise module. 83 | /// 84 | /// @pre A noise module was passed to the SetModule() method. 85 | const module::Module& GetModule () const 86 | { 87 | assert (m_pModule != NULL); 88 | return *m_pModule; 89 | } 90 | 91 | /// Returns the output value from the noise module given the 92 | /// one-dimensional coordinate of the specified input value located 93 | /// on the line segment. 94 | /// 95 | /// @param p The distance along the line segment (ranges from 0.0 96 | /// to 1.0) 97 | /// 98 | /// @returns The output value from the noise module. 99 | /// 100 | /// @pre A noise module was passed to the SetModule() method. 101 | /// @pre The start and end points of the line segment were specified. 102 | /// 103 | /// The output value is generated by the noise module passed to the 104 | /// SetModule() method. This value may be attenuated (moved toward 105 | /// 0.0) as @a p approaches either end of the line segment; this is 106 | /// the default behavior. 107 | /// 108 | /// If the value is not to be attenuated, @a p can safely range 109 | /// outside the 0.0 to 1.0 range; the output value will be 110 | /// extrapolated along the line that this segment is part of. 111 | double GetValue (double p) const; 112 | 113 | /// Sets a flag indicating that the output value is to be attenuated 114 | /// (moved toward 0.0) as the ends of the line segment are approached. 115 | /// 116 | /// @param att A flag that specifies whether the output value is to be 117 | /// attenuated. 118 | void SetAttenuate (bool att) 119 | { 120 | m_attenuate = att; 121 | } 122 | 123 | /// Sets the position ( @a x, @a y, @a z ) of the end of the line 124 | /// segment to choose values along. 125 | /// 126 | /// @param x x coordinate of the end position. 127 | /// @param y y coordinate of the end position. 128 | /// @param z z coordinate of the end position. 129 | void SetEndPoint (double x, double y, double z) 130 | { 131 | m_x1 = x; 132 | m_y1 = y; 133 | m_z1 = z; 134 | } 135 | 136 | /// Sets the noise module that is used to generate the output values. 137 | /// 138 | /// @param module The noise module that is used to generate the output 139 | /// values. 140 | /// 141 | /// This noise module must exist for the lifetime of this object, 142 | /// until you pass a new noise module to this method. 143 | void SetModule (const module::Module& module) 144 | { 145 | m_pModule = &module; 146 | } 147 | 148 | /// Sets the position ( @a x, @a y, @a z ) of the start of the line 149 | /// segment to choose values along. 150 | /// 151 | /// @param x x coordinate of the start position. 152 | /// @param y y coordinate of the start position. 153 | /// @param z z coordinate of the start position. 154 | void SetStartPoint (double x, double y, double z) 155 | { 156 | m_x0 = x; 157 | m_y0 = y; 158 | m_z0 = z; 159 | } 160 | 161 | private: 162 | 163 | /// A flag that specifies whether the value is to be attenuated 164 | /// (moved toward 0.0) as the ends of the line segment are approached. 165 | bool m_attenuate; 166 | 167 | /// A pointer to the noise module used to generate the output values. 168 | const module::Module* m_pModule; 169 | 170 | /// @a x coordinate of the start of the line segment. 171 | double m_x0; 172 | 173 | /// @a x coordinate of the end of the line segment. 174 | double m_x1; 175 | 176 | /// @a y coordinate of the start of the line segment. 177 | double m_y0; 178 | 179 | /// @a y coordinate of the end of the line segment. 180 | double m_y1; 181 | 182 | /// @a z coordinate of the start of the line segment. 183 | double m_z0; 184 | 185 | /// @a z coordinate of the end of the line segment. 186 | double m_z1; 187 | 188 | }; 189 | 190 | /// @} 191 | 192 | /// @} 193 | 194 | } 195 | 196 | } 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /src/noise/model/model.h: -------------------------------------------------------------------------------- 1 | // model.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODEL_H 24 | #define NOISE_MODEL_H 25 | 26 | #include "cylinder.h" 27 | #include "line.h" 28 | #include "plane.h" 29 | #include "sphere.h" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/noise/model/plane.h: -------------------------------------------------------------------------------- 1 | // plane.h 2 | // 3 | // Copyright (C) 2004 Owen Jacobson 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is ojacobson@lionsanctuary.net 20 | // 21 | 22 | #ifndef NOISE_MODEL_PLANE_H 23 | #define NOISE_MODEL_PLANE_H 24 | 25 | #include 26 | #include "../module/modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace model 32 | { 33 | /// @addtogroup libnoise 34 | /// @{ 35 | 36 | /// @addtogroup models 37 | /// @{ 38 | 39 | /// Model that defines the surface of a plane. 40 | /// 41 | /// This model returns an output value from a noise module given the 42 | /// coordinates of an input value located on the surface of an ( @a x, 43 | /// @a z ) plane. 44 | /// 45 | /// To generate an output value, pass the ( @a x, @a z ) coordinates of 46 | /// an input value to the GetValue() method. 47 | /// 48 | /// This model is useful for creating: 49 | /// - two-dimensional textures 50 | /// - terrain height maps for local areas 51 | /// 52 | /// This plane extends infinitely in both directions. 53 | class NOISE_EXPORT Plane 54 | { 55 | 56 | public: 57 | 58 | /// Constructor. 59 | Plane (); 60 | 61 | /// Constructor 62 | /// 63 | /// @param module The noise module that is used to generate the output 64 | /// values. 65 | Plane (const module::Module& module); 66 | 67 | /// Returns the noise module that is used to generate the output 68 | /// values. 69 | /// 70 | /// @returns A reference to the noise module. 71 | /// 72 | /// @pre A noise module was passed to the SetModule() method. 73 | const module::Module& GetModule () const 74 | { 75 | assert (m_pModule != NULL); 76 | return *m_pModule; 77 | } 78 | 79 | /// Returns the output value from the noise module given the 80 | /// ( @a x, @a z ) coordinates of the specified input value located 81 | /// on the surface of the plane. 82 | /// 83 | /// @param x The @a x coordinate of the input value. 84 | /// @param z The @a z coordinate of the input value. 85 | /// 86 | /// @returns The output value from the noise module. 87 | /// 88 | /// @pre A noise module was passed to the SetModule() method. 89 | /// 90 | /// This output value is generated by the noise module passed to the 91 | /// SetModule() method. 92 | double GetValue (double x, double z) const; 93 | 94 | /// Sets the noise module that is used to generate the output values. 95 | /// 96 | /// @param module The noise module that is used to generate the output 97 | /// values. 98 | /// 99 | /// This noise module must exist for the lifetime of this object, 100 | /// until you pass a new noise module to this method. 101 | void SetModule (const module::Module& module) 102 | { 103 | m_pModule = &module; 104 | } 105 | 106 | private: 107 | 108 | /// A pointer to the noise module used to generate the output values. 109 | const module::Module* m_pModule; 110 | 111 | }; 112 | 113 | /// @} 114 | 115 | /// @} 116 | 117 | } 118 | 119 | } 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /src/noise/model/sphere.h: -------------------------------------------------------------------------------- 1 | // sphere.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODEL_SPHERE_H 24 | #define NOISE_MODEL_SPHERE_H 25 | 26 | #include 27 | #include "../module/modulebase.h" 28 | 29 | namespace noise 30 | { 31 | 32 | namespace model 33 | { 34 | 35 | /// @addtogroup libnoise 36 | /// @{ 37 | 38 | /// @addtogroup models 39 | /// @{ 40 | 41 | /// Model that defines the surface of a sphere. 42 | /// 43 | /// @image html modelsphere.png 44 | /// 45 | /// This model returns an output value from a noise module given the 46 | /// coordinates of an input value located on the surface of a sphere. 47 | /// 48 | /// To generate an output value, pass the (latitude, longitude) 49 | /// coordinates of an input value to the GetValue() method. 50 | /// 51 | /// This model is useful for creating: 52 | /// - seamless textures that can be mapped onto a sphere 53 | /// - terrain height maps for entire planets 54 | /// 55 | /// This sphere has a radius of 1.0 unit and its center is located at 56 | /// the origin. 57 | class NOISE_EXPORT Sphere 58 | { 59 | 60 | public: 61 | 62 | /// Constructor. 63 | Sphere (); 64 | 65 | /// Constructor 66 | /// 67 | /// @param module The noise module that is used to generate the output 68 | /// values. 69 | Sphere (const module::Module& module); 70 | 71 | /// Returns the noise module that is used to generate the output 72 | /// values. 73 | /// 74 | /// @returns A reference to the noise module. 75 | /// 76 | /// @pre A noise module was passed to the SetModule() method. 77 | const module::Module& GetModule () const 78 | { 79 | assert (m_pModule != NULL); 80 | return *m_pModule; 81 | } 82 | 83 | /// Returns the output value from the noise module given the 84 | /// (latitude, longitude) coordinates of the specified input value 85 | /// located on the surface of the sphere. 86 | /// 87 | /// @param lat The latitude of the input value, in degrees. 88 | /// @param lon The longitude of the input value, in degrees. 89 | /// 90 | /// @returns The output value from the noise module. 91 | /// 92 | /// @pre A noise module was passed to the SetModule() method. 93 | /// 94 | /// This output value is generated by the noise module passed to the 95 | /// SetModule() method. 96 | /// 97 | /// Use a negative latitude if the input value is located on the 98 | /// southern hemisphere. 99 | /// 100 | /// Use a negative longitude if the input value is located on the 101 | /// western hemisphere. 102 | double GetValue (double lat, double lon) const; 103 | 104 | /// Sets the noise module that is used to generate the output values. 105 | /// 106 | /// @param module The noise module that is used to generate the output 107 | /// values. 108 | /// 109 | /// This noise module must exist for the lifetime of this object, 110 | /// until you pass a new noise module to this method. 111 | void SetModule (const module::Module& module) 112 | { 113 | m_pModule = &module; 114 | } 115 | 116 | private: 117 | 118 | /// A pointer to the noise module used to generate the output values. 119 | const module::Module* m_pModule; 120 | 121 | }; 122 | 123 | /// @} 124 | 125 | /// @} 126 | 127 | } 128 | 129 | } 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /src/noise/module/abs.h: -------------------------------------------------------------------------------- 1 | // abs.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_ABS_H 24 | #define NOISE_MODULE_ABS_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module { 32 | 33 | /// @addtogroup libnoise 34 | /// @{ 35 | 36 | /// @addtogroup modules 37 | /// @{ 38 | 39 | /// @defgroup modifiermodules Modifier Modules 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the absolute value of the output value from 44 | /// a source module. 45 | /// 46 | /// @image html moduleabs.png 47 | /// 48 | /// This noise module requires one source module. 49 | class NOISE_EXPORT Abs: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Abs (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 1; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/noise/module/add.h: -------------------------------------------------------------------------------- 1 | // add.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_ADD_H 24 | #define NOISE_MODULE_ADD_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup combinermodules Combiner Modules 41 | /// @addtogroup combinermodules 42 | /// @{ 43 | 44 | /// Noise module that outputs the sum of the two output values from two 45 | /// source modules. 46 | /// 47 | /// @image html moduleadd.png 48 | /// 49 | /// This noise module requires two source modules. 50 | class NOISE_EXPORT Add: public Module 51 | { 52 | 53 | public: 54 | 55 | /// Constructor. 56 | Add (); 57 | 58 | virtual int GetSourceModuleCount () const 59 | { 60 | return 2; 61 | } 62 | 63 | virtual double GetValue (double x, double y, double z) const; 64 | 65 | }; 66 | 67 | /// @} 68 | 69 | /// @} 70 | 71 | /// @} 72 | 73 | } 74 | 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/noise/module/blend.h: -------------------------------------------------------------------------------- 1 | // blend.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_BLEND_H 24 | #define NOISE_MODULE_BLEND_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup selectormodules Selector Modules 41 | /// @addtogroup selectormodules 42 | /// @{ 43 | 44 | /// Noise module that outputs a weighted blend of the output values from 45 | /// two source modules given the output value supplied by a control module. 46 | /// 47 | /// @image html moduleblend.png 48 | /// 49 | /// Unlike most other noise modules, the index value assigned to a source 50 | /// module determines its role in the blending operation: 51 | /// - Source module 0 (upper left in the diagram) outputs one of the 52 | /// values to blend. 53 | /// - Source module 1 (lower left in the diagram) outputs one of the 54 | /// values to blend. 55 | /// - Source module 2 (bottom of the diagram) is known as the control 56 | /// module. The control module determines the weight of the 57 | /// blending operation. Negative values weigh the blend towards the 58 | /// output value from the source module with an index value of 0. 59 | /// Positive values weigh the blend towards the output value from the 60 | /// source module with an index value of 1. 61 | /// 62 | /// An application can pass the control module to the SetControlModule() 63 | /// method instead of the SetSourceModule() method. This may make the 64 | /// application code easier to read. 65 | /// 66 | /// This noise module uses linear interpolation to perform the blending 67 | /// operation. 68 | /// 69 | /// This noise module requires three source modules. 70 | class NOISE_EXPORT Blend: public Module 71 | { 72 | 73 | public: 74 | 75 | /// Constructor. 76 | Blend (); 77 | 78 | /// Returns the control module. 79 | /// 80 | /// @returns A reference to the control module. 81 | /// 82 | /// @pre A control module has been added to this noise module via a 83 | /// call to SetSourceModule() or SetControlModule(). 84 | /// 85 | /// @throw noise::ExceptionNoModule See the preconditions for more 86 | /// information. 87 | /// 88 | /// The control module determines the weight of the blending 89 | /// operation. Negative values weigh the blend towards the output 90 | /// value from the source module with an index value of 0. Positive 91 | /// values weigh the blend towards the output value from the source 92 | /// module with an index value of 1. 93 | const Module& GetControlModule () const 94 | { 95 | if (m_pSourceModule == NULL || m_pSourceModule[2] == NULL) { 96 | throw noise::ExceptionNoModule (); 97 | } 98 | return *(m_pSourceModule[2]); 99 | } 100 | 101 | virtual int GetSourceModuleCount () const 102 | { 103 | return 3; 104 | } 105 | 106 | virtual double GetValue (double x, double y, double z) const; 107 | 108 | /// Sets the control module. 109 | /// 110 | /// @param controlModule The control module. 111 | /// 112 | /// The control module determines the weight of the blending 113 | /// operation. Negative values weigh the blend towards the output 114 | /// value from the source module with an index value of 0. Positive 115 | /// values weigh the blend towards the output value from the source 116 | /// module with an index value of 1. 117 | /// 118 | /// This method assigns the control module an index value of 2. 119 | /// Passing the control module to this method produces the same 120 | /// results as passing the control module to the SetSourceModule() 121 | /// method while assigning that noise module an index value of 2. 122 | /// 123 | /// This control module must exist throughout the lifetime of this 124 | /// noise module unless another control module replaces that control 125 | /// module. 126 | void SetControlModule (const Module& controlModule) 127 | { 128 | assert (m_pSourceModule != NULL); 129 | m_pSourceModule[2] = &controlModule; 130 | } 131 | 132 | }; 133 | 134 | /// @} 135 | 136 | /// @} 137 | 138 | /// @} 139 | 140 | } 141 | 142 | } 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /src/noise/module/cache.h: -------------------------------------------------------------------------------- 1 | // cache.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CACHE_H 24 | #define NOISE_MODULE_CACHE_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup miscmodules Miscellaneous Modules 41 | /// @addtogroup miscmodules 42 | /// @{ 43 | 44 | /// Noise module that caches the last output value generated by a source 45 | /// module. 46 | /// 47 | /// If an application passes an input value to the GetValue() method that 48 | /// differs from the previously passed-in input value, this noise module 49 | /// instructs the source module to calculate the output value. This 50 | /// value, as well as the ( @a x, @a y, @a z ) coordinates of the input 51 | /// value, are stored (cached) in this noise module. 52 | /// 53 | /// If the application passes an input value to the GetValue() method 54 | /// that is equal to the previously passed-in input value, this noise 55 | /// module returns the cached output value without having the source 56 | /// module recalculate the output value. 57 | /// 58 | /// If an application passes a new source module to the SetSourceModule() 59 | /// method, the cache is invalidated. 60 | /// 61 | /// Caching a noise module is useful if it is used as a source module for 62 | /// multiple noise modules. If a source module is not cached, the source 63 | /// module will redundantly calculate the same output value once for each 64 | /// noise module in which it is included. 65 | /// 66 | /// This noise module requires one source module. 67 | class NOISE_EXPORT Cache: public Module 68 | { 69 | 70 | public: 71 | 72 | /// Constructor. 73 | Cache (); 74 | 75 | virtual int GetSourceModuleCount () const 76 | { 77 | return 1; 78 | } 79 | 80 | virtual double GetValue (double x, double y, double z) const; 81 | 82 | virtual void SetSourceModule (int index, const Module& sourceModule) 83 | { 84 | Module::SetSourceModule (index, sourceModule); 85 | m_isCached = false; 86 | } 87 | 88 | protected: 89 | 90 | /// The cached output value at the cached input value. 91 | mutable double m_cachedValue; 92 | 93 | /// Determines if a cached output value is stored in this noise 94 | /// module. 95 | mutable double m_isCached; 96 | 97 | /// @a x coordinate of the cached input value. 98 | mutable double m_xCache; 99 | 100 | /// @a y coordinate of the cached input value. 101 | mutable double m_yCache; 102 | 103 | /// @a z coordinate of the cached input value. 104 | mutable double m_zCache; 105 | 106 | }; 107 | 108 | /// @} 109 | 110 | /// @} 111 | 112 | /// @} 113 | 114 | } 115 | 116 | } 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /src/noise/module/checkerboard.h: -------------------------------------------------------------------------------- 1 | // checkerboard.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CHECKERBOARD_H 24 | #define NOISE_MODULE_CHECKERBOARD_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup generatormodules 41 | /// @{ 42 | 43 | /// Noise module that outputs a checkerboard pattern. 44 | /// 45 | /// @image html modulecheckerboard.png 46 | /// 47 | /// This noise module outputs unit-sized blocks of alternating values. 48 | /// The values of these blocks alternate between -1.0 and +1.0. 49 | /// 50 | /// This noise module is not really useful by itself, but it is often used 51 | /// for debugging purposes. 52 | /// 53 | /// This noise module does not require any source modules. 54 | class NOISE_EXPORT Checkerboard: public Module 55 | { 56 | 57 | public: 58 | 59 | /// Constructor. 60 | Checkerboard (); 61 | 62 | virtual int GetSourceModuleCount () const 63 | { 64 | return 0; 65 | } 66 | 67 | virtual double GetValue (double x, double y, double z) const; 68 | 69 | }; 70 | 71 | /// @} 72 | 73 | /// @} 74 | 75 | /// @} 76 | 77 | } 78 | 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/noise/module/clamp.h: -------------------------------------------------------------------------------- 1 | // clamp.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CLAMP_H 24 | #define NOISE_MODULE_CLAMP_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Default lower bound of the clamping range for the noise::module::Clamp 44 | /// noise module. 45 | const double DEFAULT_CLAMP_LOWER_BOUND = -1.0; 46 | 47 | /// Default upper bound of the clamping range for the noise::module::Clamp 48 | /// noise module. 49 | const double DEFAULT_CLAMP_UPPER_BOUND = 1.0; 50 | 51 | /// Noise module that clamps the output value from a source module to a 52 | /// range of values. 53 | /// 54 | /// @image html moduleclamp.png 55 | /// 56 | /// The range of values in which to clamp the output value is called the 57 | /// clamping range. 58 | /// 59 | /// If the output value from the source module is less than the lower 60 | /// bound of the clamping range, this noise module clamps that value to 61 | /// the lower bound. If the output value from the source module is 62 | /// greater than the upper bound of the clamping range, this noise module 63 | /// clamps that value to the upper bound. 64 | /// 65 | /// To specify the upper and lower bounds of the clamping range, call the 66 | /// SetBounds() method. 67 | /// 68 | /// This noise module requires one source module. 69 | class NOISE_EXPORT Clamp : public Module 70 | { 71 | 72 | public: 73 | 74 | /// Constructor. 75 | /// 76 | /// The default lower bound of the clamping range is set to 77 | /// noise::module::DEFAULT_CLAMP_LOWER_BOUND. 78 | /// 79 | /// The default upper bound of the clamping range is set to 80 | /// noise::module::DEFAULT_CLAMP_UPPER_BOUND. 81 | Clamp (); 82 | 83 | /// Returns the lower bound of the clamping range. 84 | /// 85 | /// @returns The lower bound. 86 | /// 87 | /// If the output value from the source module is less than the lower 88 | /// bound of the clamping range, this noise module clamps that value 89 | /// to the lower bound. 90 | double GetLowerBound () const 91 | { 92 | return m_lowerBound; 93 | } 94 | 95 | virtual int GetSourceModuleCount () const 96 | { 97 | return 1; 98 | } 99 | 100 | /// Returns the upper bound of the clamping range. 101 | /// 102 | /// @returns The upper bound. 103 | /// 104 | /// If the output value from the source module is greater than the 105 | /// upper bound of the clamping range, this noise module clamps that 106 | /// value to the upper bound. 107 | double GetUpperBound () const 108 | { 109 | return m_upperBound; 110 | } 111 | 112 | virtual double GetValue (double x, double y, double z) const; 113 | 114 | /// Sets the lower and upper bounds of the clamping range. 115 | /// 116 | /// @param lowerBound The lower bound. 117 | /// @param upperBound The upper bound. 118 | /// 119 | /// @pre The lower bound must be less than or equal to the 120 | /// upper bound. 121 | /// 122 | /// @throw noise::ExceptionInvalidParam An invalid parameter was 123 | /// specified; see the preconditions for more information. 124 | /// 125 | /// If the output value from the source module is less than the lower 126 | /// bound of the clamping range, this noise module clamps that value 127 | /// to the lower bound. If the output value from the source module 128 | /// is greater than the upper bound of the clamping range, this noise 129 | /// module clamps that value to the upper bound. 130 | void SetBounds (double lowerBound, double upperBound); 131 | 132 | protected: 133 | 134 | /// Lower bound of the clamping range. 135 | double m_lowerBound; 136 | 137 | /// Upper bound of the clamping range. 138 | double m_upperBound; 139 | 140 | }; 141 | 142 | /// @} 143 | 144 | /// @} 145 | 146 | /// @} 147 | 148 | } 149 | 150 | } 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /src/noise/module/const.h: -------------------------------------------------------------------------------- 1 | // const.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CONST_H 24 | #define NOISE_MODULE_CONST_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @defgroup generatormodules Generator Modules 41 | /// @addtogroup generatormodules 42 | /// @{ 43 | 44 | /// Default constant value for the noise::module::Const noise module. 45 | const double DEFAULT_CONST_VALUE = 0.0; 46 | 47 | /// Noise module that outputs a constant value. 48 | /// 49 | /// @image html moduleconst.png 50 | /// 51 | /// To specify the constant value, call the SetConstValue() method. 52 | /// 53 | /// This noise module is not useful by itself, but it is often used as a 54 | /// source module for other noise modules. 55 | /// 56 | /// This noise module does not require any source modules. 57 | class NOISE_EXPORT Const : public Module 58 | { 59 | 60 | public: 61 | 62 | /// Constructor. 63 | /// 64 | /// The default constant value is set to 65 | /// noise::module::DEFAULT_CONST_VALUE. 66 | Const (); 67 | 68 | /// Returns the constant output value for this noise module. 69 | /// 70 | /// @returns The constant output value for this noise module. 71 | double GetConstValue () const 72 | { 73 | return m_constValue; 74 | } 75 | 76 | virtual int GetSourceModuleCount () const 77 | { 78 | return 0; 79 | } 80 | 81 | virtual double GetValue (double x, double y, double z) const 82 | { 83 | return m_constValue; 84 | } 85 | 86 | /// Sets the constant output value for this noise module. 87 | /// 88 | /// @param constValue The constant output value for this noise module. 89 | void SetConstValue (double constValue) 90 | { 91 | m_constValue = constValue; 92 | } 93 | 94 | protected: 95 | 96 | /// Constant value. 97 | double m_constValue; 98 | 99 | }; 100 | 101 | /// @} 102 | 103 | /// @} 104 | 105 | /// @} 106 | 107 | } 108 | 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /src/noise/module/curve.h: -------------------------------------------------------------------------------- 1 | // curve.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CURVE_H 24 | #define NOISE_MODULE_CURVE_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// This structure defines a control point. 38 | /// 39 | /// Control points are used for defining splines. 40 | struct ControlPoint 41 | { 42 | 43 | /// The input value. 44 | double inputValue; 45 | 46 | /// The output value that is mapped from the input value. 47 | double outputValue; 48 | 49 | }; 50 | 51 | /// @addtogroup modules 52 | /// @{ 53 | 54 | /// @addtogroup modifiermodules 55 | /// @{ 56 | 57 | /// Noise module that maps the output value from a source module onto an 58 | /// arbitrary function curve. 59 | /// 60 | /// @image html modulecurve.png 61 | /// 62 | /// This noise module maps the output value from the source module onto an 63 | /// application-defined curve. This curve is defined by a number of 64 | /// control points; each control point has an input value 65 | /// that maps to an output value. Refer to the following 66 | /// illustration: 67 | /// 68 | /// @image html curve.png 69 | /// 70 | /// To add the control points to this curve, call the AddControlPoint() 71 | /// method. 72 | /// 73 | /// Since this curve is a cubic spline, an application must add a minimum 74 | /// of four control points to the curve. If this is not done, the 75 | /// GetValue() method fails. Each control point can have any input and 76 | /// output value, although no two control points can have the same input 77 | /// value. There is no limit to the number of control points that can be 78 | /// added to the curve. 79 | /// 80 | /// This noise module requires one source module. 81 | class NOISE_EXPORT Curve : public Module 82 | { 83 | 84 | public: 85 | 86 | /// Constructor. 87 | Curve (); 88 | 89 | /// Destructor. 90 | ~Curve (); 91 | 92 | /// Adds a control point to the curve. 93 | /// 94 | /// @param inputValue The input value stored in the control point. 95 | /// @param outputValue The output value stored in the control point. 96 | /// 97 | /// @pre No two control points have the same input value. 98 | /// 99 | /// @throw noise::ExceptionInvalidParam An invalid parameter was 100 | /// specified; see the preconditions for more information. 101 | /// 102 | /// It does not matter which order these points are added. 103 | void AddControlPoint (double inputValue, double outputValue); 104 | 105 | /// Deletes all the control points on the curve. 106 | /// 107 | /// @post All points on the curve are deleted. 108 | void ClearAllControlPoints (); 109 | 110 | /// Returns a pointer to the array of control points on the curve. 111 | /// 112 | /// @returns A pointer to the array of control points. 113 | /// 114 | /// Before calling this method, call GetControlPointCount() to 115 | /// determine the number of control points in this array. 116 | /// 117 | /// It is recommended that an application does not store this pointer 118 | /// for later use since the pointer to the array may change if the 119 | /// application calls another method of this object. 120 | const ControlPoint* GetControlPointArray () const 121 | { 122 | return m_pControlPoints; 123 | } 124 | 125 | /// Returns the number of control points on the curve. 126 | /// 127 | /// @returns The number of control points on the curve. 128 | int GetControlPointCount () const 129 | { 130 | return m_controlPointCount; 131 | } 132 | 133 | virtual int GetSourceModuleCount () const 134 | { 135 | return 1; 136 | } 137 | 138 | virtual double GetValue (double x, double y, double z) const; 139 | 140 | protected: 141 | 142 | /// Determines the array index in which to insert the control point 143 | /// into the internal control point array. 144 | /// 145 | /// @param inputValue The input value of the control point. 146 | /// 147 | /// @returns The array index in which to insert the control point. 148 | /// 149 | /// @pre No two control points have the same input value. 150 | /// 151 | /// @throw noise::ExceptionInvalidParam An invalid parameter was 152 | /// specified; see the preconditions for more information. 153 | /// 154 | /// By inserting the control point at the returned array index, this 155 | /// class ensures that the control point array is sorted by input 156 | /// value. The code that maps a value onto the curve requires a 157 | /// sorted control point array. 158 | int FindInsertionPos (double inputValue); 159 | 160 | /// Inserts the control point at the specified position in the 161 | /// internal control point array. 162 | /// 163 | /// @param insertionPos The zero-based array position in which to 164 | /// insert the control point. 165 | /// @param inputValue The input value stored in the control point. 166 | /// @param outputValue The output value stored in the control point. 167 | /// 168 | /// To make room for this new control point, this method reallocates 169 | /// the control point array and shifts all control points occurring 170 | /// after the insertion position up by one. 171 | /// 172 | /// Because the curve mapping algorithm used by this noise module 173 | /// requires that all control points in the array must be sorted by 174 | /// input value, the new control point should be inserted at the 175 | /// position in which the order is still preserved. 176 | void InsertAtPos (int insertionPos, double inputValue, 177 | double outputValue); 178 | 179 | /// Number of control points on the curve. 180 | int m_controlPointCount; 181 | 182 | /// Array that stores the control points. 183 | ControlPoint* m_pControlPoints; 184 | 185 | }; 186 | 187 | /// @} 188 | 189 | /// @} 190 | 191 | /// @} 192 | 193 | } 194 | 195 | } 196 | 197 | #endif 198 | -------------------------------------------------------------------------------- /src/noise/module/cylinders.h: -------------------------------------------------------------------------------- 1 | // cylinders.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_CYLINDERS_H 24 | #define NOISE_MODULE_CYLINDERS_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup generatormodules 41 | /// @{ 42 | 43 | /// Default frequency value for the noise::module::Cylinders noise module. 44 | const double DEFAULT_CYLINDERS_FREQUENCY = 1.0; 45 | 46 | /// Noise module that outputs concentric cylinders. 47 | /// 48 | /// @image html modulecylinders.png 49 | /// 50 | /// This noise module outputs concentric cylinders centered on the origin. 51 | /// These cylinders are oriented along the @a y axis similar to the 52 | /// concentric rings of a tree. Each cylinder extends infinitely along 53 | /// the @a y axis. 54 | /// 55 | /// The first cylinder has a radius of 1.0. Each subsequent cylinder has 56 | /// a radius that is 1.0 unit larger than the previous cylinder. 57 | /// 58 | /// The output value from this noise module is determined by the distance 59 | /// between the input value and the the nearest cylinder surface. The 60 | /// input values that are located on a cylinder surface are given the 61 | /// output value 1.0 and the input values that are equidistant from two 62 | /// cylinder surfaces are given the output value -1.0. 63 | /// 64 | /// An application can change the frequency of the concentric cylinders. 65 | /// Increasing the frequency reduces the distances between cylinders. To 66 | /// specify the frequency, call the SetFrequency() method. 67 | /// 68 | /// This noise module, modified with some low-frequency, low-power 69 | /// turbulence, is useful for generating wood-like textures. 70 | /// 71 | /// This noise module does not require any source modules. 72 | class NOISE_EXPORT Cylinders : public Module 73 | { 74 | 75 | public: 76 | 77 | /// Constructor. 78 | /// 79 | /// The default frequency is set to 80 | /// noise::module::DEFAULT_CYLINDERS_FREQUENCY. 81 | Cylinders (); 82 | 83 | /// Returns the frequency of the concentric cylinders. 84 | /// 85 | /// @returns The frequency of the concentric cylinders. 86 | /// 87 | /// Increasing the frequency increases the density of the concentric 88 | /// cylinders, reducing the distances between them. 89 | double GetFrequency () const 90 | { 91 | return m_frequency; 92 | } 93 | 94 | virtual int GetSourceModuleCount () const 95 | { 96 | return 0; 97 | } 98 | 99 | virtual double GetValue (double x, double y, double z) const; 100 | 101 | /// Sets the frequenct of the concentric cylinders. 102 | /// 103 | /// @param frequency The frequency of the concentric cylinders. 104 | /// 105 | /// Increasing the frequency increases the density of the concentric 106 | /// cylinders, reducing the distances between them. 107 | void SetFrequency (double frequency) 108 | { 109 | m_frequency = frequency; 110 | } 111 | 112 | protected: 113 | 114 | /// Frequency of the concentric cylinders. 115 | double m_frequency; 116 | 117 | }; 118 | 119 | /// @} 120 | 121 | /// @} 122 | 123 | /// @} 124 | 125 | } 126 | 127 | } 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /src/noise/module/exponent.h: -------------------------------------------------------------------------------- 1 | // exponent.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_EXPONENT_H 24 | #define NOISE_MODULE_EXPONENT_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Default exponent for the noise::module::Exponent noise module. 44 | const double DEFAULT_EXPONENT = 1.0; 45 | 46 | /// Noise module that maps the output value from a source module onto an 47 | /// exponential curve. 48 | /// 49 | /// @image html moduleexponent.png 50 | /// 51 | /// Because most noise modules will output values that range from -1.0 to 52 | /// +1.0, this noise module first normalizes this output value (the range 53 | /// becomes 0.0 to 1.0), maps that value onto an exponential curve, then 54 | /// rescales that value back to the original range. 55 | /// 56 | /// This noise module requires one source module. 57 | class NOISE_EXPORT Exponent : public Module 58 | { 59 | 60 | public: 61 | 62 | /// Constructor. 63 | /// 64 | /// The default exponent is set to noise::module::DEFAULT_EXPONENT. 65 | Exponent (); 66 | 67 | /// Returns the exponent value to apply to the output value from the 68 | /// source module. 69 | /// 70 | /// @returns The exponent value. 71 | /// 72 | /// Because most noise modules will output values that range from -1.0 73 | /// to +1.0, this noise module first normalizes this output value (the 74 | /// range becomes 0.0 to 1.0), maps that value onto an exponential 75 | /// curve, then rescales that value back to the original range. 76 | double GetExponent () const 77 | { 78 | return m_exponent; 79 | } 80 | 81 | virtual int GetSourceModuleCount () const 82 | { 83 | return 1; 84 | } 85 | 86 | virtual double GetValue (double x, double y, double z) const; 87 | 88 | /// Sets the exponent value to apply to the output value from the 89 | /// source module. 90 | /// 91 | /// @param exponent The exponent value. 92 | /// 93 | /// Because most noise modules will output values that range from -1.0 94 | /// to +1.0, this noise module first normalizes this output value (the 95 | /// range becomes 0.0 to 1.0), maps that value onto an exponential 96 | /// curve, then rescales that value back to the original range. 97 | void SetExponent (double exponent) 98 | { 99 | m_exponent = exponent; 100 | } 101 | 102 | protected: 103 | 104 | /// Exponent to apply to the output value from the source module. 105 | double m_exponent; 106 | 107 | }; 108 | 109 | /// @} 110 | 111 | /// @} 112 | 113 | /// @} 114 | 115 | } 116 | 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /src/noise/module/invert.h: -------------------------------------------------------------------------------- 1 | // invert.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_INVERT_H 24 | #define NOISE_MODULE_INVERT_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Noise module that inverts the output value from a source module. 44 | /// 45 | /// @image html moduleinvert.png 46 | /// 47 | /// This noise module requires one source module. 48 | class NOISE_EXPORT Invert: public Module 49 | { 50 | 51 | public: 52 | 53 | /// Constructor. 54 | Invert (); 55 | 56 | virtual int GetSourceModuleCount () const 57 | { 58 | return 1; 59 | } 60 | 61 | virtual double GetValue (double x, double y, double z) const; 62 | 63 | }; 64 | 65 | /// @} 66 | 67 | /// @} 68 | 69 | /// @} 70 | 71 | } 72 | 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/noise/module/max.h: -------------------------------------------------------------------------------- 1 | // max.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_MAX_H 24 | #define NOISE_MODULE_MAX_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the larger of the two output values from two 44 | /// source modules. 45 | /// 46 | /// @image html modulemax.png 47 | /// 48 | /// This noise module requires two source modules. 49 | class NOISE_EXPORT Max: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Max (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 2; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/noise/module/min.h: -------------------------------------------------------------------------------- 1 | // min.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_MIN_H 24 | #define NOISE_MODULE_MIN_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the smaller of the two output values from 44 | /// two source modules. 45 | /// 46 | /// @image html modulemin.png 47 | /// 48 | /// This noise module requires two source modules. 49 | class NOISE_EXPORT Min: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Min (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 2; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/noise/module/module.h: -------------------------------------------------------------------------------- 1 | // module.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_H 24 | #define NOISE_MODULE_H 25 | 26 | #include "add.h" 27 | #include "abs.h" 28 | #include "billow.h" 29 | #include "blend.h" 30 | #include "cache.h" 31 | #include "checkerboard.h" 32 | #include "clamp.h" 33 | #include "const.h" 34 | #include "curve.h" 35 | #include "cylinders.h" 36 | #include "displace.h" 37 | #include "exponent.h" 38 | #include "invert.h" 39 | #include "max.h" 40 | #include "min.h" 41 | #include "multiply.h" 42 | #include "perlin.h" 43 | #include "power.h" 44 | #include "ridgedmulti.h" 45 | #include "rotatepoint.h" 46 | #include "scalebias.h" 47 | #include "scalepoint.h" 48 | #include "select.h" 49 | #include "spheres.h" 50 | #include "terrace.h" 51 | #include "translatepoint.h" 52 | #include "turbulence.h" 53 | #include "voronoi.h" 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/noise/module/multiply.h: -------------------------------------------------------------------------------- 1 | // multiply.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_MULTIPLY_H 24 | #define NOISE_MODULE_MULTIPLY_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that outputs the product of the two output values from 44 | /// two source modules. 45 | /// 46 | /// @image html modulemultiply.png 47 | /// 48 | /// This noise module requires two source modules. 49 | class NOISE_EXPORT Multiply: public Module 50 | { 51 | 52 | public: 53 | 54 | /// Constructor. 55 | Multiply (); 56 | 57 | virtual int GetSourceModuleCount () const 58 | { 59 | return 2; 60 | } 61 | 62 | virtual double GetValue (double x, double y, double z) const; 63 | 64 | }; 65 | 66 | /// @} 67 | 68 | /// @} 69 | 70 | /// @} 71 | 72 | } 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/noise/module/power.h: -------------------------------------------------------------------------------- 1 | // power.h 2 | // 3 | // Copyright (C) 2004 Owen Jacobson 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is angstrom@lionsanctuary.net 20 | // 21 | 22 | #ifndef NOISE_MODULE_POWER_H 23 | #define NOISE_MODULE_POWER_H 24 | 25 | #include "modulebase.h" 26 | 27 | namespace noise 28 | { 29 | 30 | namespace module 31 | { 32 | 33 | /// @addtogroup libnoise 34 | /// @{ 35 | 36 | /// @addtogroup modules 37 | /// @{ 38 | 39 | /// @defgroup combinermodules Combiner Modules 40 | /// @addtogroup combinermodules 41 | /// @{ 42 | 43 | /// Noise module that raises the output value from a first source module 44 | /// to the power of the output value from a second source module. 45 | /// 46 | /// @image html modulepower.png 47 | /// 48 | /// The first source module must have an index value of 0. 49 | /// 50 | /// The second source module must have an index value of 1. 51 | /// 52 | /// This noise module requires two source modules. 53 | class NOISE_EXPORT Power: public Module 54 | { 55 | 56 | public: 57 | 58 | /// Constructor. 59 | Power (); 60 | 61 | virtual int GetSourceModuleCount () const 62 | { 63 | return 2; 64 | } 65 | 66 | virtual double GetValue (double x, double y, double z) const; 67 | 68 | }; 69 | 70 | /// @} 71 | 72 | /// @} 73 | 74 | /// @} 75 | 76 | } 77 | 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /src/noise/module/scalebias.h: -------------------------------------------------------------------------------- 1 | // scalebias.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_SCALEBIAS_H 24 | #define NOISE_MODULE_SCALEBIAS_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup modifiermodules 41 | /// @{ 42 | 43 | /// Default bias for the noise::module::ScaleBias noise module. 44 | const double DEFAULT_BIAS = 0.0; 45 | 46 | /// Default scale for the noise::module::ScaleBias noise module. 47 | const double DEFAULT_SCALE = 1.0; 48 | 49 | /// Noise module that applies a scaling factor and a bias to the output 50 | /// value from a source module. 51 | /// 52 | /// @image html modulescalebias.png 53 | /// 54 | /// The GetValue() method retrieves the output value from the source 55 | /// module, multiplies it with a scaling factor, adds a bias to it, then 56 | /// outputs the value. 57 | /// 58 | /// This noise module requires one source module. 59 | class NOISE_EXPORT ScaleBias : public Module 60 | { 61 | 62 | public: 63 | 64 | /// Constructor. 65 | /// 66 | /// The default bias is set to noise::module::DEFAULT_BIAS. 67 | /// 68 | /// The default scaling factor is set to noise::module::DEFAULT_SCALE. 69 | ScaleBias (); 70 | 71 | /// Returns the bias to apply to the scaled output value from the 72 | /// source module. 73 | /// 74 | /// @returns The bias to apply. 75 | /// 76 | /// The GetValue() method retrieves the output value from the source 77 | /// module, multiplies it with the scaling factor, adds the bias to 78 | /// it, then outputs the value. 79 | double GetBias () const 80 | { 81 | return m_bias; 82 | } 83 | 84 | /// Returns the scaling factor to apply to the output value from the 85 | /// source module. 86 | /// 87 | /// @returns The scaling factor to apply. 88 | /// 89 | /// The GetValue() method retrieves the output value from the source 90 | /// module, multiplies it with the scaling factor, adds the bias to 91 | /// it, then outputs the value. 92 | double GetScale () const 93 | { 94 | return m_scale; 95 | } 96 | 97 | virtual int GetSourceModuleCount () const 98 | { 99 | return 1; 100 | } 101 | 102 | virtual double GetValue (double x, double y, double z) const; 103 | 104 | /// Sets the bias to apply to the scaled output value from the source 105 | /// module. 106 | /// 107 | /// @param bias The bias to apply. 108 | /// 109 | /// The GetValue() method retrieves the output value from the source 110 | /// module, multiplies it with the scaling factor, adds the bias to 111 | /// it, then outputs the value. 112 | void SetBias (double bias) 113 | { 114 | m_bias = bias; 115 | } 116 | 117 | /// Sets the scaling factor to apply to the output value from the 118 | /// source module. 119 | /// 120 | /// @param scale The scaling factor to apply. 121 | /// 122 | /// The GetValue() method retrieves the output value from the source 123 | /// module, multiplies it with the scaling factor, adds the bias to 124 | /// it, then outputs the value. 125 | void SetScale (double scale) 126 | { 127 | m_scale = scale; 128 | } 129 | 130 | protected: 131 | 132 | /// Bias to apply to the scaled output value from the source module. 133 | double m_bias; 134 | 135 | /// Scaling factor to apply to the output value from the source 136 | /// module. 137 | double m_scale; 138 | 139 | }; 140 | 141 | /// @} 142 | 143 | /// @} 144 | 145 | /// @} 146 | 147 | } 148 | 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /src/noise/module/spheres.h: -------------------------------------------------------------------------------- 1 | // spheres.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_MODULE_SPHERES_H 24 | #define NOISE_MODULE_SPHERES_H 25 | 26 | #include "modulebase.h" 27 | 28 | namespace noise 29 | { 30 | 31 | namespace module 32 | { 33 | 34 | /// @addtogroup libnoise 35 | /// @{ 36 | 37 | /// @addtogroup modules 38 | /// @{ 39 | 40 | /// @addtogroup generatormodules 41 | /// @{ 42 | 43 | /// Default frequency value for the noise::module::Spheres noise module. 44 | const double DEFAULT_SPHERES_FREQUENCY = 1.0; 45 | 46 | /// Noise module that outputs concentric spheres. 47 | /// 48 | /// @image html modulespheres.png 49 | /// 50 | /// This noise module outputs concentric spheres centered on the origin 51 | /// like the concentric rings of an onion. 52 | /// 53 | /// The first sphere has a radius of 1.0. Each subsequent sphere has a 54 | /// radius that is 1.0 unit larger than the previous sphere. 55 | /// 56 | /// The output value from this noise module is determined by the distance 57 | /// between the input value and the the nearest spherical surface. The 58 | /// input values that are located on a spherical surface are given the 59 | /// output value 1.0 and the input values that are equidistant from two 60 | /// spherical surfaces are given the output value -1.0. 61 | /// 62 | /// An application can change the frequency of the concentric spheres. 63 | /// Increasing the frequency reduces the distances between spheres. To 64 | /// specify the frequency, call the SetFrequency() method. 65 | /// 66 | /// This noise module, modified with some low-frequency, low-power 67 | /// turbulence, is useful for generating agate-like textures. 68 | /// 69 | /// This noise module does not require any source modules. 70 | class NOISE_EXPORT Spheres : public Module 71 | { 72 | 73 | public: 74 | 75 | /// Constructor. 76 | /// 77 | /// The default frequency is set to 78 | /// noise::module::DEFAULT_SPHERES_FREQUENCY. 79 | Spheres (); 80 | 81 | /// Returns the frequency of the concentric spheres. 82 | /// 83 | /// @returns The frequency of the concentric spheres. 84 | /// 85 | /// Increasing the frequency increases the density of the concentric 86 | /// spheres, reducing the distances between them. 87 | double GetFrequency () const 88 | { 89 | return m_frequency; 90 | } 91 | 92 | virtual int GetSourceModuleCount () const 93 | { 94 | return 0; 95 | } 96 | 97 | virtual double GetValue (double x, double y, double z) const; 98 | 99 | /// Sets the frequenct of the concentric spheres. 100 | /// 101 | /// @param frequency The frequency of the concentric spheres. 102 | /// 103 | /// Increasing the frequency increases the density of the concentric 104 | /// spheres, reducing the distances between them. 105 | void SetFrequency (double frequency) 106 | { 107 | m_frequency = frequency; 108 | } 109 | 110 | protected: 111 | 112 | /// Frequency of the concentric spheres. 113 | double m_frequency; 114 | 115 | }; 116 | 117 | /// @} 118 | 119 | /// @} 120 | 121 | /// @} 122 | 123 | } 124 | 125 | } 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /src/noise/noise.h: -------------------------------------------------------------------------------- 1 | // noise.h 2 | // 3 | // Copyright (C) 2003, 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #ifndef NOISE_H 24 | #define NOISE_H 25 | 26 | /// @mainpage libnoise 27 | /// 28 | /// @section intro Introduction 29 | /// 30 | /// libnoise is a portable C++ library that is used to generate coherent 31 | /// noise, a type of smoothly-changing noise. libnoise can generate Perlin 32 | /// noise, ridged multifractal noise, and other types of coherent noise. 33 | /// 34 | /// Coherent noise is often used by graphics programmers to generate 35 | /// natural-looking textures, planetary terrain, and other things. It can 36 | /// also be used to move critters in a realistic way. 37 | /// 38 | /// libnoise is known to compile using the following compilers on the 39 | /// following platforms: 40 | /// - Microsoft Visual C++ 5.0 under Microsoft Windows 2000 Service Pack 4 41 | /// - gcc 3.3.4 under Gentoo Linux 10.0 (x86) 42 | /// 43 | /// libnoise will compile on 32-bit/64-bit platforms 44 | /// 45 | /// @section noise Noise Modules 46 | /// 47 | /// In libnoise, coherent-noise generators are encapsulated in classes called 48 | /// noise modules. There are many different types of noise modules. 49 | /// Some noise modules can combine or modify the outputs of other noise 50 | /// modules in various ways; you can join these modules together to generate 51 | /// very complex coherent noise. 52 | /// 53 | /// A noise module receives a 3-dimensional input value from the application, 54 | /// computes the noise value given that input value, and returns the resulting 55 | /// value back to the application. 56 | /// 57 | /// If the application passes the same input value to a noise module, the 58 | /// noise module returns the same output value. 59 | /// 60 | /// All noise modules are derived from the noise::module::Module abstract 61 | /// base class. 62 | /// 63 | /// @section contact Contact 64 | /// 65 | /// Contact jas for questions about libnoise. The spam-resistant email 66 | /// address is jlbezigvins@gmzigail.com (For great email, take off every 67 | /// zig.) 68 | 69 | #include "module/module.h" 70 | #include "model/model.h" 71 | #include "misc.h" 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/win32/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp 2 | // 3 | // Copyright (C) 2004 Jason Bevins 4 | // 5 | // This library is free software; you can redistribute it and/or modify it 6 | // under the terms of the GNU Lesser General Public License as published by 7 | // the Free Software Foundation; either version 2.1 of the License, or (at 8 | // your option) any later version. 9 | // 10 | // This library is distributed in the hope that it will be useful, but WITHOUT 11 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | // License (COPYING.txt) for more details. 14 | // 15 | // You should have received a copy of the GNU Lesser General Public License 16 | // along with this library; if not, write to the Free Software Foundation, 17 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | // 19 | // The developer's email is jlbezigvins@gmzigail.com (for great email, take 20 | // off every 'zig'.) 21 | // 22 | 23 | #include 24 | 25 | BOOL WINAPI DllMain (HINSTANCE hInst, ULONG reason, LPVOID lpReserved) 26 | { 27 | return TRUE; 28 | } 29 | -------------------------------------------------------------------------------- /src/win32/noise.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/src/win32/noise.aps -------------------------------------------------------------------------------- /src/win32/noise.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qknight/libnoise/9ce0737b55812f7de907e86dc633724524e3a8e8/src/win32/noise.rc -------------------------------------------------------------------------------- /src/win32/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by noise.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1000 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | --------------------------------------------------------------------------------