From 341eda975c90790920ebff6b5ef9562ed84c97d2 Mon Sep 17 00:00:00 2001 From: Overdrivr Date: Thu, 24 May 2012 20:41:08 +0200 Subject: [PATCH 01/13] NzNoise added --- build/scripts/module/noise.lua | 31 + include/Nazara/Noise/Config.hpp | 38 + include/Nazara/Noise/Debug.hpp | 11 + include/Nazara/Noise/DebugOff.hpp | 8 + include/Nazara/Noise/Noise.hpp | 27 + include/Nazara/Noise/NoiseMachine.h | 121 +++ src/Nazara/Noise/Debug/Leaks.cpp | 29 + src/Nazara/Noise/Noise.cpp | 57 ++ src/Nazara/Noise/NoiseMachine.cpp | 1054 +++++++++++++++++++++++++++ 9 files changed, 1376 insertions(+) create mode 100644 build/scripts/module/noise.lua create mode 100644 include/Nazara/Noise/Config.hpp create mode 100644 include/Nazara/Noise/Debug.hpp create mode 100644 include/Nazara/Noise/DebugOff.hpp create mode 100644 include/Nazara/Noise/Noise.hpp create mode 100644 include/Nazara/Noise/NoiseMachine.h create mode 100644 src/Nazara/Noise/Debug/Leaks.cpp create mode 100644 src/Nazara/Noise/Noise.cpp create mode 100644 src/Nazara/Noise/NoiseMachine.cpp diff --git a/build/scripts/module/noise.lua b/build/scripts/module/noise.lua new file mode 100644 index 000000000..cb168a391 --- /dev/null +++ b/build/scripts/module/noise.lua @@ -0,0 +1,31 @@ +project "NazaraNoise" + +files +{ + "../include/Nazara/Noise/**.hpp", + "../include/Nazara/Noise/**.inl", + "../src/Nazara/Noise/**.hpp", + "../src/Nazara/Noise/**.cpp" +} + +if (os.is("windows")) then + excludes { "../src/Nazara/ModuleName/Posix/*.hpp", "../src/Nazara/ModuleName/Posix/*.cpp" } +else + excludes { "../src/Nazara/ModuleName/Win32/*.hpp", "../src/Nazara/ModuleName/Win32/*.cpp" } +end + +configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraNoised" + +configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraNoise" + +configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraNoised" + +configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraNoise" \ No newline at end of file diff --git a/include/Nazara/Noise/Config.hpp b/include/Nazara/Noise/Config.hpp new file mode 100644 index 000000000..118b476b2 --- /dev/null +++ b/include/Nazara/Noise/Config.hpp @@ -0,0 +1,38 @@ +/* + Nazara Engine + + Copyright (C) 2012 AUTHORS (EMAIL) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_NOISE_HPP +#define NAZARA_CONFIG_NOISE_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +#define NAZARA_NOISE_MEMORYLEAKTRACKER 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_NOISE_SAFE 1 + +#endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/Noise/Debug.hpp b/include/Nazara/Noise/Debug.hpp new file mode 100644 index 000000000..a9853cc6c --- /dev/null +++ b/include/Nazara/Noise/Debug.hpp @@ -0,0 +1,11 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) + #include + + #define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete + #define new new(__FILE__, __LINE__) +#endif diff --git a/include/Nazara/Noise/DebugOff.hpp b/include/Nazara/Noise/DebugOff.hpp new file mode 100644 index 000000000..2fbe08003 --- /dev/null +++ b/include/Nazara/Noise/DebugOff.hpp @@ -0,0 +1,8 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#if NAZARA_NOISE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) + #undef delete + #undef new +#endif diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp new file mode 100644 index 000000000..c4925ac0a --- /dev/null +++ b/include/Nazara/Noise/Noise.hpp @@ -0,0 +1,27 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_NOISE_HPP +#define NAZARA_NOISE_HPP + +#include + +class NAZARA_API NzNoise +{ + public: + NzNoise(); + ~NzNoise(); + + bool Initialize(); + void Uninitialize(); + + static bool IsInitialized(); + + private: + static bool s_initialized; +}; + +#endif // NOISE_H diff --git a/include/Nazara/Noise/NoiseMachine.h b/include/Nazara/Noise/NoiseMachine.h new file mode 100644 index 000000000..ecbcae4ac --- /dev/null +++ b/include/Nazara/Noise/NoiseMachine.h @@ -0,0 +1,121 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NOISEMACHINE_HPP +#define NOISEMACHINE_HPP + +#include + +class NzVector2f; +class NzVector3f; +class NzVector4f; + +class NzNoiseMachine +{ + public: + NzNoiseMachine(int seed = 0); + ~NzNoiseMachine(); + + void SetNewSeed(int seed); + void ShufflePermutationTable(); + + float Get1DPerlinNoiseValue(float x, float res); + float Get2DPerlinNoiseValue(float x, float y, float res); + float Get3DPerlinNoiseValue(float x, float y, float z, float res); + float Get4DPerlinNoiseValue(float x, float y, float z, float w, float res); + + float Get2DSimplexNoiseValue(float x, float y, float res); + float Get3DSimplexNoiseValue(float x, float y, float z, float res); + float Get4DSimplexNoiseValue(float x, float y, float z, float w, float res); + + float Get2DCellNoiseValue(float x, float y, float res); + float Get3DCellNoiseValue(float x, float y, float z, float res); + float Get4DCellNoiseValue(float x, float y, float z, float w, float res); + + void SetLacunarity(float lacunarity); + void SetHurstParameter(float h); + void SetOctavesNumber(float octaves); + void RecomputeExponentArray(); + + float Get1DFBMNoiseValue(float x, float res); + float Get2DFBMNoiseValue(float x, float y, float res); + float Get3DFBMNoiseValue(float x, float y, float z, float res); + + float Get2DHybridMultiFractalNoiseValue(float x, float y, float res); + float Get3DHybridMultiFractalNoiseValue(float x, float y, float z, float res); + + protected: + private: + + //Pour tronquer les nombres + int fastfloor(float n); + + float pi; + int perm[512]; + int PermutationTemp[256]; + float gradient2[8][2]; + int gradient3[16][3]; + int gradient4[32][4]; + int lookupTable4D[64][4]; + + //multiplicative congruential generator + int UcurrentSeed; + int Ua,Uc,Um; + int Uprevious; + int Ulast; + + //----------------------- Simplex variables -------------------------------------- + + float n1, n2, n3, n4, n5; + NzVector4f A; + NzVector4i Origin; + NzVector4f d1,d2,d3,d4,d5; + NzVector4i off1, off2,off3; + NzVector4f IsoOriginDist; + NzVector4f H[5]; + + int ii,jj,kk,ll; + int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; + float lenght; + float c1,c2,c3,c4,c5,c6; + int c; + + float SkewCoeff2D; + float UnskewCoeff2D; + + float SkewCoeff3D; + float UnskewCoeff3D; + + float SkewCoeff4D; + float UnskewCoeff4D; + + //----------------------- Perlin Variables ------------------------------------- + + int x0,y0,z0,w0; + float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14; + float s[4],t[4],u[4],v[4]; + float Cx, Cy, Cz, Cw; + NzVector4f temp; + float nx,ny,nz,nw; + float tmp; + + //---------------------- Complex Noise Variables -------------------------------- + + float m_lacunarity; + float m_hurst; + float m_octaves; + bool m_parametersModified; + float exponent_array[30]; + bool first; + float value; + float remainder; + + float smax; + float smin; + +}; + +#endif // NOISEMACHINE_H diff --git a/src/Nazara/Noise/Debug/Leaks.cpp b/src/Nazara/Noise/Debug/Leaks.cpp new file mode 100644 index 000000000..2e584687c --- /dev/null +++ b/src/Nazara/Noise/Debug/Leaks.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) +#include +#include + +void* operator new(std::size_t size) throw(std::bad_alloc) +{ + return NzMemoryManager::Allocate(size, false); +} + +void* operator new[](std::size_t size) throw(std::bad_alloc) +{ + return NzMemoryManager::Allocate(size, true); +} + +void operator delete(void* pointer) throw() +{ + NzMemoryManager::Free(pointer, false); +} + +void operator delete[](void* pointer) throw() +{ + NzMemoryManager::Free(pointer, true); +} +#endif diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp new file mode 100644 index 000000000..c72266759 --- /dev/null +++ b/src/Nazara/Noise/Noise.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +NzNoise::NzNoise() +{ +} + +NzNoise::~NzNoise() +{ + if (s_initialized) + Uninitialize(); +} + +bool NzNoise::Initialize() +{ + #if NAZARA_NOISE_SAFE + if (s_initialized) + { + NazaraError("NzNoise already initialized"); + return true; + } + #endif + + // Initialisation du module + + s_initialized = true; + + return true; +} + +void NzNoise::Uninitialize() +{ + #if NAZARA_NOISE_SAFE + if (!s_initialized) + { + NazaraError("NzNoise not initialized"); + return; + } + #endif + + // Libération du module + + s_initialized = false; +} + +bool NzNoise::IsInitialized() +{ + return s_initialized; +} + +bool NzNoise::s_initialized = false; diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp new file mode 100644 index 000000000..adc288a82 --- /dev/null +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -0,0 +1,1054 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +#include + +#include +#include +#include + +NzNoiseMachine::NzNoiseMachine(float seed) +{ + pi = 3.14159265; + + SkewCoeff2D = 0.5*(sqrt(3.0) - 1.0); + UnskewCoeff2D = (3.0-sqrt(3.0))/6; + + SkewCoeff3D = 1/3; + UnskewCoeff3D = 1/6; + + SkewCoeff4D = (sqrt(5) - 1)/4; + UnskewCoeff4D = (5 - sqrt(5))/20; + + //Uniform pseudo random number generator coefficients + Ua = 16807; + Uc = 0; + Um = 2147483647; + UcurrentSeed = 0; + Uprevious = 0; + + SetNewSeed(seed); + + for(float i(0) ; i < 256 ; i++) + PermutationTemp[i] = i; + + //4D only - to find the offset with Simplex in 4D + float lookupTemp4D[][4] = + { + {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0}, + {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0}, + {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, + {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0}, + {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0}, + {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, + {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0}, + {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0} + }; + + for(float i(0) ; i < 64 ; ++i) + for(float j(0) ; j < 4 ; ++j) + lookupTable4D[i][j] = lookupTemp4D[i][j]; + + float unit = 1.0/sqrt(2); + float grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, + {1,0},{-1,0},{0,1},{0,-1}}; + + for(float i(0) ; i < 8 ; ++i) + for(float j(0) ; j < 2 ; ++j) + gradient2[i][j] = grad2Temp[i][j]; + + //On remplit les tables de gradients + float grad3Temp[][3] = { + {1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, + {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, + {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}, + {1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1} + }; + + for(float i(0) ; i < 16 ; ++i) + for(float j(0) ; j < 3 ; ++j) + gradient3[i][j] = grad3Temp[i][j]; + + float grad4Temp[][4] = + { + {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1}, + {0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1}, + {1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1}, + {-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1}, + {1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1}, + {-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1}, + {1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0}, + {-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0} + }; + + for(float i(0) ; i < 32 ; ++i) + for(float j(0) ; j < 4 ; ++j) + gradient4[i][j] = grad4Temp[i][j]; + + + m_lacunarity = 2.5f; + m_octaves = 3.0f; + m_hurst = 1.1f; + m_parametersModified = true; +} + +NzNoiseMachine::~NzNoiseMachine() +{ + +} + +void NzNoiseMachine::SetNewSeed(float seed) +{ + Uprevious = seed; + UcurrentSeed = seed; +} + +float NzNoiseMachine::GetUniformRandomValue() +{ + Ulast = Ua*Uprevious + Uc%Um; + Uprevious = Ulast; + return Ulast; +} + +void NzNoiseMachine::MixPermutationTable() +{ + float xchanger; + unsigned float ncase; + for(float j(0) ; j < 10 ; ++j) + for (float i(0); i < 256 ; ++i) + { + ncase = this->GetUniformRandomValue() & 255; + xchanger = PermutationTemp[i]; + PermutationTemp[i] = PermutationTemp[ncase]; + PermutationTemp[ncase] = xchanger; + } + + for(float i(0) ; i < 512; ++i) + perm[i]=PermutationTemp[i & 255]; +} + +//------------------------------ PERLIN ------------------------------ + +float NzNoiseMachine::Get1DPerlinNoiseValue(float x, float res) +{ + nx = x/res; + x0 = (float)(nx); + ii = x0 & 255; + + gi0 = perm[ii] % 16; + gi1 = perm[ii + 1] % 16; + + temp.X = nx-x0; + temp.Y = ny-y0; + + s[0] = gradient3[gi0][0]*temp.X; + + temp.X = nx-(x0+1); + + t[0] = gradient3[gi1][0]*temp.X; + + //Lissage + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return s[0] + Cx*(t[0]-s[0]); +} + +float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res) +{ + nx = x/res; + ny = y/res; + + //On récupère les positions de la grille associée à (x,y) + x0 = (float)(nx); + y0 = (float)(ny); + + ii = x0 & 255; + jj = y0 & 255; + + gi0 = perm[ii + perm[jj]] & 7; + gi1 = perm[ii + 1 + perm[jj]] & 7; + gi2 = perm[ii + perm[jj + 1]] & 7; + gi3 = perm[ii + 1 + perm[jj + 1]] & 7; + + //on calcule les valeurs du plan supérieur + temp.X = nx-x0; + temp.Y = ny-y0; + s[0] = gradient2[gi0][0]*temp.X + gradient2[gi0][1]*temp.Y; + + temp.X = nx-(x0+1); + temp.Y = ny-y0; + t[0] = gradient2[gi1][0]*temp.X + gradient2[gi1][1]*temp.Y; + + temp.X = nx-x0; + temp.Y = ny-(y0+1); + u[0] = gradient2[gi2][0]*temp.X + gradient2[gi2][1]*temp.Y; + + temp.X = nx-(x0+1); + temp.Y = ny-(y0+1); + v[0] = gradient2[gi3][0]*temp.X + gradient2[gi3][1]*temp.Y; + + + //Lissage + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li1 = s[0] + Cx*(t[0]-s[0]); + Li2 = u[0] + Cx*(v[0]-u[0]); + + tmp = ny - y0; + Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return Li1 + Cy*(Li2-Li1); +} +float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res) +{ + nx = x/res; + ny = y/res; + nz = z/res; + + //On récupère les positions de la grille associée à (x,y) + x0 = (float)(nx); + y0 = (float)(ny); + z0 = (float)(nz); + + ii = x0 & 255; + jj = y0 & 255; + kk = z0 & 255; + + gi0 = perm[ii + perm[jj + perm[kk]]] % 16; + gi1 = perm[ii + 1 + perm[jj + perm[kk]]] % 16; + gi2 = perm[ii + perm[jj + 1 + perm[kk]]] % 16; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] % 16; + + gi4 = perm[ii + perm[jj + perm[kk + 1]]] % 16; + gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] % 16; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] % 16; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 16; + + //on calcule les valeurs du plan inférieur + temp.X = nx-x0; + temp.Y = ny-y0; + temp.Z = nz-z0; + s[0] = gradient3[gi0][0]*temp.X + gradient3[gi0][1]*temp.Y + gradient3[gi0][2]*temp.Z; + + temp.X = nx-(x0+1); + temp.Y = ny-y0; + t[0] = gradient3[gi1][0]*temp.X + gradient3[gi1][1]*temp.Y + gradient3[gi1][2]*temp.Z; + + temp.X = nx-x0; + temp.Y = ny-(y0+1); + u[0] = gradient3[gi2][0]*temp.X + gradient3[gi2][1]*temp.Y + gradient3[gi2][2]*temp.Z; + + temp.X = nx-(x0+1); + temp.Y = ny-(y0+1); + v[0] = gradient3[gi3][0]*temp.X + gradient3[gi3][1]*temp.Y + gradient3[gi3][2]*temp.Z; + + //Les valeurs du plan supérieur + temp.X = nx-x0; + temp.Y = ny-y0; + temp.Z = nz-(z0+1); + s[1] = gradient3[gi4][0]*temp.X + gradient3[gi4][1]*temp.Y + gradient3[gi4][2]*temp.Z; + + temp.X = nx-(x0+1); + temp.Y = ny-y0; + t[1] = gradient3[gi5][0]*temp.X + gradient3[gi5][1]*temp.Y + gradient3[gi5][2]*temp.Z; + + temp.X = nx-x0; + temp.Y = ny-(y0+1); + u[1] = gradient3[gi6][0]*temp.X + gradient3[gi6][1]*temp.Y + gradient3[gi6][2]*temp.Z; + + temp.X = nx-(x0+1); + temp.Y = ny-(y0+1); + v[1] = gradient3[gi7][0]*temp.X + gradient3[gi7][1]*temp.Y + gradient3[gi7][2]*temp.Z; + + //On procède à un lissage, et on affecte le pofloat à la matrice de pixels + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li1 = s[0] + Cx*(t[0]-s[0]); + Li2 = u[0] + Cx*(v[0]-u[0]); + Li3 = s[1] + Cx*(t[1]-s[1]); + Li4 = u[1] + Cx*(v[1]-u[1]); + + tmp = ny-y0; + Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li5 = Li1 + Cy*(Li2-Li1); + Li6 = Li3 + Cy*(Li4-Li3); + + tmp = nz-z0; + Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return Li5 + Cz*(Li6-Li5); +} + +float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, float res) +{ + nx = x/res; + ny = y/res; + nz = z/res; + nw = w/res; + + //On récupère les positions de la grille associée à (x,y) + x0 = (float)(nx); + y0 = (float)(ny); + z0 = (float)(nz); + w0 = (float)(nw); + + ii = x0 & 255; + jj = y0 & 255; + kk = z0 & 255; + ll = w0 & 255; + + gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] % 32; + gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll ]]]] % 32; + gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; + + gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; + gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; + + gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] % 32; + gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] % 32; + gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; + gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; + + gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + + //Z inférieur, W inférieur + temp.X = nx-x0; + temp.Y = ny-y0; + temp.Z = nz-z0; + temp.W = nw-w0; + s[0] = gradient4[gi0][0]*temp.X + gradient4[gi0][1]*temp.Y + gradient4[gi0][2]*temp.Z + gradient4[gi0][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-y0; + t[0] = gradient4[gi1][0]*temp.X + gradient4[gi1][1]*temp.Y + gradient4[gi1][2]*temp.Z + gradient4[gi1][3]*temp.W; + + temp.X = nx-x0; + temp.Y = ny-(y0+1); + u[0] = gradient4[gi2][0]*temp.X + gradient4[gi2][1]*temp.Y + gradient4[gi2][2]*temp.Z + gradient4[gi2][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-(y0+1); + v[0] = gradient4[gi3][0]*temp.X + gradient4[gi3][1]*temp.Y + gradient4[gi3][2]*temp.Z + gradient4[gi3][3]*temp.W; + + //Z supérieur, W inférieur + temp.X = nx-x0; + temp.Y = ny-y0; + temp.Z = nz-(z0+1); + s[1] = gradient4[gi4][0]*temp.X + gradient4[gi4][1]*temp.Y + gradient4[gi4][2]*temp.Z + gradient4[gi4][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-y0; + t[1] = gradient4[gi5][0]*temp.X + gradient4[gi5][1]*temp.Y + gradient4[gi5][2]*temp.Z + gradient4[gi5][3]*temp.W; + + temp.X = nx-x0; + temp.Y = ny-(y0+1); + u[1] = gradient4[gi6][0]*temp.X + gradient4[gi6][1]*temp.Y + gradient4[gi6][2]*temp.Z + gradient4[gi6][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-(y0+1); + v[1] = gradient4[gi7][0]*temp.X + gradient4[gi7][1]*temp.Y + gradient4[gi7][2]*temp.Z + gradient4[gi7][3]*temp.W; + + //Z inférieur, W superieur + temp.X = nx-x0; + temp.Y = ny-y0; + temp.Z = nz-z0; + temp.W = nw-(w0+1); + s[2] = gradient4[gi8][0]*temp.X + gradient4[gi8][1]*temp.Y + gradient4[gi8][2]*temp.Z + gradient4[gi8][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-y0; + t[2] = gradient4[gi9][0]*temp.X + gradient4[gi9][1]*temp.Y + gradient4[gi9][2]*temp.Z + gradient4[gi9][3]*temp.W; + + temp.X = nx-x0; + temp.Y = ny-(y0+1); + u[2] = gradient4[gi10][0]*temp.X + gradient4[gi10][1]*temp.Y + gradient4[gi10][2]*temp.Z + gradient4[gi10][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-(y0+1); + v[2] = gradient4[gi11][0]*temp.X + gradient4[gi11][1]*temp.Y + gradient4[gi11][2]*temp.Z + gradient4[gi11][3]*temp.W; + + //Z supérieur, W superieur + temp.X = nx-x0; + temp.Y = ny-y0; + temp.Z = nz-(z0+1); + s[3] = gradient4[gi12][0]*temp.X + gradient4[gi12][1]*temp.Y + gradient4[gi12][2]*temp.Z + gradient4[gi12][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-y0; + t[3] = gradient4[gi13][0]*temp.X + gradient4[gi13][1]*temp.Y + gradient4[gi13][2]*temp.Z + gradient4[gi13][3]*temp.W; + + temp.X = nx-x0; + temp.Y = ny-(y0+1); + u[3] = gradient4[gi14][0]*temp.X + gradient4[gi14][1]*temp.Y + gradient4[gi14][2]*temp.Z + gradient4[gi14][3]*temp.W; + + temp.X = nx-(x0+1); + temp.Y = ny-(y0+1); + v[3] = gradient4[gi15][0]*temp.X + gradient4[gi15][1]*temp.Y + gradient4[gi15][2]*temp.Z + gradient4[gi15][3]*temp.W; + + //Li1 à Li8 : Lissage sur x + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li1 = s[0] + Cx*(t[0]-s[0]); + Li2 = u[0] + Cx*(v[0]-u[0]); + Li3 = s[1] + Cx*(t[1]-s[1]); + Li4 = u[1] + Cx*(v[1]-u[1]); + Li5 = s[2] + Cx*(t[2]-s[2]); + Li6 = u[2] + Cx*(v[2]-u[2]); + Li7 = s[3] + Cx*(t[3]-s[3]); + Li8 = u[3] + Cx*(v[3]-u[3]); + + //Li9 à Li12 : Lissage sur y + tmp = ny-y0; + Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li9 = Li1 + Cy*(Li2-Li1); + Li10 = Li3 + Cy*(Li4-Li3); + Li11 = Li5 + Cy*(Li6-Li5); + Li12 = Li7 + Cy*(Li8-Li7); + + //Li13,Li14 : Lissage sur z + tmp = nz-z0; + Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li13 = Li9 + Cz*(Li10-Li9); + Li14 = Li11 + Cz*(Li12-Li11); + + tmp = nw-w0; + Cw = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return Li13 + Cw*(Li14-Li13); +} + +//------------------------------ SIMPLEX ------------------------------ + +float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution) +{ + x /= resolution; + y /= resolution; + + + Origin.X = fastfloor(x + (x+y)*SkewCoeff2D); + Origin.Y = fastfloor(y + (x+y)*SkewCoeff2D); + + A.X = Origin.X - (Origin.X+Origin.Y)*UnskewCoeff2D; + A.Y = Origin.Y - (Origin.X+Origin.Y)*UnskewCoeff2D; + + IsoOriginDist.X = x - A.X; + IsoOriginDist.Y = y - A.Y; + + if(IsoOriginDist.X > IsoOriginDist.Y) + { + off1.X = 1; + off1.Y = 0; + } + else + { + off1.X = 0; + off1.Y = 1; + } + //On calcule les distances + d1.X = A.X - x; + d1.Y = A.Y - y; + + //?? Ordre des + et - + d2.X = d1.X + off1.X - UnskewCoeff2D; + d2.Y = d1.Y + off1.Y - UnskewCoeff2D; + + d3.X = d1.X + 1.0 - 2*UnskewCoeff2D; + d3.Y = d1.Y + 1.0 - 2*UnskewCoeff2D; + + //On récupère la valeur des gradients des trois sommets + ii = Origin.X & 255; + jj = Origin.Y & 255; + + gi0 = perm[ii + perm[jj]] % 12; + gi1 = perm[ii + off1.X + perm[jj + off1.Y]] % 12; + gi2 = perm[ii + 1 + perm[jj + 1]] % 12; + + H[0].X = gradient3[gi0][0]; + H[0].Y = gradient3[gi0][1]; + + H[1].X = gradient3[gi1][0]; + H[1].Y = gradient3[gi1][1]; + + H[2].X = gradient3[gi2][0]; + H[2].Y = gradient3[gi2][1]; + + //On ajoute les valeurs ensemble + + + n1 = H[0].X*d1.X + H[0].Y*d1.Y; + n2 = H[1].X*d2.X + H[1].Y*d2.Y; + n3 = H[2].X*d3.X + H[2].Y*d3.Y; + + lenght = 0.5; + + c1 = lenght - d1.X*d1.X - d1.Y*d1.Y; + c2 = lenght - d2.X*d2.X - d2.Y*d2.Y; + c3 = lenght - d3.X*d3.X - d3.Y*d3.Y; + + if(c1 < 0) + c1 = 0; + + if(c2 < 0) + c2 = 0; + + if(c3 < 0) + c3 = 0; + + n1 = c1*c1*c1*n1; + n2 = c2*c2*c2*n2; + n3 = c3*c3*c3*n3; + + return (n1+n2+n3)*23.2; +} + +float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float resolution) +{ + x /= resolution; + y /= resolution; + z /= resolution; + + + Origin.X = fastfloor(x + (x+y+z)*SkewCoeff3D); + Origin.Y = fastfloor(y + (x+y+z)*SkewCoeff3D); + Origin.Z = fastfloor(z + (x+y+z)*SkewCoeff3D); + + A.X = Origin.X - (Origin.X+Origin.Y+Origin.Z)*UnskewCoeff3D; + A.Y = Origin.Y - (Origin.X+Origin.Y+Origin.Z)*UnskewCoeff3D; + A.Z = Origin.Z - (Origin.X+Origin.Y+Origin.Z)*UnskewCoeff3D; + + IsoOriginDist.X = x - A.X; + IsoOriginDist.Y = y - A.Y; + IsoOriginDist.Z = z - A.Z; + + // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), + // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and + // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where + // c = 1/6. + + if(IsoOriginDist.X >= IsoOriginDist.Y) + { + if(IsoOriginDist.Y >= IsoOriginDist.Z) + { + off1.X=1; + off1.Y=0; + off1.Z=0; + off2.X=1; + off2.Y=1; + off2.Z=0; + } // X Y Z order + else if(IsoOriginDist.X >= IsoOriginDist.Z) + { + off1.X=1; // X Z Y order + off1.Y=0; + off1.Z=0; + off2.X=1; + off2.Y=0; + off2.Z=1; + } + else + { + off1.X=0; // Z X Y order + off1.Y=0; + off1.Z=1; + off2.X=1; + off2.Y=0; + off2.Z=1; + } + } + else // x0 IsoOriginDist.Y) ? 32 : 0; + c2 = (IsoOriginDist.X > IsoOriginDist.Z) ? 16 : 0; + c3 = (IsoOriginDist.Y > IsoOriginDist.Z) ? 8 : 0; + c4 = (IsoOriginDist.X > IsoOriginDist.W) ? 4 : 0; + c5 = (IsoOriginDist.Y > IsoOriginDist.W) ? 2 : 0; + c6 = (IsoOriginDist.Z > IsoOriginDist.W) ? 1 : 0; + c = c1 + c2 + c3 + c4 + c5 + c6; + // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. + // Many values of c will never occur, since e.g. x>y>z>w makes x=3 ? 1 : 0; + off1.Y = lookupTable4D[c][1]>=3 ? 1 : 0; + off1.Z = lookupTable4D[c][2]>=3 ? 1 : 0; + off1.W = lookupTable4D[c][3]>=3 ? 1 : 0; + // The number 2 in the "simplex" array is at the second largest coordinate. + off2.X = lookupTable4D[c][0]>=2 ? 1 : 0; + off2.Y = lookupTable4D[c][1]>=2 ? 1 : 0; + off2.Z = lookupTable4D[c][2]>=2 ? 1 : 0; + off2.W = lookupTable4D[c][3]>=2 ? 1 : 0; + // The number 1 in the "simplex" array is at the second smallest coordinate. + off3.X = lookupTable4D[c][0]>=1 ? 1 : 0; + off3.Y = lookupTable4D[c][1]>=1 ? 1 : 0; + off3.Z = lookupTable4D[c][2]>=1 ? 1 : 0; + off3.W = lookupTable4D[c][3]>=1 ? 1 : 0; + // The fifth corner has all coordinate offsets = 1, so no need to look that up. + + //On calcule les distances + d1.X = A.X - x; + d1.Y = A.Y - y; + d1.Z = A.Z - z; + d1.W = A.W - w; + + d2.X = d1.X + off1.X - UnskewCoeff4D; + d2.Y = d1.Y + off1.Y - UnskewCoeff4D; + d2.Z = d1.Z + off1.Z - UnskewCoeff4D; + d2.W = d1.W + off1.W - UnskewCoeff4D; + + d3.X = d1.X + off2.X - 2*UnskewCoeff4D; + d3.Y = d1.Y + off2.Y - 2*UnskewCoeff4D; + d3.Z = d1.Z + off2.Z - 2*UnskewCoeff4D; + d3.W = d1.W + off2.W - 2*UnskewCoeff4D; + + d4.X = d1.X + off3.X - 3*UnskewCoeff4D; + d4.Y = d1.Y + off3.Y - 3*UnskewCoeff4D; + d4.Z = d1.Z + off3.Z - 3*UnskewCoeff4D; + d4.W = d1.W + off3.W - 3*UnskewCoeff4D; + + d5.X = d1.X + 1.0 - 4*UnskewCoeff4D; + d5.Y = d1.Y + 1.0 - 4*UnskewCoeff4D; + d5.Z = d1.Z + 1.0 - 4*UnskewCoeff4D; + d5.W = d1.W + 1.0 - 4*UnskewCoeff4D; + + //On récupère la valeur des gradients des trois sommets + ii = Origin.X & 255; + jj = Origin.Y & 255; + kk = Origin.Z & 255; + ll = Origin.W & 255; + + gi0 = perm[ii + perm[jj + perm[kk+perm[ll]]]] % 32; + gi1 = perm[ii + off1.X + perm[jj + off1.Y + perm[kk + off1.Z + perm[ll + off1.W]]]] % 32; + gi2 = perm[ii + off2.X + perm[jj + off2.Y + perm[kk + off2.Z + perm[ll + off2.W]]]] % 32; + gi3 = perm[ii + off3.X + perm[jj + off3.Y + perm[kk + off3.Z + perm[ll + off3.W]]]] % 32; + gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + + //On ajoute les valeurs ensemble + + n1 = gradient4[gi0][0]*d1.X + gradient4[gi0][1]*d1.Y + gradient4[gi0][2]*d1.Z + gradient4[gi0][3]*d1.W; + n2 = gradient4[gi1][0]*d2.X + gradient4[gi1][1]*d2.Y + gradient4[gi1][2]*d2.Z + gradient4[gi1][3]*d2.W; + n3 = gradient4[gi2][0]*d3.X + gradient4[gi2][1]*d3.Y + gradient4[gi2][2]*d3.Z + gradient4[gi2][3]*d3.W; + n4 = gradient4[gi3][0]*d4.X + gradient4[gi3][1]*d4.Y + gradient4[gi3][2]*d4.Z + gradient4[gi3][3]*d4.W; + n5 = gradient4[gi4][0]*d5.X + gradient4[gi4][1]*d5.Y + gradient4[gi4][2]*d5.Z + gradient4[gi4][3]*d5.W; + + lenght = 0.6; + + c1 = lenght - d1.X*d1.X - d1.Y*d1.Y - d1.Z*d1.Z - d1.W*d1.W; + c2 = lenght - d2.X*d2.X - d2.Y*d2.Y - d2.Z*d2.Z - d2.W*d2.W; + c3 = lenght - d3.X*d3.X - d3.Y*d3.Y - d3.Z*d3.Z - d3.W*d3.W; + c4 = lenght - d4.X*d4.X - d4.Y*d4.Y - d4.Z*d4.Z - d4.W*d4.W; + c5 = lenght - d5.X*d5.X - d5.Y*d5.Y - d5.Z*d5.Z - d5.W*d5.W; + + if(c1 < 0) + c1 = 0; + + if(c2 < 0) + c2 = 0; + + if(c3 < 0) + c3 = 0; + + if(c4 < 0) + c4 = 0; + + if(c5 < 0) + c5 = 0; + + n1 = c1*c1*c1*n1; + n2 = c2*c2*c2*n2; + n3 = c3*c3*c3*n3; + n4 = c4*c4*c4*n4; + n5 = c5*c5*c5*n5; + + //return n3*30; + return (n1+n2+n3+n4+n5)*17.6995; +} + +//------------------------------ CELL ------------------------------ + +float NzNoiseMachine::Get2DCellNoiseValue(float x, float y, float res) +{ + +} + +float NzNoiseMachine::Get3DCellNoiseValue(float x, float y, float z, float res) +{ + x /= res; + y /= res; + z /= res; + + //On récupère les positions de la grille associée à (x,y) + x0 = (float)(x); + y0 = (float)(y); + z0 = (float)(z); + + return 0;//(float)((float)(this->Random3D(x0,y0,z0,SEED_A)) % 1000)/1000; +} +float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, float res) +{ + x /= res; + y /= res; + z /= res; + w /= res; + + //On récupère les positions de la grille associée à (x,y) + x0 = (float)(x) & 255; + y0 = (float)(y) & 255; + z0 = (float)(z) & 255; + w0 = (float)(w) & 255; + + return perm[x0 + perm[y0 + perm[z0 + perm[w0]]]] / 128.f - 1; +} + +void NzNoiseMachine::SetLacunarity(float lacunarity) +{ + if(lacunarity != m_lacunarity) + { + m_lacunarity = lacunarity; + m_parametersModified = true; + } +} + +void NzNoiseMachine::SetHurstParameter(float h) +{ + if(h != m_hurst) + { + m_hurst = h; + m_parametersModified = true; + } +} + +void NzNoiseMachine::SetOctavesNumber(float octaves) +{ + if(octaves != m_octaves && octaves < 30) + { + m_octaves = h; + m_parametersModified = true; + } +} + +void NzNoiseMachine::RecomputeExponentArray() +{ + // precompute and store spectral weights + float frequency = 1.0; + for (float i(0) ; i < m_octaves; ++i) + { + //compute weight for each frequency + exponent_array[i] = pow( frequency, -m_hurst ); + frequency *= m_lacunarity; + + } + m_parametersModified = false; +} + +//------------------------------ FBM ------------------------------ + +float NzNoiseMachine::Get1DFBMNoiseValue(float x, float res) +{ + value = 0.0; + + if(parametersModified) + { + RecomputeExponentArray(); + } + + // inner loop of spectral construction + for (float i(0); i < octaves; ++i) + { + value += Get1DPerlinNoiseValue(x,resolution) * exponent_array[i]; + x *= lacunarity; + } + remainder = octaves - (float)octaves; + + //Doesn't seem to work + if(remainder != 0) + value += remainder * Get1DPerlinNoiseValue(x,resolution) * exponent_array[(float)octaves-1]; + + return value*sum; +} + +float NzNoiseMachine::Get2DFBMNoiseValue(float x, float y, float res) +{ + value = 0.0; + + if(parametersModified) + { + RecomputeExponentArray(); + } + + // inner loop of spectral construction + for (float i(0); i < octaves; ++i) + { + value += Get2DdPerlinNoiseValue(x,y,resolution) * exponent_array[i]; + x *= lacunarity; + y *= lacunarity; + } + remainder = octaves - (float)octaves; + + //Doesn't seem to work + if(remainder != 0) + value += remainder * Get2DSimplexNoiseValue(x,y,resolution) * exponent_array[(float)octaves-1]; + + return value*sum; + +} +float NzNoiseMachine::Get3DFBMNoiseValue(float x, float y, float z, float res) +{ + value = 0.0; + + if(parametersModified) + { + RecomputeExponentArray(); + } + + // inner loop of spectral construction + for (float i(0); i < octaves; ++i) + { + value += Get3DSimplexNoiseValue(x,y,z,resolution) * exponent_array[i]; + x *= lacunarity; + y *= lacunarity; + z *= lacunarity; + } + remainder = octaves - (float)octaves; + + //Doesn't seem to work + if(remainder != 0) + value += remainder * Get3DSimplexNoiseValue(x,y,z,resolution) * exponent_array[(float)octaves-1]; + + return value*sum; +} + +//------------------------------ HYBRID MULTIFRACTAL ------------------------------ + +float NzNoiseMachine::Get2DHybridMultiFractalNoiseValue(float x, float y, float res) +{ + float frequency, result, signal, weight, remainder; + float offset = 1; + + if(parametersModified) + { + RecomputeExponentArray(); + } + + // get first octave + result = (Get2DSimplexNoiseValue(x,y,resolution) + offset) * exponent_array[0]; + weight = result; + // increase frequency + x *= lacunarity; + y *= lacunarity; + + // spectral construction inner loop + for (float i(1) ; i < octaves; ++i) + { + // prevent divergence + if ( weight > 1.0 ) + weight = 1.0; + + signal = ( Get2DSimplexNoiseValue(x,y,resolution) + offset ) * exponent_array[i]; + result += weight * signal; + // update the (monotonically decreasing) weighting value + // (this is why H must specify a high fractal dimension) + weight *= signal; + + x *= lacunarity; + y *= lacunarity; + + } + // take care of remainder + remainder = octaves - (float)octaves; + + if(remainder != 0) + result += remainder * Get2DSimplexNoiseValue(x,y,resolution) * exponent_array[(float)octaves-1]; + + return result; + +} + +float NzNoiseMachine::Get3DHybridMultiFractalNoiseValue(float x, float y, float z, float res) +{ + float frequency, result, signal, weight, remainder; + float offset = 1; + + if(parametersModified) + { + RecomputeExponentArray(); + } + // get first octave of function + result = (Get3DSimplexNoiseValue(x,y,z,resolution) + offset) * exponent_array[0]; + weight = result; + // increase frequency + x *= lacunarity; + y *= lacunarity; + + // spectral construction inner loop + for (float i(1) ; i < octaves; ++i) + { + // prevent divergence + if ( weight > 1.0 ) + weight = 1.0; + + signal = ( Get3DSimplexNoiseValue(x,y,z,resolution) + offset ) * exponent_array[i]; + result += weight * signal; + // update the (monotonically decreasing) weighting value + // (this is why H must specify a high fractal dimension) + weight *= signal; + + x *= lacunarity; + y *= lacunarity; + + } + // take care of remainder + remainder = octaves - (float)octaves; + + if(remainder != 0) + result += remainder * Get3DSimplexNoiseValue(x,y,z,resolution) * exponent_array[(float)octaves-1]; + + return result; +} + + +float NzNoiseMachine::fastfloor(float n) +{ + if(n >= 0) + return float(n); + else + return float(n-1); +} From 5f765a354b46c685f779e9af4ed29ee7f00d5967 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Thu, 24 May 2012 20:54:01 +0200 Subject: [PATCH 02/13] Changed contributor name --- include/Nazara/Noise/Config.hpp | 2 +- include/Nazara/Noise/Debug.hpp | 2 +- include/Nazara/Noise/DebugOff.hpp | 2 +- include/Nazara/Noise/Noise.hpp | 2 +- include/Nazara/Noise/NoiseMachine.h | 2 +- src/Nazara/Noise/Debug/Leaks.cpp | 2 +- src/Nazara/Noise/Noise.cpp | 2 +- src/Nazara/Noise/NoiseMachine.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/Nazara/Noise/Config.hpp b/include/Nazara/Noise/Config.hpp index 118b476b2..0b628002a 100644 --- a/include/Nazara/Noise/Config.hpp +++ b/include/Nazara/Noise/Config.hpp @@ -1,7 +1,7 @@ /* Nazara Engine - Copyright (C) 2012 AUTHORS (EMAIL) + Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/include/Nazara/Noise/Debug.hpp b/include/Nazara/Noise/Debug.hpp index a9853cc6c..d06344f48 100644 --- a/include/Nazara/Noise/Debug.hpp +++ b/include/Nazara/Noise/Debug.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 AUTHORS +// Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Noise/DebugOff.hpp b/include/Nazara/Noise/DebugOff.hpp index 2fbe08003..324f33c2b 100644 --- a/include/Nazara/Noise/DebugOff.hpp +++ b/include/Nazara/Noise/DebugOff.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 AUTHORS +// Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp index c4925ac0a..9a702c44f 100644 --- a/include/Nazara/Noise/Noise.hpp +++ b/include/Nazara/Noise/Noise.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 AUTHORS +// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Noise/NoiseMachine.h b/include/Nazara/Noise/NoiseMachine.h index ecbcae4ac..fb09d5de5 100644 --- a/include/Nazara/Noise/NoiseMachine.h +++ b/include/Nazara/Noise/NoiseMachine.h @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Rémi Bèges +// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/src/Nazara/Noise/Debug/Leaks.cpp b/src/Nazara/Noise/Debug/Leaks.cpp index 2e584687c..c2566bb3f 100644 --- a/src/Nazara/Noise/Debug/Leaks.cpp +++ b/src/Nazara/Noise/Debug/Leaks.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 AUTHORS +// Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp index c72266759..151fdc0ed 100644 --- a/src/Nazara/Noise/Noise.cpp +++ b/src/Nazara/Noise/Noise.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 AUTHORS +// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index adc288a82..cbc306420 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Rémi Bèges +// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp From cd701a429be5ba14a95fe6cb35aea1a2e30cf991 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Sun, 27 May 2012 21:15:12 +0200 Subject: [PATCH 03/13] =?UTF-8?q?'q'=20n'est=20pas=20reconnu=20en=20tant?= =?UTF-8?q?=20que=20commande=20interne=20ou=20externe,=20un=20programme=20?= =?UTF-8?q?ex=C2=82cutable=20ou=20un=20fichier=20de=20commandes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Nazara/Noise/NoiseMachine.h | 121 ---- src/Nazara/Noise/NoiseMachine.cpp | 885 +++++++++++++--------------- 2 files changed, 395 insertions(+), 611 deletions(-) delete mode 100644 include/Nazara/Noise/NoiseMachine.h diff --git a/include/Nazara/Noise/NoiseMachine.h b/include/Nazara/Noise/NoiseMachine.h deleted file mode 100644 index fb09d5de5..000000000 --- a/include/Nazara/Noise/NoiseMachine.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NOISEMACHINE_HPP -#define NOISEMACHINE_HPP - -#include - -class NzVector2f; -class NzVector3f; -class NzVector4f; - -class NzNoiseMachine -{ - public: - NzNoiseMachine(int seed = 0); - ~NzNoiseMachine(); - - void SetNewSeed(int seed); - void ShufflePermutationTable(); - - float Get1DPerlinNoiseValue(float x, float res); - float Get2DPerlinNoiseValue(float x, float y, float res); - float Get3DPerlinNoiseValue(float x, float y, float z, float res); - float Get4DPerlinNoiseValue(float x, float y, float z, float w, float res); - - float Get2DSimplexNoiseValue(float x, float y, float res); - float Get3DSimplexNoiseValue(float x, float y, float z, float res); - float Get4DSimplexNoiseValue(float x, float y, float z, float w, float res); - - float Get2DCellNoiseValue(float x, float y, float res); - float Get3DCellNoiseValue(float x, float y, float z, float res); - float Get4DCellNoiseValue(float x, float y, float z, float w, float res); - - void SetLacunarity(float lacunarity); - void SetHurstParameter(float h); - void SetOctavesNumber(float octaves); - void RecomputeExponentArray(); - - float Get1DFBMNoiseValue(float x, float res); - float Get2DFBMNoiseValue(float x, float y, float res); - float Get3DFBMNoiseValue(float x, float y, float z, float res); - - float Get2DHybridMultiFractalNoiseValue(float x, float y, float res); - float Get3DHybridMultiFractalNoiseValue(float x, float y, float z, float res); - - protected: - private: - - //Pour tronquer les nombres - int fastfloor(float n); - - float pi; - int perm[512]; - int PermutationTemp[256]; - float gradient2[8][2]; - int gradient3[16][3]; - int gradient4[32][4]; - int lookupTable4D[64][4]; - - //multiplicative congruential generator - int UcurrentSeed; - int Ua,Uc,Um; - int Uprevious; - int Ulast; - - //----------------------- Simplex variables -------------------------------------- - - float n1, n2, n3, n4, n5; - NzVector4f A; - NzVector4i Origin; - NzVector4f d1,d2,d3,d4,d5; - NzVector4i off1, off2,off3; - NzVector4f IsoOriginDist; - NzVector4f H[5]; - - int ii,jj,kk,ll; - int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; - float lenght; - float c1,c2,c3,c4,c5,c6; - int c; - - float SkewCoeff2D; - float UnskewCoeff2D; - - float SkewCoeff3D; - float UnskewCoeff3D; - - float SkewCoeff4D; - float UnskewCoeff4D; - - //----------------------- Perlin Variables ------------------------------------- - - int x0,y0,z0,w0; - float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14; - float s[4],t[4],u[4],v[4]; - float Cx, Cy, Cz, Cw; - NzVector4f temp; - float nx,ny,nz,nw; - float tmp; - - //---------------------- Complex Noise Variables -------------------------------- - - float m_lacunarity; - float m_hurst; - float m_octaves; - bool m_parametersModified; - float exponent_array[30]; - bool first; - float value; - float remainder; - - float smax; - float smin; - -}; - -#endif // NOISEMACHINE_H diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index cbc306420..28e7fa82a 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -1,19 +1,15 @@ -// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) +// Copyright (C) 2012 Rémi Bèges // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include -#include -#include - #include #include #include #include -NzNoiseMachine::NzNoiseMachine(float seed) +NzNoiseMachine::NzNoiseMachine(int seed) { pi = 3.14159265; @@ -26,7 +22,6 @@ NzNoiseMachine::NzNoiseMachine(float seed) SkewCoeff4D = (sqrt(5) - 1)/4; UnskewCoeff4D = (5 - sqrt(5))/20; - //Uniform pseudo random number generator coefficients Ua = 16807; Uc = 0; Um = 2147483647; @@ -35,11 +30,10 @@ NzNoiseMachine::NzNoiseMachine(float seed) SetNewSeed(seed); - for(float i(0) ; i < 256 ; i++) + for(int i(0) ; i < 256 ; i++) PermutationTemp[i] = i; - //4D only - to find the offset with Simplex in 4D - float lookupTemp4D[][4] = + int lookupTemp4D[][4] = { {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0}, {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0}, @@ -51,31 +45,30 @@ NzNoiseMachine::NzNoiseMachine(float seed) {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0} }; - for(float i(0) ; i < 64 ; ++i) - for(float j(0) ; j < 4 ; ++j) + for(int i(0) ; i < 64 ; ++i) + for(int j(0) ; j < 4 ; ++j) lookupTable4D[i][j] = lookupTemp4D[i][j]; float unit = 1.0/sqrt(2); float grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, {1,0},{-1,0},{0,1},{0,-1}}; - for(float i(0) ; i < 8 ; ++i) - for(float j(0) ; j < 2 ; ++j) + for(int i(0) ; i < 8 ; ++i) + for(int j(0) ; j < 2 ; ++j) gradient2[i][j] = grad2Temp[i][j]; - //On remplit les tables de gradients - float grad3Temp[][3] = { + int grad3Temp[][3] = { {1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}, {1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1} }; - for(float i(0) ; i < 16 ; ++i) - for(float j(0) ; j < 3 ; ++j) + for(int i(0) ; i < 16 ; ++i) + for(int j(0) ; j < 3 ; ++j) gradient3[i][j] = grad3Temp[i][j]; - float grad4Temp[][4] = + int grad4Temp[][4] = { {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1}, {0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1}, @@ -87,11 +80,10 @@ NzNoiseMachine::NzNoiseMachine(float seed) {-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0} }; - for(float i(0) ; i < 32 ; ++i) - for(float j(0) ; j < 4 ; ++j) + for(int i(0) ; i < 32 ; ++i) + for(int j(0) ; j < 4 ; ++j) gradient4[i][j] = grad4Temp[i][j]; - m_lacunarity = 2.5f; m_octaves = 3.0f; m_hurst = 1.1f; @@ -100,28 +92,28 @@ NzNoiseMachine::NzNoiseMachine(float seed) NzNoiseMachine::~NzNoiseMachine() { - } -void NzNoiseMachine::SetNewSeed(float seed) +void NzNoiseMachine::SetNewSeed(int seed) { Uprevious = seed; UcurrentSeed = seed; } -float NzNoiseMachine::GetUniformRandomValue() +int NzNoiseMachine::GetUniformRandomValue() { Ulast = Ua*Uprevious + Uc%Um; Uprevious = Ulast; return Ulast; } -void NzNoiseMachine::MixPermutationTable() +void NzNoiseMachine::ShufflePermutationTable() { - float xchanger; - unsigned float ncase; - for(float j(0) ; j < 10 ; ++j) - for (float i(0); i < 256 ; ++i) + int xchanger; + unsigned int ncase; + + for(int j(0) ; j < 10 ; ++j) + for (int i(0); i < 256 ; ++i) { ncase = this->GetUniformRandomValue() & 255; xchanger = PermutationTemp[i]; @@ -129,7 +121,7 @@ void NzNoiseMachine::MixPermutationTable() PermutationTemp[ncase] = xchanger; } - for(float i(0) ; i < 512; ++i) + for(int i(0) ; i < 512; ++i) perm[i]=PermutationTemp[i & 255]; } @@ -138,22 +130,21 @@ void NzNoiseMachine::MixPermutationTable() float NzNoiseMachine::Get1DPerlinNoiseValue(float x, float res) { nx = x/res; - x0 = (float)(nx); + x0 = (int)(nx); ii = x0 & 255; gi0 = perm[ii] % 16; gi1 = perm[ii + 1] % 16; - temp.X = nx-x0; - temp.Y = ny-y0; + temp.x = nx-x0; + temp.y = ny-y0; - s[0] = gradient3[gi0][0]*temp.X; + s[0] = gradient3[gi0][0]*temp.x; - temp.X = nx-(x0+1); + temp.x = nx-(x0+1); - t[0] = gradient3[gi1][0]*temp.X; + t[0] = gradient3[gi1][0]*temp.x; - //Lissage tmp = nx-x0; Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); @@ -165,9 +156,8 @@ float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res) nx = x/res; ny = y/res; - //On récupère les positions de la grille associée à (x,y) - x0 = (float)(nx); - y0 = (float)(ny); + x0 = (int)(nx); + y0 = (int)(ny); ii = x0 & 255; jj = y0 & 255; @@ -177,25 +167,22 @@ float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res) gi2 = perm[ii + perm[jj + 1]] & 7; gi3 = perm[ii + 1 + perm[jj + 1]] & 7; - //on calcule les valeurs du plan supérieur - temp.X = nx-x0; - temp.Y = ny-y0; - s[0] = gradient2[gi0][0]*temp.X + gradient2[gi0][1]*temp.Y; + temp.x = nx-x0; + temp.y = ny-y0; + s[0] = gradient2[gi0][0]*temp.x + gradient2[gi0][1]*temp.y; - temp.X = nx-(x0+1); - temp.Y = ny-y0; - t[0] = gradient2[gi1][0]*temp.X + gradient2[gi1][1]*temp.Y; + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[0] = gradient2[gi1][0]*temp.x + gradient2[gi1][1]*temp.y; - temp.X = nx-x0; - temp.Y = ny-(y0+1); - u[0] = gradient2[gi2][0]*temp.X + gradient2[gi2][1]*temp.Y; + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[0] = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y; - temp.X = nx-(x0+1); - temp.Y = ny-(y0+1); - v[0] = gradient2[gi3][0]*temp.X + gradient2[gi3][1]*temp.Y; + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[0] = gradient2[gi3][0]*temp.x + gradient2[gi3][1]*temp.y; - - //Lissage tmp = nx-x0; Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); @@ -213,10 +200,9 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res ny = y/res; nz = z/res; - //On récupère les positions de la grille associée à (x,y) - x0 = (float)(nx); - y0 = (float)(ny); - z0 = (float)(nz); + x0 = (int)(nx); + y0 = (int)(ny); + z0 = (int)(nz); ii = x0 & 255; jj = y0 & 255; @@ -232,43 +218,40 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] % 16; gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 16; - //on calcule les valeurs du plan inférieur - temp.X = nx-x0; - temp.Y = ny-y0; - temp.Z = nz-z0; - s[0] = gradient3[gi0][0]*temp.X + gradient3[gi0][1]*temp.Y + gradient3[gi0][2]*temp.Z; + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-z0; + s[0] = gradient3[gi0][0]*temp.x + gradient3[gi0][1]*temp.y + gradient3[gi0][2]*temp.z; - temp.X = nx-(x0+1); - temp.Y = ny-y0; - t[0] = gradient3[gi1][0]*temp.X + gradient3[gi1][1]*temp.Y + gradient3[gi1][2]*temp.Z; + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[0] = gradient3[gi1][0]*temp.x + gradient3[gi1][1]*temp.y + gradient3[gi1][2]*temp.z; - temp.X = nx-x0; - temp.Y = ny-(y0+1); - u[0] = gradient3[gi2][0]*temp.X + gradient3[gi2][1]*temp.Y + gradient3[gi2][2]*temp.Z; + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; - temp.X = nx-(x0+1); - temp.Y = ny-(y0+1); - v[0] = gradient3[gi3][0]*temp.X + gradient3[gi3][1]*temp.Y + gradient3[gi3][2]*temp.Z; + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[0] = gradient3[gi3][0]*temp.x + gradient3[gi3][1]*temp.y + gradient3[gi3][2]*temp.z; - //Les valeurs du plan supérieur - temp.X = nx-x0; - temp.Y = ny-y0; - temp.Z = nz-(z0+1); - s[1] = gradient3[gi4][0]*temp.X + gradient3[gi4][1]*temp.Y + gradient3[gi4][2]*temp.Z; + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-(z0+1); + s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z; - temp.X = nx-(x0+1); - temp.Y = ny-y0; - t[1] = gradient3[gi5][0]*temp.X + gradient3[gi5][1]*temp.Y + gradient3[gi5][2]*temp.Z; + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z; - temp.X = nx-x0; - temp.Y = ny-(y0+1); - u[1] = gradient3[gi6][0]*temp.X + gradient3[gi6][1]*temp.Y + gradient3[gi6][2]*temp.Z; + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z; - temp.X = nx-(x0+1); - temp.Y = ny-(y0+1); - v[1] = gradient3[gi7][0]*temp.X + gradient3[gi7][1]*temp.Y + gradient3[gi7][2]*temp.Z; + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z; - //On procède à un lissage, et on affecte le pofloat à la matrice de pixels tmp = nx-x0; Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); @@ -296,11 +279,10 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, nz = z/res; nw = w/res; - //On récupère les positions de la grille associée à (x,y) - x0 = (float)(nx); - y0 = (float)(ny); - z0 = (float)(nz); - w0 = (float)(nw); + x0 = (int)(nx); + y0 = (int)(ny); + z0 = (int)(nz); + w0 = (int)(nw); ii = x0 & 255; jj = y0 & 255; @@ -327,81 +309,76 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; - //Z inférieur, W inférieur - temp.X = nx-x0; - temp.Y = ny-y0; - temp.Z = nz-z0; - temp.W = nw-w0; - s[0] = gradient4[gi0][0]*temp.X + gradient4[gi0][1]*temp.Y + gradient4[gi0][2]*temp.Z + gradient4[gi0][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-z0; + temp.w = nw-w0; + s[0] = gradient4[gi0][0]*temp.x + gradient4[gi0][1]*temp.y + gradient4[gi0][2]*temp.z + gradient4[gi0][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-y0; - t[0] = gradient4[gi1][0]*temp.X + gradient4[gi1][1]*temp.Y + gradient4[gi1][2]*temp.Z + gradient4[gi1][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[0] = gradient4[gi1][0]*temp.x + gradient4[gi1][1]*temp.y + gradient4[gi1][2]*temp.z + gradient4[gi1][3]*temp.w; - temp.X = nx-x0; - temp.Y = ny-(y0+1); - u[0] = gradient4[gi2][0]*temp.X + gradient4[gi2][1]*temp.Y + gradient4[gi2][2]*temp.Z + gradient4[gi2][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-(y0+1); - v[0] = gradient4[gi3][0]*temp.X + gradient4[gi3][1]*temp.Y + gradient4[gi3][2]*temp.Z + gradient4[gi3][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w; - //Z supérieur, W inférieur - temp.X = nx-x0; - temp.Y = ny-y0; - temp.Z = nz-(z0+1); - s[1] = gradient4[gi4][0]*temp.X + gradient4[gi4][1]*temp.Y + gradient4[gi4][2]*temp.Z + gradient4[gi4][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-(z0+1); + s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-y0; - t[1] = gradient4[gi5][0]*temp.X + gradient4[gi5][1]*temp.Y + gradient4[gi5][2]*temp.Z + gradient4[gi5][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[1] = gradient4[gi5][0]*temp.x + gradient4[gi5][1]*temp.y + gradient4[gi5][2]*temp.z + gradient4[gi5][3]*temp.w; - temp.X = nx-x0; - temp.Y = ny-(y0+1); - u[1] = gradient4[gi6][0]*temp.X + gradient4[gi6][1]*temp.Y + gradient4[gi6][2]*temp.Z + gradient4[gi6][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-(y0+1); - v[1] = gradient4[gi7][0]*temp.X + gradient4[gi7][1]*temp.Y + gradient4[gi7][2]*temp.Z + gradient4[gi7][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w; - //Z inférieur, W superieur - temp.X = nx-x0; - temp.Y = ny-y0; - temp.Z = nz-z0; - temp.W = nw-(w0+1); - s[2] = gradient4[gi8][0]*temp.X + gradient4[gi8][1]*temp.Y + gradient4[gi8][2]*temp.Z + gradient4[gi8][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-z0; + temp.w = nw-(w0+1); + s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-y0; - t[2] = gradient4[gi9][0]*temp.X + gradient4[gi9][1]*temp.Y + gradient4[gi9][2]*temp.Z + gradient4[gi9][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[2] = gradient4[gi9][0]*temp.x + gradient4[gi9][1]*temp.y + gradient4[gi9][2]*temp.z + gradient4[gi9][3]*temp.w; - temp.X = nx-x0; - temp.Y = ny-(y0+1); - u[2] = gradient4[gi10][0]*temp.X + gradient4[gi10][1]*temp.Y + gradient4[gi10][2]*temp.Z + gradient4[gi10][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-(y0+1); - v[2] = gradient4[gi11][0]*temp.X + gradient4[gi11][1]*temp.Y + gradient4[gi11][2]*temp.Z + gradient4[gi11][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w; - //Z supérieur, W superieur - temp.X = nx-x0; - temp.Y = ny-y0; - temp.Z = nz-(z0+1); - s[3] = gradient4[gi12][0]*temp.X + gradient4[gi12][1]*temp.Y + gradient4[gi12][2]*temp.Z + gradient4[gi12][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-(z0+1); + s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-y0; - t[3] = gradient4[gi13][0]*temp.X + gradient4[gi13][1]*temp.Y + gradient4[gi13][2]*temp.Z + gradient4[gi13][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[3] = gradient4[gi13][0]*temp.x + gradient4[gi13][1]*temp.y + gradient4[gi13][2]*temp.z + gradient4[gi13][3]*temp.w; - temp.X = nx-x0; - temp.Y = ny-(y0+1); - u[3] = gradient4[gi14][0]*temp.X + gradient4[gi14][1]*temp.Y + gradient4[gi14][2]*temp.Z + gradient4[gi14][3]*temp.W; + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w; - temp.X = nx-(x0+1); - temp.Y = ny-(y0+1); - v[3] = gradient4[gi15][0]*temp.X + gradient4[gi15][1]*temp.Y + gradient4[gi15][2]*temp.Z + gradient4[gi15][3]*temp.W; + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w; - //Li1 à Li8 : Lissage sur x tmp = nx-x0; Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); @@ -414,7 +391,6 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, Li7 = s[3] + Cx*(t[3]-s[3]); Li8 = u[3] + Cx*(v[3]-u[3]); - //Li9 à Li12 : Lissage sur y tmp = ny-y0; Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); @@ -423,7 +399,6 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, Li11 = Li5 + Cy*(Li6-Li5); Li12 = Li7 + Cy*(Li8-Li7); - //Li13,Li14 : Lissage sur z tmp = nz-z0; Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); @@ -444,72 +419,65 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution) y /= resolution; - Origin.X = fastfloor(x + (x+y)*SkewCoeff2D); - Origin.Y = fastfloor(y + (x+y)*SkewCoeff2D); + Origin.x = fastfloor(x + (x + y) * SkewCoeff2D); + Origin.y = fastfloor(y + (x + y) * SkewCoeff2D); - A.X = Origin.X - (Origin.X+Origin.Y)*UnskewCoeff2D; - A.Y = Origin.Y - (Origin.X+Origin.Y)*UnskewCoeff2D; + A.x = Origin.x - (Origin.x + Origin.y) * UnskewCoeff2D; + A.y = Origin.y - (Origin.x + Origin.y) * UnskewCoeff2D; - IsoOriginDist.X = x - A.X; - IsoOriginDist.Y = y - A.Y; + IsoOriginDist.x = x - A.x; + IsoOriginDist.y = y - A.y; - if(IsoOriginDist.X > IsoOriginDist.Y) + if(IsoOriginDist.x > IsoOriginDist.y) { - off1.X = 1; - off1.Y = 0; + off1.x = 1; + off1.y = 0; } else { - off1.X = 0; - off1.Y = 1; + off1.x = 0; + off1.y = 1; } - //On calcule les distances - d1.X = A.X - x; - d1.Y = A.Y - y; - //?? Ordre des + et - - d2.X = d1.X + off1.X - UnskewCoeff2D; - d2.Y = d1.Y + off1.Y - UnskewCoeff2D; + d1.x = A.x - x; + d1.y = A.y - y; - d3.X = d1.X + 1.0 - 2*UnskewCoeff2D; - d3.Y = d1.Y + 1.0 - 2*UnskewCoeff2D; + d2.x = d1.x + off1.x - UnskewCoeff2D; + d2.y = d1.y + off1.y - UnskewCoeff2D; - //On récupère la valeur des gradients des trois sommets - ii = Origin.X & 255; - jj = Origin.Y & 255; + d3.x = d1.x + 1.0 - 2 * UnskewCoeff2D; + d3.y = d1.y + 1.0 - 2 * UnskewCoeff2D; + + ii = Origin.x & 255; + jj = Origin.y & 255; gi0 = perm[ii + perm[jj]] % 12; - gi1 = perm[ii + off1.X + perm[jj + off1.Y]] % 12; + gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 12; gi2 = perm[ii + 1 + perm[jj + 1]] % 12; - H[0].X = gradient3[gi0][0]; - H[0].Y = gradient3[gi0][1]; + H[0].x = gradient3[gi0][0]; + H[0].y = gradient3[gi0][1]; - H[1].X = gradient3[gi1][0]; - H[1].Y = gradient3[gi1][1]; + H[1].x = gradient3[gi1][0]; + H[1].y = gradient3[gi1][1]; - H[2].X = gradient3[gi2][0]; - H[2].Y = gradient3[gi2][1]; + H[2].x = gradient3[gi2][0]; + H[2].y = gradient3[gi2][1]; - //On ajoute les valeurs ensemble - - - n1 = H[0].X*d1.X + H[0].Y*d1.Y; - n2 = H[1].X*d2.X + H[1].Y*d2.Y; - n3 = H[2].X*d3.X + H[2].Y*d3.Y; + n1 = H[0].x * d1.x + H[0].y * d1.y; + n2 = H[1].x * d2.x + H[1].y * d2.y; + n3 = H[2].x * d3.x + H[2].y * d3.y; lenght = 0.5; - c1 = lenght - d1.X*d1.X - d1.Y*d1.Y; - c2 = lenght - d2.X*d2.X - d2.Y*d2.Y; - c3 = lenght - d3.X*d3.X - d3.Y*d3.Y; + c1 = lenght - d1.x * d1.x - d1.y * d1.y; + c2 = lenght - d2.x * d2.x - d2.y * d2.y; + c3 = lenght - d3.x * d3.x - d3.y * d3.y; if(c1 < 0) c1 = 0; - if(c2 < 0) c2 = 0; - if(c3 < 0) c3 = 0; @@ -526,134 +494,122 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re y /= resolution; z /= resolution; + Origin.x = fastfloor(x + (x + y + z) * SkewCoeff3D); + Origin.y = fastfloor(y + (x + y + z) * SkewCoeff3D); + Origin.z = fastfloor(z + (x + y + z) * SkewCoeff3D); - Origin.X = fastfloor(x + (x+y+z)*SkewCoeff3D); - Origin.Y = fastfloor(y + (x+y+z)*SkewCoeff3D); - Origin.Z = fastfloor(z + (x+y+z)*SkewCoeff3D); + A.x = Origin.x - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; + A.y = Origin.y - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; + A.z = Origin.z - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; - A.X = Origin.X - (Origin.X+Origin.Y+Origin.Z)*UnskewCoeff3D; - A.Y = Origin.Y - (Origin.X+Origin.Y+Origin.Z)*UnskewCoeff3D; - A.Z = Origin.Z - (Origin.X+Origin.Y+Origin.Z)*UnskewCoeff3D; + IsoOriginDist.x = x - A.x; + IsoOriginDist.y = y - A.y; + IsoOriginDist.z = z - A.z; - IsoOriginDist.X = x - A.X; - IsoOriginDist.Y = y - A.Y; - IsoOriginDist.Z = z - A.Z; - - // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), - // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and - // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where - // c = 1/6. - - if(IsoOriginDist.X >= IsoOriginDist.Y) + if(IsoOriginDist.x >= IsoOriginDist.y) { - if(IsoOriginDist.Y >= IsoOriginDist.Z) + if(IsoOriginDist.y >= IsoOriginDist.z) { - off1.X=1; - off1.Y=0; - off1.Z=0; - off2.X=1; - off2.Y=1; - off2.Z=0; - } // X Y Z order - else if(IsoOriginDist.X >= IsoOriginDist.Z) + off1.x = 1; + off1.y = 0; + off1.z = 0; + off2.x = 1; + off2.y = 1; + off2.z = 0; + } + else if(IsoOriginDist.x >= IsoOriginDist.z) { - off1.X=1; // X Z Y order - off1.Y=0; - off1.Z=0; - off2.X=1; - off2.Y=0; - off2.Z=1; + off1.x = 1; + off1.y = 0; + off1.z = 0; + off2.x = 1; + off2.y = 0; + off2.z = 1; } else { - off1.X=0; // Z X Y order - off1.Y=0; - off1.Z=1; - off2.X=1; - off2.Y=0; - off2.Z=1; + off1.x = 0; + off1.y = 0; + off1.z = 1; + off2.x = 1; + off2.y = 0; + off2.z = 1; } } - else // x0 IsoOriginDist.Y) ? 32 : 0; - c2 = (IsoOriginDist.X > IsoOriginDist.Z) ? 16 : 0; - c3 = (IsoOriginDist.Y > IsoOriginDist.Z) ? 8 : 0; - c4 = (IsoOriginDist.X > IsoOriginDist.W) ? 4 : 0; - c5 = (IsoOriginDist.Y > IsoOriginDist.W) ? 2 : 0; - c6 = (IsoOriginDist.Z > IsoOriginDist.W) ? 1 : 0; + c1 = (IsoOriginDist.x > IsoOriginDist.y) ? 32 : 0; + c2 = (IsoOriginDist.x > IsoOriginDist.z) ? 16 : 0; + c3 = (IsoOriginDist.y > IsoOriginDist.z) ? 8 : 0; + c4 = (IsoOriginDist.x > IsoOriginDist.w) ? 4 : 0; + c5 = (IsoOriginDist.y > IsoOriginDist.w) ? 2 : 0; + c6 = (IsoOriginDist.z > IsoOriginDist.w) ? 1 : 0; c = c1 + c2 + c3 + c4 + c5 + c6; - // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. - // Many values of c will never occur, since e.g. x>y>z>w makes x=3 ? 1 : 0; - off1.Y = lookupTable4D[c][1]>=3 ? 1 : 0; - off1.Z = lookupTable4D[c][2]>=3 ? 1 : 0; - off1.W = lookupTable4D[c][3]>=3 ? 1 : 0; - // The number 2 in the "simplex" array is at the second largest coordinate. - off2.X = lookupTable4D[c][0]>=2 ? 1 : 0; - off2.Y = lookupTable4D[c][1]>=2 ? 1 : 0; - off2.Z = lookupTable4D[c][2]>=2 ? 1 : 0; - off2.W = lookupTable4D[c][3]>=2 ? 1 : 0; - // The number 1 in the "simplex" array is at the second smallest coordinate. - off3.X = lookupTable4D[c][0]>=1 ? 1 : 0; - off3.Y = lookupTable4D[c][1]>=1 ? 1 : 0; - off3.Z = lookupTable4D[c][2]>=1 ? 1 : 0; - off3.W = lookupTable4D[c][3]>=1 ? 1 : 0; - // The fifth corner has all coordinate offsets = 1, so no need to look that up. - //On calcule les distances - d1.X = A.X - x; - d1.Y = A.Y - y; - d1.Z = A.Z - z; - d1.W = A.W - w; + off1.x = lookupTable4D[c][0] >= 3 ? 1 : 0; + off1.y = lookupTable4D[c][1] >= 3 ? 1 : 0; + off1.z = lookupTable4D[c][2] >= 3 ? 1 : 0; + off1.w = lookupTable4D[c][3] >= 3 ? 1 : 0; - d2.X = d1.X + off1.X - UnskewCoeff4D; - d2.Y = d1.Y + off1.Y - UnskewCoeff4D; - d2.Z = d1.Z + off1.Z - UnskewCoeff4D; - d2.W = d1.W + off1.W - UnskewCoeff4D; + off2.x = lookupTable4D[c][0] >= 2 ? 1 : 0; + off2.y = lookupTable4D[c][1] >= 2 ? 1 : 0; + off2.z = lookupTable4D[c][2] >= 2 ? 1 : 0; + off2.w = lookupTable4D[c][3] >= 2 ? 1 : 0; - d3.X = d1.X + off2.X - 2*UnskewCoeff4D; - d3.Y = d1.Y + off2.Y - 2*UnskewCoeff4D; - d3.Z = d1.Z + off2.Z - 2*UnskewCoeff4D; - d3.W = d1.W + off2.W - 2*UnskewCoeff4D; + off3.x = lookupTable4D[c][0] >= 1 ? 1 : 0; + off3.y = lookupTable4D[c][1] >= 1 ? 1 : 0; + off3.z = lookupTable4D[c][2] >= 1 ? 1 : 0; + off3.w = lookupTable4D[c][3] >= 1 ? 1 : 0; - d4.X = d1.X + off3.X - 3*UnskewCoeff4D; - d4.Y = d1.Y + off3.Y - 3*UnskewCoeff4D; - d4.Z = d1.Z + off3.Z - 3*UnskewCoeff4D; - d4.W = d1.W + off3.W - 3*UnskewCoeff4D; + d1.x = A.x - x; + d1.y = A.y - y; + d1.z = A.z - z; + d1.w = A.w - w; - d5.X = d1.X + 1.0 - 4*UnskewCoeff4D; - d5.Y = d1.Y + 1.0 - 4*UnskewCoeff4D; - d5.Z = d1.Z + 1.0 - 4*UnskewCoeff4D; - d5.W = d1.W + 1.0 - 4*UnskewCoeff4D; + d2.x = d1.x + off1.x - UnskewCoeff4D; + d2.y = d1.y + off1.y - UnskewCoeff4D; + d2.z = d1.z + off1.z - UnskewCoeff4D; + d2.w = d1.w + off1.w - UnskewCoeff4D; - //On récupère la valeur des gradients des trois sommets - ii = Origin.X & 255; - jj = Origin.Y & 255; - kk = Origin.Z & 255; - ll = Origin.W & 255; + d3.x = d1.x + off2.x - 2*UnskewCoeff4D; + d3.y = d1.y + off2.y - 2*UnskewCoeff4D; + d3.z = d1.z + off2.z - 2*UnskewCoeff4D; + d3.w = d1.w + off2.w - 2*UnskewCoeff4D; - gi0 = perm[ii + perm[jj + perm[kk+perm[ll]]]] % 32; - gi1 = perm[ii + off1.X + perm[jj + off1.Y + perm[kk + off1.Z + perm[ll + off1.W]]]] % 32; - gi2 = perm[ii + off2.X + perm[jj + off2.Y + perm[kk + off2.Z + perm[ll + off2.W]]]] % 32; - gi3 = perm[ii + off3.X + perm[jj + off3.Y + perm[kk + off3.Z + perm[ll + off3.W]]]] % 32; + d4.x = d1.x + off3.x - 3*UnskewCoeff4D; + d4.y = d1.y + off3.y - 3*UnskewCoeff4D; + d4.z = d1.z + off3.z - 3*UnskewCoeff4D; + d4.w = d1.w + off3.w - 3*UnskewCoeff4D; + + d5.x = d1.x + 1.0 - 4*UnskewCoeff4D; + d5.y = d1.y + 1.0 - 4*UnskewCoeff4D; + d5.z = d1.z + 1.0 - 4*UnskewCoeff4D; + d5.w = d1.w + 1.0 - 4*UnskewCoeff4D; + + ii = Origin.x & 255; + jj = Origin.y & 255; + kk = Origin.z & 255; + ll = Origin.w & 255; + + gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32; + gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] % 32; + gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] % 32; + gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] % 32; gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; - //On ajoute les valeurs ensemble - - n1 = gradient4[gi0][0]*d1.X + gradient4[gi0][1]*d1.Y + gradient4[gi0][2]*d1.Z + gradient4[gi0][3]*d1.W; - n2 = gradient4[gi1][0]*d2.X + gradient4[gi1][1]*d2.Y + gradient4[gi1][2]*d2.Z + gradient4[gi1][3]*d2.W; - n3 = gradient4[gi2][0]*d3.X + gradient4[gi2][1]*d3.Y + gradient4[gi2][2]*d3.Z + gradient4[gi2][3]*d3.W; - n4 = gradient4[gi3][0]*d4.X + gradient4[gi3][1]*d4.Y + gradient4[gi3][2]*d4.Z + gradient4[gi3][3]*d4.W; - n5 = gradient4[gi4][0]*d5.X + gradient4[gi4][1]*d5.Y + gradient4[gi4][2]*d5.Z + gradient4[gi4][3]*d5.W; + n1 = gradient4[gi0][0]*d1.x + gradient4[gi0][1]*d1.y + gradient4[gi0][2]*d1.z + gradient4[gi0][3]*d1.w; + n2 = gradient4[gi1][0]*d2.x + gradient4[gi1][1]*d2.y + gradient4[gi1][2]*d2.z + gradient4[gi1][3]*d2.w; + n3 = gradient4[gi2][0]*d3.x + gradient4[gi2][1]*d3.y + gradient4[gi2][2]*d3.z + gradient4[gi2][3]*d3.w; + n4 = gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w; + n5 = gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w; lenght = 0.6; - c1 = lenght - d1.X*d1.X - d1.Y*d1.Y - d1.Z*d1.Z - d1.W*d1.W; - c2 = lenght - d2.X*d2.X - d2.Y*d2.Y - d2.Z*d2.Z - d2.W*d2.W; - c3 = lenght - d3.X*d3.X - d3.Y*d3.Y - d3.Z*d3.Z - d3.W*d3.W; - c4 = lenght - d4.X*d4.X - d4.Y*d4.Y - d4.Z*d4.Z - d4.W*d4.W; - c5 = lenght - d5.X*d5.X - d5.Y*d5.Y - d5.Z*d5.Z - d5.W*d5.W; + c1 = lenght - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; + c2 = lenght - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; + c3 = lenght - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w; + c4 = lenght - d4.x*d4.x - d4.y*d4.y - d4.z*d4.z - d4.w*d4.w; + c5 = lenght - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w; if(c1 < 0) c1 = 0; - if(c2 < 0) c2 = 0; - if(c3 < 0) c3 = 0; - if(c4 < 0) c4 = 0; - if(c5 < 0) c5 = 0; @@ -798,7 +733,6 @@ float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, n4 = c4*c4*c4*n4; n5 = c5*c5*c5*n5; - //return n3*30; return (n1+n2+n3+n4+n5)*17.6995; } @@ -806,7 +740,7 @@ float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, float NzNoiseMachine::Get2DCellNoiseValue(float x, float y, float res) { - + return 0; } float NzNoiseMachine::Get3DCellNoiseValue(float x, float y, float z, float res) @@ -815,12 +749,11 @@ float NzNoiseMachine::Get3DCellNoiseValue(float x, float y, float z, float res) y /= res; z /= res; - //On récupère les positions de la grille associée à (x,y) - x0 = (float)(x); - y0 = (float)(y); - z0 = (float)(z); + x0 = (int)(x); + y0 = (int)(y); + z0 = (int)(z); - return 0;//(float)((float)(this->Random3D(x0,y0,z0,SEED_A)) % 1000)/1000; + return 0; } float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, float res) { @@ -829,13 +762,12 @@ float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, fl z /= res; w /= res; - //On récupère les positions de la grille associée à (x,y) - x0 = (float)(x) & 255; - y0 = (float)(y) & 255; - z0 = (float)(z) & 255; - w0 = (float)(w) & 255; + x0 = (int)(x) & 255; + y0 = (int)(y) & 255; + z0 = (int)(z) & 255; + w0 = (int)(w) & 255; - return perm[x0 + perm[y0 + perm[z0 + perm[w0]]]] / 128.f - 1; + return 0; } void NzNoiseMachine::SetLacunarity(float lacunarity) @@ -860,23 +792,27 @@ void NzNoiseMachine::SetOctavesNumber(float octaves) { if(octaves != m_octaves && octaves < 30) { - m_octaves = h; + m_octaves = octaves; m_parametersModified = true; } } void NzNoiseMachine::RecomputeExponentArray() { - // precompute and store spectral weights - float frequency = 1.0; - for (float i(0) ; i < m_octaves; ++i) + if(m_parametersModified) { - //compute weight for each frequency - exponent_array[i] = pow( frequency, -m_hurst ); - frequency *= m_lacunarity; + float frequency = 1.0; + m_sum = 0.f; + for (int i(0) ; i < m_octaves; ++i) + { + exponent_array[i] = pow( frequency, -m_hurst ); + frequency *= m_lacunarity; + m_sum += exponent_array[i]; + + } + m_parametersModified = false; } - m_parametersModified = false; } //------------------------------ FBM ------------------------------ @@ -884,119 +820,94 @@ void NzNoiseMachine::RecomputeExponentArray() float NzNoiseMachine::Get1DFBMNoiseValue(float x, float res) { value = 0.0; + RecomputeExponentArray(); - if(parametersModified) + for (int i(0); i < m_octaves; ++i) { - RecomputeExponentArray(); + value += Get1DPerlinNoiseValue(x,res) * exponent_array[i]; + x *= m_lacunarity; } + remainder = m_octaves - (float)m_octaves; - // inner loop of spectral construction - for (float i(0); i < octaves; ++i) - { - value += Get1DPerlinNoiseValue(x,resolution) * exponent_array[i]; - x *= lacunarity; - } - remainder = octaves - (float)octaves; - - //Doesn't seem to work if(remainder != 0) - value += remainder * Get1DPerlinNoiseValue(x,resolution) * exponent_array[(float)octaves-1]; + value += remainder * Get1DPerlinNoiseValue(x,res) * exponent_array[(int)m_octaves-1]; - return value*sum; + return value * m_sum; } float NzNoiseMachine::Get2DFBMNoiseValue(float x, float y, float res) { value = 0.0; + RecomputeExponentArray(); - if(parametersModified) + for (int i(0); i < m_octaves; ++i) { - RecomputeExponentArray(); + value += Get2DPerlinNoiseValue(x,y,res) * exponent_array[i]; + x *= m_lacunarity; + y *= m_lacunarity; } + remainder = m_octaves - (int)m_octaves; - // inner loop of spectral construction - for (float i(0); i < octaves; ++i) - { - value += Get2DdPerlinNoiseValue(x,y,resolution) * exponent_array[i]; - x *= lacunarity; - y *= lacunarity; - } - remainder = octaves - (float)octaves; - - //Doesn't seem to work if(remainder != 0) - value += remainder * Get2DSimplexNoiseValue(x,y,resolution) * exponent_array[(float)octaves-1]; - - return value*sum; + value += remainder * Get2DSimplexNoiseValue(x,y,res) * exponent_array[(int)m_octaves-1]; + return value * m_sum; } + float NzNoiseMachine::Get3DFBMNoiseValue(float x, float y, float z, float res) { value = 0.0; + RecomputeExponentArray(); - if(parametersModified) + for(int i(0); i < m_octaves; ++i) { - RecomputeExponentArray(); + value += Get3DSimplexNoiseValue(x,y,z,res) * exponent_array[i]; + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; } + remainder = m_octaves - (int)m_octaves; - // inner loop of spectral construction - for (float i(0); i < octaves; ++i) - { - value += Get3DSimplexNoiseValue(x,y,z,resolution) * exponent_array[i]; - x *= lacunarity; - y *= lacunarity; - z *= lacunarity; - } - remainder = octaves - (float)octaves; - - //Doesn't seem to work if(remainder != 0) - value += remainder * Get3DSimplexNoiseValue(x,y,z,resolution) * exponent_array[(float)octaves-1]; + value += remainder * Get3DSimplexNoiseValue(x,y,z,res) * exponent_array[(int)m_octaves-1]; - return value*sum; + return value * m_sum; } //------------------------------ HYBRID MULTIFRACTAL ------------------------------ float NzNoiseMachine::Get2DHybridMultiFractalNoiseValue(float x, float y, float res) { - float frequency, result, signal, weight, remainder; + float result, signal, weight, remainder; float offset = 1; - if(parametersModified) - { - RecomputeExponentArray(); - } + RecomputeExponentArray(); - // get first octave - result = (Get2DSimplexNoiseValue(x,y,resolution) + offset) * exponent_array[0]; + result = (Get2DSimplexNoiseValue(x,y,res) + offset) * exponent_array[0]; weight = result; - // increase frequency - x *= lacunarity; - y *= lacunarity; - // spectral construction inner loop - for (float i(1) ; i < octaves; ++i) + x *= m_lacunarity; + y *= m_lacunarity; + + for(int i(1) ; i < m_octaves; ++i) { - // prevent divergence - if ( weight > 1.0 ) + if(weight > 1.0) weight = 1.0; - signal = ( Get2DSimplexNoiseValue(x,y,resolution) + offset ) * exponent_array[i]; + signal = (Get2DSimplexNoiseValue(x,y,res) + offset) * exponent_array[i]; result += weight * signal; - // update the (monotonically decreasing) weighting value - // (this is why H must specify a high fractal dimension) + weight *= signal; - x *= lacunarity; - y *= lacunarity; + x *= m_lacunarity; + y *= m_lacunarity; } - // take care of remainder - remainder = octaves - (float)octaves; + + remainder = m_octaves - (int)m_octaves; if(remainder != 0) - result += remainder * Get2DSimplexNoiseValue(x,y,resolution) * exponent_array[(float)octaves-1]; + result += remainder * Get2DSimplexNoiseValue(x,y,res) * exponent_array[(int)m_octaves-1]; return result; @@ -1004,51 +915,45 @@ float NzNoiseMachine::Get2DHybridMultiFractalNoiseValue(float x, float y, float float NzNoiseMachine::Get3DHybridMultiFractalNoiseValue(float x, float y, float z, float res) { - float frequency, result, signal, weight, remainder; + float result, signal, weight, remainder; float offset = 1; - if(parametersModified) - { - RecomputeExponentArray(); - } - // get first octave of function - result = (Get3DSimplexNoiseValue(x,y,z,resolution) + offset) * exponent_array[0]; - weight = result; - // increase frequency - x *= lacunarity; - y *= lacunarity; + RecomputeExponentArray(); - // spectral construction inner loop - for (float i(1) ; i < octaves; ++i) + result = (Get3DSimplexNoiseValue(x,y,z,res) + offset) * exponent_array[0]; + weight = result; + + x *= m_lacunarity; + y *= m_lacunarity; + + for(int i(1) ; i < m_octaves; ++i) { - // prevent divergence - if ( weight > 1.0 ) + + if(weight > 1.0) weight = 1.0; - signal = ( Get3DSimplexNoiseValue(x,y,z,resolution) + offset ) * exponent_array[i]; + signal = ( Get3DSimplexNoiseValue(x,y,z,res) + offset ) * exponent_array[i]; result += weight * signal; - // update the (monotonically decreasing) weighting value - // (this is why H must specify a high fractal dimension) + weight *= signal; - x *= lacunarity; - y *= lacunarity; + x *= m_lacunarity; + y *= m_lacunarity; } - // take care of remainder - remainder = octaves - (float)octaves; + + remainder = m_octaves - (int)m_octaves; if(remainder != 0) - result += remainder * Get3DSimplexNoiseValue(x,y,z,resolution) * exponent_array[(float)octaves-1]; + result += remainder * Get3DSimplexNoiseValue(x,y,z,res) * exponent_array[(int)m_octaves-1]; return result; } - -float NzNoiseMachine::fastfloor(float n) +int NzNoiseMachine::fastfloor(float n) { if(n >= 0) - return float(n); + return int(n); else - return float(n-1); + return int(n-1); } From 7578a1b957b6ff530052316fc991f899f3e6ad22 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Sun, 27 May 2012 21:18:52 +0200 Subject: [PATCH 04/13] Fixed implementation of NzNoise + typo + small optimisations --- include/Nazara/Noise/NoiseMachine.hpp | 123 ++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 include/Nazara/Noise/NoiseMachine.hpp diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp new file mode 100644 index 000000000..5f8787ad4 --- /dev/null +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -0,0 +1,123 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NOISEMACHINE_HPP +#define NOISEMACHINE_HPP + +#include +#include +#include +#include + +//TODO : tableau de gradients en float au lieu de int ? Ou alors condition ternaires ? + +class NzNoiseMachine +{ + public: + NzNoiseMachine(int seed = 0); + ~NzNoiseMachine(); + + void SetNewSeed(int seed); + int GetUniformRandomValue(); + void ShufflePermutationTable(); + + float Get1DPerlinNoiseValue (float x, float res); + float Get2DPerlinNoiseValue (float x, float y, float res); + float Get3DPerlinNoiseValue (float x, float y, float z, float res); + float Get4DPerlinNoiseValue (float x, float y, float z, float w, float res); + + float Get2DSimplexNoiseValue(float x, float y, float res); + float Get3DSimplexNoiseValue(float x, float y, float z, float res); + float Get4DSimplexNoiseValue(float x, float y, float z, float w, float res); + + float Get2DCellNoiseValue(float x, float y, float res); + float Get3DCellNoiseValue(float x, float y, float z, float res); + float Get4DCellNoiseValue(float x, float y, float z, float w, float res); + + void SetLacunarity(float lacunarity); + void SetHurstParameter(float h); + void SetOctavesNumber(float octaves); + void RecomputeExponentArray(); + + float Get1DFBMNoiseValue(float x, float res); + float Get2DFBMNoiseValue(float x, float y, float res); + float Get3DFBMNoiseValue(float x, float y, float z, float res); + + float Get2DHybridMultiFractalNoiseValue(float x, float y, float res); + float Get3DHybridMultiFractalNoiseValue(float x, float y, float z, float res); + + protected: + private: + + //Pour tronquer les nombres + int fastfloor(float n); + + float pi; + int perm[512]; + int PermutationTemp[256]; + float gradient2[8][2]; + int gradient3[16][3]; + int gradient4[32][4]; + int lookupTable4D[64][4]; + + //multiplicative congruential generator + int UcurrentSeed; + int Ua,Uc,Um; + int Uprevious; + int Ulast; + + //----------------------- Simplex variables -------------------------------------- + + float n1, n2, n3, n4, n5; + NzVector4f A; + NzVector4i Origin; + NzVector4f d1,d2,d3,d4,d5; + NzVector4i off1, off2,off3; + NzVector4f IsoOriginDist; + NzVector4f H[5]; + + int ii,jj,kk,ll; + int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; + float lenght; + float c1,c2,c3,c4,c5,c6; + int c; + + float SkewCoeff2D; + float UnskewCoeff2D; + + float SkewCoeff3D; + float UnskewCoeff3D; + + float SkewCoeff4D; + float UnskewCoeff4D; + + //----------------------- Perlin Variables ------------------------------------- + + int x0,y0,z0,w0; + float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14; + float s[4],t[4],u[4],v[4]; + float Cx, Cy, Cz, Cw; + NzVector4f temp; + float nx,ny,nz,nw; + float tmp; + + //---------------------- Complex Noise Variables -------------------------------- + + float m_lacunarity; + float m_hurst; + float m_octaves; + bool m_parametersModified; + float exponent_array[30]; + bool first; + float value; + float remainder; + float m_sum; + float smax; + float smin; + +}; + +#endif // NOISEMACHINE_H From 57d9af6b568a952e05e2b0171239bc0246cefdf3 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Tue, 29 May 2012 20:28:31 +0200 Subject: [PATCH 05/13] NzNoise new architecture + Perlin 1D algorithm modified --- include/Nazara/Noise/NoiseBase.hpp | 30 ++++++++ include/Nazara/Noise/NoiseMachine.hpp | 22 ++---- include/Nazara/Noise/Perlin1D.hpp | 38 ++++++++++ include/Nazara/Noise/Perlin1D.inl | 37 +++++++++ src/Nazara/Noise/NoiseBase.cpp | 60 +++++++++++++++ src/Nazara/Noise/NoiseMachine.cpp | 103 ++++++++------------------ 6 files changed, 203 insertions(+), 87 deletions(-) create mode 100644 include/Nazara/Noise/NoiseBase.hpp create mode 100644 include/Nazara/Noise/Perlin1D.hpp create mode 100644 include/Nazara/Noise/Perlin1D.inl create mode 100644 src/Nazara/Noise/NoiseBase.cpp diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp new file mode 100644 index 000000000..af8a66632 --- /dev/null +++ b/include/Nazara/Noise/NoiseBase.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NOISEBASE_H +#define NOISEBASE_H + +#include + +class NzNoiseBase +{ + public: + NzNoiseBase(int seed = 0); + virtual ~NzNoiseBase(); + + void SetNewSeed(int seed); + int GetUniformRandomValue(); + void ShufflePermutationTable(); + protected: + int perm[512]; + private: + int Ua, Uc, Um; + int UcurrentSeed; + int Uprevious, Ulast; + +}; + +#endif // NOISEBASE_H diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp index 5f8787ad4..fa3a60ea1 100644 --- a/include/Nazara/Noise/NoiseMachine.hpp +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -8,22 +8,22 @@ #define NOISEMACHINE_HPP #include +//#include +#include "NoiseBase.hpp" #include #include #include -//TODO : tableau de gradients en float au lieu de int ? Ou alors condition ternaires ? +//TODO : tableau de gradients en float au lieu de int ? Ou condition ternaires ? +// utiliser fastfloor partout +// vérifier bon fonctionnement perlin1d -class NzNoiseMachine +class NzNoiseMachine : public NzNoiseBase { public: NzNoiseMachine(int seed = 0); ~NzNoiseMachine(); - void SetNewSeed(int seed); - int GetUniformRandomValue(); - void ShufflePermutationTable(); - float Get1DPerlinNoiseValue (float x, float res); float Get2DPerlinNoiseValue (float x, float y, float res); float Get3DPerlinNoiseValue (float x, float y, float z, float res); @@ -55,20 +55,12 @@ class NzNoiseMachine //Pour tronquer les nombres int fastfloor(float n); - float pi; - int perm[512]; - int PermutationTemp[256]; + int gradient1[2]; float gradient2[8][2]; int gradient3[16][3]; int gradient4[32][4]; int lookupTable4D[64][4]; - //multiplicative congruential generator - int UcurrentSeed; - int Ua,Uc,Um; - int Uprevious; - int Ulast; - //----------------------- Simplex variables -------------------------------------- float n1, n2, n3, n4, n5; diff --git a/include/Nazara/Noise/Perlin1D.hpp b/include/Nazara/Noise/Perlin1D.hpp new file mode 100644 index 000000000..533ccc0a7 --- /dev/null +++ b/include/Nazara/Noise/Perlin1D.hpp @@ -0,0 +1,38 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef PERLIN1D_H +#define PERLIN1D_H + +#include +//#include +#include "NoiseBase.hpp" + +template class NzPerlin1D : public NzNoiseBase +{ + public: + NzPerlin1D(); + T GetValue(T x, T res); + ~NzPerlin1D() = default; + protected: + private: + int x0; + int gi0,gi1; + int ii; + int gradient1[16]; + T s,t; + T Cx; + T nx; + T tmp; +}; + +typedef NzPerlin1D NzPerlin1Df; +typedef NzPerlin1D NzPerlin1Dd; + +//#include +#include "Perlin1D.inl" + +#endif // PERLIN1D_H diff --git a/include/Nazara/Noise/Perlin1D.inl b/include/Nazara/Noise/Perlin1D.inl new file mode 100644 index 000000000..75b5c524e --- /dev/null +++ b/include/Nazara/Noise/Perlin1D.inl @@ -0,0 +1,37 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +//#include +//#include +//#include +#include + +template +NzPerlin1D::NzPerlin1D() +{ + gradient1[0] = 1; + gradient1[1] = -1; +} + +template +T NzPerlin1D::GetValue(T x, T res) +{ + nx = x/res; + x0 = static_cast(nx); + ii = x0 & 255; + + gi0 = perm[ii] % 2; + gi1 = perm[ii + 1] % 2; + + tmp = nx-x0; + s = gradient1[gi0]*tmp; + + tmp = nx-(x0+1); + t = gradient1[gi1]*tmp; + + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return s + Cx*(t-s); +} diff --git a/src/Nazara/Noise/NoiseBase.cpp b/src/Nazara/Noise/NoiseBase.cpp new file mode 100644 index 000000000..940a3ecf8 --- /dev/null +++ b/src/Nazara/Noise/NoiseBase.cpp @@ -0,0 +1,60 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include "NoiseBase.hpp" +//#include +//#include +//#include +//#include + +NzNoiseBase::NzNoiseBase(int seed) +{ + Ua = 16807; + Uc = 0; + Um = 2147483647; + UcurrentSeed = 0; + Uprevious = 0; + + SetNewSeed(seed); + + for(int i(0) ; i < 256 ; i++) + perm[i] = i; + +} + +void NzNoiseBase::SetNewSeed(int seed) +{ + Uprevious = seed; + UcurrentSeed = seed; +} + +int NzNoiseBase::GetUniformRandomValue() +{ + Ulast = Ua*Uprevious + Uc%Um; + Uprevious = Ulast; + return Ulast; +} + +void NzNoiseBase::ShufflePermutationTable() +{ + int xchanger; + unsigned int ncase; + + for(int j(0) ; j < 10 ; ++j) + for (int i(0); i < 256 ; ++i) + { + ncase = this->GetUniformRandomValue() & 255; + xchanger = perm[i]; + perm[i] = perm[ncase]; + perm[ncase] = xchanger; + } + + for(int i(256) ; i < 512; ++i) + perm[i] = perm[i & 255]; +} + +NzNoiseBase::~NzNoiseBase() +{ + //dtor +} diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index 28e7fa82a..8a1e2e697 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -1,18 +1,14 @@ // Copyright (C) 2012 Rémi Bèges // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -#include -#include -#include +#include "NoiseMachine.hpp" +//#include +//#include +//#include +//#include NzNoiseMachine::NzNoiseMachine(int seed) { - pi = 3.14159265; - SkewCoeff2D = 0.5*(sqrt(3.0) - 1.0); UnskewCoeff2D = (3.0-sqrt(3.0))/6; @@ -22,16 +18,6 @@ NzNoiseMachine::NzNoiseMachine(int seed) SkewCoeff4D = (sqrt(5) - 1)/4; UnskewCoeff4D = (5 - sqrt(5))/20; - Ua = 16807; - Uc = 0; - Um = 2147483647; - UcurrentSeed = 0; - Uprevious = 0; - - SetNewSeed(seed); - - for(int i(0) ; i < 256 ; i++) - PermutationTemp[i] = i; int lookupTemp4D[][4] = { @@ -49,6 +35,9 @@ NzNoiseMachine::NzNoiseMachine(int seed) for(int j(0) ; j < 4 ; ++j) lookupTable4D[i][j] = lookupTemp4D[i][j]; + gradient1[0] = 1; + gradient1[1] = -1; + float unit = 1.0/sqrt(2); float grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, {1,0},{-1,0},{0,1},{0,-1}}; @@ -94,56 +83,26 @@ NzNoiseMachine::~NzNoiseMachine() { } -void NzNoiseMachine::SetNewSeed(int seed) -{ - Uprevious = seed; - UcurrentSeed = seed; -} -int NzNoiseMachine::GetUniformRandomValue() -{ - Ulast = Ua*Uprevious + Uc%Um; - Uprevious = Ulast; - return Ulast; -} - -void NzNoiseMachine::ShufflePermutationTable() -{ - int xchanger; - unsigned int ncase; - - for(int j(0) ; j < 10 ; ++j) - for (int i(0); i < 256 ; ++i) - { - ncase = this->GetUniformRandomValue() & 255; - xchanger = PermutationTemp[i]; - PermutationTemp[i] = PermutationTemp[ncase]; - PermutationTemp[ncase] = xchanger; - } - - for(int i(0) ; i < 512; ++i) - perm[i]=PermutationTemp[i & 255]; -} //------------------------------ PERLIN ------------------------------ float NzNoiseMachine::Get1DPerlinNoiseValue(float x, float res) { nx = x/res; - x0 = (int)(nx); + x0 = static_cast(nx); ii = x0 & 255; - gi0 = perm[ii] % 16; - gi1 = perm[ii + 1] % 16; + gi0 = perm[ii] % 2; + gi1 = perm[ii + 1] % 2; temp.x = nx-x0; - temp.y = ny-y0; - s[0] = gradient3[gi0][0]*temp.x; + s[0] = gradient1[gi0]*temp.x; temp.x = nx-(x0+1); - t[0] = gradient3[gi1][0]*temp.x; + t[0] = gradient1[gi1]*temp.x; tmp = nx-x0; Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); @@ -156,8 +115,8 @@ float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res) nx = x/res; ny = y/res; - x0 = (int)(nx); - y0 = (int)(ny); + x0 = static_cast(nx); + y0 = static_cast(ny); ii = x0 & 255; jj = y0 & 255; @@ -200,9 +159,9 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res ny = y/res; nz = z/res; - x0 = (int)(nx); - y0 = (int)(ny); - z0 = (int)(nz); + x0 = static_cast(nx); + y0 = static_cast(ny); + z0 = static_cast(nz); ii = x0 & 255; jj = y0 & 255; @@ -279,10 +238,10 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, nz = z/res; nw = w/res; - x0 = (int)(nx); - y0 = (int)(ny); - z0 = (int)(nz); - w0 = (int)(nw); + x0 = static_cast(nx); + y0 = static_cast(ny); + z0 = static_cast(nz); + w0 = static_cast(nw); ii = x0 & 255; jj = y0 & 255; @@ -749,9 +708,9 @@ float NzNoiseMachine::Get3DCellNoiseValue(float x, float y, float z, float res) y /= res; z /= res; - x0 = (int)(x); - y0 = (int)(y); - z0 = (int)(z); + x0 = static_cast(x); + y0 = static_cast(y); + z0 = static_cast(z); return 0; } @@ -762,10 +721,10 @@ float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, fl z /= res; w /= res; - x0 = (int)(x) & 255; - y0 = (int)(y) & 255; - z0 = (int)(z) & 255; - w0 = (int)(w) & 255; + x0 = static_cast(x) & 255; + y0 = static_cast(y) & 255; + z0 = static_cast(z) & 255; + w0 = static_cast(w) & 255; return 0; } @@ -953,7 +912,7 @@ float NzNoiseMachine::Get3DHybridMultiFractalNoiseValue(float x, float y, float int NzNoiseMachine::fastfloor(float n) { if(n >= 0) - return int(n); + return static_cast(n); else - return int(n-1); + return static_cast(n-1); } From 784787cd79d0c8b968320e633ece3b63ba3c730a Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Wed, 30 May 2012 19:30:51 +0200 Subject: [PATCH 06/13] Suppressed perlin1d, added perlin 2,3,4 and simplex 2 classes + minor fixes/optimisations on noisemachine --- include/Nazara/Noise/Perlin2D.hpp | 40 +++++++ include/Nazara/Noise/Perlin2D.inl | 65 +++++++++++ include/Nazara/Noise/Perlin3D.hpp | 40 +++++++ include/Nazara/Noise/Perlin3D.inl | 101 +++++++++++++++++ include/Nazara/Noise/Perlin4D.hpp | 40 +++++++ include/Nazara/Noise/Perlin4D.inl | 167 +++++++++++++++++++++++++++++ include/Nazara/Noise/Simplex2D.hpp | 43 ++++++++ include/Nazara/Noise/Simplex2D.inl | 88 +++++++++++++++ 8 files changed, 584 insertions(+) create mode 100644 include/Nazara/Noise/Perlin2D.hpp create mode 100644 include/Nazara/Noise/Perlin2D.inl create mode 100644 include/Nazara/Noise/Perlin3D.hpp create mode 100644 include/Nazara/Noise/Perlin3D.inl create mode 100644 include/Nazara/Noise/Perlin4D.hpp create mode 100644 include/Nazara/Noise/Perlin4D.inl create mode 100644 include/Nazara/Noise/Simplex2D.hpp create mode 100644 include/Nazara/Noise/Simplex2D.inl diff --git a/include/Nazara/Noise/Perlin2D.hpp b/include/Nazara/Noise/Perlin2D.hpp new file mode 100644 index 000000000..1633c10fb --- /dev/null +++ b/include/Nazara/Noise/Perlin2D.hpp @@ -0,0 +1,40 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef PERLIN2D_H +#define PERLIN2D_H + +#include +#include +#include + +template class NzPerlin2D : public NzNoiseBase +{ + public: + NzPerlin2D(); + T GetValue(T x, T y, T res); + ~NzPerlin2D() = default; + protected: + private: + int x0, y0; + int gi0,gi1,gi2,gi3; + int ii, jj; + T gradient2[8][2]; + T s,t,u,v; + T Cx,Cy; + T Li1, Li2; + T nx, ny; + T tmp; + NzVector2 temp; +}; + +typedef NzPerlin2D NzPerlin2Df; +typedef NzPerlin2D NzPerlin2Dd; + +#include + +#endif // PERLIN2D_H + diff --git a/include/Nazara/Noise/Perlin2D.inl b/include/Nazara/Noise/Perlin2D.inl new file mode 100644 index 000000000..df06d2679 --- /dev/null +++ b/include/Nazara/Noise/Perlin2D.inl @@ -0,0 +1,65 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +template +NzPerlin2D::NzPerlin2D() +{ + T unit = 1.0/sqrt(2); + T grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, + {1,0},{-1,0},{0,1},{0,-1}}; + + for(int i(0) ; i < 8 ; ++i) + for(int j(0) ; j < 2 ; ++j) + gradient2[i][j] = grad2Temp[i][j]; +} + +template +T NzPerlin2D::GetValue(T x, T y, T res) +{ + nx = x/res; + ny = y/res; + + x0 = static_cast(nx); + y0 = static_cast(ny); + + ii = x0 & 255; + jj = y0 & 255; + + gi0 = perm[ii + perm[jj]] & 7; + gi1 = perm[ii + 1 + perm[jj]] & 7; + gi2 = perm[ii + perm[jj + 1]] & 7; + gi3 = perm[ii + 1 + perm[jj + 1]] & 7; + + temp.x = nx-x0; + temp.y = ny-y0; + s = gradient2[gi0][0]*temp.x + gradient2[gi0][1]*temp.y; + + temp.x = nx-(x0+1); + temp.y = ny-y0; + t = gradient2[gi1][0]*temp.x + gradient2[gi1][1]*temp.y; + + temp.x = nx-x0; + temp.y = ny-(y0+1); + u = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y; + + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v = gradient2[gi3][0]*temp.x + gradient2[gi3][1]*temp.y; + + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li1 = s + Cx*(t-s); + Li2 = u + Cx*(v-u); + + tmp = ny - y0; + Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return Li1 + Cy*(Li2-Li1); +} + diff --git a/include/Nazara/Noise/Perlin3D.hpp b/include/Nazara/Noise/Perlin3D.hpp new file mode 100644 index 000000000..ca01b891d --- /dev/null +++ b/include/Nazara/Noise/Perlin3D.hpp @@ -0,0 +1,40 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef PERLIN3D_H +#define PERLIN3D_H + +#include +#include +#include + +template class NzPerlin3D : public NzNoiseBase +{ + public: + NzPerlin3D(); + T GetValue(T x, T y, T z, T res); + ~NzPerlin3D() = default; + protected: + private: + int x0,y0,z0; + int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7; + int ii,jj,kk; + int gradient3[16][3]; + T Li1,Li2,Li3,Li4,Li5,Li6; + T s[2],t[2],u[2],v[2]; + T Cx,Cy,Cz; + T nx,ny,nz; + T tmp; + NzVector3 temp; + +}; + +typedef NzPerlin3D NzPerlin3Df; +typedef NzPerlin3D NzPerlin3Dd; + +#include + +#endif // PERLIN3D_H diff --git a/include/Nazara/Noise/Perlin3D.inl b/include/Nazara/Noise/Perlin3D.inl new file mode 100644 index 000000000..8bf832dfe --- /dev/null +++ b/include/Nazara/Noise/Perlin3D.inl @@ -0,0 +1,101 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +template +NzPerlin3D::NzPerlin3D() +{ + int grad3Temp[][3] = { + {1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, + {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, + {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}, + {1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1} + }; + + for(int i(0) ; i < 16 ; ++i) + for(int j(0) ; j < 3 ; ++j) + gradient3[i][j] = grad3Temp[i][j]; +} + +template +T NzPerlin3D::GetValue(T x, T y, T z, T res) +{ + nx = x/res; + ny = y/res; + nz = z/res; + + x0 = static_cast(nx); + y0 = static_cast(ny); + z0 = static_cast(nz); + + ii = x0 & 255; + jj = y0 & 255; + kk = z0 & 255; + + gi0 = perm[ii + perm[jj + perm[kk]]] % 16; + gi1 = perm[ii + 1 + perm[jj + perm[kk]]] % 16; + gi2 = perm[ii + perm[jj + 1 + perm[kk]]] % 16; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] % 16; + + gi4 = perm[ii + perm[jj + perm[kk + 1]]] % 16; + gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] % 16; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] % 16; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 16; + + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-z0; + s[0] = gradient3[gi0][0]*temp.x + gradient3[gi0][1]*temp.y + gradient3[gi0][2]*temp.z; + + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[0] = gradient3[gi1][0]*temp.x + gradient3[gi1][1]*temp.y + gradient3[gi1][2]*temp.z; + + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; + + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[0] = gradient3[gi3][0]*temp.x + gradient3[gi3][1]*temp.y + gradient3[gi3][2]*temp.z; + + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-(z0+1); + s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z; + + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z; + + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z; + + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z; + + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li1 = s[0] + Cx*(t[0]-s[0]); + Li2 = u[0] + Cx*(v[0]-u[0]); + Li3 = s[1] + Cx*(t[1]-s[1]); + Li4 = u[1] + Cx*(v[1]-u[1]); + + tmp = ny-y0; + Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li5 = Li1 + Cy*(Li2-Li1); + Li6 = Li3 + Cy*(Li4-Li3); + + tmp = nz-z0; + Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return Li5 + Cz*(Li6-Li5); +} diff --git a/include/Nazara/Noise/Perlin4D.hpp b/include/Nazara/Noise/Perlin4D.hpp new file mode 100644 index 000000000..c0af6feb1 --- /dev/null +++ b/include/Nazara/Noise/Perlin4D.hpp @@ -0,0 +1,40 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef PERLIN4D_H +#define PERLIN4D_H + +#include +#include +#include + +template class NzPerlin4D : public NzNoiseBase +{ + public: + NzPerlin4D(); + T GetValue(T x, T y, T z, T w, T res); + ~NzPerlin4D() = default; + protected: + private: + int x0,y0,z0,w0; + int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; + int ii,jj,kk,ll; + int gradient4[32][4]; + T Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14; + T s[4],t[4],u[4],v[4]; + T Cx,Cy,Cz,Cw; + T nx,ny,nz,nw; + T tmp; + NzVector4 temp; + +}; + +typedef NzPerlin4D NzPerlin4Df; +typedef NzPerlin4D NzPerlin4Dd; + +#include + +#endif // PERLIN4D_H diff --git a/include/Nazara/Noise/Perlin4D.inl b/include/Nazara/Noise/Perlin4D.inl new file mode 100644 index 000000000..4b51c127d --- /dev/null +++ b/include/Nazara/Noise/Perlin4D.inl @@ -0,0 +1,167 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +template +NzPerlin4D::NzPerlin4D() +{ + int grad4Temp[][4] = + { + {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1}, + {0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1}, + {1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1}, + {-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1}, + {1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1}, + {-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1}, + {1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0}, + {-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0} + }; + + for(int i(0) ; i < 32 ; ++i) + for(int j(0) ; j < 4 ; ++j) + gradient4[i][j] = grad4Temp[i][j]; +} + +template +T NzPerlin4D::GetValue(T x, T y, T z, T w, T res) +{ + nx = x/res; + ny = y/res; + nz = z/res; + nw = w/res; + + x0 = static_cast(nx); + y0 = static_cast(ny); + z0 = static_cast(nz); + w0 = static_cast(nw); + + ii = x0 & 255; + jj = y0 & 255; + kk = z0 & 255; + ll = w0 & 255; + + gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] % 32; + gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll ]]]] % 32; + gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; + + gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; + gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; + + gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] % 32; + gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] % 32; + gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; + gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; + + gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-z0; + temp.w = nw-w0; + s[0] = gradient4[gi0][0]*temp.x + gradient4[gi0][1]*temp.y + gradient4[gi0][2]*temp.z + gradient4[gi0][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[0] = gradient4[gi1][0]*temp.x + gradient4[gi1][1]*temp.y + gradient4[gi1][2]*temp.z + gradient4[gi1][3]*temp.w; + + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w; + + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-(z0+1); + s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[1] = gradient4[gi5][0]*temp.x + gradient4[gi5][1]*temp.y + gradient4[gi5][2]*temp.z + gradient4[gi5][3]*temp.w; + + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w; + + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-z0; + temp.w = nw-(w0+1); + s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[2] = gradient4[gi9][0]*temp.x + gradient4[gi9][1]*temp.y + gradient4[gi9][2]*temp.z + gradient4[gi9][3]*temp.w; + + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w; + + temp.x = nx-x0; + temp.y = ny-y0; + temp.z = nz-(z0+1); + s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-y0; + t[3] = gradient4[gi13][0]*temp.x + gradient4[gi13][1]*temp.y + gradient4[gi13][2]*temp.z + gradient4[gi13][3]*temp.w; + + temp.x = nx-x0; + temp.y = ny-(y0+1); + u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w; + + temp.x = nx-(x0+1); + temp.y = ny-(y0+1); + v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w; + + tmp = nx-x0; + Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li1 = s[0] + Cx*(t[0]-s[0]); + Li2 = u[0] + Cx*(v[0]-u[0]); + Li3 = s[1] + Cx*(t[1]-s[1]); + Li4 = u[1] + Cx*(v[1]-u[1]); + Li5 = s[2] + Cx*(t[2]-s[2]); + Li6 = u[2] + Cx*(v[2]-u[2]); + Li7 = s[3] + Cx*(t[3]-s[3]); + Li8 = u[3] + Cx*(v[3]-u[3]); + + tmp = ny-y0; + Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li9 = Li1 + Cy*(Li2-Li1); + Li10 = Li3 + Cy*(Li4-Li3); + Li11 = Li5 + Cy*(Li6-Li5); + Li12 = Li7 + Cy*(Li8-Li7); + + tmp = nz-z0; + Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + Li13 = Li9 + Cz*(Li10-Li9); + Li14 = Li11 + Cz*(Li12-Li11); + + tmp = nw-w0; + Cw = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + + return Li13 + Cw*(Li14-Li13); +} diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp new file mode 100644 index 000000000..79434b471 --- /dev/null +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -0,0 +1,43 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef SIMPLEX2D_H +#define SIMPLEX2D_H + +#include +#include +#include + + +template class NzSimplex2D : public NzNoiseBase +{ + public: + NzSimplex2D(); + T GetValue(T x, T y, T res); + ~NzSimplex2D() = default; + protected: + private: + int ii,jj; + int gi0,gi1,gi2; + NzVector2i Origin,off1; + T n1,n2,n3; + T c1,c2,c3; + T gradient2[8][2]; + T UnskewCoeff2D; + T SkewCoeff2D; + NzVector2 A, IsoOriginDist; + NzVector2 d1,d2,d3; + + +}; + +typedef NzSimplex2D NzSimplex2Df; +typedef NzSimplex2D NzSimplex2Dd; + +#include + +#endif // SIMPLEX2D_H + diff --git a/include/Nazara/Noise/Simplex2D.inl b/include/Nazara/Noise/Simplex2D.inl new file mode 100644 index 000000000..129501617 --- /dev/null +++ b/include/Nazara/Noise/Simplex2D.inl @@ -0,0 +1,88 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include + +template +NzSimplex2D::NzSimplex2D() +{ + + T unit = 1.0/sqrt(2); + T grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, + {1,0},{-1,0},{0,1},{0,-1}}; + + for(int i(0) ; i < 8 ; ++i) + for(int j(0) ; j < 2 ; ++j) + gradient2[i][j] = grad2Temp[i][j]; + + SkewCoeff2D = 0.5*(sqrt(3.0) - 1.0); + UnskewCoeff2D = (3.0-sqrt(3.0))/6; +} + +template +T NzSimplex2D::GetValue(T x, T y, T res) +{ + x /= res; + y /= res; + + Origin.x = fastfloor(x + (x + y) * SkewCoeff2D); + Origin.y = fastfloor(y + (x + y) * SkewCoeff2D); + + A.x = Origin.x - (Origin.x + Origin.y) * UnskewCoeff2D; + A.y = Origin.y - (Origin.x + Origin.y) * UnskewCoeff2D; + + IsoOriginDist.x = x - A.x; + IsoOriginDist.y = y - A.y; + + if(IsoOriginDist.x > IsoOriginDist.y) + { + off1.x = 1; + off1.y = 0; + } + else + { + off1.x = 0; + off1.y = 1; + } + + d1.x = A.x - x; + d1.y = A.y - y; + + d2.x = d1.x + off1.x - UnskewCoeff2D; + d2.y = d1.y + off1.y - UnskewCoeff2D; + + d3.x = d1.x + 1.0 - 2 * UnskewCoeff2D; + d3.y = d1.y + 1.0 - 2 * UnskewCoeff2D; + + ii = Origin.x & 255; + jj = Origin.y & 255; + + gi0 = perm[ii + perm[jj]] % 8; + gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 8; + gi2 = perm[ii + 1 + perm[jj + 1]] % 8; + + n1 = gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y; + n2 = gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y; + n3 = gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y; + + c1 = 0.5 - d1.x * d1.x - d1.y * d1.y; + c2 = 0.5 - d2.x * d2.x - d2.y * d2.y; + c3 = 0.5 - d3.x * d3.x - d3.y * d3.y; + + if(c1 < 0) + c1 = 0; + if(c2 < 0) + c2 = 0; + if(c3 < 0) + c3 = 0; + + n1 = c1*c1*c1*n1; + n2 = c2*c2*c2*n2; + n3 = c3*c3*c3*n3; + + return (n1+n2+n3)*23.2; +} + From 9008c368028296d34350f15e3707906441db513c Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Thu, 31 May 2012 15:32:22 +0200 Subject: [PATCH 07/13] Added NzDynaTerrain (basis) + simplex3d 4d for nznoise --- build/scripts/module/dynaterrain.lua | 31 ++++ include/Nazara/DynaTerrain/Config.hpp | 38 +++++ include/Nazara/DynaTerrain/Debug.hpp | 11 ++ include/Nazara/DynaTerrain/DebugOff.hpp | 8 + include/Nazara/DynaTerrain/DynaTerrain.hpp | 27 ++++ include/Nazara/DynaTerrain/Node.hpp | 71 +++++++++ include/Nazara/DynaTerrain/Patch.hpp | 35 +++++ include/Nazara/DynaTerrain/QuadTree.hpp | 30 ++++ include/Nazara/Noise/Simplex3D.hpp | 45 ++++++ include/Nazara/Noise/Simplex3D.inl | 158 ++++++++++++++++++++ include/Nazara/Noise/Simplex4D.hpp | 47 ++++++ include/Nazara/Noise/Simplex4D.inl | 161 +++++++++++++++++++++ 12 files changed, 662 insertions(+) create mode 100644 build/scripts/module/dynaterrain.lua create mode 100644 include/Nazara/DynaTerrain/Config.hpp create mode 100644 include/Nazara/DynaTerrain/Debug.hpp create mode 100644 include/Nazara/DynaTerrain/DebugOff.hpp create mode 100644 include/Nazara/DynaTerrain/DynaTerrain.hpp create mode 100644 include/Nazara/DynaTerrain/Node.hpp create mode 100644 include/Nazara/DynaTerrain/Patch.hpp create mode 100644 include/Nazara/DynaTerrain/QuadTree.hpp create mode 100644 include/Nazara/Noise/Simplex3D.hpp create mode 100644 include/Nazara/Noise/Simplex3D.inl create mode 100644 include/Nazara/Noise/Simplex4D.hpp create mode 100644 include/Nazara/Noise/Simplex4D.inl diff --git a/build/scripts/module/dynaterrain.lua b/build/scripts/module/dynaterrain.lua new file mode 100644 index 000000000..31847eb8c --- /dev/null +++ b/build/scripts/module/dynaterrain.lua @@ -0,0 +1,31 @@ +project "NazaraModuleName" + +files +{ + "../include/Nazara/ModuleName/**.hpp", + "../include/Nazara/ModuleName/**.inl", + "../src/Nazara/ModuleName/**.hpp", + "../src/Nazara/ModuleName/**.cpp" +} + +if (os.is("windows")) then + excludes { "../src/Nazara/ModuleName/Posix/*.hpp", "../src/Nazara/ModuleName/Posix/*.cpp" } +else + excludes { "../src/Nazara/ModuleName/Win32/*.hpp", "../src/Nazara/ModuleName/Win32/*.cpp" } +end + +configuration "DebugStatic" + links "NazaraCored-s" + targetname "NazaraModuleNamed" + +configuration "ReleaseStatic" + links "NazaraCore-s" + targetname "NazaraModuleName" + +configuration "DebugDLL" + links "NazaraCored" + targetname "NazaraModuleNamed" + +configuration "ReleaseDLL" + links "NazaraCore" + targetname "NazaraModuleName" \ No newline at end of file diff --git a/include/Nazara/DynaTerrain/Config.hpp b/include/Nazara/DynaTerrain/Config.hpp new file mode 100644 index 000000000..9527720de --- /dev/null +++ b/include/Nazara/DynaTerrain/Config.hpp @@ -0,0 +1,38 @@ +/* + Nazara Engine + + Copyright (C) 2012 AUTHORS (EMAIL) + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#pragma once + +#ifndef NAZARA_CONFIG_MODULENAME_HPP +#define NAZARA_CONFIG_MODULENAME_HPP + +/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci + +// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) +#define NAZARA_MODULENAME_MEMORYLEAKTRACKER 0 + +// Active les tests de sécurité basés sur le code (Conseillé pour le développement) +#define NAZARA_MODULENAME_SAFE 1 + +#endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/DynaTerrain/Debug.hpp b/include/Nazara/DynaTerrain/Debug.hpp new file mode 100644 index 000000000..fa2f9482e --- /dev/null +++ b/include/Nazara/DynaTerrain/Debug.hpp @@ -0,0 +1,11 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) + #include + + #define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete + #define new new(__FILE__, __LINE__) +#endif diff --git a/include/Nazara/DynaTerrain/DebugOff.hpp b/include/Nazara/DynaTerrain/DebugOff.hpp new file mode 100644 index 000000000..0a21b742d --- /dev/null +++ b/include/Nazara/DynaTerrain/DebugOff.hpp @@ -0,0 +1,8 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) + #undef delete + #undef new +#endif diff --git a/include/Nazara/DynaTerrain/DynaTerrain.hpp b/include/Nazara/DynaTerrain/DynaTerrain.hpp new file mode 100644 index 000000000..70d8f6918 --- /dev/null +++ b/include/Nazara/DynaTerrain/DynaTerrain.hpp @@ -0,0 +1,27 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_MODULENAME_HPP +#define NAZARA_MODULENAME_HPP + +#include + +class NAZARA_API NzModuleName +{ + public: + NzModuleName(); + ~NzModuleName(); + + bool Initialize(); + void Uninitialize(); + + static bool IsInitialized(); + + private: + static bool s_initialized; +}; + +#endif // NAZARA_MODULENAME_HPP diff --git a/include/Nazara/DynaTerrain/Node.hpp b/include/Nazara/DynaTerrain/Node.hpp new file mode 100644 index 000000000..f7e6bd430 --- /dev/null +++ b/include/Nazara/DynaTerrain/Node.hpp @@ -0,0 +1,71 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NODE_H +#define NODE_H + +#include + +#include +#include "Patch.hpp" +class NzQuadTree; + + +//SUPPRIMER LES NODES FILS OU SEULEMENT LES PATCHS CONTENUS ? POUR L'INSTANT SUPPRESSION DES PATCHS + +class NzNode +{ + public: + enum nzDirection + { + TOP, + BOTTOM, + LEFT, + RIGHT, + TOPLEFT, + TOPRIGHT, + BOTTOMLEFT, + BOTTOMRIGHT, + CENTER + }; + + NzNode(NzQuadTree* quad, NzNode* parent, const NzVector2f& center, const NzVector2f& size, nzDirection dir = CENTER); + ~NzNode(); + + void Subdivide(); + void Refine(bool eraseMemory); + + void CreatePatch(const NzVector2f& center, const NzVector2f& size); + void DeletePatch(); + + unsigned short int GetLevel() const; + + bool IsLeaf() const; + bool IsRoot() const; + + //Retourne le voisin le plus proche dans la direction indiqué, de niveau de profondeur inférieur ou égal + bool LocateNeighbor(nzDirection dir, NzNode* neighbor); + + + private: + NzQuadTree* m_associatedQuadTree; + NzNode* m_parent; + NzNode* m_topLeftLeaf; + NzNode* m_topRightLeaf; + NzNode* m_bottomLeftLeaf; + NzNode* m_bottomRightLeaf; + bool m_isLeaf; + bool m_isRoot; + bool m_patchMemoryAllocated; + unsigned short int m_level; + + NzPatch* m_patch; + NzVector2f m_center; + NzVector2f m_size; + nzDirection m_direction; +}; + +#endif // NODE_H diff --git a/include/Nazara/DynaTerrain/Patch.hpp b/include/Nazara/DynaTerrain/Patch.hpp new file mode 100644 index 000000000..a546f2f41 --- /dev/null +++ b/include/Nazara/DynaTerrain/Patch.hpp @@ -0,0 +1,35 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef PATCH_H +#define PATCH_H + +#include + +#include + +class NzPatch +{ + public: + NzPatch(NzVector2f center, NzVector2f size); + ~NzPatch(); + + NzVector2f GetCenter() const; + NzVector2f GetSize() const; + + bool IntersectsCircle(const NzVector2f& center, double radius); + bool IsContainedByCircle(const NzVector2f& center, double radius); + + NzPatch* LocatePatch(const NzVector2f& position); + + protected: + private: + + NzVector2f m_center; + NzVector2f m_size; +}; + +#endif // PATCH_H diff --git a/include/Nazara/DynaTerrain/QuadTree.hpp b/include/Nazara/DynaTerrain/QuadTree.hpp new file mode 100644 index 000000000..8ed3f9dde --- /dev/null +++ b/include/Nazara/DynaTerrain/QuadTree.hpp @@ -0,0 +1,30 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef QUADTREE_H +#define QUADTREE_H + +#include + +#include +#include +#include "Node.hpp" + +class NzQuadTree +{ + public: + NzQuadTree(const NzVector2f& terrainCenter, const NzVector2f& terrainSize); + void RegisterLeaf(NzNode* node); + bool UnRegisterLeaf(NzNode* node); + NzNode* GetRootPtr(); + ~NzQuadTree(); + private: + NzNode* root; + //N'a pas la charge des objets en mémoire + std::list leaves; +}; + +#endif // QUADTREE_H diff --git a/include/Nazara/Noise/Simplex3D.hpp b/include/Nazara/Noise/Simplex3D.hpp new file mode 100644 index 000000000..dface2886 --- /dev/null +++ b/include/Nazara/Noise/Simplex3D.hpp @@ -0,0 +1,45 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef SIMPLEX3D_H +#define SIMPLEX3D_H + +#include +//#include +#include "NoiseBase.hpp" +#include + + +template class NzSimplex3D : public NzNoiseBase +{ + public: + NzSimplex3D(); + T GetValue(T x, T y, T z, T res); + ~NzSimplex3D() = default; + protected: + private: + int ii,jj,kk; + int gi0,gi1,gi2,gi3; + NzVector3i Origin,off1,off2; + T n1,n2,n3,n4; + T c1,c2,c3,c4; + T gradient3[16][3]; + T UnskewCoeff3D; + T SkewCoeff3D; + NzVector3 A, IsoOriginDist; + NzVector3 d1,d2,d3,d4; + + +}; + +typedef NzSimplex3D NzSimplex3Df; +typedef NzSimplex3D NzSimplex3Dd; + +//#include +#include "Simplex3D.inl" + +#endif // SIMPLEX3D_H + diff --git a/include/Nazara/Noise/Simplex3D.inl b/include/Nazara/Noise/Simplex3D.inl new file mode 100644 index 000000000..dea0881e2 --- /dev/null +++ b/include/Nazara/Noise/Simplex3D.inl @@ -0,0 +1,158 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +//#include +//#include +//#include + +template +NzSimplex3D::NzSimplex3D() +{ + SkewCoeff3D = 1/3; + UnskewCoeff3D = 1/6; + + int grad3Temp[][3] = { + {1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, + {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, + {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}, + {1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1} + }; + + for(int i(0) ; i < 16 ; ++i) + for(int j(0) ; j < 3 ; ++j) + gradient3[i][j] = grad3Temp[i][j]; +} + +template +T NzSimplex3D::GetValue(T x, T y, T z, T res) +{ + x /= res; + y /= res; + z /= res; + + Origin.x = fastfloor(x + (x + y + z) * SkewCoeff3D); + Origin.y = fastfloor(y + (x + y + z) * SkewCoeff3D); + Origin.z = fastfloor(z + (x + y + z) * SkewCoeff3D); + + A.x = Origin.x - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; + A.y = Origin.y - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; + A.z = Origin.z - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; + + IsoOriginDist.x = x - A.x; + IsoOriginDist.y = y - A.y; + IsoOriginDist.z = z - A.z; + + if(IsoOriginDist.x >= IsoOriginDist.y) + { + if(IsoOriginDist.y >= IsoOriginDist.z) + { + off1.x = 1; + off1.y = 0; + off1.z = 0; + off2.x = 1; + off2.y = 1; + off2.z = 0; + } + else if(IsoOriginDist.x >= IsoOriginDist.z) + { + off1.x = 1; + off1.y = 0; + off1.z = 0; + off2.x = 1; + off2.y = 0; + off2.z = 1; + } + else + { + off1.x = 0; + off1.y = 0; + off1.z = 1; + off2.x = 1; + off2.y = 0; + off2.z = 1; + } + } + else + { + if(IsoOriginDist.y < IsoOriginDist.z) + { + off1.x = 0; + off1.y = 0; + off1.z = 1; + off2.x = 0; + off2.y = 1; + off2.z = 1; + } + else if(IsoOriginDist.x < IsoOriginDist.z) + { + off1.x = 0; + off1.y = 1; + off1.z = 0; + off2.x = 0; + off2.y = 1; + off2.z = 1; + } + else + { + off1.x = 0; + off1.y = 1; + off1.z = 0; + off2.x = 1; + off2.y = 1; + off2.z = 0; + } + } + + d1.x = A.x - x; + d1.y = A.y - y; + d1.z = A.z - z; + + d2.x = d1.x + off1.x - UnskewCoeff3D; + d2.y = d1.y + off1.y - UnskewCoeff3D; + d2.z = d1.z + off1.z - UnskewCoeff3D; + + d3.x = d1.x + off2.x - 2*UnskewCoeff3D; + d3.y = d1.y + off2.y - 2*UnskewCoeff3D; + d3.z = d1.z + off2.z - 2*UnskewCoeff3D; + + d4.x = d1.x + 1.0 - 3*UnskewCoeff3D; + d4.y = d1.y + 1.0 - 3*UnskewCoeff3D; + d4.z = d1.z + 1.0 - 3*UnskewCoeff3D; + + ii = Origin.x & 255; + jj = Origin.y & 255; + kk = Origin.z & 255; + + gi0 = perm[ii + perm[jj + perm[kk]]] % 12; + gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z]]] % 12; + gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z]]] % 12; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 12; + + n1 = gradient3[gi0][0] * d1.x + gradient3[gi0][1] * d1.y + gradient3[gi0][2] * d1.z; + n2 = gradient3[gi1][0] * d2.x + gradient3[gi1][1] * d2.y + gradient3[gi1][2] * d2.z; + n3 = gradient3[gi2][0] * d3.x + gradient3[gi2][1] * d3.y + gradient3[gi2][2] * d3.z; + n4 = gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z; + + c1 = 0.6 - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z; + c2 = 0.6 - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z; + c3 = 0.6 - d3.x * d3.x - d3.y * d3.y - d3.z * d3.z; + c4 = 0.6 - d4.x * d4.x - d4.y * d4.y - d4.z * d4.z; + + if(c1 < 0) + c1 = 0; + if(c2 < 0) + c2 = 0; + if(c3 < 0) + c3 = 0; + if(c4 < 0) + c4 = 0; + + n1 = c1*c1*c1*n1; + n2 = c2*c2*c2*n2; + n3 = c3*c3*c3*n3; + n4 = c4*c4*c4*n4; + + return (n1+n2+n3+n4)*17.6995; +} + diff --git a/include/Nazara/Noise/Simplex4D.hpp b/include/Nazara/Noise/Simplex4D.hpp new file mode 100644 index 000000000..7c9982822 --- /dev/null +++ b/include/Nazara/Noise/Simplex4D.hpp @@ -0,0 +1,47 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef SIMPLEX4D_H +#define SIMPLEX4D_H + +#include +//#include +#include "NoiseBase.hpp" +#include + + +template class NzSimplex4D : public NzNoiseBase +{ + public: + NzSimplex4D(); + T GetValue(T x, T y, T z, T w, T res); + ~NzSimplex4D() = default; + protected: + private: + int ii,jj,kk,ll; + int gi0,gi1,gi2,gi3,gi4; + NzVector4i Origin,off1,off2,off3; + T n1,n2,n3,n4,n5; + T c1,c2,c3,c4,c5,c6; + T gradient4[32][4]; + int lookupTable4D[64][4]; + int c; + T UnskewCoeff4D; + T SkewCoeff4D; + NzVector4 A, IsoOriginDist; + NzVector4 d1,d2,d3,d4,d5; + + +}; + +typedef NzSimplex4D NzSimplex4Df; +typedef NzSimplex4D NzSimplex4Dd; + +//#include +#include "Simplex4D.inl" + +#endif // SIMPLEX4D_H + diff --git a/include/Nazara/Noise/Simplex4D.inl b/include/Nazara/Noise/Simplex4D.inl new file mode 100644 index 000000000..de840679d --- /dev/null +++ b/include/Nazara/Noise/Simplex4D.inl @@ -0,0 +1,161 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +//#include +//#include +//#include + +template +NzSimplex4D::NzSimplex4D() +{ + SkewCoeff4D = (sqrt(5) - 1)/4; + UnskewCoeff4D = (5 - sqrt(5))/20; + + int lookupTemp4D[][4] = + { + {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0}, + {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0}, + {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, + {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0}, + {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0}, + {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, + {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0}, + {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0} + }; + + for(int i(0) ; i < 64 ; ++i) + for(int j(0) ; j < 4 ; ++j) + lookupTable4D[i][j] = lookupTemp4D[i][j]; + + int grad4Temp[][4] = + { + {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1}, + {0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1}, + {1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1}, + {-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1}, + {1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1}, + {-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1}, + {1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0}, + {-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0} + }; + + for(int i(0) ; i < 32 ; ++i) + for(int j(0) ; j < 4 ; ++j) + gradient4[i][j] = grad4Temp[i][j]; +} + +template +T NzSimplex4D::GetValue(T x, T y, T z, T w, T res) +{ + x /= res; + y /= res; + z /= res; + w /= res; + + Origin.x = fastfloor(x + (x + y + z + w) * SkewCoeff4D); + Origin.y = fastfloor(y + (x + y + z + w) * SkewCoeff4D); + Origin.z = fastfloor(z + (x + y + z + w) * SkewCoeff4D); + Origin.w = fastfloor(w + (x + y + z + w) * SkewCoeff4D); + + A.x = Origin.x - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; + A.y = Origin.y - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; + A.z = Origin.z - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; + A.w = Origin.w - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; + + IsoOriginDist.x = x - A.x; + IsoOriginDist.y = y - A.y; + IsoOriginDist.z = z - A.z; + IsoOriginDist.w = w - A.w; + + c1 = (IsoOriginDist.x > IsoOriginDist.y) ? 32 : 0; + c2 = (IsoOriginDist.x > IsoOriginDist.z) ? 16 : 0; + c3 = (IsoOriginDist.y > IsoOriginDist.z) ? 8 : 0; + c4 = (IsoOriginDist.x > IsoOriginDist.w) ? 4 : 0; + c5 = (IsoOriginDist.y > IsoOriginDist.w) ? 2 : 0; + c6 = (IsoOriginDist.z > IsoOriginDist.w) ? 1 : 0; + c = c1 + c2 + c3 + c4 + c5 + c6; + + off1.x = lookupTable4D[c][0] >= 3 ? 1 : 0; + off1.y = lookupTable4D[c][1] >= 3 ? 1 : 0; + off1.z = lookupTable4D[c][2] >= 3 ? 1 : 0; + off1.w = lookupTable4D[c][3] >= 3 ? 1 : 0; + + off2.x = lookupTable4D[c][0] >= 2 ? 1 : 0; + off2.y = lookupTable4D[c][1] >= 2 ? 1 : 0; + off2.z = lookupTable4D[c][2] >= 2 ? 1 : 0; + off2.w = lookupTable4D[c][3] >= 2 ? 1 : 0; + + off3.x = lookupTable4D[c][0] >= 1 ? 1 : 0; + off3.y = lookupTable4D[c][1] >= 1 ? 1 : 0; + off3.z = lookupTable4D[c][2] >= 1 ? 1 : 0; + off3.w = lookupTable4D[c][3] >= 1 ? 1 : 0; + + d1.x = A.x - x; + d1.y = A.y - y; + d1.z = A.z - z; + d1.w = A.w - w; + + d2.x = d1.x + off1.x - UnskewCoeff4D; + d2.y = d1.y + off1.y - UnskewCoeff4D; + d2.z = d1.z + off1.z - UnskewCoeff4D; + d2.w = d1.w + off1.w - UnskewCoeff4D; + + d3.x = d1.x + off2.x - 2*UnskewCoeff4D; + d3.y = d1.y + off2.y - 2*UnskewCoeff4D; + d3.z = d1.z + off2.z - 2*UnskewCoeff4D; + d3.w = d1.w + off2.w - 2*UnskewCoeff4D; + + d4.x = d1.x + off3.x - 3*UnskewCoeff4D; + d4.y = d1.y + off3.y - 3*UnskewCoeff4D; + d4.z = d1.z + off3.z - 3*UnskewCoeff4D; + d4.w = d1.w + off3.w - 3*UnskewCoeff4D; + + d5.x = d1.x + 1.0 - 4*UnskewCoeff4D; + d5.y = d1.y + 1.0 - 4*UnskewCoeff4D; + d5.z = d1.z + 1.0 - 4*UnskewCoeff4D; + d5.w = d1.w + 1.0 - 4*UnskewCoeff4D; + + ii = Origin.x & 255; + jj = Origin.y & 255; + kk = Origin.z & 255; + ll = Origin.w & 255; + + gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32; + gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] % 32; + gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] % 32; + gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] % 32; + gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + + n1 = gradient4[gi0][0]*d1.x + gradient4[gi0][1]*d1.y + gradient4[gi0][2]*d1.z + gradient4[gi0][3]*d1.w; + n2 = gradient4[gi1][0]*d2.x + gradient4[gi1][1]*d2.y + gradient4[gi1][2]*d2.z + gradient4[gi1][3]*d2.w; + n3 = gradient4[gi2][0]*d3.x + gradient4[gi2][1]*d3.y + gradient4[gi2][2]*d3.z + gradient4[gi2][3]*d3.w; + n4 = gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w; + n5 = gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w; + + c1 = 0.6 - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; + c2 = 0.6 - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; + c3 = 0.6 - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w; + c4 = 0.6 - d4.x*d4.x - d4.y*d4.y - d4.z*d4.z - d4.w*d4.w; + c5 = 0.6 - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w; + + if(c1 < 0) + c1 = 0; + if(c2 < 0) + c2 = 0; + if(c3 < 0) + c3 = 0; + if(c4 < 0) + c4 = 0; + if(c5 < 0) + c5 = 0; + + n1 = c1*c1*c1*n1; + n2 = c2*c2*c2*n2; + n3 = c3*c3*c3*n3; + n4 = c4*c4*c4*n4; + n5 = c5*c5*c5*n5; + + return (n1+n2+n3+n4+n5)*17.6995; +} + From 4d975fa67eb07627cabe01e89563dbcff2d8251a Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Thu, 31 May 2012 15:35:52 +0200 Subject: [PATCH 08/13] Forgot to commit some stuff (noise+dynaterrain) from previous commit --- include/Nazara/Noise/Noise.hpp | 2 +- include/Nazara/Noise/NoiseBase.hpp | 2 + include/Nazara/Noise/NoiseMachine.hpp | 15 +- include/Nazara/Noise/Perlin1D.hpp | 38 --- include/Nazara/Noise/Perlin1D.inl | 37 --- include/Nazara/Noise/Perlin2D.hpp | 6 +- include/Nazara/Noise/Perlin2D.inl | 6 +- include/Nazara/Noise/Perlin3D.hpp | 6 +- include/Nazara/Noise/Perlin3D.inl | 6 +- include/Nazara/Noise/Perlin4D.hpp | 6 +- include/Nazara/Noise/Perlin4D.inl | 6 +- include/Nazara/Noise/Simplex2D.hpp | 6 +- include/Nazara/Noise/Simplex2D.inl | 6 +- src/Nazara/DynaTerrain/Debug/Leaks.cpp | 29 +++ src/Nazara/DynaTerrain/DynaTerrain.cpp | 57 +++++ src/Nazara/DynaTerrain/Node.cpp | 317 +++++++++++++++++++++++++ src/Nazara/DynaTerrain/Patch.cpp | 47 ++++ src/Nazara/DynaTerrain/QuadTree.cpp | 36 +++ src/Nazara/Noise/Noise.cpp | 2 +- src/Nazara/Noise/NoiseBase.cpp | 36 +++ src/Nazara/Noise/NoiseMachine.cpp | 129 +++------- 21 files changed, 589 insertions(+), 206 deletions(-) delete mode 100644 include/Nazara/Noise/Perlin1D.hpp delete mode 100644 include/Nazara/Noise/Perlin1D.inl create mode 100644 src/Nazara/DynaTerrain/Debug/Leaks.cpp create mode 100644 src/Nazara/DynaTerrain/DynaTerrain.cpp create mode 100644 src/Nazara/DynaTerrain/Node.cpp create mode 100644 src/Nazara/DynaTerrain/Patch.cpp create mode 100644 src/Nazara/DynaTerrain/QuadTree.cpp diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp index 9a702c44f..c4925ac0a 100644 --- a/include/Nazara/Noise/Noise.hpp +++ b/include/Nazara/Noise/Noise.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) +// Copyright (C) 2012 AUTHORS // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp index af8a66632..0bd37ab47 100644 --- a/include/Nazara/Noise/NoiseBase.hpp +++ b/include/Nazara/Noise/NoiseBase.hpp @@ -18,6 +18,8 @@ class NzNoiseBase void SetNewSeed(int seed); int GetUniformRandomValue(); void ShufflePermutationTable(); + int fastfloor(float n); + int JenkinsHash(int a, int b, int c); protected: int perm[512]; private: diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp index fa3a60ea1..751c186c7 100644 --- a/include/Nazara/Noise/NoiseMachine.hpp +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -16,7 +16,8 @@ //TODO : tableau de gradients en float au lieu de int ? Ou condition ternaires ? // utiliser fastfloor partout -// vérifier bon fonctionnement perlin1d +// utiliser copies paramètres pour économiser mémoire +// améliorer le mélange de la table de perm class NzNoiseMachine : public NzNoiseBase { @@ -24,7 +25,6 @@ class NzNoiseMachine : public NzNoiseBase NzNoiseMachine(int seed = 0); ~NzNoiseMachine(); - float Get1DPerlinNoiseValue (float x, float res); float Get2DPerlinNoiseValue (float x, float y, float res); float Get3DPerlinNoiseValue (float x, float y, float z, float res); float Get4DPerlinNoiseValue (float x, float y, float z, float w, float res); @@ -42,7 +42,6 @@ class NzNoiseMachine : public NzNoiseBase void SetOctavesNumber(float octaves); void RecomputeExponentArray(); - float Get1DFBMNoiseValue(float x, float res); float Get2DFBMNoiseValue(float x, float y, float res); float Get3DFBMNoiseValue(float x, float y, float z, float res); @@ -52,10 +51,6 @@ class NzNoiseMachine : public NzNoiseBase protected: private: - //Pour tronquer les nombres - int fastfloor(float n); - - int gradient1[2]; float gradient2[8][2]; int gradient3[16][3]; int gradient4[32][4]; @@ -65,15 +60,13 @@ class NzNoiseMachine : public NzNoiseBase float n1, n2, n3, n4, n5; NzVector4f A; - NzVector4i Origin; NzVector4f d1,d2,d3,d4,d5; - NzVector4i off1, off2,off3; NzVector4f IsoOriginDist; - NzVector4f H[5]; + NzVector4i Origin; + NzVector4i off1, off2,off3; int ii,jj,kk,ll; int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; - float lenght; float c1,c2,c3,c4,c5,c6; int c; diff --git a/include/Nazara/Noise/Perlin1D.hpp b/include/Nazara/Noise/Perlin1D.hpp deleted file mode 100644 index 533ccc0a7..000000000 --- a/include/Nazara/Noise/Perlin1D.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef PERLIN1D_H -#define PERLIN1D_H - -#include -//#include -#include "NoiseBase.hpp" - -template class NzPerlin1D : public NzNoiseBase -{ - public: - NzPerlin1D(); - T GetValue(T x, T res); - ~NzPerlin1D() = default; - protected: - private: - int x0; - int gi0,gi1; - int ii; - int gradient1[16]; - T s,t; - T Cx; - T nx; - T tmp; -}; - -typedef NzPerlin1D NzPerlin1Df; -typedef NzPerlin1D NzPerlin1Dd; - -//#include -#include "Perlin1D.inl" - -#endif // PERLIN1D_H diff --git a/include/Nazara/Noise/Perlin1D.inl b/include/Nazara/Noise/Perlin1D.inl deleted file mode 100644 index 75b5c524e..000000000 --- a/include/Nazara/Noise/Perlin1D.inl +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -//#include -//#include -//#include -#include - -template -NzPerlin1D::NzPerlin1D() -{ - gradient1[0] = 1; - gradient1[1] = -1; -} - -template -T NzPerlin1D::GetValue(T x, T res) -{ - nx = x/res; - x0 = static_cast(nx); - ii = x0 & 255; - - gi0 = perm[ii] % 2; - gi1 = perm[ii + 1] % 2; - - tmp = nx-x0; - s = gradient1[gi0]*tmp; - - tmp = nx-(x0+1); - t = gradient1[gi1]*tmp; - - tmp = nx-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - - return s + Cx*(t-s); -} diff --git a/include/Nazara/Noise/Perlin2D.hpp b/include/Nazara/Noise/Perlin2D.hpp index 1633c10fb..6b693fa23 100644 --- a/include/Nazara/Noise/Perlin2D.hpp +++ b/include/Nazara/Noise/Perlin2D.hpp @@ -8,7 +8,8 @@ #define PERLIN2D_H #include -#include +//#include +#include "NoiseBase.hpp" #include template class NzPerlin2D : public NzNoiseBase @@ -34,7 +35,8 @@ template class NzPerlin2D : public NzNoiseBase typedef NzPerlin2D NzPerlin2Df; typedef NzPerlin2D NzPerlin2Dd; -#include +//#include +#include "Perlin2D.inl" #endif // PERLIN2D_H diff --git a/include/Nazara/Noise/Perlin2D.inl b/include/Nazara/Noise/Perlin2D.inl index df06d2679..2d84517fb 100644 --- a/include/Nazara/Noise/Perlin2D.inl +++ b/include/Nazara/Noise/Perlin2D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#include -#include +//#include +//#include +//#include template NzPerlin2D::NzPerlin2D() diff --git a/include/Nazara/Noise/Perlin3D.hpp b/include/Nazara/Noise/Perlin3D.hpp index ca01b891d..74eb53557 100644 --- a/include/Nazara/Noise/Perlin3D.hpp +++ b/include/Nazara/Noise/Perlin3D.hpp @@ -8,7 +8,8 @@ #define PERLIN3D_H #include -#include +//#include +#include "NoiseBase.hpp" #include template class NzPerlin3D : public NzNoiseBase @@ -35,6 +36,7 @@ template class NzPerlin3D : public NzNoiseBase typedef NzPerlin3D NzPerlin3Df; typedef NzPerlin3D NzPerlin3Dd; -#include +//#include +#include "Perlin3D.inl" #endif // PERLIN3D_H diff --git a/include/Nazara/Noise/Perlin3D.inl b/include/Nazara/Noise/Perlin3D.inl index 8bf832dfe..99f3334e9 100644 --- a/include/Nazara/Noise/Perlin3D.inl +++ b/include/Nazara/Noise/Perlin3D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#include -#include +//#include +//#include +//#include template NzPerlin3D::NzPerlin3D() diff --git a/include/Nazara/Noise/Perlin4D.hpp b/include/Nazara/Noise/Perlin4D.hpp index c0af6feb1..897e3250e 100644 --- a/include/Nazara/Noise/Perlin4D.hpp +++ b/include/Nazara/Noise/Perlin4D.hpp @@ -8,7 +8,8 @@ #define PERLIN4D_H #include -#include +//#include +#include "NoiseBase.hpp" #include template class NzPerlin4D : public NzNoiseBase @@ -35,6 +36,7 @@ template class NzPerlin4D : public NzNoiseBase typedef NzPerlin4D NzPerlin4Df; typedef NzPerlin4D NzPerlin4Dd; -#include +//#include +#include "Perlin4D.inl" #endif // PERLIN4D_H diff --git a/include/Nazara/Noise/Perlin4D.inl b/include/Nazara/Noise/Perlin4D.inl index 4b51c127d..5df9b6a43 100644 --- a/include/Nazara/Noise/Perlin4D.inl +++ b/include/Nazara/Noise/Perlin4D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#include -#include +//#include +//#include +//#include template NzPerlin4D::NzPerlin4D() diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp index 79434b471..8d2221c09 100644 --- a/include/Nazara/Noise/Simplex2D.hpp +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -8,7 +8,8 @@ #define SIMPLEX2D_H #include -#include +//#include +#include "NoiseBase.hpp" #include @@ -37,7 +38,8 @@ template class NzSimplex2D : public NzNoiseBase typedef NzSimplex2D NzSimplex2Df; typedef NzSimplex2D NzSimplex2Dd; -#include +//#include +#include "Simplex2D.inl" #endif // SIMPLEX2D_H diff --git a/include/Nazara/Noise/Simplex2D.inl b/include/Nazara/Noise/Simplex2D.inl index 129501617..1b3ac9311 100644 --- a/include/Nazara/Noise/Simplex2D.inl +++ b/include/Nazara/Noise/Simplex2D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#include -#include +//#include +//#include +//#include template NzSimplex2D::NzSimplex2D() diff --git a/src/Nazara/DynaTerrain/Debug/Leaks.cpp b/src/Nazara/DynaTerrain/Debug/Leaks.cpp new file mode 100644 index 000000000..13e396e67 --- /dev/null +++ b/src/Nazara/DynaTerrain/Debug/Leaks.cpp @@ -0,0 +1,29 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) +#include +#include + +void* operator new(std::size_t size) throw(std::bad_alloc) +{ + return NzMemoryManager::Allocate(size, false); +} + +void* operator new[](std::size_t size) throw(std::bad_alloc) +{ + return NzMemoryManager::Allocate(size, true); +} + +void operator delete(void* pointer) throw() +{ + NzMemoryManager::Free(pointer, false); +} + +void operator delete[](void* pointer) throw() +{ + NzMemoryManager::Free(pointer, true); +} +#endif diff --git a/src/Nazara/DynaTerrain/DynaTerrain.cpp b/src/Nazara/DynaTerrain/DynaTerrain.cpp new file mode 100644 index 000000000..f6cbd4530 --- /dev/null +++ b/src/Nazara/DynaTerrain/DynaTerrain.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2012 AUTHORS +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +NzModuleName::NzModuleName() +{ +} + +NzModuleName::~NzModuleName() +{ + if (s_initialized) + Uninitialize(); +} + +bool NzModuleName::Initialize() +{ + #if NAZARA_MODULENAME_SAFE + if (s_initialized) + { + NazaraError("ModuleName already initialized"); + return true; + } + #endif + + // Initialisation du module + + s_initialized = true; + + return true; +} + +void NzModuleName::Uninitialize() +{ + #if NAZARA_MODULENAME_SAFE + if (!s_initialized) + { + NazaraError("ModuleName not initialized"); + return; + } + #endif + + // Libération du module + + s_initialized = false; +} + +bool NzModuleName::IsInitialized() +{ + return s_initialized; +} + +bool NzModuleName::s_initialized = false; diff --git a/src/Nazara/DynaTerrain/Node.cpp b/src/Nazara/DynaTerrain/Node.cpp new file mode 100644 index 000000000..4b479dde0 --- /dev/null +++ b/src/Nazara/DynaTerrain/Node.cpp @@ -0,0 +1,317 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include "Node.hpp" +#include "QuadTree.hpp" +#include +//#include +//#include +//#include +//#include + + +NzNode::NzNode(NzQuadTree* quad, NzNode* parent, const NzVector2f& center, const NzVector2f& size, nzDirection dir) +{ + m_direction = dir; + m_center = center; + m_size = size; + m_isLeaf = false; + m_patchMemoryAllocated = false; + + m_associatedQuadTree = quad; + + m_topLeftLeaf = nullptr; + m_topRightLeaf = nullptr; + m_bottomLeftLeaf = nullptr; + m_bottomRightLeaf = nullptr; + + if(parent == 0) + { + m_isRoot = true; + m_level = 0; + } + else + { + m_level = parent->GetLevel()+1; + m_parent = parent; + m_isRoot = false; + } +} + +NzNode::~NzNode() +{ + if(m_isLeaf) + m_associatedQuadTree->UnRegisterLeaf(this); + if(m_patchMemoryAllocated) + delete m_patch; +} + +void NzNode::Subdivide() +{ + m_isLeaf = false; + m_associatedQuadTree->UnRegisterLeaf(this); + + if(m_topLeftLeaf == nullptr) + { + m_topLeftLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x-m_size.x/2.f, + m_center.y+m_size.y/2.f),m_size/2.f,TOPLEFT); + m_topLeftLeaf->m_isLeaf = true; + m_associatedQuadTree->RegisterLeaf(m_topLeftLeaf); + } + if(m_topRightLeaf == nullptr) + { + m_topRightLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x+m_size.x/2.f, + m_center.y+m_size.y/2.f),m_size/2.f,TOPRIGHT); + m_topRightLeaf->m_isLeaf = true; + m_associatedQuadTree->RegisterLeaf(m_topRightLeaf); + } + if(m_bottomLeftLeaf = nullptr) + { + m_bottomLeftLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x-m_size.x/2.f, + m_center.y-m_size.y/2.f),m_size/2.f,BOTTOMLEFT); + m_bottomLeftLeaf->m_isLeaf = true; + m_associatedQuadTree->RegisterLeaf(m_bottomLeftLeaf); + } + if(m_bottomRightLeaf = nullptr) + { + m_bottomRightLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x+m_size.x/2.f, + m_center.y-m_size.y/2.f),m_size/2.f,BOTTOMRIGHT); + m_bottomRightLeaf->m_isLeaf = true; + m_associatedQuadTree->RegisterLeaf(m_bottomRightLeaf); + } + + +} + +void NzNode::Refine(bool eraseMemory) +{ + m_isLeaf = true; + m_associatedQuadTree->RegisterLeaf(this); + if(eraseMemory) + { + /* + delete m_topLeftLeaf; + delete m_topRightLeaf; + delete m_bottomLeftLeaf; + delete m_bottomRightLeaf; + + m_topLeftLeaf = nullptr; + m_topRightLeaf = nullptr; + m_bottomLeftLeaf = nullptr; + m_bottomRightLeaf = nullptr;*/ + + m_topLeftLeaf->DeletePatch(); + m_topRightLeaf->DeletePatch(); + m_bottomLeftLeaf->DeletePatch(); + m_bottomRightLeaf->DeletePatch(); + } + //else + //{ + m_topLeftLeaf->m_isLeaf = false; + m_topRightLeaf->m_isLeaf = false; + m_bottomLeftLeaf->m_isLeaf = false; + m_bottomRightLeaf->m_isLeaf = false; + + m_associatedQuadTree->UnRegisterLeaf(m_topLeftLeaf); + m_associatedQuadTree->UnRegisterLeaf(m_topRightLeaf); + m_associatedQuadTree->UnRegisterLeaf(m_bottomLeftLeaf); + m_associatedQuadTree->UnRegisterLeaf(m_bottomRightLeaf); + //} + +} + +void NzNode::CreatePatch(const NzVector2f& center, const NzVector2f& size) +{ + m_patchMemoryAllocated = true; + m_patch = new NzPatch(center,size); +} + +void NzNode::DeletePatch() +{ + m_patchMemoryAllocated = false; + delete m_patch; +} + +unsigned short int NzNode::GetLevel() const +{ + return m_level; +} + +bool NzNode::LocateNeighbor(nzDirection dir, NzNode* neighbor) +{ + NzNode* temp = m_parent; + std::stack treePath; + treePath.push(m_direction); + neighbor = nullptr; + + switch(dir) + { + case TOP: + //Part 1 + while(temp->m_direction != (BOTTOMLEFT || BOTTOMRIGHT || CENTER)) + { + treePath.push(temp->m_direction); + temp = temp->m_parent; + } + + //Part 2 + if(temp->m_direction == BOTTOMLEFT) + temp = temp->m_parent->m_topLeftLeaf; + else if(temp->m_direction == BOTTOMRIGHT) + temp = temp->m_parent->m_topRightLeaf; + else if(temp->m_direction == CENTER) + return false;//No Neighbor existing + + //Part 3 + while(!temp->IsLeaf()) + { + if(treePath.empty()) + { + //Le chemin de redescente est plus court que celui de montée (level[node départ] < level[node d'arrivée]) + break; + } + else + { + if(treePath.top() == TOPRIGHT) + temp = temp->m_bottomRightLeaf; + else if(treePath.top() == TOPLEFT) + temp = temp->m_bottomLeftLeaf; + else//D'uh ? + { + //Logger une erreur + return false; + } + treePath.pop(); + } + } + neighbor = temp; + return true; + break; + + case BOTTOM: + //Part 1 + while(temp->m_direction != (TOPLEFT || TOPRIGHT || CENTER)) + { + treePath.push(temp->m_direction); + temp = temp->m_parent; + } + + //Part 2 + if(temp->m_direction == TOPLEFT) + temp = temp->m_parent->m_bottomLeftLeaf; + else if(temp->m_direction == TOPRIGHT) + temp = temp->m_parent->m_bottomRightLeaf; + else if(temp->m_direction == CENTER) + return false;//No Neighbor existing + + //Part 3 + while(!temp->IsLeaf()) + { + if(treePath.empty()) + { + //Le chemin de redescente est plus court que celui de montée (level[node départ] < level[node d'arrivée]) + break; + } + else + { + if(treePath.top() == BOTTOMRIGHT) + temp = temp->m_topRightLeaf; + else if(treePath.top() == BOTTOMLEFT) + temp = temp->m_topLeftLeaf; + else//D'uh ? + { + //Logger une erreur + return false; + } + treePath.pop(); + } + } + neighbor = temp; + return true; + break; + + case LEFT: + //Part 1 + while(temp->m_direction != (TOPRIGHT || BOTTOMRIGHT || CENTER)) + { + treePath.push(temp->m_direction); + temp = temp->m_parent; + } + + //Part 2 + if(temp->m_direction == TOPRIGHT) + temp = temp->m_parent->m_topLeftLeaf; + else if(temp->m_direction == BOTTOMRIGHT) + temp = temp->m_parent->m_bottomLeftLeaf; + else if(temp->m_direction == CENTER) + return false;//No Neighbor existing + + //Part 3 + while(!temp->IsLeaf()) + { + if(treePath.top() == TOPLEFT) + temp = temp->m_topRightLeaf; + else if(treePath.top() == BOTTOMLEFT) + temp = temp->m_bottomRightLeaf; + else//D'uh ? + { + //Logger une erreur + return false; + } + treePath.pop(); + } + neighbor = temp; + return true; + break; + + case RIGHT: + //Part 1 + while(temp->m_direction != (TOPLEFT || BOTTOMLEFT || CENTER)) + { + treePath.push(temp->m_direction); + temp = temp->m_parent; + } + + //Part 2 + if(temp->m_direction == TOPLEFT) + temp = temp->m_parent->m_topRightLeaf; + else if(temp->m_direction == BOTTOMLEFT) + temp = temp->m_parent->m_bottomRightLeaf; + else if(temp->m_direction == CENTER) + return false;//No Neighbor existing + + //Part 3 + while(!temp->IsLeaf()) + { + if(treePath.top() == TOPRIGHT) + temp = temp->m_topLeftLeaf; + else if(treePath.top() == BOTTOMRIGHT) + temp = temp->m_bottomLeftLeaf; + else//D'uh ? + { + //Logger une erreur + return false; + } + treePath.pop(); + } + neighbor = temp; + return true; + break; + + default : + return false; + break; + } +} + +bool NzNode::IsLeaf() const +{ + return m_isLeaf; +} + +bool NzNode::IsRoot() const +{ + return m_isRoot; +} + diff --git a/src/Nazara/DynaTerrain/Patch.cpp b/src/Nazara/DynaTerrain/Patch.cpp new file mode 100644 index 000000000..305bd479a --- /dev/null +++ b/src/Nazara/DynaTerrain/Patch.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include "Patch.hpp" +//#include +//#include +//#include +//#include + + + +NzPatch::NzPatch(NzVector2f center, NzVector2f size) +{ + m_center = center; + m_size = size; +} + +NzPatch::~NzPatch() +{ + //dtor +} + +NzVector2f NzPatch::GetCenter() const +{ + +} + +NzVector2f NzPatch::GetSize() const +{ + +} + +bool NzPatch::IntersectsCircle(const NzVector2f& center, double radius) +{ + +} + +bool NzPatch::IsContainedByCircle(const NzVector2f& center, double radius) +{ + +} + +NzPatch* NzPatch::LocatePatch(const NzVector2f& position) +{ + +} diff --git a/src/Nazara/DynaTerrain/QuadTree.cpp b/src/Nazara/DynaTerrain/QuadTree.cpp new file mode 100644 index 000000000..03f0d8d09 --- /dev/null +++ b/src/Nazara/DynaTerrain/QuadTree.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include "QuadTree.hpp" + +//#include +//#include +//#include +//#include + +NzQuadTree::NzQuadTree(const NzVector2f& terrainCenter, const NzVector2f& terrainSize) +{ + root = new NzNode(this,0,terrainCenter,terrainSize); +} + +void NzQuadTree::RegisterLeaf(NzNode* node) +{ + leaves.push_back(node); +} + +bool NzQuadTree::UnRegisterLeaf(NzNode* node) +{ + leaves.remove(node); +} + +NzNode* NzQuadTree::GetRootPtr() +{ + return root; +} + +NzQuadTree::~NzQuadTree() +{ + //dtor +} + diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp index 151fdc0ed..c72266759 100644 --- a/src/Nazara/Noise/Noise.cpp +++ b/src/Nazara/Noise/Noise.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi{dot}beges{at}gmail{dot}com) +// Copyright (C) 2012 AUTHORS // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/src/Nazara/Noise/NoiseBase.cpp b/src/Nazara/Noise/NoiseBase.cpp index 940a3ecf8..f864ad6ac 100644 --- a/src/Nazara/Noise/NoiseBase.cpp +++ b/src/Nazara/Noise/NoiseBase.cpp @@ -54,6 +54,42 @@ void NzNoiseBase::ShufflePermutationTable() perm[i] = perm[i & 255]; } +int NzNoiseBase::fastfloor(float n) +{ + if(n >= 0) + return static_cast(n); + else + return static_cast(n-1); +} + +int NzNoiseBase::JenkinsHash(int a, int b, int c) +{ + a = a-b; a = a - c; a = a^(static_cast(c) >> 13); + b = b-c; b = b - a; b = b^(a << 8); + c = c-a; c = c - b; c = c^(static_cast(b) >> 13); + a = a-b; a = a - c; a = a^(static_cast(c) >> 12); + b = b-c; b = b - a; b = b^(a << 16); + c = c-a; c = c - b; c = c^(static_cast(b) >> 5); + a = a-b; a = a - c; a = a^(static_cast(c) >> 3); + b = b-c; b = b - a; b = b^(a << 10); + c = c-a; c = c - b; c = c^(static_cast(b) >> 15); + return c; +} + +/* +//key = 64 bits +public long hash64shift(long key) +{ + key = (~key) + (key << 21); // key = (key << 21) - key - 1; + key = key ^ (key >>> 24); + key = (key + (key << 3)) + (key << 8); // key * 265 + key = key ^ (key >>> 14); + key = (key + (key << 2)) + (key << 4); // key * 21 + key = key ^ (key >>> 28); + key = key + (key << 31); + return key; +}*/ + NzNoiseBase::~NzNoiseBase() { //dtor diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index 8a1e2e697..2b2b42fc5 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -35,9 +35,6 @@ NzNoiseMachine::NzNoiseMachine(int seed) for(int j(0) ; j < 4 ; ++j) lookupTable4D[i][j] = lookupTemp4D[i][j]; - gradient1[0] = 1; - gradient1[1] = -1; - float unit = 1.0/sqrt(2); float grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, {1,0},{-1,0},{0,1},{0,-1}}; @@ -87,29 +84,6 @@ NzNoiseMachine::~NzNoiseMachine() //------------------------------ PERLIN ------------------------------ -float NzNoiseMachine::Get1DPerlinNoiseValue(float x, float res) -{ - nx = x/res; - x0 = static_cast(nx); - ii = x0 & 255; - - gi0 = perm[ii] % 2; - gi1 = perm[ii + 1] % 2; - - temp.x = nx-x0; - - s[0] = gradient1[gi0]*temp.x; - - temp.x = nx-(x0+1); - - t[0] = gradient1[gi1]*temp.x; - - tmp = nx-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - - return s[0] + Cx*(t[0]-s[0]); -} - float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res) { nx = x/res; @@ -372,10 +346,10 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, //------------------------------ SIMPLEX ------------------------------ -float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution) +float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res) { - x /= resolution; - y /= resolution; + x /= res; + y /= res; Origin.x = fastfloor(x + (x + y) * SkewCoeff2D); @@ -410,28 +384,17 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution) ii = Origin.x & 255; jj = Origin.y & 255; - gi0 = perm[ii + perm[jj]] % 12; - gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 12; - gi2 = perm[ii + 1 + perm[jj + 1]] % 12; + gi0 = perm[ii + perm[jj]] % 8; + gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 8; + gi2 = perm[ii + 1 + perm[jj + 1]] % 8; - H[0].x = gradient3[gi0][0]; - H[0].y = gradient3[gi0][1]; + n1 = gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y; + n2 = gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y; + n3 = gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y; - H[1].x = gradient3[gi1][0]; - H[1].y = gradient3[gi1][1]; - - H[2].x = gradient3[gi2][0]; - H[2].y = gradient3[gi2][1]; - - n1 = H[0].x * d1.x + H[0].y * d1.y; - n2 = H[1].x * d2.x + H[1].y * d2.y; - n3 = H[2].x * d3.x + H[2].y * d3.y; - - lenght = 0.5; - - c1 = lenght - d1.x * d1.x - d1.y * d1.y; - c2 = lenght - d2.x * d2.x - d2.y * d2.y; - c3 = lenght - d3.x * d3.x - d3.y * d3.y; + c1 = 0.5 - d1.x * d1.x - d1.y * d1.y; + c2 = 0.5 - d2.x * d2.x - d2.y * d2.y; + c3 = 0.5 - d3.x * d3.x - d3.y * d3.y; if(c1 < 0) c1 = 0; @@ -447,11 +410,11 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution) return (n1+n2+n3)*23.2; } -float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float resolution) +float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float res) { - x /= resolution; - y /= resolution; - z /= resolution; + x /= res; + y /= res; + z /= res; Origin.x = fastfloor(x + (x + y + z) * SkewCoeff3D); Origin.y = fastfloor(y + (x + y + z) * SkewCoeff3D); @@ -556,12 +519,10 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re n3 = gradient3[gi2][0] * d3.x + gradient3[gi2][1] * d3.y + gradient3[gi2][2] * d3.z; n4 = gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z; - lenght = 0.6; - - c1 = lenght - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z; - c2 = lenght - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z; - c3 = lenght - d3.x * d3.x - d3.y * d3.y - d3.z * d3.z; - c4 = lenght - d4.x * d4.x - d4.y * d4.y - d4.z * d4.z; + c1 = 0.6 - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z; + c2 = 0.6 - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z; + c3 = 0.6 - d3.x * d3.x - d3.y * d3.y - d3.z * d3.z; + c4 = 0.6 - d4.x * d4.x - d4.y * d4.y - d4.z * d4.z; if(c1 < 0) c1 = 0; @@ -580,12 +541,12 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re return (n1+n2+n3+n4)*17.6995; } -float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, float resolution) +float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, float res) { - x /= resolution; - y /= resolution; - z /= resolution; - w /= resolution; + x /= res; + y /= res; + z /= res; + w /= res; Origin.x = fastfloor(x + (x + y + z + w) * SkewCoeff4D); Origin.y = fastfloor(y + (x + y + z + w) * SkewCoeff4D); @@ -667,13 +628,11 @@ float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, n4 = gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w; n5 = gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w; - lenght = 0.6; - - c1 = lenght - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; - c2 = lenght - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; - c3 = lenght - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w; - c4 = lenght - d4.x*d4.x - d4.y*d4.y - d4.z*d4.z - d4.w*d4.w; - c5 = lenght - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w; + c1 = 0.6 - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; + c2 = 0.6 - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; + c3 = 0.6 - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w; + c4 = 0.6 - d4.x*d4.x - d4.y*d4.y - d4.z*d4.z - d4.w*d4.w; + c5 = 0.6 - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w; if(c1 < 0) c1 = 0; @@ -712,7 +671,7 @@ float NzNoiseMachine::Get3DCellNoiseValue(float x, float y, float z, float res) y0 = static_cast(y); z0 = static_cast(z); - return 0; + return (this->JenkinsHash(x0,y0,z0) & 255); } float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, float res) { @@ -776,24 +735,6 @@ void NzNoiseMachine::RecomputeExponentArray() //------------------------------ FBM ------------------------------ -float NzNoiseMachine::Get1DFBMNoiseValue(float x, float res) -{ - value = 0.0; - RecomputeExponentArray(); - - for (int i(0); i < m_octaves; ++i) - { - value += Get1DPerlinNoiseValue(x,res) * exponent_array[i]; - x *= m_lacunarity; - } - remainder = m_octaves - (float)m_octaves; - - if(remainder != 0) - value += remainder * Get1DPerlinNoiseValue(x,res) * exponent_array[(int)m_octaves-1]; - - return value * m_sum; -} - float NzNoiseMachine::Get2DFBMNoiseValue(float x, float y, float res) { value = 0.0; @@ -908,11 +849,3 @@ float NzNoiseMachine::Get3DHybridMultiFractalNoiseValue(float x, float y, float return result; } - -int NzNoiseMachine::fastfloor(float n) -{ - if(n >= 0) - return static_cast(n); - else - return static_cast(n-1); -} From 5d7f8acbc8e9d1e2dc601b14feabadb7f3aee3d5 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Tue, 5 Jun 2012 22:00:09 +0200 Subject: [PATCH 09/13] Perlin 2,3,4 optimisations + Simplex imp fixed + improved architecture --- include/Nazara/Noise/ComplexNoiseBase.hpp | 36 +++ include/Nazara/Noise/Noise.hpp | 2 +- include/Nazara/Noise/NoiseBase.hpp | 1 + include/Nazara/Noise/NoiseMachine.hpp | 35 +-- include/Nazara/Noise/Perlin2D.hpp | 2 - include/Nazara/Noise/Perlin2D.inl | 38 ++- include/Nazara/Noise/Perlin3D.inl | 78 +++--- include/Nazara/Noise/Perlin4D.inl | 8 +- include/Nazara/Noise/Simplex2D.hpp | 4 +- include/Nazara/Noise/Simplex2D.inl | 59 +++-- src/Nazara/Noise/ComplexNoiseBase.cpp | 61 +++++ src/Nazara/Noise/Noise.cpp | 4 +- src/Nazara/Noise/NoiseBase.cpp | 7 +- src/Nazara/Noise/NoiseMachine.cpp | 289 ++++++++-------------- 14 files changed, 307 insertions(+), 317 deletions(-) create mode 100644 include/Nazara/Noise/ComplexNoiseBase.hpp create mode 100644 src/Nazara/Noise/ComplexNoiseBase.cpp diff --git a/include/Nazara/Noise/ComplexNoiseBase.hpp b/include/Nazara/Noise/ComplexNoiseBase.hpp new file mode 100644 index 000000000..e1f159e9f --- /dev/null +++ b/include/Nazara/Noise/ComplexNoiseBase.hpp @@ -0,0 +1,36 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef COMPLEXNOISEBASE_H +#define COMPLEXNOISEBASE_H + +#include +//#include +#include "NoiseBase.hpp" + +class NzComplexNoiseBase : public NzNoiseBase +{ + public: + NzComplexNoiseBase(); + ~NzComplexNoiseBase(); + + void SetLacunarity(float lacunarity); + void SetHurstParameter(float h); + void SetOctavesNumber(float octaves); + void RecomputeExponentArray(); + + protected: + float m_lacunarity; + float m_hurst; + float m_octaves; + float exponent_array[30]; + float m_sum; + private: + bool m_parametersModified; + +}; + +#endif // COMPLEXNOISEBASE_H diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp index c4925ac0a..61b062b5b 100644 --- a/include/Nazara/Noise/Noise.hpp +++ b/include/Nazara/Noise/Noise.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 AUTHORS +// Copyright (C) 2012 Rémi Bèges // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp index 0bd37ab47..06f0d37ca 100644 --- a/include/Nazara/Noise/NoiseBase.hpp +++ b/include/Nazara/Noise/NoiseBase.hpp @@ -18,6 +18,7 @@ class NzNoiseBase void SetNewSeed(int seed); int GetUniformRandomValue(); void ShufflePermutationTable(); + int fastfloor(float n); int JenkinsHash(int a, int b, int c); protected: diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp index 751c186c7..3be3cebe9 100644 --- a/include/Nazara/Noise/NoiseMachine.hpp +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -8,22 +8,20 @@ #define NOISEMACHINE_HPP #include -//#include -#include "NoiseBase.hpp" +//#include +#include "ComplexNoiseBase.hpp" #include #include #include -//TODO : tableau de gradients en float au lieu de int ? Ou condition ternaires ? -// utiliser fastfloor partout -// utiliser copies paramètres pour économiser mémoire -// améliorer le mélange de la table de perm +//TODO : AMELIORER MELANGE TABLE PERMUTATION +// PB MULTIPLES APPELS SHUFFLEPERMUTATIONTABLE() -class NzNoiseMachine : public NzNoiseBase +class NzNoiseMachine : public NzComplexNoiseBase { public: NzNoiseMachine(int seed = 0); - ~NzNoiseMachine(); + ~NzNoiseMachine() = default; float Get2DPerlinNoiseValue (float x, float y, float res); float Get3DPerlinNoiseValue (float x, float y, float z, float res); @@ -37,11 +35,6 @@ class NzNoiseMachine : public NzNoiseBase float Get3DCellNoiseValue(float x, float y, float z, float res); float Get4DCellNoiseValue(float x, float y, float z, float w, float res); - void SetLacunarity(float lacunarity); - void SetHurstParameter(float h); - void SetOctavesNumber(float octaves); - void RecomputeExponentArray(); - float Get2DFBMNoiseValue(float x, float y, float res); float Get3DFBMNoiseValue(float x, float y, float z, float res); @@ -59,11 +52,11 @@ class NzNoiseMachine : public NzNoiseBase //----------------------- Simplex variables -------------------------------------- float n1, n2, n3, n4, n5; - NzVector4f A; - NzVector4f d1,d2,d3,d4,d5; - NzVector4f IsoOriginDist; + NzVector4f d1,d2,d3,d4,d5,unskewedCubeOrigin,unskewedDistToOrigin; + NzVector4i off1, off2,off3,skewedCubeOrigin; + + NzVector4f A,IsoOriginDist; NzVector4i Origin; - NzVector4i off1, off2,off3; int ii,jj,kk,ll; int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; @@ -86,20 +79,14 @@ class NzNoiseMachine : public NzNoiseBase float s[4],t[4],u[4],v[4]; float Cx, Cy, Cz, Cw; NzVector4f temp; - float nx,ny,nz,nw; float tmp; //---------------------- Complex Noise Variables -------------------------------- - float m_lacunarity; - float m_hurst; - float m_octaves; - bool m_parametersModified; - float exponent_array[30]; + bool first; float value; float remainder; - float m_sum; float smax; float smin; diff --git a/include/Nazara/Noise/Perlin2D.hpp b/include/Nazara/Noise/Perlin2D.hpp index 6b693fa23..614d7e6a1 100644 --- a/include/Nazara/Noise/Perlin2D.hpp +++ b/include/Nazara/Noise/Perlin2D.hpp @@ -27,8 +27,6 @@ template class NzPerlin2D : public NzNoiseBase T s,t,u,v; T Cx,Cy; T Li1, Li2; - T nx, ny; - T tmp; NzVector2 temp; }; diff --git a/include/Nazara/Noise/Perlin2D.inl b/include/Nazara/Noise/Perlin2D.inl index 2d84517fb..2225eb024 100644 --- a/include/Nazara/Noise/Perlin2D.inl +++ b/include/Nazara/Noise/Perlin2D.inl @@ -9,9 +9,8 @@ template NzPerlin2D::NzPerlin2D() { - T unit = 1.0/sqrt(2); - T grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, - {1,0},{-1,0},{0,1},{0,-1}}; + T grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1}, + {1,0},{-1,0},{0,1},{0,-1}}; for(int i(0) ; i < 8 ; ++i) for(int j(0) ; j < 2 ; ++j) @@ -21,11 +20,11 @@ NzPerlin2D::NzPerlin2D() template T NzPerlin2D::GetValue(T x, T y, T res) { - nx = x/res; - ny = y/res; + x /= res; + y /= res; - x0 = static_cast(nx); - y0 = static_cast(ny); + x0 = fastfloor(x); + y0 = fastfloor(y); ii = x0 & 255; jj = y0 & 255; @@ -35,31 +34,26 @@ T NzPerlin2D::GetValue(T x, T y, T res) gi2 = perm[ii + perm[jj + 1]] & 7; gi3 = perm[ii + 1 + perm[jj + 1]] & 7; - temp.x = nx-x0; - temp.y = ny-y0; + temp.x = x-x0; + temp.y = y-y0; + + Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10); + Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10); + s = gradient2[gi0][0]*temp.x + gradient2[gi0][1]*temp.y; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t = gradient2[gi1][0]*temp.x + gradient2[gi1][1]*temp.y; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y; - - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.y = y-(y0+1); v = gradient2[gi3][0]*temp.x + gradient2[gi3][1]*temp.y; - tmp = nx-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + temp.x = x-x0; + u = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y; Li1 = s + Cx*(t-s); Li2 = u + Cx*(v-u); - tmp = ny - y0; - Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - return Li1 + Cy*(Li2-Li1); } diff --git a/include/Nazara/Noise/Perlin3D.inl b/include/Nazara/Noise/Perlin3D.inl index 99f3334e9..8e30f5a69 100644 --- a/include/Nazara/Noise/Perlin3D.inl +++ b/include/Nazara/Noise/Perlin3D.inl @@ -24,78 +24,68 @@ NzPerlin3D::NzPerlin3D() template T NzPerlin3D::GetValue(T x, T y, T z, T res) { - nx = x/res; - ny = y/res; - nz = z/res; + x /= res; + y /= res; + z /= res; - x0 = static_cast(nx); - y0 = static_cast(ny); - z0 = static_cast(nz); + x0 = fastfloor(x); + y0 = fastfloor(y); + z0 = fastfloor(z); ii = x0 & 255; jj = y0 & 255; kk = z0 & 255; - gi0 = perm[ii + perm[jj + perm[kk]]] % 16; - gi1 = perm[ii + 1 + perm[jj + perm[kk]]] % 16; - gi2 = perm[ii + perm[jj + 1 + perm[kk]]] % 16; - gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] % 16; + gi0 = perm[ii + perm[jj + perm[kk]]] & 15; + gi1 = perm[ii + 1 + perm[jj + perm[kk]]] & 15; + gi2 = perm[ii + perm[jj + 1 + perm[kk]]] & 15; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] & 15; - gi4 = perm[ii + perm[jj + perm[kk + 1]]] % 16; - gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] % 16; - gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] % 16; - gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 16; + gi4 = perm[ii + perm[jj + perm[kk + 1]]] & 15; + gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] & 15; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] & 15; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] & 15; + + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-z0; + + Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10); + Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10); + Cz = temp.z * temp.z * temp.z * (temp.z * (temp.z * 6 - 15) + 10); - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-z0; s[0] = gradient3[gi0][0]*temp.x + gradient3[gi0][1]*temp.y + gradient3[gi0][2]*temp.z; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[0] = gradient3[gi1][0]*temp.x + gradient3[gi1][1]*temp.y + gradient3[gi1][2]*temp.z; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; - - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.y = y-(y0+1); v[0] = gradient3[gi3][0]*temp.x + gradient3[gi3][1]*temp.y + gradient3[gi3][2]*temp.z; - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-(z0+1); + temp.x = x-x0; + u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; + + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-(z0+1); s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z; - - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.y = y-(y0+1); v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z; - tmp = nx-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + temp.x = x-x0; + u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z; Li1 = s[0] + Cx*(t[0]-s[0]); Li2 = u[0] + Cx*(v[0]-u[0]); Li3 = s[1] + Cx*(t[1]-s[1]); Li4 = u[1] + Cx*(v[1]-u[1]); - tmp = ny-y0; - Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - Li5 = Li1 + Cy*(Li2-Li1); Li6 = Li3 + Cy*(Li4-Li3); - tmp = nz-z0; - Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - return Li5 + Cz*(Li6-Li5); } diff --git a/include/Nazara/Noise/Perlin4D.inl b/include/Nazara/Noise/Perlin4D.inl index 5df9b6a43..2ad741d8d 100644 --- a/include/Nazara/Noise/Perlin4D.inl +++ b/include/Nazara/Noise/Perlin4D.inl @@ -34,10 +34,10 @@ T NzPerlin4D::GetValue(T x, T y, T z, T w, T res) nz = z/res; nw = w/res; - x0 = static_cast(nx); - y0 = static_cast(ny); - z0 = static_cast(nz); - w0 = static_cast(nw); + x0 = fastfloor(nx); + y0 = fastfloor(ny); + z0 = fastfloor(nz); + w0 = fastfloor(nw); ii = x0 & 255; jj = y0 & 255; diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp index 8d2221c09..e292587df 100644 --- a/include/Nazara/Noise/Simplex2D.hpp +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -23,13 +23,13 @@ template class NzSimplex2D : public NzNoiseBase private: int ii,jj; int gi0,gi1,gi2; - NzVector2i Origin,off1; + NzVector2i skewedCubeOrigin,off1; T n1,n2,n3; T c1,c2,c3; T gradient2[8][2]; T UnskewCoeff2D; T SkewCoeff2D; - NzVector2 A, IsoOriginDist; + NzVector2 unskewedCubeOrigin, unskewedDistToOrigin; NzVector2 d1,d2,d3; diff --git a/include/Nazara/Noise/Simplex2D.inl b/include/Nazara/Noise/Simplex2D.inl index 1b3ac9311..3479c13f3 100644 --- a/include/Nazara/Noise/Simplex2D.inl +++ b/include/Nazara/Noise/Simplex2D.inl @@ -9,10 +9,8 @@ template NzSimplex2D::NzSimplex2D() { - - T unit = 1.0/sqrt(2); - T grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, - {1,0},{-1,0},{0,1},{0,-1}}; + T grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1}, + {1,0},{-1,0},{0,1},{0,-1}}; for(int i(0) ; i < 8 ; ++i) for(int j(0) ; j < 2 ; ++j) @@ -28,16 +26,16 @@ T NzSimplex2D::GetValue(T x, T y, T res) x /= res; y /= res; - Origin.x = fastfloor(x + (x + y) * SkewCoeff2D); - Origin.y = fastfloor(y + (x + y) * SkewCoeff2D); + skewedCubeOrigin.x = fastfloor(x + (x + y) * SkewCoeff2D); + skewedCubeOrigin.y = fastfloor(y + (x + y) * SkewCoeff2D); - A.x = Origin.x - (Origin.x + Origin.y) * UnskewCoeff2D; - A.y = Origin.y - (Origin.x + Origin.y) * UnskewCoeff2D; + unskewedCubeOrigin.x = skewedCubeOrigin.x - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; + unskewedCubeOrigin.y = skewedCubeOrigin.y - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; - IsoOriginDist.x = x - A.x; - IsoOriginDist.y = y - A.y; + unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; + unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; - if(IsoOriginDist.x > IsoOriginDist.y) + if(unskewedDistToOrigin.x > unskewedDistToOrigin.y) { off1.x = 1; off1.y = 0; @@ -48,8 +46,9 @@ T NzSimplex2D::GetValue(T x, T y, T res) off1.y = 1; } - d1.x = A.x - x; - d1.y = A.y - y; + + d1.x = unskewedCubeOrigin.x - x; + d1.y = unskewedCubeOrigin.y - y; d2.x = d1.x + off1.x - UnskewCoeff2D; d2.y = d1.y + off1.y - UnskewCoeff2D; @@ -57,32 +56,32 @@ T NzSimplex2D::GetValue(T x, T y, T res) d3.x = d1.x + 1.0 - 2 * UnskewCoeff2D; d3.y = d1.y + 1.0 - 2 * UnskewCoeff2D; - ii = Origin.x & 255; - jj = Origin.y & 255; + ii = skewedCubeOrigin.x & 255; + jj = skewedCubeOrigin.y & 255; - gi0 = perm[ii + perm[jj]] % 8; - gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 8; - gi2 = perm[ii + 1 + perm[jj + 1]] % 8; - - n1 = gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y; - n2 = gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y; - n3 = gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y; + gi0 = perm[ii + perm[jj]] & 7; + gi1 = perm[ii + off1.x + perm[jj + off1.y]] & 7; + gi2 = perm[ii + 1 + perm[jj + 1]] & 7; c1 = 0.5 - d1.x * d1.x - d1.y * d1.y; c2 = 0.5 - d2.x * d2.x - d2.y * d2.y; c3 = 0.5 - d3.x * d3.x - d3.y * d3.y; if(c1 < 0) - c1 = 0; + n1 = 0; + else + n1 = c1*c1*c1*c1*(gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y); + if(c2 < 0) - c2 = 0; + n2 = 0; + else + n2 = c2*c2*c2*c2*(gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y); + if(c3 < 0) - c3 = 0; + n3 = 0; + else + n3 = c3*c3*c3*c3*(gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y); - n1 = c1*c1*c1*n1; - n2 = c2*c2*c2*n2; - n3 = c3*c3*c3*n3; - - return (n1+n2+n3)*23.2; + return (n1+n2+n3)*70; } diff --git a/src/Nazara/Noise/ComplexNoiseBase.cpp b/src/Nazara/Noise/ComplexNoiseBase.cpp new file mode 100644 index 000000000..cd0288c3d --- /dev/null +++ b/src/Nazara/Noise/ComplexNoiseBase.cpp @@ -0,0 +1,61 @@ +#include "ComplexNoiseBase.hpp" +#include + +NzComplexNoiseBase::NzComplexNoiseBase() +{ + m_parametersModified = true; + m_lacunarity = 5.0f; + m_hurst = 1.2f; + m_octaves = 3.0f; +} + +void NzComplexNoiseBase::SetLacunarity(float lacunarity) +{ + if(lacunarity != m_lacunarity) + { + m_lacunarity = lacunarity; + m_parametersModified = true; + } +} + +void NzComplexNoiseBase::SetHurstParameter(float h) +{ + if(h != m_hurst) + { + m_hurst = h; + m_parametersModified = true; + } +} + +void NzComplexNoiseBase::SetOctavesNumber(float octaves) +{ + if(octaves != m_octaves && octaves < 30) + { + m_octaves = octaves; + m_parametersModified = true; + } +} + +void NzComplexNoiseBase::RecomputeExponentArray() +{ + if(m_parametersModified) + { + float frequency = 1.0; + m_sum = 0.f; + for (int i(0) ; i < m_octaves; ++i) + { + exponent_array[i] = std::pow( frequency, -m_hurst ); + frequency *= m_lacunarity; + + m_sum += exponent_array[i]; + + } + m_parametersModified = false; + } +} + + +NzComplexNoiseBase::~NzComplexNoiseBase() +{ + //dtor +} diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp index c72266759..06c7c13af 100644 --- a/src/Nazara/Noise/Noise.cpp +++ b/src/Nazara/Noise/Noise.cpp @@ -1,9 +1,9 @@ -// Copyright (C) 2012 AUTHORS +// Copyright (C) 2012 Rémi Bèges // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include +#include #include #include diff --git a/src/Nazara/Noise/NoiseBase.cpp b/src/Nazara/Noise/NoiseBase.cpp index f864ad6ac..2f9b76b2d 100644 --- a/src/Nazara/Noise/NoiseBase.cpp +++ b/src/Nazara/Noise/NoiseBase.cpp @@ -41,7 +41,7 @@ void NzNoiseBase::ShufflePermutationTable() int xchanger; unsigned int ncase; - for(int j(0) ; j < 10 ; ++j) + for(int j(0) ; j < 20 ; ++j) for (int i(0); i < 256 ; ++i) { ncase = this->GetUniformRandomValue() & 255; @@ -56,10 +56,7 @@ void NzNoiseBase::ShufflePermutationTable() int NzNoiseBase::fastfloor(float n) { - if(n >= 0) - return static_cast(n); - else - return static_cast(n-1); + return (n >= 0) ? static_cast(n) : static_cast(n-1); } int NzNoiseBase::JenkinsHash(int a, int b, int c) diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index 2b2b42fc5..476ba3e3f 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -35,8 +35,7 @@ NzNoiseMachine::NzNoiseMachine(int seed) for(int j(0) ; j < 4 ; ++j) lookupTable4D[i][j] = lookupTemp4D[i][j]; - float unit = 1.0/sqrt(2); - float grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, + float grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1}, {1,0},{-1,0},{0,1},{0,-1}}; for(int i(0) ; i < 8 ; ++i) @@ -69,28 +68,17 @@ NzNoiseMachine::NzNoiseMachine(int seed) for(int i(0) ; i < 32 ; ++i) for(int j(0) ; j < 4 ; ++j) gradient4[i][j] = grad4Temp[i][j]; - - m_lacunarity = 2.5f; - m_octaves = 3.0f; - m_hurst = 1.1f; - m_parametersModified = true; } -NzNoiseMachine::~NzNoiseMachine() -{ -} - - - //------------------------------ PERLIN ------------------------------ float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res) { - nx = x/res; - ny = y/res; + x /= res; + y /= res; - x0 = static_cast(nx); - y0 = static_cast(ny); + x0 = fastfloor(x); + y0 = fastfloor(y); ii = x0 & 255; jj = y0 & 255; @@ -100,42 +88,37 @@ float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res) gi2 = perm[ii + perm[jj + 1]] & 7; gi3 = perm[ii + 1 + perm[jj + 1]] & 7; - temp.x = nx-x0; - temp.y = ny-y0; + temp.x = x-x0; + temp.y = y-y0; + + Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10); + Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10); + s[0] = gradient2[gi0][0]*temp.x + gradient2[gi0][1]*temp.y; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[0] = gradient2[gi1][0]*temp.x + gradient2[gi1][1]*temp.y; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u[0] = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y; - - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.y = y-(y0+1); v[0] = gradient2[gi3][0]*temp.x + gradient2[gi3][1]*temp.y; - tmp = nx-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + temp.x = x-x0; + u[0] = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y; Li1 = s[0] + Cx*(t[0]-s[0]); Li2 = u[0] + Cx*(v[0]-u[0]); - tmp = ny - y0; - Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - return Li1 + Cy*(Li2-Li1); } float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res) { - nx = x/res; - ny = y/res; - nz = z/res; + x /= res; + y /= res; + z /= res; - x0 = static_cast(nx); - y0 = static_cast(ny); - z0 = static_cast(nz); + x0 = static_cast(x); + y0 = static_cast(y); + z0 = static_cast(z); ii = x0 & 255; jj = y0 & 255; @@ -151,41 +134,38 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] % 16; gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 16; - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-z0; + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-z0; s[0] = gradient3[gi0][0]*temp.x + gradient3[gi0][1]*temp.y + gradient3[gi0][2]*temp.z; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[0] = gradient3[gi1][0]*temp.x + gradient3[gi1][1]*temp.y + gradient3[gi1][2]*temp.z; - temp.x = nx-x0; - temp.y = ny-(y0+1); + temp.x = x-x0; + temp.y = y-(y0+1); u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.x = x-(x0+1); v[0] = gradient3[gi3][0]*temp.x + gradient3[gi3][1]*temp.y + gradient3[gi3][2]*temp.z; - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-(z0+1); + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-(z0+1); s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z; - temp.x = nx-x0; - temp.y = ny-(y0+1); + temp.x = x-x0; + temp.y = y-(y0+1); u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z; - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.x = x-(x0+1); + temp.y = y-(y0+1); v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z; - tmp = nx-x0; + tmp = x-x0; Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); Li1 = s[0] + Cx*(t[0]-s[0]); @@ -193,13 +173,13 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res Li3 = s[1] + Cx*(t[1]-s[1]); Li4 = u[1] + Cx*(v[1]-u[1]); - tmp = ny-y0; + tmp = y-y0; Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); Li5 = Li1 + Cy*(Li2-Li1); Li6 = Li3 + Cy*(Li4-Li3); - tmp = nz-z0; + tmp = z-z0; Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); return Li5 + Cz*(Li6-Li5); @@ -207,15 +187,15 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, float res) { - nx = x/res; - ny = y/res; - nz = z/res; - nw = w/res; + x /= res; + y /= res; + z /= res; + w /= res; - x0 = static_cast(nx); - y0 = static_cast(ny); - z0 = static_cast(nz); - w0 = static_cast(nw); + x0 = static_cast(x); + y0 = static_cast(y); + z0 = static_cast(z); + w0 = static_cast(w); ii = x0 & 255; jj = y0 & 255; @@ -242,77 +222,69 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-z0; - temp.w = nw-w0; + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-z0; + temp.w = w-w0; s[0] = gradient4[gi0][0]*temp.x + gradient4[gi0][1]*temp.y + gradient4[gi0][2]*temp.z + gradient4[gi0][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[0] = gradient4[gi1][0]*temp.x + gradient4[gi1][1]*temp.y + gradient4[gi1][2]*temp.z + gradient4[gi1][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); + temp.x = x-x0; + temp.y = y-(y0+1); u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.x = x-(x0+1); v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-(z0+1); + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-(z0+1); s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[1] = gradient4[gi5][0]*temp.x + gradient4[gi5][1]*temp.y + gradient4[gi5][2]*temp.z + gradient4[gi5][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); + temp.x = x-x0; + temp.y = y-(y0+1); u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.x = x-(x0+1); v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-z0; - temp.w = nw-(w0+1); + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-z0; + temp.w = w-(w0+1); s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[2] = gradient4[gi9][0]*temp.x + gradient4[gi9][1]*temp.y + gradient4[gi9][2]*temp.z + gradient4[gi9][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); + temp.x = x-x0; + temp.y = y-(y0+1); u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.x = x-(x0+1); v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-y0; - temp.z = nz-(z0+1); + temp.x = x-x0; + temp.y = y-y0; + temp.z = z-(z0+1); s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-y0; + temp.x = x-(x0+1); t[3] = gradient4[gi13][0]*temp.x + gradient4[gi13][1]*temp.y + gradient4[gi13][2]*temp.z + gradient4[gi13][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); + temp.x = x-x0; + temp.y = y-(y0+1); u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w; - temp.x = nx-(x0+1); - temp.y = ny-(y0+1); + temp.x = x-(x0+1); v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w; - tmp = nx-x0; + tmp = x-x0; Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); Li1 = s[0] + Cx*(t[0]-s[0]); @@ -324,7 +296,7 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, Li7 = s[3] + Cx*(t[3]-s[3]); Li8 = u[3] + Cx*(v[3]-u[3]); - tmp = ny-y0; + tmp = y-y0; Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); Li9 = Li1 + Cy*(Li2-Li1); @@ -332,13 +304,13 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, Li11 = Li5 + Cy*(Li6-Li5); Li12 = Li7 + Cy*(Li8-Li7); - tmp = nz-z0; + tmp = z-z0; Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); Li13 = Li9 + Cz*(Li10-Li9); Li14 = Li11 + Cz*(Li12-Li11); - tmp = nw-w0; + tmp = w-w0; Cw = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); return Li13 + Cw*(Li14-Li13); @@ -351,17 +323,16 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res) x /= res; y /= res; + skewedCubeOrigin.x = fastfloor(x + (x + y) * SkewCoeff2D); + skewedCubeOrigin.y = fastfloor(y + (x + y) * SkewCoeff2D); - Origin.x = fastfloor(x + (x + y) * SkewCoeff2D); - Origin.y = fastfloor(y + (x + y) * SkewCoeff2D); + unskewedCubeOrigin.x = skewedCubeOrigin.x - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; + unskewedCubeOrigin.y = skewedCubeOrigin.y - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; - A.x = Origin.x - (Origin.x + Origin.y) * UnskewCoeff2D; - A.y = Origin.y - (Origin.x + Origin.y) * UnskewCoeff2D; + unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; + unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; - IsoOriginDist.x = x - A.x; - IsoOriginDist.y = y - A.y; - - if(IsoOriginDist.x > IsoOriginDist.y) + if(unskewedDistToOrigin.x > unskewedDistToOrigin.y) { off1.x = 1; off1.y = 0; @@ -372,8 +343,9 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res) off1.y = 1; } - d1.x = A.x - x; - d1.y = A.y - y; + + d1.x = unskewedCubeOrigin.x - x; + d1.y = unskewedCubeOrigin.y - y; d2.x = d1.x + off1.x - UnskewCoeff2D; d2.y = d1.y + off1.y - UnskewCoeff2D; @@ -381,33 +353,33 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res) d3.x = d1.x + 1.0 - 2 * UnskewCoeff2D; d3.y = d1.y + 1.0 - 2 * UnskewCoeff2D; - ii = Origin.x & 255; - jj = Origin.y & 255; + ii = skewedCubeOrigin.x & 255; + jj = skewedCubeOrigin.y & 255; - gi0 = perm[ii + perm[jj]] % 8; - gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 8; - gi2 = perm[ii + 1 + perm[jj + 1]] % 8; - - n1 = gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y; - n2 = gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y; - n3 = gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y; + gi0 = perm[ii + perm[jj]] & 7; + gi1 = perm[ii + off1.x + perm[jj + off1.y]] & 7; + gi2 = perm[ii + 1 + perm[jj + 1]] & 7; c1 = 0.5 - d1.x * d1.x - d1.y * d1.y; c2 = 0.5 - d2.x * d2.x - d2.y * d2.y; c3 = 0.5 - d3.x * d3.x - d3.y * d3.y; if(c1 < 0) - c1 = 0; + n1 = 0; + else + n1 = c1*c1*c1*c1*(gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y); + if(c2 < 0) - c2 = 0; + n2 = 0; + else + n2 = c2*c2*c2*c2*(gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y); + if(c3 < 0) - c3 = 0; + n3 = 0; + else + n3 = c3*c3*c3*c3*(gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y); - n1 = c1*c1*c1*n1; - n2 = c2*c2*c2*n2; - n3 = c3*c3*c3*n3; - - return (n1+n2+n3)*23.2; + return (n1+n2+n3)*70; } float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float res) @@ -688,51 +660,6 @@ float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, fl return 0; } -void NzNoiseMachine::SetLacunarity(float lacunarity) -{ - if(lacunarity != m_lacunarity) - { - m_lacunarity = lacunarity; - m_parametersModified = true; - } -} - -void NzNoiseMachine::SetHurstParameter(float h) -{ - if(h != m_hurst) - { - m_hurst = h; - m_parametersModified = true; - } -} - -void NzNoiseMachine::SetOctavesNumber(float octaves) -{ - if(octaves != m_octaves && octaves < 30) - { - m_octaves = octaves; - m_parametersModified = true; - } -} - -void NzNoiseMachine::RecomputeExponentArray() -{ - if(m_parametersModified) - { - float frequency = 1.0; - m_sum = 0.f; - for (int i(0) ; i < m_octaves; ++i) - { - exponent_array[i] = pow( frequency, -m_hurst ); - frequency *= m_lacunarity; - - m_sum += exponent_array[i]; - - } - m_parametersModified = false; - } -} - //------------------------------ FBM ------------------------------ float NzNoiseMachine::Get2DFBMNoiseValue(float x, float y, float res) From ebba6adae41848013d328b214e0240350dfb8b44 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Thu, 7 Jun 2012 13:10:58 +0200 Subject: [PATCH 10/13] Simplex & Perlin fully work now (all dimensions) + dynaTerrain removed temp --- build/scripts/module/dynaterrain.lua | 31 -- include/Nazara/DynaTerrain/Config.hpp | 38 --- include/Nazara/DynaTerrain/Debug.hpp | 11 - include/Nazara/DynaTerrain/DebugOff.hpp | 8 - include/Nazara/DynaTerrain/DynaTerrain.hpp | 27 -- include/Nazara/DynaTerrain/Node.hpp | 71 ---- include/Nazara/DynaTerrain/Patch.hpp | 35 -- include/Nazara/DynaTerrain/QuadTree.hpp | 30 -- include/Nazara/Noise/NoiseMachine.hpp | 10 +- include/Nazara/Noise/Perlin3D.inl | 1 - include/Nazara/Noise/Perlin4D.inl | 83 ++--- include/Nazara/Noise/Simplex2D.hpp | 1 + include/Nazara/Noise/Simplex2D.inl | 20 +- include/Nazara/Noise/Simplex3D.hpp | 9 +- include/Nazara/Noise/Simplex3D.inl | 109 +++--- include/Nazara/Noise/Simplex4D.hpp | 5 +- include/Nazara/Noise/Simplex4D.inl | 133 ++++---- src/Nazara/DynaTerrain/Debug/Leaks.cpp | 29 -- src/Nazara/DynaTerrain/DynaTerrain.cpp | 57 ---- src/Nazara/DynaTerrain/Node.cpp | 317 ------------------ src/Nazara/DynaTerrain/Patch.cpp | 47 --- src/Nazara/DynaTerrain/QuadTree.cpp | 36 -- src/Nazara/Noise/NoiseMachine.cpp | 370 ++++++++++----------- 23 files changed, 354 insertions(+), 1124 deletions(-) delete mode 100644 build/scripts/module/dynaterrain.lua delete mode 100644 include/Nazara/DynaTerrain/Config.hpp delete mode 100644 include/Nazara/DynaTerrain/Debug.hpp delete mode 100644 include/Nazara/DynaTerrain/DebugOff.hpp delete mode 100644 include/Nazara/DynaTerrain/DynaTerrain.hpp delete mode 100644 include/Nazara/DynaTerrain/Node.hpp delete mode 100644 include/Nazara/DynaTerrain/Patch.hpp delete mode 100644 include/Nazara/DynaTerrain/QuadTree.hpp delete mode 100644 src/Nazara/DynaTerrain/Debug/Leaks.cpp delete mode 100644 src/Nazara/DynaTerrain/DynaTerrain.cpp delete mode 100644 src/Nazara/DynaTerrain/Node.cpp delete mode 100644 src/Nazara/DynaTerrain/Patch.cpp delete mode 100644 src/Nazara/DynaTerrain/QuadTree.cpp diff --git a/build/scripts/module/dynaterrain.lua b/build/scripts/module/dynaterrain.lua deleted file mode 100644 index 31847eb8c..000000000 --- a/build/scripts/module/dynaterrain.lua +++ /dev/null @@ -1,31 +0,0 @@ -project "NazaraModuleName" - -files -{ - "../include/Nazara/ModuleName/**.hpp", - "../include/Nazara/ModuleName/**.inl", - "../src/Nazara/ModuleName/**.hpp", - "../src/Nazara/ModuleName/**.cpp" -} - -if (os.is("windows")) then - excludes { "../src/Nazara/ModuleName/Posix/*.hpp", "../src/Nazara/ModuleName/Posix/*.cpp" } -else - excludes { "../src/Nazara/ModuleName/Win32/*.hpp", "../src/Nazara/ModuleName/Win32/*.cpp" } -end - -configuration "DebugStatic" - links "NazaraCored-s" - targetname "NazaraModuleNamed" - -configuration "ReleaseStatic" - links "NazaraCore-s" - targetname "NazaraModuleName" - -configuration "DebugDLL" - links "NazaraCored" - targetname "NazaraModuleNamed" - -configuration "ReleaseDLL" - links "NazaraCore" - targetname "NazaraModuleName" \ No newline at end of file diff --git a/include/Nazara/DynaTerrain/Config.hpp b/include/Nazara/DynaTerrain/Config.hpp deleted file mode 100644 index 9527720de..000000000 --- a/include/Nazara/DynaTerrain/Config.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - Nazara Engine - - Copyright (C) 2012 AUTHORS (EMAIL) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_MODULENAME_HPP -#define NAZARA_CONFIG_MODULENAME_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution) -#define NAZARA_MODULENAME_MEMORYLEAKTRACKER 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_MODULENAME_SAFE 1 - -#endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/DynaTerrain/Debug.hpp b/include/Nazara/DynaTerrain/Debug.hpp deleted file mode 100644 index fa2f9482e..000000000 --- a/include/Nazara/DynaTerrain/Debug.hpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) - #include - - #define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete - #define new new(__FILE__, __LINE__) -#endif diff --git a/include/Nazara/DynaTerrain/DebugOff.hpp b/include/Nazara/DynaTerrain/DebugOff.hpp deleted file mode 100644 index 0a21b742d..000000000 --- a/include/Nazara/DynaTerrain/DebugOff.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) - #undef delete - #undef new -#endif diff --git a/include/Nazara/DynaTerrain/DynaTerrain.hpp b/include/Nazara/DynaTerrain/DynaTerrain.hpp deleted file mode 100644 index 70d8f6918..000000000 --- a/include/Nazara/DynaTerrain/DynaTerrain.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_MODULENAME_HPP -#define NAZARA_MODULENAME_HPP - -#include - -class NAZARA_API NzModuleName -{ - public: - NzModuleName(); - ~NzModuleName(); - - bool Initialize(); - void Uninitialize(); - - static bool IsInitialized(); - - private: - static bool s_initialized; -}; - -#endif // NAZARA_MODULENAME_HPP diff --git a/include/Nazara/DynaTerrain/Node.hpp b/include/Nazara/DynaTerrain/Node.hpp deleted file mode 100644 index f7e6bd430..000000000 --- a/include/Nazara/DynaTerrain/Node.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NODE_H -#define NODE_H - -#include - -#include -#include "Patch.hpp" -class NzQuadTree; - - -//SUPPRIMER LES NODES FILS OU SEULEMENT LES PATCHS CONTENUS ? POUR L'INSTANT SUPPRESSION DES PATCHS - -class NzNode -{ - public: - enum nzDirection - { - TOP, - BOTTOM, - LEFT, - RIGHT, - TOPLEFT, - TOPRIGHT, - BOTTOMLEFT, - BOTTOMRIGHT, - CENTER - }; - - NzNode(NzQuadTree* quad, NzNode* parent, const NzVector2f& center, const NzVector2f& size, nzDirection dir = CENTER); - ~NzNode(); - - void Subdivide(); - void Refine(bool eraseMemory); - - void CreatePatch(const NzVector2f& center, const NzVector2f& size); - void DeletePatch(); - - unsigned short int GetLevel() const; - - bool IsLeaf() const; - bool IsRoot() const; - - //Retourne le voisin le plus proche dans la direction indiqué, de niveau de profondeur inférieur ou égal - bool LocateNeighbor(nzDirection dir, NzNode* neighbor); - - - private: - NzQuadTree* m_associatedQuadTree; - NzNode* m_parent; - NzNode* m_topLeftLeaf; - NzNode* m_topRightLeaf; - NzNode* m_bottomLeftLeaf; - NzNode* m_bottomRightLeaf; - bool m_isLeaf; - bool m_isRoot; - bool m_patchMemoryAllocated; - unsigned short int m_level; - - NzPatch* m_patch; - NzVector2f m_center; - NzVector2f m_size; - nzDirection m_direction; -}; - -#endif // NODE_H diff --git a/include/Nazara/DynaTerrain/Patch.hpp b/include/Nazara/DynaTerrain/Patch.hpp deleted file mode 100644 index a546f2f41..000000000 --- a/include/Nazara/DynaTerrain/Patch.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef PATCH_H -#define PATCH_H - -#include - -#include - -class NzPatch -{ - public: - NzPatch(NzVector2f center, NzVector2f size); - ~NzPatch(); - - NzVector2f GetCenter() const; - NzVector2f GetSize() const; - - bool IntersectsCircle(const NzVector2f& center, double radius); - bool IsContainedByCircle(const NzVector2f& center, double radius); - - NzPatch* LocatePatch(const NzVector2f& position); - - protected: - private: - - NzVector2f m_center; - NzVector2f m_size; -}; - -#endif // PATCH_H diff --git a/include/Nazara/DynaTerrain/QuadTree.hpp b/include/Nazara/DynaTerrain/QuadTree.hpp deleted file mode 100644 index 8ed3f9dde..000000000 --- a/include/Nazara/DynaTerrain/QuadTree.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef QUADTREE_H -#define QUADTREE_H - -#include - -#include -#include -#include "Node.hpp" - -class NzQuadTree -{ - public: - NzQuadTree(const NzVector2f& terrainCenter, const NzVector2f& terrainSize); - void RegisterLeaf(NzNode* node); - bool UnRegisterLeaf(NzNode* node); - NzNode* GetRootPtr(); - ~NzQuadTree(); - private: - NzNode* root; - //N'a pas la charge des objets en mémoire - std::list leaves; -}; - -#endif // QUADTREE_H diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp index 3be3cebe9..f7b60f0e5 100644 --- a/include/Nazara/Noise/NoiseMachine.hpp +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -49,17 +49,17 @@ class NzNoiseMachine : public NzComplexNoiseBase int gradient4[32][4]; int lookupTable4D[64][4]; + //----------------------- Common variables -------------------------------------- + int ii,jj,kk,ll; + int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; + //----------------------- Simplex variables -------------------------------------- float n1, n2, n3, n4, n5; NzVector4f d1,d2,d3,d4,d5,unskewedCubeOrigin,unskewedDistToOrigin; NzVector4i off1, off2,off3,skewedCubeOrigin; - NzVector4f A,IsoOriginDist; - NzVector4i Origin; - int ii,jj,kk,ll; - int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; float c1,c2,c3,c4,c5,c6; int c; @@ -72,6 +72,8 @@ class NzNoiseMachine : public NzComplexNoiseBase float SkewCoeff4D; float UnskewCoeff4D; + float sum; + //----------------------- Perlin Variables ------------------------------------- int x0,y0,z0,w0; diff --git a/include/Nazara/Noise/Perlin3D.inl b/include/Nazara/Noise/Perlin3D.inl index 8e30f5a69..bbf01665a 100644 --- a/include/Nazara/Noise/Perlin3D.inl +++ b/include/Nazara/Noise/Perlin3D.inl @@ -65,7 +65,6 @@ T NzPerlin3D::GetValue(T x, T y, T z, T res) temp.x = x-x0; u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; - temp.x = x-x0; temp.y = y-y0; temp.z = z-(z0+1); s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z; diff --git a/include/Nazara/Noise/Perlin4D.inl b/include/Nazara/Noise/Perlin4D.inl index 2ad741d8d..c8de3b255 100644 --- a/include/Nazara/Noise/Perlin4D.inl +++ b/include/Nazara/Noise/Perlin4D.inl @@ -44,98 +44,88 @@ T NzPerlin4D::GetValue(T x, T y, T z, T w, T res) kk = z0 & 255; ll = w0 & 255; - gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] % 32; - gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll ]]]] % 32; - gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; - gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; + gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] & 31; + gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll ]]]] & 31; + gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll ]]]] & 31; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll ]]]] & 31; - gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; - gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; - gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; - gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; + gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll ]]]] & 31; + gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll ]]]] & 31; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] & 31; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] & 31; - gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] % 32; - gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] % 32; - gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; - gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; + gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] & 31; + gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] & 31; + gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31; + gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31; - gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; - gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; - gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; - gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31; temp.x = nx-x0; temp.y = ny-y0; temp.z = nz-z0; temp.w = nw-w0; + + Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10); + Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10); + Cz = temp.z * temp.z * temp.z * (temp.z * (temp.z * 6 - 15) + 10); + Cw = temp.w * temp.w * temp.w * (temp.w * (temp.w * 6 - 15) + 10); + s[0] = gradient4[gi0][0]*temp.x + gradient4[gi0][1]*temp.y + gradient4[gi0][2]*temp.z + gradient4[gi0][3]*temp.w; temp.x = nx-(x0+1); - temp.y = ny-y0; t[0] = gradient4[gi1][0]*temp.x + gradient4[gi1][1]*temp.y + gradient4[gi1][2]*temp.z + gradient4[gi1][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w; - - temp.x = nx-(x0+1); temp.y = ny-(y0+1); v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w; temp.x = nx-x0; + u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w; + temp.y = ny-y0; temp.z = nz-(z0+1); s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w; temp.x = nx-(x0+1); - temp.y = ny-y0; t[1] = gradient4[gi5][0]*temp.x + gradient4[gi5][1]*temp.y + gradient4[gi5][2]*temp.z + gradient4[gi5][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w; - - temp.x = nx-(x0+1); temp.y = ny-(y0+1); v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w; temp.x = nx-x0; + u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w; + + temp.y = ny-y0; temp.z = nz-z0; temp.w = nw-(w0+1); s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.w; temp.x = nx-(x0+1); - temp.y = ny-y0; t[2] = gradient4[gi9][0]*temp.x + gradient4[gi9][1]*temp.y + gradient4[gi9][2]*temp.z + gradient4[gi9][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w; - - temp.x = nx-(x0+1); temp.y = ny-(y0+1); v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w; temp.x = nx-x0; + u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w; + + temp.y = ny-y0; temp.z = nz-(z0+1); s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w; temp.x = nx-(x0+1); - temp.y = ny-y0; t[3] = gradient4[gi13][0]*temp.x + gradient4[gi13][1]*temp.y + gradient4[gi13][2]*temp.z + gradient4[gi13][3]*temp.w; - temp.x = nx-x0; - temp.y = ny-(y0+1); - u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w; - - temp.x = nx-(x0+1); temp.y = ny-(y0+1); v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w; - tmp = nx-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + temp.x = nx-x0; + u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w; Li1 = s[0] + Cx*(t[0]-s[0]); Li2 = u[0] + Cx*(v[0]-u[0]); @@ -146,22 +136,13 @@ T NzPerlin4D::GetValue(T x, T y, T z, T w, T res) Li7 = s[3] + Cx*(t[3]-s[3]); Li8 = u[3] + Cx*(v[3]-u[3]); - tmp = ny-y0; - Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - Li9 = Li1 + Cy*(Li2-Li1); Li10 = Li3 + Cy*(Li4-Li3); Li11 = Li5 + Cy*(Li6-Li5); Li12 = Li7 + Cy*(Li8-Li7); - tmp = nz-z0; - Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - Li13 = Li9 + Cz*(Li10-Li9); Li14 = Li11 + Cz*(Li12-Li11); - tmp = nw-w0; - Cw = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - return Li13 + Cw*(Li14-Li13); } diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp index e292587df..d1af5aaed 100644 --- a/include/Nazara/Noise/Simplex2D.hpp +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -29,6 +29,7 @@ template class NzSimplex2D : public NzNoiseBase T gradient2[8][2]; T UnskewCoeff2D; T SkewCoeff2D; + T sum; NzVector2 unskewedCubeOrigin, unskewedDistToOrigin; NzVector2 d1,d2,d3; diff --git a/include/Nazara/Noise/Simplex2D.inl b/include/Nazara/Noise/Simplex2D.inl index 3479c13f3..0c7ab3c93 100644 --- a/include/Nazara/Noise/Simplex2D.inl +++ b/include/Nazara/Noise/Simplex2D.inl @@ -17,7 +17,7 @@ NzSimplex2D::NzSimplex2D() gradient2[i][j] = grad2Temp[i][j]; SkewCoeff2D = 0.5*(sqrt(3.0) - 1.0); - UnskewCoeff2D = (3.0-sqrt(3.0))/6; + UnskewCoeff2D = (3.0-sqrt(3.0))/6.; } template @@ -26,11 +26,13 @@ T NzSimplex2D::GetValue(T x, T y, T res) x /= res; y /= res; - skewedCubeOrigin.x = fastfloor(x + (x + y) * SkewCoeff2D); - skewedCubeOrigin.y = fastfloor(y + (x + y) * SkewCoeff2D); + sum = (x + y) * SkewCoeff2D; + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); - unskewedCubeOrigin.x = skewedCubeOrigin.x - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; - unskewedCubeOrigin.y = skewedCubeOrigin.y - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; + sum = (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; + unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; + unskewedCubeOrigin.y = skewedCubeOrigin.y - sum; unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; @@ -46,9 +48,7 @@ T NzSimplex2D::GetValue(T x, T y, T res) off1.y = 1; } - - d1.x = unskewedCubeOrigin.x - x; - d1.y = unskewedCubeOrigin.y - y; + d1 = - unskewedDistToOrigin; d2.x = d1.x + off1.x - UnskewCoeff2D; d2.y = d1.y + off1.y - UnskewCoeff2D; @@ -59,9 +59,9 @@ T NzSimplex2D::GetValue(T x, T y, T res) ii = skewedCubeOrigin.x & 255; jj = skewedCubeOrigin.y & 255; - gi0 = perm[ii + perm[jj]] & 7; + gi0 = perm[ii + perm[jj ]] & 7; gi1 = perm[ii + off1.x + perm[jj + off1.y]] & 7; - gi2 = perm[ii + 1 + perm[jj + 1]] & 7; + gi2 = perm[ii + 1 + perm[jj + 1 ]] & 7; c1 = 0.5 - d1.x * d1.x - d1.y * d1.y; c2 = 0.5 - d2.x * d2.x - d2.y * d2.y; diff --git a/include/Nazara/Noise/Simplex3D.hpp b/include/Nazara/Noise/Simplex3D.hpp index dface2886..6a95fbb78 100644 --- a/include/Nazara/Noise/Simplex3D.hpp +++ b/include/Nazara/Noise/Simplex3D.hpp @@ -10,7 +10,7 @@ #include //#include #include "NoiseBase.hpp" -#include + template class NzSimplex3D : public NzNoiseBase @@ -23,13 +23,14 @@ template class NzSimplex3D : public NzNoiseBase private: int ii,jj,kk; int gi0,gi1,gi2,gi3; - NzVector3i Origin,off1,off2; + NzVector3i skewedCubeOrigin,off1,off2; T n1,n2,n3,n4; T c1,c2,c3,c4; - T gradient3[16][3]; + T gradient3[12][3]; T UnskewCoeff3D; T SkewCoeff3D; - NzVector3 A, IsoOriginDist; + T sum; + NzVector3 unskewedCubeOrigin, unskewedDistToOrigin; NzVector3 d1,d2,d3,d4; diff --git a/include/Nazara/Noise/Simplex3D.inl b/include/Nazara/Noise/Simplex3D.inl index dea0881e2..94ab86a6f 100644 --- a/include/Nazara/Noise/Simplex3D.inl +++ b/include/Nazara/Noise/Simplex3D.inl @@ -5,21 +5,19 @@ //#include //#include //#include +#include template NzSimplex3D::NzSimplex3D() { - SkewCoeff3D = 1/3; - UnskewCoeff3D = 1/6; + SkewCoeff3D = 1/3.; + UnskewCoeff3D = 1/6.; - int grad3Temp[][3] = { - {1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, - {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, - {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}, - {1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1} - }; + int grad3Temp[][3] = {{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, + {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, + {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}}; - for(int i(0) ; i < 16 ; ++i) + for(int i(0) ; i < 12 ; ++i) for(int j(0) ; j < 3 ; ++j) gradient3[i][j] = grad3Temp[i][j]; } @@ -31,21 +29,23 @@ T NzSimplex3D::GetValue(T x, T y, T z, T res) y /= res; z /= res; - Origin.x = fastfloor(x + (x + y + z) * SkewCoeff3D); - Origin.y = fastfloor(y + (x + y + z) * SkewCoeff3D); - Origin.z = fastfloor(z + (x + y + z) * SkewCoeff3D); + sum = (x + y + z) * SkewCoeff3D; + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); + skewedCubeOrigin.z = fastfloor(z + sum); - A.x = Origin.x - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; - A.y = Origin.y - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; - A.z = Origin.z - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; + sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z) * UnskewCoeff3D; + unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; + unskewedCubeOrigin.y = skewedCubeOrigin.y - sum; + unskewedCubeOrigin.z = skewedCubeOrigin.z - sum; - IsoOriginDist.x = x - A.x; - IsoOriginDist.y = y - A.y; - IsoOriginDist.z = z - A.z; + unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; + unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; + unskewedDistToOrigin.z = z - unskewedCubeOrigin.z; - if(IsoOriginDist.x >= IsoOriginDist.y) + if(unskewedDistToOrigin.x >= unskewedDistToOrigin.y) { - if(IsoOriginDist.y >= IsoOriginDist.z) + if(unskewedDistToOrigin.y >= unskewedDistToOrigin.z) { off1.x = 1; off1.y = 0; @@ -54,7 +54,7 @@ T NzSimplex3D::GetValue(T x, T y, T z, T res) off2.y = 1; off2.z = 0; } - else if(IsoOriginDist.x >= IsoOriginDist.z) + else if(unskewedDistToOrigin.x >= unskewedDistToOrigin.z) { off1.x = 1; off1.y = 0; @@ -75,7 +75,7 @@ T NzSimplex3D::GetValue(T x, T y, T z, T res) } else { - if(IsoOriginDist.y < IsoOriginDist.z) + if(unskewedDistToOrigin.y < unskewedDistToOrigin.z) { off1.x = 0; off1.y = 0; @@ -84,7 +84,7 @@ T NzSimplex3D::GetValue(T x, T y, T z, T res) off2.y = 1; off2.z = 1; } - else if(IsoOriginDist.x < IsoOriginDist.z) + else if(unskewedDistToOrigin.x < unskewedDistToOrigin.z) { off1.x = 0; off1.y = 1; @@ -104,35 +104,28 @@ T NzSimplex3D::GetValue(T x, T y, T z, T res) } } - d1.x = A.x - x; - d1.y = A.y - y; - d1.z = A.z - z; + d1 = unskewedDistToOrigin; - d2.x = d1.x + off1.x - UnskewCoeff3D; - d2.y = d1.y + off1.y - UnskewCoeff3D; - d2.z = d1.z + off1.z - UnskewCoeff3D; + d2.x = d1.x - off1.x + UnskewCoeff3D; + d2.y = d1.y - off1.y + UnskewCoeff3D; + d2.z = d1.z - off1.z + UnskewCoeff3D; - d3.x = d1.x + off2.x - 2*UnskewCoeff3D; - d3.y = d1.y + off2.y - 2*UnskewCoeff3D; - d3.z = d1.z + off2.z - 2*UnskewCoeff3D; + d3.x = d1.x - off2.x + 2*UnskewCoeff3D; + d3.y = d1.y - off2.y + 2*UnskewCoeff3D; + d3.z = d1.z - off2.z + 2*UnskewCoeff3D; - d4.x = d1.x + 1.0 - 3*UnskewCoeff3D; - d4.y = d1.y + 1.0 - 3*UnskewCoeff3D; - d4.z = d1.z + 1.0 - 3*UnskewCoeff3D; + d4.x = d1.x - 1.0 + 3*UnskewCoeff3D; + d4.y = d1.y - 1.0 + 3*UnskewCoeff3D; + d4.z = d1.z - 1.0 + 3*UnskewCoeff3D; - ii = Origin.x & 255; - jj = Origin.y & 255; - kk = Origin.z & 255; + ii = skewedCubeOrigin.x & 255; + jj = skewedCubeOrigin.y & 255; + kk = skewedCubeOrigin.z & 255; - gi0 = perm[ii + perm[jj + perm[kk]]] % 12; + gi0 = perm[ii + perm[jj + perm[kk ]]] % 12; gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z]]] % 12; gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z]]] % 12; - gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 12; - - n1 = gradient3[gi0][0] * d1.x + gradient3[gi0][1] * d1.y + gradient3[gi0][2] * d1.z; - n2 = gradient3[gi1][0] * d2.x + gradient3[gi1][1] * d2.y + gradient3[gi1][2] * d2.z; - n3 = gradient3[gi2][0] * d3.x + gradient3[gi2][1] * d3.y + gradient3[gi2][2] * d3.z; - n4 = gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 ]]] % 12; c1 = 0.6 - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z; c2 = 0.6 - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z; @@ -140,19 +133,25 @@ T NzSimplex3D::GetValue(T x, T y, T z, T res) c4 = 0.6 - d4.x * d4.x - d4.y * d4.y - d4.z * d4.z; if(c1 < 0) - c1 = 0; + n1 = 0; + else + n1 = c1*c1*c1*c1*(gradient3[gi0][0] * d1.x + gradient3[gi0][1] * d1.y + gradient3[gi0][2] * d1.z); + if(c2 < 0) - c2 = 0; + n2 = 0; + else + n2 = c2*c2*c2*c2*(gradient3[gi1][0] * d2.x + gradient3[gi1][1] * d2.y + gradient3[gi1][2] * d2.z); + if(c3 < 0) - c3 = 0; + n3 = 0; + else + n3 = c3*c3*c3*c3*(gradient3[gi2][0] * d3.x + gradient3[gi2][1] * d3.y + gradient3[gi2][2] * d3.z); + if(c4 < 0) - c4 = 0; + n4 = 0; + else + n4 = c4*c4*c4*c4*(gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z); - n1 = c1*c1*c1*n1; - n2 = c2*c2*c2*n2; - n3 = c3*c3*c3*n3; - n4 = c4*c4*c4*n4; - - return (n1+n2+n3+n4)*17.6995; + return (n1+n2+n3+n4)*32; } diff --git a/include/Nazara/Noise/Simplex4D.hpp b/include/Nazara/Noise/Simplex4D.hpp index 7c9982822..62f08e2b5 100644 --- a/include/Nazara/Noise/Simplex4D.hpp +++ b/include/Nazara/Noise/Simplex4D.hpp @@ -23,7 +23,7 @@ template class NzSimplex4D : public NzNoiseBase private: int ii,jj,kk,ll; int gi0,gi1,gi2,gi3,gi4; - NzVector4i Origin,off1,off2,off3; + NzVector4i skewedCubeOrigin,off1,off2,off3; T n1,n2,n3,n4,n5; T c1,c2,c3,c4,c5,c6; T gradient4[32][4]; @@ -31,7 +31,8 @@ template class NzSimplex4D : public NzNoiseBase int c; T UnskewCoeff4D; T SkewCoeff4D; - NzVector4 A, IsoOriginDist; + T sum; + NzVector4 unskewedCubeOrigin, unskewedDistToOrigin; NzVector4 d1,d2,d3,d4,d5; diff --git a/include/Nazara/Noise/Simplex4D.inl b/include/Nazara/Noise/Simplex4D.inl index de840679d..db6b86397 100644 --- a/include/Nazara/Noise/Simplex4D.inl +++ b/include/Nazara/Noise/Simplex4D.inl @@ -9,8 +9,8 @@ template NzSimplex4D::NzSimplex4D() { - SkewCoeff4D = (sqrt(5) - 1)/4; - UnskewCoeff4D = (5 - sqrt(5))/20; + SkewCoeff4D = (sqrt(5.) - 1.)/4.; + UnskewCoeff4D = (5. - sqrt(5.))/20.; int lookupTemp4D[][4] = { @@ -53,27 +53,29 @@ T NzSimplex4D::GetValue(T x, T y, T z, T w, T res) z /= res; w /= res; - Origin.x = fastfloor(x + (x + y + z + w) * SkewCoeff4D); - Origin.y = fastfloor(y + (x + y + z + w) * SkewCoeff4D); - Origin.z = fastfloor(z + (x + y + z + w) * SkewCoeff4D); - Origin.w = fastfloor(w + (x + y + z + w) * SkewCoeff4D); + sum = (x + y + z + w) * SkewCoeff4D; + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); + skewedCubeOrigin.z = fastfloor(z + sum); + skewedCubeOrigin.w = fastfloor(w + sum); - A.x = Origin.x - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; - A.y = Origin.y - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; - A.z = Origin.z - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; - A.w = Origin.w - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; + sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z + skewedCubeOrigin.w) * UnskewCoeff4D; + unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; + unskewedCubeOrigin.y = skewedCubeOrigin.y - sum; + unskewedCubeOrigin.z = skewedCubeOrigin.z - sum; + unskewedCubeOrigin.w = skewedCubeOrigin.w - sum; - IsoOriginDist.x = x - A.x; - IsoOriginDist.y = y - A.y; - IsoOriginDist.z = z - A.z; - IsoOriginDist.w = w - A.w; + unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; + unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; + unskewedDistToOrigin.z = z - unskewedCubeOrigin.z; + unskewedDistToOrigin.w = w - unskewedCubeOrigin.w; - c1 = (IsoOriginDist.x > IsoOriginDist.y) ? 32 : 0; - c2 = (IsoOriginDist.x > IsoOriginDist.z) ? 16 : 0; - c3 = (IsoOriginDist.y > IsoOriginDist.z) ? 8 : 0; - c4 = (IsoOriginDist.x > IsoOriginDist.w) ? 4 : 0; - c5 = (IsoOriginDist.y > IsoOriginDist.w) ? 2 : 0; - c6 = (IsoOriginDist.z > IsoOriginDist.w) ? 1 : 0; + c1 = (unskewedDistToOrigin.x > unskewedDistToOrigin.y) ? 32 : 0; + c2 = (unskewedDistToOrigin.x > unskewedDistToOrigin.z) ? 16 : 0; + c3 = (unskewedDistToOrigin.y > unskewedDistToOrigin.z) ? 8 : 0; + c4 = (unskewedDistToOrigin.x > unskewedDistToOrigin.w) ? 4 : 0; + c5 = (unskewedDistToOrigin.y > unskewedDistToOrigin.w) ? 2 : 0; + c6 = (unskewedDistToOrigin.z > unskewedDistToOrigin.w) ? 1 : 0; c = c1 + c2 + c3 + c4 + c5 + c6; off1.x = lookupTable4D[c][0] >= 3 ? 1 : 0; @@ -91,48 +93,39 @@ T NzSimplex4D::GetValue(T x, T y, T z, T w, T res) off3.z = lookupTable4D[c][2] >= 1 ? 1 : 0; off3.w = lookupTable4D[c][3] >= 1 ? 1 : 0; - d1.x = A.x - x; - d1.y = A.y - y; - d1.z = A.z - z; - d1.w = A.w - w; + d1 = unskewedDistToOrigin; - d2.x = d1.x + off1.x - UnskewCoeff4D; - d2.y = d1.y + off1.y - UnskewCoeff4D; - d2.z = d1.z + off1.z - UnskewCoeff4D; - d2.w = d1.w + off1.w - UnskewCoeff4D; + d2.x = d1.x - off1.x + UnskewCoeff4D; + d2.y = d1.y - off1.y + UnskewCoeff4D; + d2.z = d1.z - off1.z + UnskewCoeff4D; + d2.w = d1.w - off1.w + UnskewCoeff4D; - d3.x = d1.x + off2.x - 2*UnskewCoeff4D; - d3.y = d1.y + off2.y - 2*UnskewCoeff4D; - d3.z = d1.z + off2.z - 2*UnskewCoeff4D; - d3.w = d1.w + off2.w - 2*UnskewCoeff4D; + d3.x = d1.x - off2.x + 2*UnskewCoeff4D; + d3.y = d1.y - off2.y + 2*UnskewCoeff4D; + d3.z = d1.z - off2.z + 2*UnskewCoeff4D; + d3.w = d1.w - off2.w + 2*UnskewCoeff4D; - d4.x = d1.x + off3.x - 3*UnskewCoeff4D; - d4.y = d1.y + off3.y - 3*UnskewCoeff4D; - d4.z = d1.z + off3.z - 3*UnskewCoeff4D; - d4.w = d1.w + off3.w - 3*UnskewCoeff4D; + d4.x = d1.x - off3.x + 3*UnskewCoeff4D; + d4.y = d1.y - off3.y + 3*UnskewCoeff4D; + d4.z = d1.z - off3.z + 3*UnskewCoeff4D; + d4.w = d1.w - off3.w + 3*UnskewCoeff4D; - d5.x = d1.x + 1.0 - 4*UnskewCoeff4D; - d5.y = d1.y + 1.0 - 4*UnskewCoeff4D; - d5.z = d1.z + 1.0 - 4*UnskewCoeff4D; - d5.w = d1.w + 1.0 - 4*UnskewCoeff4D; + d5.x = d1.x - 1.0 + 4*UnskewCoeff4D; + d5.y = d1.y - 1.0 + 4*UnskewCoeff4D; + d5.z = d1.z - 1.0 + 4*UnskewCoeff4D; + d5.w = d1.w - 1.0 + 4*UnskewCoeff4D; - ii = Origin.x & 255; - jj = Origin.y & 255; - kk = Origin.z & 255; - ll = Origin.w & 255; + ii = skewedCubeOrigin.x & 255; + jj = skewedCubeOrigin.y & 255; + kk = skewedCubeOrigin.z & 255; + ll = skewedCubeOrigin.w & 255; - gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32; - gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] % 32; - gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] % 32; - gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] % 32; + gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31; + gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] & 31; + gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] & 31; + gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] & 31; gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; - n1 = gradient4[gi0][0]*d1.x + gradient4[gi0][1]*d1.y + gradient4[gi0][2]*d1.z + gradient4[gi0][3]*d1.w; - n2 = gradient4[gi1][0]*d2.x + gradient4[gi1][1]*d2.y + gradient4[gi1][2]*d2.z + gradient4[gi1][3]*d2.w; - n3 = gradient4[gi2][0]*d3.x + gradient4[gi2][1]*d3.y + gradient4[gi2][2]*d3.z + gradient4[gi2][3]*d3.w; - n4 = gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w; - n5 = gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w; - c1 = 0.6 - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; c2 = 0.6 - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; c3 = 0.6 - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w; @@ -140,22 +133,30 @@ T NzSimplex4D::GetValue(T x, T y, T z, T w, T res) c5 = 0.6 - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w; if(c1 < 0) - c1 = 0; + n1 = 0; + else + n1 = c1*c1*c1*c1*(gradient4[gi0][0]*d1.x + gradient4[gi0][1]*d1.y + gradient4[gi0][2]*d1.z + gradient4[gi0][3]*d1.w); + if(c2 < 0) - c2 = 0; + n2 = 0; + else + n2 = c2*c2*c2*c2*(gradient4[gi1][0]*d2.x + gradient4[gi1][1]*d2.y + gradient4[gi1][2]*d2.z + gradient4[gi1][3]*d2.w); + if(c3 < 0) - c3 = 0; + n3 = 0; + else + n3 = c3*c3*c3*c3*(gradient4[gi2][0]*d3.x + gradient4[gi2][1]*d3.y + gradient4[gi2][2]*d3.z + gradient4[gi2][3]*d3.w); + if(c4 < 0) - c4 = 0; + n4 = 0; + else + n4 = c4*c4*c4*c4*(gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w); + if(c5 < 0) - c5 = 0; + n5 = 0; + else + n5 = c5*c5*c5*c5*(gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w); - n1 = c1*c1*c1*n1; - n2 = c2*c2*c2*n2; - n3 = c3*c3*c3*n3; - n4 = c4*c4*c4*n4; - n5 = c5*c5*c5*n5; - - return (n1+n2+n3+n4+n5)*17.6995; + return (n1+n2+n3+n4+n5)*27.0; } diff --git a/src/Nazara/DynaTerrain/Debug/Leaks.cpp b/src/Nazara/DynaTerrain/Debug/Leaks.cpp deleted file mode 100644 index 13e396e67..000000000 --- a/src/Nazara/DynaTerrain/Debug/Leaks.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) -#include -#include - -void* operator new(std::size_t size) throw(std::bad_alloc) -{ - return NzMemoryManager::Allocate(size, false); -} - -void* operator new[](std::size_t size) throw(std::bad_alloc) -{ - return NzMemoryManager::Allocate(size, true); -} - -void operator delete(void* pointer) throw() -{ - NzMemoryManager::Free(pointer, false); -} - -void operator delete[](void* pointer) throw() -{ - NzMemoryManager::Free(pointer, true); -} -#endif diff --git a/src/Nazara/DynaTerrain/DynaTerrain.cpp b/src/Nazara/DynaTerrain/DynaTerrain.cpp deleted file mode 100644 index f6cbd4530..000000000 --- a/src/Nazara/DynaTerrain/DynaTerrain.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2012 AUTHORS -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -NzModuleName::NzModuleName() -{ -} - -NzModuleName::~NzModuleName() -{ - if (s_initialized) - Uninitialize(); -} - -bool NzModuleName::Initialize() -{ - #if NAZARA_MODULENAME_SAFE - if (s_initialized) - { - NazaraError("ModuleName already initialized"); - return true; - } - #endif - - // Initialisation du module - - s_initialized = true; - - return true; -} - -void NzModuleName::Uninitialize() -{ - #if NAZARA_MODULENAME_SAFE - if (!s_initialized) - { - NazaraError("ModuleName not initialized"); - return; - } - #endif - - // Libération du module - - s_initialized = false; -} - -bool NzModuleName::IsInitialized() -{ - return s_initialized; -} - -bool NzModuleName::s_initialized = false; diff --git a/src/Nazara/DynaTerrain/Node.cpp b/src/Nazara/DynaTerrain/Node.cpp deleted file mode 100644 index 4b479dde0..000000000 --- a/src/Nazara/DynaTerrain/Node.cpp +++ /dev/null @@ -1,317 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include "Node.hpp" -#include "QuadTree.hpp" -#include -//#include -//#include -//#include -//#include - - -NzNode::NzNode(NzQuadTree* quad, NzNode* parent, const NzVector2f& center, const NzVector2f& size, nzDirection dir) -{ - m_direction = dir; - m_center = center; - m_size = size; - m_isLeaf = false; - m_patchMemoryAllocated = false; - - m_associatedQuadTree = quad; - - m_topLeftLeaf = nullptr; - m_topRightLeaf = nullptr; - m_bottomLeftLeaf = nullptr; - m_bottomRightLeaf = nullptr; - - if(parent == 0) - { - m_isRoot = true; - m_level = 0; - } - else - { - m_level = parent->GetLevel()+1; - m_parent = parent; - m_isRoot = false; - } -} - -NzNode::~NzNode() -{ - if(m_isLeaf) - m_associatedQuadTree->UnRegisterLeaf(this); - if(m_patchMemoryAllocated) - delete m_patch; -} - -void NzNode::Subdivide() -{ - m_isLeaf = false; - m_associatedQuadTree->UnRegisterLeaf(this); - - if(m_topLeftLeaf == nullptr) - { - m_topLeftLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x-m_size.x/2.f, - m_center.y+m_size.y/2.f),m_size/2.f,TOPLEFT); - m_topLeftLeaf->m_isLeaf = true; - m_associatedQuadTree->RegisterLeaf(m_topLeftLeaf); - } - if(m_topRightLeaf == nullptr) - { - m_topRightLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x+m_size.x/2.f, - m_center.y+m_size.y/2.f),m_size/2.f,TOPRIGHT); - m_topRightLeaf->m_isLeaf = true; - m_associatedQuadTree->RegisterLeaf(m_topRightLeaf); - } - if(m_bottomLeftLeaf = nullptr) - { - m_bottomLeftLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x-m_size.x/2.f, - m_center.y-m_size.y/2.f),m_size/2.f,BOTTOMLEFT); - m_bottomLeftLeaf->m_isLeaf = true; - m_associatedQuadTree->RegisterLeaf(m_bottomLeftLeaf); - } - if(m_bottomRightLeaf = nullptr) - { - m_bottomRightLeaf = new NzNode(m_associatedQuadTree,this,NzVector2f(m_center.x+m_size.x/2.f, - m_center.y-m_size.y/2.f),m_size/2.f,BOTTOMRIGHT); - m_bottomRightLeaf->m_isLeaf = true; - m_associatedQuadTree->RegisterLeaf(m_bottomRightLeaf); - } - - -} - -void NzNode::Refine(bool eraseMemory) -{ - m_isLeaf = true; - m_associatedQuadTree->RegisterLeaf(this); - if(eraseMemory) - { - /* - delete m_topLeftLeaf; - delete m_topRightLeaf; - delete m_bottomLeftLeaf; - delete m_bottomRightLeaf; - - m_topLeftLeaf = nullptr; - m_topRightLeaf = nullptr; - m_bottomLeftLeaf = nullptr; - m_bottomRightLeaf = nullptr;*/ - - m_topLeftLeaf->DeletePatch(); - m_topRightLeaf->DeletePatch(); - m_bottomLeftLeaf->DeletePatch(); - m_bottomRightLeaf->DeletePatch(); - } - //else - //{ - m_topLeftLeaf->m_isLeaf = false; - m_topRightLeaf->m_isLeaf = false; - m_bottomLeftLeaf->m_isLeaf = false; - m_bottomRightLeaf->m_isLeaf = false; - - m_associatedQuadTree->UnRegisterLeaf(m_topLeftLeaf); - m_associatedQuadTree->UnRegisterLeaf(m_topRightLeaf); - m_associatedQuadTree->UnRegisterLeaf(m_bottomLeftLeaf); - m_associatedQuadTree->UnRegisterLeaf(m_bottomRightLeaf); - //} - -} - -void NzNode::CreatePatch(const NzVector2f& center, const NzVector2f& size) -{ - m_patchMemoryAllocated = true; - m_patch = new NzPatch(center,size); -} - -void NzNode::DeletePatch() -{ - m_patchMemoryAllocated = false; - delete m_patch; -} - -unsigned short int NzNode::GetLevel() const -{ - return m_level; -} - -bool NzNode::LocateNeighbor(nzDirection dir, NzNode* neighbor) -{ - NzNode* temp = m_parent; - std::stack treePath; - treePath.push(m_direction); - neighbor = nullptr; - - switch(dir) - { - case TOP: - //Part 1 - while(temp->m_direction != (BOTTOMLEFT || BOTTOMRIGHT || CENTER)) - { - treePath.push(temp->m_direction); - temp = temp->m_parent; - } - - //Part 2 - if(temp->m_direction == BOTTOMLEFT) - temp = temp->m_parent->m_topLeftLeaf; - else if(temp->m_direction == BOTTOMRIGHT) - temp = temp->m_parent->m_topRightLeaf; - else if(temp->m_direction == CENTER) - return false;//No Neighbor existing - - //Part 3 - while(!temp->IsLeaf()) - { - if(treePath.empty()) - { - //Le chemin de redescente est plus court que celui de montée (level[node départ] < level[node d'arrivée]) - break; - } - else - { - if(treePath.top() == TOPRIGHT) - temp = temp->m_bottomRightLeaf; - else if(treePath.top() == TOPLEFT) - temp = temp->m_bottomLeftLeaf; - else//D'uh ? - { - //Logger une erreur - return false; - } - treePath.pop(); - } - } - neighbor = temp; - return true; - break; - - case BOTTOM: - //Part 1 - while(temp->m_direction != (TOPLEFT || TOPRIGHT || CENTER)) - { - treePath.push(temp->m_direction); - temp = temp->m_parent; - } - - //Part 2 - if(temp->m_direction == TOPLEFT) - temp = temp->m_parent->m_bottomLeftLeaf; - else if(temp->m_direction == TOPRIGHT) - temp = temp->m_parent->m_bottomRightLeaf; - else if(temp->m_direction == CENTER) - return false;//No Neighbor existing - - //Part 3 - while(!temp->IsLeaf()) - { - if(treePath.empty()) - { - //Le chemin de redescente est plus court que celui de montée (level[node départ] < level[node d'arrivée]) - break; - } - else - { - if(treePath.top() == BOTTOMRIGHT) - temp = temp->m_topRightLeaf; - else if(treePath.top() == BOTTOMLEFT) - temp = temp->m_topLeftLeaf; - else//D'uh ? - { - //Logger une erreur - return false; - } - treePath.pop(); - } - } - neighbor = temp; - return true; - break; - - case LEFT: - //Part 1 - while(temp->m_direction != (TOPRIGHT || BOTTOMRIGHT || CENTER)) - { - treePath.push(temp->m_direction); - temp = temp->m_parent; - } - - //Part 2 - if(temp->m_direction == TOPRIGHT) - temp = temp->m_parent->m_topLeftLeaf; - else if(temp->m_direction == BOTTOMRIGHT) - temp = temp->m_parent->m_bottomLeftLeaf; - else if(temp->m_direction == CENTER) - return false;//No Neighbor existing - - //Part 3 - while(!temp->IsLeaf()) - { - if(treePath.top() == TOPLEFT) - temp = temp->m_topRightLeaf; - else if(treePath.top() == BOTTOMLEFT) - temp = temp->m_bottomRightLeaf; - else//D'uh ? - { - //Logger une erreur - return false; - } - treePath.pop(); - } - neighbor = temp; - return true; - break; - - case RIGHT: - //Part 1 - while(temp->m_direction != (TOPLEFT || BOTTOMLEFT || CENTER)) - { - treePath.push(temp->m_direction); - temp = temp->m_parent; - } - - //Part 2 - if(temp->m_direction == TOPLEFT) - temp = temp->m_parent->m_topRightLeaf; - else if(temp->m_direction == BOTTOMLEFT) - temp = temp->m_parent->m_bottomRightLeaf; - else if(temp->m_direction == CENTER) - return false;//No Neighbor existing - - //Part 3 - while(!temp->IsLeaf()) - { - if(treePath.top() == TOPRIGHT) - temp = temp->m_topLeftLeaf; - else if(treePath.top() == BOTTOMRIGHT) - temp = temp->m_bottomLeftLeaf; - else//D'uh ? - { - //Logger une erreur - return false; - } - treePath.pop(); - } - neighbor = temp; - return true; - break; - - default : - return false; - break; - } -} - -bool NzNode::IsLeaf() const -{ - return m_isLeaf; -} - -bool NzNode::IsRoot() const -{ - return m_isRoot; -} - diff --git a/src/Nazara/DynaTerrain/Patch.cpp b/src/Nazara/DynaTerrain/Patch.cpp deleted file mode 100644 index 305bd479a..000000000 --- a/src/Nazara/DynaTerrain/Patch.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include "Patch.hpp" -//#include -//#include -//#include -//#include - - - -NzPatch::NzPatch(NzVector2f center, NzVector2f size) -{ - m_center = center; - m_size = size; -} - -NzPatch::~NzPatch() -{ - //dtor -} - -NzVector2f NzPatch::GetCenter() const -{ - -} - -NzVector2f NzPatch::GetSize() const -{ - -} - -bool NzPatch::IntersectsCircle(const NzVector2f& center, double radius) -{ - -} - -bool NzPatch::IsContainedByCircle(const NzVector2f& center, double radius) -{ - -} - -NzPatch* NzPatch::LocatePatch(const NzVector2f& position) -{ - -} diff --git a/src/Nazara/DynaTerrain/QuadTree.cpp b/src/Nazara/DynaTerrain/QuadTree.cpp deleted file mode 100644 index 03f0d8d09..000000000 --- a/src/Nazara/DynaTerrain/QuadTree.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include "QuadTree.hpp" - -//#include -//#include -//#include -//#include - -NzQuadTree::NzQuadTree(const NzVector2f& terrainCenter, const NzVector2f& terrainSize) -{ - root = new NzNode(this,0,terrainCenter,terrainSize); -} - -void NzQuadTree::RegisterLeaf(NzNode* node) -{ - leaves.push_back(node); -} - -bool NzQuadTree::UnRegisterLeaf(NzNode* node) -{ - leaves.remove(node); -} - -NzNode* NzQuadTree::GetRootPtr() -{ - return root; -} - -NzQuadTree::~NzQuadTree() -{ - //dtor -} - diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index 476ba3e3f..4181a8086 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -116,40 +116,43 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res y /= res; z /= res; - x0 = static_cast(x); - y0 = static_cast(y); - z0 = static_cast(z); + x0 = fastfloor(x); + y0 = fastfloor(y); + z0 = fastfloor(z); ii = x0 & 255; jj = y0 & 255; kk = z0 & 255; - gi0 = perm[ii + perm[jj + perm[kk]]] % 16; - gi1 = perm[ii + 1 + perm[jj + perm[kk]]] % 16; - gi2 = perm[ii + perm[jj + 1 + perm[kk]]] % 16; - gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] % 16; + gi0 = perm[ii + perm[jj + perm[kk ]]] & 15; + gi1 = perm[ii + 1 + perm[jj + perm[kk ]]] & 15; + gi2 = perm[ii + perm[jj + 1 + perm[kk ]]] & 15; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk ]]] & 15; - gi4 = perm[ii + perm[jj + perm[kk + 1]]] % 16; - gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] % 16; - gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] % 16; - gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 16; + gi4 = perm[ii + perm[jj + perm[kk + 1]]] & 15; + gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] & 15; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] & 15; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] & 15; temp.x = x-x0; temp.y = y-y0; temp.z = z-z0; + + Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10); + Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10); + Cz = temp.z * temp.z * temp.z * (temp.z * (temp.z * 6 - 15) + 10); + s[0] = gradient3[gi0][0]*temp.x + gradient3[gi0][1]*temp.y + gradient3[gi0][2]*temp.z; temp.x = x-(x0+1); t[0] = gradient3[gi1][0]*temp.x + gradient3[gi1][1]*temp.y + gradient3[gi1][2]*temp.z; - temp.x = x-x0; temp.y = y-(y0+1); - u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; - - temp.x = x-(x0+1); v[0] = gradient3[gi3][0]*temp.x + gradient3[gi3][1]*temp.y + gradient3[gi3][2]*temp.z; temp.x = x-x0; + u[0] = gradient3[gi2][0]*temp.x + gradient3[gi2][1]*temp.y + gradient3[gi2][2]*temp.z; + temp.y = y-y0; temp.z = z-(z0+1); s[1] = gradient3[gi4][0]*temp.x + gradient3[gi4][1]*temp.y + gradient3[gi4][2]*temp.z; @@ -157,31 +160,20 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res temp.x = x-(x0+1); t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z; - temp.x = x-x0; - temp.y = y-(y0+1); - u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z; - - temp.x = x-(x0+1); temp.y = y-(y0+1); v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z; - tmp = x-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + temp.x = x-x0; + u[1] = gradient3[gi6][0]*temp.x + gradient3[gi6][1]*temp.y + gradient3[gi6][2]*temp.z; Li1 = s[0] + Cx*(t[0]-s[0]); Li2 = u[0] + Cx*(v[0]-u[0]); Li3 = s[1] + Cx*(t[1]-s[1]); Li4 = u[1] + Cx*(v[1]-u[1]); - tmp = y-y0; - Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - Li5 = Li1 + Cy*(Li2-Li1); Li6 = Li3 + Cy*(Li4-Li3); - tmp = z-z0; - Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - return Li5 + Cz*(Li6-Li5); } @@ -192,53 +184,57 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, z /= res; w /= res; - x0 = static_cast(x); - y0 = static_cast(y); - z0 = static_cast(z); - w0 = static_cast(w); + x0 = fastfloor(x); + y0 = fastfloor(y); + z0 = fastfloor(z); + w0 = fastfloor(w); ii = x0 & 255; jj = y0 & 255; kk = z0 & 255; ll = w0 & 255; - gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] % 32; - gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll ]]]] % 32; - gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; - gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll ]]]] % 32; + gi0 = perm[ii + perm[jj + perm[kk + perm[ll ]]]] & 31; + gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll ]]]] & 31; + gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll ]]]] & 31; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll ]]]] & 31; - gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; - gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll ]]]] % 32; - gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; - gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] % 32; + gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll ]]]] & 31; + gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll ]]]] & 31; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] & 31; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll ]]]] & 31; - gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] % 32; - gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] % 32; - gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; - gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] % 32; + gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] & 31; + gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] & 31; + gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31; + gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31; - gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; - gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] % 32; - gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; - gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; + gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31; temp.x = x-x0; temp.y = y-y0; temp.z = z-z0; temp.w = w-w0; + + Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10); + Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10); + Cz = temp.z * temp.z * temp.z * (temp.z * (temp.z * 6 - 15) + 10); + Cw = temp.w * temp.w * temp.w * (temp.w * (temp.w * 6 - 15) + 10); + s[0] = gradient4[gi0][0]*temp.x + gradient4[gi0][1]*temp.y + gradient4[gi0][2]*temp.z + gradient4[gi0][3]*temp.w; temp.x = x-(x0+1); t[0] = gradient4[gi1][0]*temp.x + gradient4[gi1][1]*temp.y + gradient4[gi1][2]*temp.z + gradient4[gi1][3]*temp.w; - temp.x = x-x0; temp.y = y-(y0+1); - u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w; - - temp.x = x-(x0+1); v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w; temp.x = x-x0; + u[0] = gradient4[gi2][0]*temp.x + gradient4[gi2][1]*temp.y + gradient4[gi2][2]*temp.z + gradient4[gi2][3]*temp.w; + temp.y = y-y0; temp.z = z-(z0+1); s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w; @@ -246,14 +242,13 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, temp.x = x-(x0+1); t[1] = gradient4[gi5][0]*temp.x + gradient4[gi5][1]*temp.y + gradient4[gi5][2]*temp.z + gradient4[gi5][3]*temp.w; - temp.x = x-x0; temp.y = y-(y0+1); - u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w; - - temp.x = x-(x0+1); v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w; temp.x = x-x0; + u[1] = gradient4[gi6][0]*temp.x + gradient4[gi6][1]*temp.y + gradient4[gi6][2]*temp.z + gradient4[gi6][3]*temp.w; + + temp.y = y-y0; temp.z = z-z0; temp.w = w-(w0+1); @@ -262,14 +257,12 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, temp.x = x-(x0+1); t[2] = gradient4[gi9][0]*temp.x + gradient4[gi9][1]*temp.y + gradient4[gi9][2]*temp.z + gradient4[gi9][3]*temp.w; - temp.x = x-x0; temp.y = y-(y0+1); - u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w; - - temp.x = x-(x0+1); v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w; temp.x = x-x0; + u[2] = gradient4[gi10][0]*temp.x + gradient4[gi10][1]*temp.y + gradient4[gi10][2]*temp.z + gradient4[gi10][3]*temp.w; + temp.y = y-y0; temp.z = z-(z0+1); s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w; @@ -277,15 +270,11 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, temp.x = x-(x0+1); t[3] = gradient4[gi13][0]*temp.x + gradient4[gi13][1]*temp.y + gradient4[gi13][2]*temp.z + gradient4[gi13][3]*temp.w; - temp.x = x-x0; temp.y = y-(y0+1); - u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w; - - temp.x = x-(x0+1); v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w; - tmp = x-x0; - Cx = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); + temp.x = x-x0; + u[3] = gradient4[gi14][0]*temp.x + gradient4[gi14][1]*temp.y + gradient4[gi14][2]*temp.z + gradient4[gi14][3]*temp.w; Li1 = s[0] + Cx*(t[0]-s[0]); Li2 = u[0] + Cx*(v[0]-u[0]); @@ -296,23 +285,14 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, Li7 = s[3] + Cx*(t[3]-s[3]); Li8 = u[3] + Cx*(v[3]-u[3]); - tmp = y-y0; - Cy = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - Li9 = Li1 + Cy*(Li2-Li1); Li10 = Li3 + Cy*(Li4-Li3); Li11 = Li5 + Cy*(Li6-Li5); Li12 = Li7 + Cy*(Li8-Li7); - tmp = z-z0; - Cz = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - Li13 = Li9 + Cz*(Li10-Li9); Li14 = Li11 + Cz*(Li12-Li11); - tmp = w-w0; - Cw = tmp * tmp * tmp * (tmp * (tmp * 6 - 15) + 10); - return Li13 + Cw*(Li14-Li13); } @@ -323,11 +303,13 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res) x /= res; y /= res; - skewedCubeOrigin.x = fastfloor(x + (x + y) * SkewCoeff2D); - skewedCubeOrigin.y = fastfloor(y + (x + y) * SkewCoeff2D); + sum = (x + y) * SkewCoeff2D; + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); - unskewedCubeOrigin.x = skewedCubeOrigin.x - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; - unskewedCubeOrigin.y = skewedCubeOrigin.y - (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; + sum = (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; + unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; + unskewedCubeOrigin.y = skewedCubeOrigin.y - sum; unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; @@ -343,9 +325,7 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res) off1.y = 1; } - - d1.x = unskewedCubeOrigin.x - x; - d1.y = unskewedCubeOrigin.y - y; + d1 = - unskewedDistToOrigin; d2.x = d1.x + off1.x - UnskewCoeff2D; d2.y = d1.y + off1.y - UnskewCoeff2D; @@ -356,9 +336,9 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res) ii = skewedCubeOrigin.x & 255; jj = skewedCubeOrigin.y & 255; - gi0 = perm[ii + perm[jj]] & 7; + gi0 = perm[ii + perm[jj ]] & 7; gi1 = perm[ii + off1.x + perm[jj + off1.y]] & 7; - gi2 = perm[ii + 1 + perm[jj + 1]] & 7; + gi2 = perm[ii + 1 + perm[jj + 1 ]] & 7; c1 = 0.5 - d1.x * d1.x - d1.y * d1.y; c2 = 0.5 - d2.x * d2.x - d2.y * d2.y; @@ -388,21 +368,23 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re y /= res; z /= res; - Origin.x = fastfloor(x + (x + y + z) * SkewCoeff3D); - Origin.y = fastfloor(y + (x + y + z) * SkewCoeff3D); - Origin.z = fastfloor(z + (x + y + z) * SkewCoeff3D); + sum = (x + y + z) * SkewCoeff3D; + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); + skewedCubeOrigin.z = fastfloor(z + sum); - A.x = Origin.x - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; - A.y = Origin.y - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; - A.z = Origin.z - (Origin.x + Origin.y + Origin.z) * UnskewCoeff3D; + sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z) * UnskewCoeff3D; + unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; + unskewedCubeOrigin.y = skewedCubeOrigin.y - sum; + unskewedCubeOrigin.z = skewedCubeOrigin.z - sum; - IsoOriginDist.x = x - A.x; - IsoOriginDist.y = y - A.y; - IsoOriginDist.z = z - A.z; + unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; + unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; + unskewedDistToOrigin.z = z - unskewedCubeOrigin.z; - if(IsoOriginDist.x >= IsoOriginDist.y) + if(unskewedDistToOrigin.x >= unskewedDistToOrigin.y) { - if(IsoOriginDist.y >= IsoOriginDist.z) + if(unskewedDistToOrigin.y >= unskewedDistToOrigin.z) { off1.x = 1; off1.y = 0; @@ -411,7 +393,7 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re off2.y = 1; off2.z = 0; } - else if(IsoOriginDist.x >= IsoOriginDist.z) + else if(unskewedDistToOrigin.x >= unskewedDistToOrigin.z) { off1.x = 1; off1.y = 0; @@ -432,7 +414,7 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re } else { - if(IsoOriginDist.y < IsoOriginDist.z) + if(unskewedDistToOrigin.y < unskewedDistToOrigin.z) { off1.x = 0; off1.y = 0; @@ -441,7 +423,7 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re off2.y = 1; off2.z = 1; } - else if(IsoOriginDist.x < IsoOriginDist.z) + else if(unskewedDistToOrigin.x < unskewedDistToOrigin.z) { off1.x = 0; off1.y = 1; @@ -461,35 +443,28 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re } } - d1.x = A.x - x; - d1.y = A.y - y; - d1.z = A.z - z; + d1 = unskewedDistToOrigin; - d2.x = d1.x + off1.x - UnskewCoeff3D; - d2.y = d1.y + off1.y - UnskewCoeff3D; - d2.z = d1.z + off1.z - UnskewCoeff3D; + d2.x = d1.x - off1.x + UnskewCoeff3D; + d2.y = d1.y - off1.y + UnskewCoeff3D; + d2.z = d1.z - off1.z + UnskewCoeff3D; - d3.x = d1.x + off2.x - 2*UnskewCoeff3D; - d3.y = d1.y + off2.y - 2*UnskewCoeff3D; - d3.z = d1.z + off2.z - 2*UnskewCoeff3D; + d3.x = d1.x - off2.x + 2*UnskewCoeff3D; + d3.y = d1.y - off2.y + 2*UnskewCoeff3D; + d3.z = d1.z - off2.z + 2*UnskewCoeff3D; - d4.x = d1.x + 1.0 - 3*UnskewCoeff3D; - d4.y = d1.y + 1.0 - 3*UnskewCoeff3D; - d4.z = d1.z + 1.0 - 3*UnskewCoeff3D; + d4.x = d1.x - 1.0 + 3*UnskewCoeff3D; + d4.y = d1.y - 1.0 + 3*UnskewCoeff3D; + d4.z = d1.z - 1.0 + 3*UnskewCoeff3D; - ii = Origin.x & 255; - jj = Origin.y & 255; - kk = Origin.z & 255; + ii = skewedCubeOrigin.x & 255; + jj = skewedCubeOrigin.y & 255; + kk = skewedCubeOrigin.z & 255; - gi0 = perm[ii + perm[jj + perm[kk]]] % 12; + gi0 = perm[ii + perm[jj + perm[kk ]]] % 12; gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z]]] % 12; gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z]]] % 12; - gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] % 12; - - n1 = gradient3[gi0][0] * d1.x + gradient3[gi0][1] * d1.y + gradient3[gi0][2] * d1.z; - n2 = gradient3[gi1][0] * d2.x + gradient3[gi1][1] * d2.y + gradient3[gi1][2] * d2.z; - n3 = gradient3[gi2][0] * d3.x + gradient3[gi2][1] * d3.y + gradient3[gi2][2] * d3.z; - n4 = gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 ]]] % 12; c1 = 0.6 - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z; c2 = 0.6 - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z; @@ -497,20 +472,26 @@ float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float re c4 = 0.6 - d4.x * d4.x - d4.y * d4.y - d4.z * d4.z; if(c1 < 0) - c1 = 0; + n1 = 0; + else + n1 = c1*c1*c1*c1*(gradient3[gi0][0] * d1.x + gradient3[gi0][1] * d1.y + gradient3[gi0][2] * d1.z); + if(c2 < 0) - c2 = 0; + n2 = 0; + else + n2 = c2*c2*c2*c2*(gradient3[gi1][0] * d2.x + gradient3[gi1][1] * d2.y + gradient3[gi1][2] * d2.z); + if(c3 < 0) - c3 = 0; + n3 = 0; + else + n3 = c3*c3*c3*c3*(gradient3[gi2][0] * d3.x + gradient3[gi2][1] * d3.y + gradient3[gi2][2] * d3.z); + if(c4 < 0) - c4 = 0; + n4 = 0; + else + n4 = c4*c4*c4*c4*(gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z); - n1 = c1*c1*c1*n1; - n2 = c2*c2*c2*n2; - n3 = c3*c3*c3*n3; - n4 = c4*c4*c4*n4; - - return (n1+n2+n3+n4)*17.6995; + return (n1+n2+n3+n4)*32; } float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, float res) @@ -520,27 +501,29 @@ float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, z /= res; w /= res; - Origin.x = fastfloor(x + (x + y + z + w) * SkewCoeff4D); - Origin.y = fastfloor(y + (x + y + z + w) * SkewCoeff4D); - Origin.z = fastfloor(z + (x + y + z + w) * SkewCoeff4D); - Origin.w = fastfloor(w + (x + y + z + w) * SkewCoeff4D); + sum = (x + y + z + w) * SkewCoeff4D; + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); + skewedCubeOrigin.z = fastfloor(z + sum); + skewedCubeOrigin.w = fastfloor(w + sum); - A.x = Origin.x - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; - A.y = Origin.y - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; - A.z = Origin.z - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; - A.w = Origin.w - (Origin.x + Origin.y + Origin.z + Origin.w) * UnskewCoeff4D; + sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z + skewedCubeOrigin.w) * UnskewCoeff4D; + unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; + unskewedCubeOrigin.y = skewedCubeOrigin.y - sum; + unskewedCubeOrigin.z = skewedCubeOrigin.z - sum; + unskewedCubeOrigin.w = skewedCubeOrigin.w - sum; - IsoOriginDist.x = x - A.x; - IsoOriginDist.y = y - A.y; - IsoOriginDist.z = z - A.z; - IsoOriginDist.w = w - A.w; + unskewedDistToOrigin.x = x - unskewedCubeOrigin.x; + unskewedDistToOrigin.y = y - unskewedCubeOrigin.y; + unskewedDistToOrigin.z = z - unskewedCubeOrigin.z; + unskewedDistToOrigin.w = w - unskewedCubeOrigin.w; - c1 = (IsoOriginDist.x > IsoOriginDist.y) ? 32 : 0; - c2 = (IsoOriginDist.x > IsoOriginDist.z) ? 16 : 0; - c3 = (IsoOriginDist.y > IsoOriginDist.z) ? 8 : 0; - c4 = (IsoOriginDist.x > IsoOriginDist.w) ? 4 : 0; - c5 = (IsoOriginDist.y > IsoOriginDist.w) ? 2 : 0; - c6 = (IsoOriginDist.z > IsoOriginDist.w) ? 1 : 0; + c1 = (unskewedDistToOrigin.x > unskewedDistToOrigin.y) ? 32 : 0; + c2 = (unskewedDistToOrigin.x > unskewedDistToOrigin.z) ? 16 : 0; + c3 = (unskewedDistToOrigin.y > unskewedDistToOrigin.z) ? 8 : 0; + c4 = (unskewedDistToOrigin.x > unskewedDistToOrigin.w) ? 4 : 0; + c5 = (unskewedDistToOrigin.y > unskewedDistToOrigin.w) ? 2 : 0; + c6 = (unskewedDistToOrigin.z > unskewedDistToOrigin.w) ? 1 : 0; c = c1 + c2 + c3 + c4 + c5 + c6; off1.x = lookupTable4D[c][0] >= 3 ? 1 : 0; @@ -558,48 +541,39 @@ float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, off3.z = lookupTable4D[c][2] >= 1 ? 1 : 0; off3.w = lookupTable4D[c][3] >= 1 ? 1 : 0; - d1.x = A.x - x; - d1.y = A.y - y; - d1.z = A.z - z; - d1.w = A.w - w; + d1 = unskewedDistToOrigin; - d2.x = d1.x + off1.x - UnskewCoeff4D; - d2.y = d1.y + off1.y - UnskewCoeff4D; - d2.z = d1.z + off1.z - UnskewCoeff4D; - d2.w = d1.w + off1.w - UnskewCoeff4D; + d2.x = d1.x - off1.x + UnskewCoeff4D; + d2.y = d1.y - off1.y + UnskewCoeff4D; + d2.z = d1.z - off1.z + UnskewCoeff4D; + d2.w = d1.w - off1.w + UnskewCoeff4D; - d3.x = d1.x + off2.x - 2*UnskewCoeff4D; - d3.y = d1.y + off2.y - 2*UnskewCoeff4D; - d3.z = d1.z + off2.z - 2*UnskewCoeff4D; - d3.w = d1.w + off2.w - 2*UnskewCoeff4D; + d3.x = d1.x - off2.x + 2*UnskewCoeff4D; + d3.y = d1.y - off2.y + 2*UnskewCoeff4D; + d3.z = d1.z - off2.z + 2*UnskewCoeff4D; + d3.w = d1.w - off2.w + 2*UnskewCoeff4D; - d4.x = d1.x + off3.x - 3*UnskewCoeff4D; - d4.y = d1.y + off3.y - 3*UnskewCoeff4D; - d4.z = d1.z + off3.z - 3*UnskewCoeff4D; - d4.w = d1.w + off3.w - 3*UnskewCoeff4D; + d4.x = d1.x - off3.x + 3*UnskewCoeff4D; + d4.y = d1.y - off3.y + 3*UnskewCoeff4D; + d4.z = d1.z - off3.z + 3*UnskewCoeff4D; + d4.w = d1.w - off3.w + 3*UnskewCoeff4D; - d5.x = d1.x + 1.0 - 4*UnskewCoeff4D; - d5.y = d1.y + 1.0 - 4*UnskewCoeff4D; - d5.z = d1.z + 1.0 - 4*UnskewCoeff4D; - d5.w = d1.w + 1.0 - 4*UnskewCoeff4D; + d5.x = d1.x - 1.0 + 4*UnskewCoeff4D; + d5.y = d1.y - 1.0 + 4*UnskewCoeff4D; + d5.z = d1.z - 1.0 + 4*UnskewCoeff4D; + d5.w = d1.w - 1.0 + 4*UnskewCoeff4D; - ii = Origin.x & 255; - jj = Origin.y & 255; - kk = Origin.z & 255; - ll = Origin.w & 255; + ii = skewedCubeOrigin.x & 255; + jj = skewedCubeOrigin.y & 255; + kk = skewedCubeOrigin.z & 255; + ll = skewedCubeOrigin.w & 255; - gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] % 32; - gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] % 32; - gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] % 32; - gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] % 32; + gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31; + gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] & 31; + gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] & 31; + gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] & 31; gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; - n1 = gradient4[gi0][0]*d1.x + gradient4[gi0][1]*d1.y + gradient4[gi0][2]*d1.z + gradient4[gi0][3]*d1.w; - n2 = gradient4[gi1][0]*d2.x + gradient4[gi1][1]*d2.y + gradient4[gi1][2]*d2.z + gradient4[gi1][3]*d2.w; - n3 = gradient4[gi2][0]*d3.x + gradient4[gi2][1]*d3.y + gradient4[gi2][2]*d3.z + gradient4[gi2][3]*d3.w; - n4 = gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w; - n5 = gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w; - c1 = 0.6 - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; c2 = 0.6 - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; c3 = 0.6 - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w; @@ -607,23 +581,31 @@ float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, c5 = 0.6 - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w; if(c1 < 0) - c1 = 0; + n1 = 0; + else + n1 = c1*c1*c1*c1*(gradient4[gi0][0]*d1.x + gradient4[gi0][1]*d1.y + gradient4[gi0][2]*d1.z + gradient4[gi0][3]*d1.w); + if(c2 < 0) - c2 = 0; + n2 = 0; + else + n2 = c2*c2*c2*c2*(gradient4[gi1][0]*d2.x + gradient4[gi1][1]*d2.y + gradient4[gi1][2]*d2.z + gradient4[gi1][3]*d2.w); + if(c3 < 0) - c3 = 0; + n3 = 0; + else + n3 = c3*c3*c3*c3*(gradient4[gi2][0]*d3.x + gradient4[gi2][1]*d3.y + gradient4[gi2][2]*d3.z + gradient4[gi2][3]*d3.w); + if(c4 < 0) - c4 = 0; + n4 = 0; + else + n4 = c4*c4*c4*c4*(gradient4[gi3][0]*d4.x + gradient4[gi3][1]*d4.y + gradient4[gi3][2]*d4.z + gradient4[gi3][3]*d4.w); + if(c5 < 0) - c5 = 0; + n5 = 0; + else + n5 = c5*c5*c5*c5*(gradient4[gi4][0]*d5.x + gradient4[gi4][1]*d5.y + gradient4[gi4][2]*d5.z + gradient4[gi4][3]*d5.w); - n1 = c1*c1*c1*n1; - n2 = c2*c2*c2*n2; - n3 = c3*c3*c3*n3; - n4 = c4*c4*c4*n4; - n5 = c5*c5*c5*n5; - - return (n1+n2+n3+n4+n5)*17.6995; + return (n1+n2+n3+n4+n5)*27.0; } //------------------------------ CELL ------------------------------ From 879a33878e03165059805bc24defd19ea40ac34e Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Sat, 9 Jun 2012 17:07:01 +0200 Subject: [PATCH 11/13] fixed typo --- build/scripts/module/noise.lua | 12 ++++++------ include/Nazara/Noise/ComplexNoiseBase.hpp | 5 ++--- include/Nazara/Noise/NoiseBase.hpp | 2 +- include/Nazara/Noise/NoiseMachine.hpp | 5 ++--- include/Nazara/Noise/Perlin2D.hpp | 8 +++----- include/Nazara/Noise/Perlin2D.inl | 7 ++++--- include/Nazara/Noise/Perlin3D.hpp | 8 +++----- include/Nazara/Noise/Perlin3D.inl | 8 +++++--- include/Nazara/Noise/Perlin4D.hpp | 8 +++----- include/Nazara/Noise/Perlin4D.inl | 8 +++++--- include/Nazara/Noise/Simplex2D.hpp | 9 +++------ include/Nazara/Noise/Simplex2D.inl | 7 ++++--- include/Nazara/Noise/Simplex3D.hpp | 11 ++++------- include/Nazara/Noise/Simplex3D.inl | 8 ++++---- include/Nazara/Noise/Simplex4D.hpp | 9 +++------ include/Nazara/Noise/Simplex4D.inl | 7 ++++--- src/Nazara/Noise/ComplexNoiseBase.cpp | 9 ++++++++- src/Nazara/Noise/Noise.cpp | 2 +- src/Nazara/Noise/NoiseBase.cpp | 9 ++++----- src/Nazara/Noise/NoiseMachine.cpp | 10 +++++----- 20 files changed, 74 insertions(+), 78 deletions(-) diff --git a/build/scripts/module/noise.lua b/build/scripts/module/noise.lua index cb168a391..55f21fc76 100644 --- a/build/scripts/module/noise.lua +++ b/build/scripts/module/noise.lua @@ -2,16 +2,16 @@ project "NazaraNoise" files { - "../include/Nazara/Noise/**.hpp", - "../include/Nazara/Noise/**.inl", - "../src/Nazara/Noise/**.hpp", - "../src/Nazara/Noise/**.cpp" + "../include/Nazara/Noise/**.hpp", + "../include/Nazara/Noise/**.inl", + "../src/Nazara/Noise/**.hpp", + "../src/Nazara/Noise/**.cpp" } if (os.is("windows")) then - excludes { "../src/Nazara/ModuleName/Posix/*.hpp", "../src/Nazara/ModuleName/Posix/*.cpp" } + excludes { "../src/Nazara/Noise/Posix/*.hpp", "../src/Nazara/Noise/Posix/*.cpp" } else - excludes { "../src/Nazara/ModuleName/Win32/*.hpp", "../src/Nazara/ModuleName/Win32/*.cpp" } + excludes { "../src/Nazara/Noise/Win32/*.hpp", "../src/Nazara/Noise/Win32/*.cpp" } end configuration "DebugStatic" diff --git a/include/Nazara/Noise/ComplexNoiseBase.hpp b/include/Nazara/Noise/ComplexNoiseBase.hpp index e1f159e9f..c242eea81 100644 --- a/include/Nazara/Noise/ComplexNoiseBase.hpp +++ b/include/Nazara/Noise/ComplexNoiseBase.hpp @@ -8,10 +8,9 @@ #define COMPLEXNOISEBASE_H #include -//#include -#include "NoiseBase.hpp" +#include -class NzComplexNoiseBase : public NzNoiseBase +class NAZARA_API NzComplexNoiseBase : public NzNoiseBase { public: NzComplexNoiseBase(); diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp index 06f0d37ca..3bab56163 100644 --- a/include/Nazara/Noise/NoiseBase.hpp +++ b/include/Nazara/Noise/NoiseBase.hpp @@ -9,7 +9,7 @@ #include -class NzNoiseBase +class NAZARA_API NzNoiseBase { public: NzNoiseBase(int seed = 0); diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp index f7b60f0e5..83315ab3c 100644 --- a/include/Nazara/Noise/NoiseMachine.hpp +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -8,8 +8,7 @@ #define NOISEMACHINE_HPP #include -//#include -#include "ComplexNoiseBase.hpp" +#include #include #include #include @@ -17,7 +16,7 @@ //TODO : AMELIORER MELANGE TABLE PERMUTATION // PB MULTIPLES APPELS SHUFFLEPERMUTATIONTABLE() -class NzNoiseMachine : public NzComplexNoiseBase +class NAZARA_API NzNoiseMachine : public NzComplexNoiseBase { public: NzNoiseMachine(int seed = 0); diff --git a/include/Nazara/Noise/Perlin2D.hpp b/include/Nazara/Noise/Perlin2D.hpp index 614d7e6a1..286228dc2 100644 --- a/include/Nazara/Noise/Perlin2D.hpp +++ b/include/Nazara/Noise/Perlin2D.hpp @@ -8,11 +8,10 @@ #define PERLIN2D_H #include -//#include -#include "NoiseBase.hpp" +#include #include -template class NzPerlin2D : public NzNoiseBase +template class NAZARA_API NzPerlin2D : public NzNoiseBase { public: NzPerlin2D(); @@ -33,8 +32,7 @@ template class NzPerlin2D : public NzNoiseBase typedef NzPerlin2D NzPerlin2Df; typedef NzPerlin2D NzPerlin2Dd; -//#include -#include "Perlin2D.inl" +#include #endif // PERLIN2D_H diff --git a/include/Nazara/Noise/Perlin2D.inl b/include/Nazara/Noise/Perlin2D.inl index 2225eb024..a823aba81 100644 --- a/include/Nazara/Noise/Perlin2D.inl +++ b/include/Nazara/Noise/Perlin2D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -//#include -//#include -//#include +#include +#include +#include template NzPerlin2D::NzPerlin2D() @@ -57,3 +57,4 @@ T NzPerlin2D::GetValue(T x, T y, T res) return Li1 + Cy*(Li2-Li1); } +#include diff --git a/include/Nazara/Noise/Perlin3D.hpp b/include/Nazara/Noise/Perlin3D.hpp index 74eb53557..736d63bde 100644 --- a/include/Nazara/Noise/Perlin3D.hpp +++ b/include/Nazara/Noise/Perlin3D.hpp @@ -8,11 +8,10 @@ #define PERLIN3D_H #include -//#include -#include "NoiseBase.hpp" +#include #include -template class NzPerlin3D : public NzNoiseBase +template class NAZARA_API NzPerlin3D : public NzNoiseBase { public: NzPerlin3D(); @@ -36,7 +35,6 @@ template class NzPerlin3D : public NzNoiseBase typedef NzPerlin3D NzPerlin3Df; typedef NzPerlin3D NzPerlin3Dd; -//#include -#include "Perlin3D.inl" +#include #endif // PERLIN3D_H diff --git a/include/Nazara/Noise/Perlin3D.inl b/include/Nazara/Noise/Perlin3D.inl index bbf01665a..60231979a 100644 --- a/include/Nazara/Noise/Perlin3D.inl +++ b/include/Nazara/Noise/Perlin3D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -//#include -//#include -//#include +#include +#include +#include template NzPerlin3D::NzPerlin3D() @@ -88,3 +88,5 @@ T NzPerlin3D::GetValue(T x, T y, T z, T res) return Li5 + Cz*(Li6-Li5); } + +#include diff --git a/include/Nazara/Noise/Perlin4D.hpp b/include/Nazara/Noise/Perlin4D.hpp index 897e3250e..165583b00 100644 --- a/include/Nazara/Noise/Perlin4D.hpp +++ b/include/Nazara/Noise/Perlin4D.hpp @@ -8,11 +8,10 @@ #define PERLIN4D_H #include -//#include -#include "NoiseBase.hpp" +#include #include -template class NzPerlin4D : public NzNoiseBase +template class NAZARA_API NzPerlin4D : public NzNoiseBase { public: NzPerlin4D(); @@ -36,7 +35,6 @@ template class NzPerlin4D : public NzNoiseBase typedef NzPerlin4D NzPerlin4Df; typedef NzPerlin4D NzPerlin4Dd; -//#include -#include "Perlin4D.inl" +#include #endif // PERLIN4D_H diff --git a/include/Nazara/Noise/Perlin4D.inl b/include/Nazara/Noise/Perlin4D.inl index c8de3b255..b009098f8 100644 --- a/include/Nazara/Noise/Perlin4D.inl +++ b/include/Nazara/Noise/Perlin4D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -//#include -//#include -//#include +#include +#include +#include template NzPerlin4D::NzPerlin4D() @@ -146,3 +146,5 @@ T NzPerlin4D::GetValue(T x, T y, T z, T w, T res) return Li13 + Cw*(Li14-Li13); } + +#include diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp index d1af5aaed..8905fda22 100644 --- a/include/Nazara/Noise/Simplex2D.hpp +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -8,12 +8,10 @@ #define SIMPLEX2D_H #include -//#include -#include "NoiseBase.hpp" +#include #include - -template class NzSimplex2D : public NzNoiseBase +template class NAZARA_API NzSimplex2D : public NzNoiseBase { public: NzSimplex2D(); @@ -39,8 +37,7 @@ template class NzSimplex2D : public NzNoiseBase typedef NzSimplex2D NzSimplex2Df; typedef NzSimplex2D NzSimplex2Dd; -//#include -#include "Simplex2D.inl" +#include #endif // SIMPLEX2D_H diff --git a/include/Nazara/Noise/Simplex2D.inl b/include/Nazara/Noise/Simplex2D.inl index 0c7ab3c93..3d019fd54 100644 --- a/include/Nazara/Noise/Simplex2D.inl +++ b/include/Nazara/Noise/Simplex2D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -//#include -//#include -//#include +#include +#include +#include template NzSimplex2D::NzSimplex2D() @@ -85,3 +85,4 @@ T NzSimplex2D::GetValue(T x, T y, T res) return (n1+n2+n3)*70; } +#include diff --git a/include/Nazara/Noise/Simplex3D.hpp b/include/Nazara/Noise/Simplex3D.hpp index 6a95fbb78..0e49cecbf 100644 --- a/include/Nazara/Noise/Simplex3D.hpp +++ b/include/Nazara/Noise/Simplex3D.hpp @@ -8,12 +8,10 @@ #define SIMPLEX3D_H #include -//#include -#include "NoiseBase.hpp" +#include +#include - - -template class NzSimplex3D : public NzNoiseBase +template class NAZARA_API NzSimplex3D : public NzNoiseBase { public: NzSimplex3D(); @@ -39,8 +37,7 @@ template class NzSimplex3D : public NzNoiseBase typedef NzSimplex3D NzSimplex3Df; typedef NzSimplex3D NzSimplex3Dd; -//#include -#include "Simplex3D.inl" +#include #endif // SIMPLEX3D_H diff --git a/include/Nazara/Noise/Simplex3D.inl b/include/Nazara/Noise/Simplex3D.inl index 94ab86a6f..d0bd3bf0d 100644 --- a/include/Nazara/Noise/Simplex3D.inl +++ b/include/Nazara/Noise/Simplex3D.inl @@ -2,10 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -//#include -//#include -//#include -#include +#include +#include +#include template NzSimplex3D::NzSimplex3D() @@ -155,3 +154,4 @@ T NzSimplex3D::GetValue(T x, T y, T z, T res) return (n1+n2+n3+n4)*32; } +#include diff --git a/include/Nazara/Noise/Simplex4D.hpp b/include/Nazara/Noise/Simplex4D.hpp index 62f08e2b5..bf53d7a5b 100644 --- a/include/Nazara/Noise/Simplex4D.hpp +++ b/include/Nazara/Noise/Simplex4D.hpp @@ -8,12 +8,10 @@ #define SIMPLEX4D_H #include -//#include -#include "NoiseBase.hpp" +#include #include - -template class NzSimplex4D : public NzNoiseBase +template class NAZARA_API NzSimplex4D : public NzNoiseBase { public: NzSimplex4D(); @@ -41,8 +39,7 @@ template class NzSimplex4D : public NzNoiseBase typedef NzSimplex4D NzSimplex4Df; typedef NzSimplex4D NzSimplex4Dd; -//#include -#include "Simplex4D.inl" +#include #endif // SIMPLEX4D_H diff --git a/include/Nazara/Noise/Simplex4D.inl b/include/Nazara/Noise/Simplex4D.inl index db6b86397..413467b85 100644 --- a/include/Nazara/Noise/Simplex4D.inl +++ b/include/Nazara/Noise/Simplex4D.inl @@ -2,9 +2,9 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -//#include -//#include -//#include +#include +#include +#include template NzSimplex4D::NzSimplex4D() @@ -160,3 +160,4 @@ T NzSimplex4D::GetValue(T x, T y, T z, T w, T res) return (n1+n2+n3+n4+n5)*27.0; } +#include diff --git a/src/Nazara/Noise/ComplexNoiseBase.cpp b/src/Nazara/Noise/ComplexNoiseBase.cpp index cd0288c3d..7a94422da 100644 --- a/src/Nazara/Noise/ComplexNoiseBase.cpp +++ b/src/Nazara/Noise/ComplexNoiseBase.cpp @@ -1,5 +1,12 @@ -#include "ComplexNoiseBase.hpp" +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include #include +#include +#include +#include NzComplexNoiseBase::NzComplexNoiseBase() { diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp index 06c7c13af..59a5889fb 100644 --- a/src/Nazara/Noise/Noise.cpp +++ b/src/Nazara/Noise/Noise.cpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#include +#include #include #include diff --git a/src/Nazara/Noise/NoiseBase.cpp b/src/Nazara/Noise/NoiseBase.cpp index 2f9b76b2d..e718b01be 100644 --- a/src/Nazara/Noise/NoiseBase.cpp +++ b/src/Nazara/Noise/NoiseBase.cpp @@ -2,11 +2,10 @@ // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include "NoiseBase.hpp" -//#include -//#include -//#include -//#include +#include +#include +#include +#include NzNoiseBase::NzNoiseBase(int seed) { diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index 4181a8086..194e73049 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -1,11 +1,11 @@ // Copyright (C) 2012 Rémi Bèges // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp -#include "NoiseMachine.hpp" -//#include -//#include -//#include -//#include + +#include +#include +#include +#include NzNoiseMachine::NzNoiseMachine(int seed) { From 23bb9da0bd45842d990293869d5cc2cace986e44 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Sun, 10 Jun 2012 10:27:51 +0200 Subject: [PATCH 12/13] Fixed typo + minor errors --- include/Nazara/Noise/ComplexNoiseBase.hpp | 8 ++++---- include/Nazara/Noise/Debug.hpp | 2 +- include/Nazara/Noise/Noise.hpp | 2 +- include/Nazara/Noise/NoiseBase.hpp | 8 ++++---- include/Nazara/Noise/NoiseMachine.hpp | 5 +---- include/Nazara/Noise/Perlin2D.hpp | 6 +++--- include/Nazara/Noise/Perlin3D.hpp | 6 +++--- include/Nazara/Noise/Perlin4D.hpp | 6 +++--- include/Nazara/Noise/Simplex2D.hpp | 6 +++--- include/Nazara/Noise/Simplex3D.hpp | 6 +++--- include/Nazara/Noise/Simplex4D.hpp | 4 ++-- src/Nazara/Noise/ComplexNoiseBase.cpp | 6 ------ src/Nazara/Noise/Debug/Leaks.cpp | 3 ++- src/Nazara/Noise/Noise.cpp | 2 ++ src/Nazara/Noise/NoiseBase.cpp | 22 ++++------------------ src/Nazara/Noise/NoiseMachine.cpp | 2 ++ 16 files changed, 38 insertions(+), 56 deletions(-) diff --git a/include/Nazara/Noise/ComplexNoiseBase.hpp b/include/Nazara/Noise/ComplexNoiseBase.hpp index c242eea81..a9db6870e 100644 --- a/include/Nazara/Noise/ComplexNoiseBase.hpp +++ b/include/Nazara/Noise/ComplexNoiseBase.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef COMPLEXNOISEBASE_H -#define COMPLEXNOISEBASE_H +#ifndef COMPLEXNOISEBASE_HPP +#define COMPLEXNOISEBASE_HPP #include #include @@ -14,7 +14,7 @@ class NAZARA_API NzComplexNoiseBase : public NzNoiseBase { public: NzComplexNoiseBase(); - ~NzComplexNoiseBase(); + ~NzComplexNoiseBase() = default; void SetLacunarity(float lacunarity); void SetHurstParameter(float h); @@ -32,4 +32,4 @@ class NAZARA_API NzComplexNoiseBase : public NzNoiseBase }; -#endif // COMPLEXNOISEBASE_H +#endif // COMPLEXNOISEBASE_HPP diff --git a/include/Nazara/Noise/Debug.hpp b/include/Nazara/Noise/Debug.hpp index d06344f48..c26ad1c80 100644 --- a/include/Nazara/Noise/Debug.hpp +++ b/include/Nazara/Noise/Debug.hpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) +#if NAZARA_NOISE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) #include #define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp index 61b062b5b..a42cad927 100644 --- a/include/Nazara/Noise/Noise.hpp +++ b/include/Nazara/Noise/Noise.hpp @@ -24,4 +24,4 @@ class NAZARA_API NzNoise static bool s_initialized; }; -#endif // NOISE_H +#endif // NOISE_HPP diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp index 3bab56163..331d227df 100644 --- a/include/Nazara/Noise/NoiseBase.hpp +++ b/include/Nazara/Noise/NoiseBase.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef NOISEBASE_H -#define NOISEBASE_H +#ifndef NOISEBASE_HPP +#define NOISEBASE_HPP #include @@ -13,7 +13,7 @@ class NAZARA_API NzNoiseBase { public: NzNoiseBase(int seed = 0); - virtual ~NzNoiseBase(); + ~NzNoiseBase() = default; void SetNewSeed(int seed); int GetUniformRandomValue(); @@ -30,4 +30,4 @@ class NAZARA_API NzNoiseBase }; -#endif // NOISEBASE_H +#endif // NOISEBASE_HPP diff --git a/include/Nazara/Noise/NoiseMachine.hpp b/include/Nazara/Noise/NoiseMachine.hpp index 83315ab3c..4c221628f 100644 --- a/include/Nazara/Noise/NoiseMachine.hpp +++ b/include/Nazara/Noise/NoiseMachine.hpp @@ -13,9 +13,6 @@ #include #include -//TODO : AMELIORER MELANGE TABLE PERMUTATION -// PB MULTIPLES APPELS SHUFFLEPERMUTATIONTABLE() - class NAZARA_API NzNoiseMachine : public NzComplexNoiseBase { public: @@ -93,4 +90,4 @@ class NAZARA_API NzNoiseMachine : public NzComplexNoiseBase }; -#endif // NOISEMACHINE_H +#endif // NOISEMACHINE_HPP diff --git a/include/Nazara/Noise/Perlin2D.hpp b/include/Nazara/Noise/Perlin2D.hpp index 286228dc2..18e7ae875 100644 --- a/include/Nazara/Noise/Perlin2D.hpp +++ b/include/Nazara/Noise/Perlin2D.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef PERLIN2D_H -#define PERLIN2D_H +#ifndef PERLIN2D_HPP +#define PERLIN2D_HPP #include #include @@ -34,5 +34,5 @@ typedef NzPerlin2D NzPerlin2Dd; #include -#endif // PERLIN2D_H +#endif // PERLIN2D_HPP diff --git a/include/Nazara/Noise/Perlin3D.hpp b/include/Nazara/Noise/Perlin3D.hpp index 736d63bde..a425dc384 100644 --- a/include/Nazara/Noise/Perlin3D.hpp +++ b/include/Nazara/Noise/Perlin3D.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef PERLIN3D_H -#define PERLIN3D_H +#ifndef PERLIN3D_HPP +#define PERLIN3D_HPP #include #include @@ -37,4 +37,4 @@ typedef NzPerlin3D NzPerlin3Dd; #include -#endif // PERLIN3D_H +#endif // PERLIN3D_HPP diff --git a/include/Nazara/Noise/Perlin4D.hpp b/include/Nazara/Noise/Perlin4D.hpp index 165583b00..b5a25ee4d 100644 --- a/include/Nazara/Noise/Perlin4D.hpp +++ b/include/Nazara/Noise/Perlin4D.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef PERLIN4D_H -#define PERLIN4D_H +#ifndef PERLIN4D_HPP +#define PERLIN4D_HPP #include #include @@ -37,4 +37,4 @@ typedef NzPerlin4D NzPerlin4Dd; #include -#endif // PERLIN4D_H +#endif // PERLIN4D_HPP diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp index 8905fda22..78d896f7d 100644 --- a/include/Nazara/Noise/Simplex2D.hpp +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef SIMPLEX2D_H -#define SIMPLEX2D_H +#ifndef SIMPLEX2D_HPP +#define SIMPLEX2D_HPP #include #include @@ -39,5 +39,5 @@ typedef NzSimplex2D NzSimplex2Dd; #include -#endif // SIMPLEX2D_H +#endif // SIMPLEX2D_HPP diff --git a/include/Nazara/Noise/Simplex3D.hpp b/include/Nazara/Noise/Simplex3D.hpp index 0e49cecbf..399705072 100644 --- a/include/Nazara/Noise/Simplex3D.hpp +++ b/include/Nazara/Noise/Simplex3D.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef SIMPLEX3D_H -#define SIMPLEX3D_H +#ifndef SIMPLEX3D_HPP +#define SIMPLEX3D_HPP #include #include @@ -39,5 +39,5 @@ typedef NzSimplex3D NzSimplex3Dd; #include -#endif // SIMPLEX3D_H +#endif // SIMPLEX3D_HPP diff --git a/include/Nazara/Noise/Simplex4D.hpp b/include/Nazara/Noise/Simplex4D.hpp index bf53d7a5b..f932d212b 100644 --- a/include/Nazara/Noise/Simplex4D.hpp +++ b/include/Nazara/Noise/Simplex4D.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef SIMPLEX4D_H -#define SIMPLEX4D_H +#ifndef SIMPLEX4D_HPP +#define SIMPLEX4D_HPP #include #include diff --git a/src/Nazara/Noise/ComplexNoiseBase.cpp b/src/Nazara/Noise/ComplexNoiseBase.cpp index 7a94422da..0388a7786 100644 --- a/src/Nazara/Noise/ComplexNoiseBase.cpp +++ b/src/Nazara/Noise/ComplexNoiseBase.cpp @@ -60,9 +60,3 @@ void NzComplexNoiseBase::RecomputeExponentArray() m_parametersModified = false; } } - - -NzComplexNoiseBase::~NzComplexNoiseBase() -{ - //dtor -} diff --git a/src/Nazara/Noise/Debug/Leaks.cpp b/src/Nazara/Noise/Debug/Leaks.cpp index c2566bb3f..81ed5eb4d 100644 --- a/src/Nazara/Noise/Debug/Leaks.cpp +++ b/src/Nazara/Noise/Debug/Leaks.cpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) +#if NAZARA_NOISE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG) #include #include @@ -26,4 +26,5 @@ void operator delete[](void* pointer) throw() { NzMemoryManager::Free(pointer, true); } + #endif diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp index 59a5889fb..8d5dd92f5 100644 --- a/src/Nazara/Noise/Noise.cpp +++ b/src/Nazara/Noise/Noise.cpp @@ -55,3 +55,5 @@ bool NzNoise::IsInitialized() } bool NzNoise::s_initialized = false; + +//#include //A INCLURE ? diff --git a/src/Nazara/Noise/NoiseBase.cpp b/src/Nazara/Noise/NoiseBase.cpp index e718b01be..410e2b95d 100644 --- a/src/Nazara/Noise/NoiseBase.cpp +++ b/src/Nazara/Noise/NoiseBase.cpp @@ -40,6 +40,9 @@ void NzNoiseBase::ShufflePermutationTable() int xchanger; unsigned int ncase; + for(int i(0) ; i < 256 ; i++) + perm[i] = i; + for(int j(0) ; j < 20 ; ++j) for (int i(0); i < 256 ; ++i) { @@ -72,21 +75,4 @@ int NzNoiseBase::JenkinsHash(int a, int b, int c) return c; } -/* -//key = 64 bits -public long hash64shift(long key) -{ - key = (~key) + (key << 21); // key = (key << 21) - key - 1; - key = key ^ (key >>> 24); - key = (key + (key << 3)) + (key << 8); // key * 265 - key = key ^ (key >>> 14); - key = (key + (key << 2)) + (key << 4); // key * 21 - key = key ^ (key >>> 28); - key = key + (key << 31); - return key; -}*/ - -NzNoiseBase::~NzNoiseBase() -{ - //dtor -} +#include diff --git a/src/Nazara/Noise/NoiseMachine.cpp b/src/Nazara/Noise/NoiseMachine.cpp index 194e73049..e695d46fe 100644 --- a/src/Nazara/Noise/NoiseMachine.cpp +++ b/src/Nazara/Noise/NoiseMachine.cpp @@ -758,3 +758,5 @@ float NzNoiseMachine::Get3DHybridMultiFractalNoiseValue(float x, float y, float return result; } + +#include From 90faf844ed7bc14656feb8858e5cb517469c1dcd Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Mon, 11 Jun 2012 00:29:09 +0200 Subject: [PATCH 13/13] Fixed contributor's name --- include/Nazara/Noise/Config.hpp | 4 ++++ include/Nazara/Noise/Debug.hpp | 2 +- include/Nazara/Noise/DebugOff.hpp | 2 +- readme.txt | 2 +- readme_fr.txt | 2 +- src/Nazara/Noise/Debug/Leaks.cpp | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/Nazara/Noise/Config.hpp b/include/Nazara/Noise/Config.hpp index 0b628002a..77cb9d990 100644 --- a/include/Nazara/Noise/Config.hpp +++ b/include/Nazara/Noise/Config.hpp @@ -3,6 +3,10 @@ Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) + Nazara Engine - NzNoise Module + + Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to diff --git a/include/Nazara/Noise/Debug.hpp b/include/Nazara/Noise/Debug.hpp index c26ad1c80..1f8a08966 100644 --- a/include/Nazara/Noise/Debug.hpp +++ b/include/Nazara/Noise/Debug.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) +// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/include/Nazara/Noise/DebugOff.hpp b/include/Nazara/Noise/DebugOff.hpp index 324f33c2b..1162e79c0 100644 --- a/include/Nazara/Noise/DebugOff.hpp +++ b/include/Nazara/Noise/DebugOff.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) +// Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/readme.txt b/readme.txt index a4cc42567..02814821f 100644 --- a/readme.txt +++ b/readme.txt @@ -12,7 +12,7 @@ Authors ------- Jérôme "Lynix" Leclercq - main developper (Lynix680@gmail.com) -Rémi "overdrivr" Bèges - developper & helper (remi.beges@laposte.net) +Rémi "overdrivr" Bèges - developper & helper - NzNoise Module - (remi.beges@laposte.net) Install ------- diff --git a/readme_fr.txt b/readme_fr.txt index 81c3e99ad..a31c39eca 100644 --- a/readme_fr.txt +++ b/readme_fr.txt @@ -12,7 +12,7 @@ Auteurs ------- Jérôme "Lynix" Leclercq - développeur principal (Lynix680@gmail.com) -Rémi "overdrivr" Bèges - développeur & aide (remi.beges@laposte.net) +Rémi "overdrivr" Bèges - développeur & aide - module NzNoise - (remi.beges@laposte.net) Installation ------------ diff --git a/src/Nazara/Noise/Debug/Leaks.cpp b/src/Nazara/Noise/Debug/Leaks.cpp index 81ed5eb4d..3e65ef142 100644 --- a/src/Nazara/Noise/Debug/Leaks.cpp +++ b/src/Nazara/Noise/Debug/Leaks.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com) +// Copyright (C) 2012 Rémi Bèges // This file is part of the "Nazara Engine". // For conditions of distribution and use, see copyright notice in Config.hpp