NzNoise added

This commit is contained in:
Overdrivr 2012-05-24 20:41:08 +02:00
parent 570e0a8070
commit 341eda975c
9 changed files with 1376 additions and 0 deletions

View File

@ -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"

View File

@ -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

View File

@ -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 <Nazara/Noise/Config.hpp>
#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@ -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

View File

@ -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 <Nazara/Prerequesites.hpp>
class NAZARA_API NzNoise
{
public:
NzNoise();
~NzNoise();
bool Initialize();
void Uninitialize();
static bool IsInitialized();
private:
static bool s_initialized;
};
#endif // NOISE_H

View File

@ -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 <Nazara/Prerequesites.hpp>
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

View File

@ -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 <Nazara/Noise/Config.hpp>
#if NAZARA_MODULENAME_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#include <new>
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

View File

@ -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 <Nazara/Noise/Noise.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Debug.hpp>
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;

File diff suppressed because it is too large Load Diff