Simplex & Perlin fully work now (all dimensions) + dynaTerrain removed temp

This commit is contained in:
Remi Beges 2012-06-07 13:10:58 +02:00
parent 5d7f8acbc8
commit ebba6adae4
23 changed files with 354 additions and 1124 deletions

View File

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

View File

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

View File

@ -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 <Nazara/ModuleName/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

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

View File

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

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector2.hpp>
#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

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector2.hpp>
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

View File

@ -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 <Nazara/Prerequesites.hpp>
#include <list>
#include <Nazara/Math/Vector2.hpp>
#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<NzNode*> leaves;
};
#endif // QUADTREE_H

View File

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

View File

@ -65,7 +65,6 @@ T NzPerlin3D<T>::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;

View File

@ -44,98 +44,88 @@ T NzPerlin4D<T>::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<T>::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);
}

View File

@ -29,6 +29,7 @@ template <typename T> class NzSimplex2D : public NzNoiseBase
T gradient2[8][2];
T UnskewCoeff2D;
T SkewCoeff2D;
T sum;
NzVector2<T> unskewedCubeOrigin, unskewedDistToOrigin;
NzVector2<T> d1,d2,d3;

View File

@ -17,7 +17,7 @@ NzSimplex2D<T>::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 <typename T>
@ -26,11 +26,13 @@ T NzSimplex2D<T>::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<T>::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<T>::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;

View File

@ -10,7 +10,7 @@
#include <Nazara/Prerequesites.hpp>
//#include <Nazara/Noise/NoiseBase.hpp>
#include "NoiseBase.hpp"
#include <Nazara/Math/Vector3.hpp>
template <typename T> class NzSimplex3D : public NzNoiseBase
@ -23,13 +23,14 @@ template <typename T> 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<T> A, IsoOriginDist;
T sum;
NzVector3<T> unskewedCubeOrigin, unskewedDistToOrigin;
NzVector3<T> d1,d2,d3,d4;

View File

@ -5,21 +5,19 @@
//#include <Nazara/Noise/Error.hpp>
//#include <Nazara/Noise/Config.hpp>
//#include <Nazara/Noise/Debug.hpp>
#include <iostream>
template <typename T>
NzSimplex3D<T>::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<T>::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<T>::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<T>::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<T>::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<T>::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<T>::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;
}

View File

@ -23,7 +23,7 @@ template <typename T> 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 <typename T> class NzSimplex4D : public NzNoiseBase
int c;
T UnskewCoeff4D;
T SkewCoeff4D;
NzVector4<T> A, IsoOriginDist;
T sum;
NzVector4<T> unskewedCubeOrigin, unskewedDistToOrigin;
NzVector4<T> d1,d2,d3,d4,d5;

View File

@ -9,8 +9,8 @@
template <typename T>
NzSimplex4D<T>::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<T>::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<T>::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<T>::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;
}

View File

@ -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 <Nazara/ModuleName/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

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

View File

@ -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 <stack>
//#include <Nazara/DynaTerrain/NoiseBase.hpp>
//#include <Nazara/DynaTerrain/Error.hpp>
//#include <Nazara/DynaTerrain/Config.hpp>
//#include <Nazara/DynaTerrain/Debug.hpp>
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<nzDirection> 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;
}

View File

@ -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 <Nazara/DynaTerrain/NoiseBase.hpp>
//#include <Nazara/DynaTerrain/Error.hpp>
//#include <Nazara/DynaTerrain/Config.hpp>
//#include <Nazara/DynaTerrain/Debug.hpp>
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)
{
}

View File

@ -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 <Nazara/DynaTerrain/NoiseBase.hpp>
//#include <Nazara/DynaTerrain/Error.hpp>
//#include <Nazara/DynaTerrain/Config.hpp>
//#include <Nazara/DynaTerrain/Debug.hpp>
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
}

View File

@ -116,40 +116,43 @@ float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res
y /= res;
z /= res;
x0 = static_cast<int>(x);
y0 = static_cast<int>(y);
z0 = static_cast<int>(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<int>(x);
y0 = static_cast<int>(y);
z0 = static_cast<int>(z);
w0 = static_cast<int>(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 ------------------------------