Noise: Fix errors/warnings

Former-commit-id: 1b0766a947b41e6154ef6d0ce7a9dbd58a718f35 [formerly 5204c1e68556379ca8cc69a1db8684eccb5e188d]
Former-commit-id: 75dbce8928d51b58555c319705c965616b5b965a
This commit is contained in:
Lynix 2016-06-19 16:09:22 +02:00
parent 5970682035
commit c7d4f7ca83
4 changed files with 35 additions and 36 deletions

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Noise/NoiseBase.hpp> #include <Nazara/Noise/NoiseBase.hpp>
#include <numeric>
#include <Nazara/Noise/Debug.hpp> #include <Nazara/Noise/Debug.hpp>
namespace Nz namespace Nz

View File

@ -76,9 +76,6 @@ namespace Nz
float Li1,Li2,Li3,Li4,Li5,Li6; float Li1,Li2,Li3,Li4,Li5,Li6;
float s[2],t[2],u[2],v[2]; float s[2],t[2],u[2],v[2];
float Cx,Cy,Cz; float Cx,Cy,Cz;
float nx,ny,nz;
float tmp;
float tempx,tempy,tempz; float tempx,tempy,tempz;
xc = x * scale; xc = x * scale;
@ -157,7 +154,6 @@ namespace Nz
float s[4],t[4],u[4],v[4]; float s[4],t[4],u[4],v[4];
float Cx,Cy,Cz,Cw; float Cx,Cy,Cz,Cw;
float tmp;
float tempx,tempy,tempz,tempw; float tempx,tempy,tempz,tempw;
xc = x * scale; xc = x * scale;

View File

@ -12,12 +12,12 @@ namespace Nz
{ {
namespace namespace
{ {
constexpr float s_SkewCoeff2D = 0.5f * (M_SQRT3 - 1.f); constexpr float s_SkewCoeff2D = 0.5f * (float(M_SQRT3) - 1.f);
constexpr float s_UnskewCoeff2D = (3.f - M_SQRT3)/6.f; constexpr float s_UnskewCoeff2D = (3.f - float(M_SQRT3))/6.f;
constexpr float s_SkewCoeff3D = 1.f / 3.f; constexpr float s_SkewCoeff3D = 1.f / 3.f;
constexpr float s_UnskewCoeff3D = 1.f / 6.f; constexpr float s_UnskewCoeff3D = 1.f / 6.f;
constexpr float s_SkewCoeff4D = (M_SQRT5 - 1.f)/4.f; constexpr float s_SkewCoeff4D = (float(M_SQRT5) - 1.f)/4.f;
constexpr float s_UnskewCoeff4D = (5.f - M_SQRT5)/20.f; constexpr float s_UnskewCoeff4D = (5.f - float(M_SQRT5))/20.f;
} }
Simplex::Simplex(unsigned int seed) Simplex::Simplex(unsigned int seed)
@ -39,7 +39,7 @@ namespace Nz
Vector2f unskewedDistToOrigin(xc - unskewedCubeOrigin.x, yc - unskewedCubeOrigin.y); Vector2f unskewedDistToOrigin(xc - unskewedCubeOrigin.x, yc - unskewedCubeOrigin.y);
Vector2f off1; Vector2ui off1;
if(unskewedDistToOrigin.x > unskewedDistToOrigin.y) if(unskewedDistToOrigin.x > unskewedDistToOrigin.y)
off1.Set(1, 0); off1.Set(1, 0);
else else
@ -47,7 +47,7 @@ namespace Nz
std::array<Vector2f, 3> d; std::array<Vector2f, 3> d;
d[0] = -unskewedDistToOrigin; d[0] = -unskewedDistToOrigin;
d[1] = d[0] + off1 - Vector2f(s_UnskewCoeff2D); d[1] = d[0] + Vector2f(off1) - Vector2f(s_UnskewCoeff2D);
d[2] = d[0] + Vector2f(1.f - 2.f * s_UnskewCoeff2D); d[2] = d[0] + Vector2f(1.f - 2.f * s_UnskewCoeff2D);
Vector2i offset(skewedCubeOrigin.x & 255, skewedCubeOrigin.y & 255); Vector2i offset(skewedCubeOrigin.x & 255, skewedCubeOrigin.y & 255);
@ -248,7 +248,7 @@ namespace Nz
int c; int c;
float n1,n2,n3,n4,n5; float n1,n2,n3,n4,n5;
float c1,c2,c3,c4,c5,c6; float c1,c2,c3,c4,c5;
float sum; float sum;
float unskewedCubeOriginx,unskewedCubeOriginy,unskewedCubeOriginz,unskewedCubeOriginw; float unskewedCubeOriginx,unskewedCubeOriginy,unskewedCubeOriginz,unskewedCubeOriginw;
@ -280,13 +280,13 @@ namespace Nz
unskewedDistToOriginz = zc - unskewedCubeOriginz; unskewedDistToOriginz = zc - unskewedCubeOriginz;
unskewedDistToOriginw = wc - unskewedCubeOriginw; unskewedDistToOriginw = wc - unskewedCubeOriginw;
c1 = (unskewedDistToOriginx > unskewedDistToOriginy) ? 32 : 0; c = 0;
c2 = (unskewedDistToOriginx > unskewedDistToOriginz) ? 16 : 0; c += (unskewedDistToOriginx > unskewedDistToOriginy) ? 32 : 0;
c3 = (unskewedDistToOriginy > unskewedDistToOriginz) ? 8 : 0; c += (unskewedDistToOriginx > unskewedDistToOriginz) ? 16 : 0;
c4 = (unskewedDistToOriginx > unskewedDistToOriginw) ? 4 : 0; c += (unskewedDistToOriginy > unskewedDistToOriginz) ? 8 : 0;
c5 = (unskewedDistToOriginy > unskewedDistToOriginw) ? 2 : 0; c += (unskewedDistToOriginx > unskewedDistToOriginw) ? 4 : 0;
c6 = (unskewedDistToOriginz > unskewedDistToOriginw) ? 1 : 0; c += (unskewedDistToOriginy > unskewedDistToOriginw) ? 2 : 0;
c = c1 + c2 + c3 + c4 + c5 + c6; c += (unskewedDistToOriginz > unskewedDistToOriginw) ? 1 : 0;
off1x = lookupTable[c][0] >= 3 ? 1 : 0; off1x = lookupTable[c][0] >= 3 ? 1 : 0;
off1y = lookupTable[c][1] >= 3 ? 1 : 0; off1y = lookupTable[c][1] >= 3 ? 1 : 0;

View File

@ -14,10 +14,10 @@ namespace Nz
{ {
static constexpr std::array<float, 4> m_functionScales = static constexpr std::array<float, 4> m_functionScales =
{ {
1.f / M_SQRT2, 1.f / float(M_SQRT2),
0.5f / M_SQRT2, 0.5f / float(M_SQRT2),
0.5f / M_SQRT2, 0.5f / float(M_SQRT2),
0.5f / M_SQRT2 0.5f / float(M_SQRT2)
}; };
} }
Worley::Worley() : Worley::Worley() :
@ -53,58 +53,60 @@ namespace Nz
SquareTest(x0,y0,xc,yc,featurePoints); SquareTest(x0,y0,xc,yc,featurePoints);
std::size_t functionIndex = static_cast<std::size_t>(m_function);
auto it = featurePoints.begin(); auto it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if(fractx < it->first) if(fractx < it->first)
SquareTest(x0 - 1,y0,xc,yc,featurePoints); SquareTest(x0 - 1,y0,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if(1.f - fractx < it->first) if(1.f - fractx < it->first)
SquareTest(x0 + 1,y0,xc,yc,featurePoints); SquareTest(x0 + 1,y0,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if(fracty < it->first) if(fracty < it->first)
SquareTest(x0,y0 - 1,xc,yc,featurePoints); SquareTest(x0,y0 - 1,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if (1.f - fracty < it->first) if (1.f - fracty < it->first)
SquareTest(x0,y0 + 1,xc,yc,featurePoints); SquareTest(x0,y0 + 1,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if (fractx < it->first && fracty < it->first) if (fractx < it->first && fracty < it->first)
SquareTest(x0 - 1, y0 - 1,xc,yc,featurePoints); SquareTest(x0 - 1, y0 - 1,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if (1.f - fractx < it->first && fracty < it->first) if (1.f - fractx < it->first && fracty < it->first)
SquareTest(x0 + 1, y0 - 1,xc,yc,featurePoints); SquareTest(x0 + 1, y0 - 1,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if (fractx < it->first && 1.f - fracty < it->first) if (fractx < it->first && 1.f - fracty < it->first)
SquareTest(x0 - 1, y0 + 1,xc,yc,featurePoints); SquareTest(x0 - 1, y0 + 1,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
if(1.f - fractx < it->first && 1.f - fracty < it->first) if(1.f - fractx < it->first && 1.f - fracty < it->first)
SquareTest(x0 + 1, y0 + 1,xc,yc,featurePoints); SquareTest(x0 + 1, y0 + 1,xc,yc,featurePoints);
it = featurePoints.begin(); it = featurePoints.begin();
std::advance(it, m_function); std::advance(it, functionIndex);
return it->first * m_functionScales[m_function]; return it->first * m_functionScales[functionIndex];
} }
float Worley::Get(float x, float y, float z, float scale) const float Worley::Get(float x, float y, float z, float scale) const
@ -127,16 +129,16 @@ namespace Nz
int ii = xi & 255; int ii = xi & 255;
int jj = yi & 255; int jj = yi & 255;
int seed = m_permutations[ii + m_permutations[jj]]; std::size_t seed = m_permutations[ii + m_permutations[jj]];
//On initialise notre rng avec seed //On initialise notre rng avec seed
std::minstd_rand0 randomNumberGenerator(seed); std::minstd_rand0 randomNumberGenerator(static_cast<unsigned int>(seed));
//On prend un nombre de points à déterminer dans le cube, compris entre 1 et 8 //On prend un nombre de points à déterminer dans le cube, compris entre 1 et 8
unsigned int m = (seed & 7) + 1; std::size_t m = (seed & 7) + 1;
//On calcule les emplacements des différents points //On calcule les emplacements des différents points
for(unsigned int i(0) ; i < m ; ++i) for(std::size_t i(0) ; i < m; ++i)
{ {
Nz::Vector2f featurePoint; Nz::Vector2f featurePoint;
featurePoint.x = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(xi); featurePoint.x = (randomNumberGenerator() & 1023) / 1023.f + static_cast<float>(xi);