Forgot to commit some stuff (noise+dynaterrain) from previous commit

This commit is contained in:
Remi Beges 2012-05-31 15:35:52 +02:00
parent 9008c36802
commit 4d975fa67e
21 changed files with 589 additions and 206 deletions

View File

@ -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". // This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp

View File

@ -18,6 +18,8 @@ class NzNoiseBase
void SetNewSeed(int seed); void SetNewSeed(int seed);
int GetUniformRandomValue(); int GetUniformRandomValue();
void ShufflePermutationTable(); void ShufflePermutationTable();
int fastfloor(float n);
int JenkinsHash(int a, int b, int c);
protected: protected:
int perm[512]; int perm[512];
private: private:

View File

@ -16,7 +16,8 @@
//TODO : tableau de gradients en float au lieu de int ? Ou condition ternaires ? //TODO : tableau de gradients en float au lieu de int ? Ou condition ternaires ?
// utiliser fastfloor partout // 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 class NzNoiseMachine : public NzNoiseBase
{ {
@ -24,7 +25,6 @@ class NzNoiseMachine : public NzNoiseBase
NzNoiseMachine(int seed = 0); NzNoiseMachine(int seed = 0);
~NzNoiseMachine(); ~NzNoiseMachine();
float Get1DPerlinNoiseValue (float x, float res);
float Get2DPerlinNoiseValue (float x, float y, float res); float Get2DPerlinNoiseValue (float x, float y, float res);
float Get3DPerlinNoiseValue (float x, float y, float z, 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 Get4DPerlinNoiseValue (float x, float y, float z, float w, float res);
@ -42,7 +42,6 @@ class NzNoiseMachine : public NzNoiseBase
void SetOctavesNumber(float octaves); void SetOctavesNumber(float octaves);
void RecomputeExponentArray(); void RecomputeExponentArray();
float Get1DFBMNoiseValue(float x, float res);
float Get2DFBMNoiseValue(float x, float y, float res); float Get2DFBMNoiseValue(float x, float y, float res);
float Get3DFBMNoiseValue(float x, float y, float z, float res); float Get3DFBMNoiseValue(float x, float y, float z, float res);
@ -52,10 +51,6 @@ class NzNoiseMachine : public NzNoiseBase
protected: protected:
private: private:
//Pour tronquer les nombres
int fastfloor(float n);
int gradient1[2];
float gradient2[8][2]; float gradient2[8][2];
int gradient3[16][3]; int gradient3[16][3];
int gradient4[32][4]; int gradient4[32][4];
@ -65,15 +60,13 @@ class NzNoiseMachine : public NzNoiseBase
float n1, n2, n3, n4, n5; float n1, n2, n3, n4, n5;
NzVector4f A; NzVector4f A;
NzVector4i Origin;
NzVector4f d1,d2,d3,d4,d5; NzVector4f d1,d2,d3,d4,d5;
NzVector4i off1, off2,off3;
NzVector4f IsoOriginDist; NzVector4f IsoOriginDist;
NzVector4f H[5]; NzVector4i Origin;
NzVector4i off1, off2,off3;
int ii,jj,kk,ll; int ii,jj,kk,ll;
int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; 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; float c1,c2,c3,c4,c5,c6;
int c; int c;

View File

@ -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 <Nazara/Prerequesites.hpp>
//#include <Nazara/Noise/NoiseBase.hpp>
#include "NoiseBase.hpp"
template <typename T> 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<float> NzPerlin1Df;
typedef NzPerlin1D<double> NzPerlin1Dd;
//#include <Nazara/Noise/Perlin1D.inl>
#include "Perlin1D.inl"
#endif // PERLIN1D_H

View File

@ -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 <Nazara/Noise/Error.hpp>
//#include <Nazara/Noise/Config.hpp>
//#include <Nazara/Noise/Debug.hpp>
#include <iostream>
template <typename T>
NzPerlin1D<T>::NzPerlin1D()
{
gradient1[0] = 1;
gradient1[1] = -1;
}
template <typename T>
T NzPerlin1D<T>::GetValue(T x, T res)
{
nx = x/res;
x0 = static_cast<int>(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);
}

View File

@ -8,7 +8,8 @@
#define PERLIN2D_H #define PERLIN2D_H
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/NoiseBase.hpp> //#include <Nazara/Noise/NoiseBase.hpp>
#include "NoiseBase.hpp"
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
template <typename T> class NzPerlin2D : public NzNoiseBase template <typename T> class NzPerlin2D : public NzNoiseBase
@ -34,7 +35,8 @@ template <typename T> class NzPerlin2D : public NzNoiseBase
typedef NzPerlin2D<float> NzPerlin2Df; typedef NzPerlin2D<float> NzPerlin2Df;
typedef NzPerlin2D<double> NzPerlin2Dd; typedef NzPerlin2D<double> NzPerlin2Dd;
#include <Nazara/Noise/Perlin2D.inl> //#include <Nazara/Noise/Perlin2D.inl>
#include "Perlin2D.inl"
#endif // PERLIN2D_H #endif // PERLIN2D_H

View File

@ -2,9 +2,9 @@
// This file is part of the "Nazara Engine". // This file is part of the "Nazara Engine".
// 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/Error.hpp> //#include <Nazara/Noise/Error.hpp>
#include <Nazara/Noise/Config.hpp> //#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Debug.hpp> //#include <Nazara/Noise/Debug.hpp>
template <typename T> template <typename T>
NzPerlin2D<T>::NzPerlin2D() NzPerlin2D<T>::NzPerlin2D()

View File

@ -8,7 +8,8 @@
#define PERLIN3D_H #define PERLIN3D_H
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/NoiseBase.hpp> //#include <Nazara/Noise/NoiseBase.hpp>
#include "NoiseBase.hpp"
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
template <typename T> class NzPerlin3D : public NzNoiseBase template <typename T> class NzPerlin3D : public NzNoiseBase
@ -35,6 +36,7 @@ template <typename T> class NzPerlin3D : public NzNoiseBase
typedef NzPerlin3D<float> NzPerlin3Df; typedef NzPerlin3D<float> NzPerlin3Df;
typedef NzPerlin3D<double> NzPerlin3Dd; typedef NzPerlin3D<double> NzPerlin3Dd;
#include <Nazara/Noise/Perlin3D.inl> //#include <Nazara/Noise/Perlin3D.inl>
#include "Perlin3D.inl"
#endif // PERLIN3D_H #endif // PERLIN3D_H

View File

@ -2,9 +2,9 @@
// This file is part of the "Nazara Engine". // This file is part of the "Nazara Engine".
// 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/Error.hpp> //#include <Nazara/Noise/Error.hpp>
#include <Nazara/Noise/Config.hpp> //#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Debug.hpp> //#include <Nazara/Noise/Debug.hpp>
template <typename T> template <typename T>
NzPerlin3D<T>::NzPerlin3D() NzPerlin3D<T>::NzPerlin3D()

View File

@ -8,7 +8,8 @@
#define PERLIN4D_H #define PERLIN4D_H
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/NoiseBase.hpp> //#include <Nazara/Noise/NoiseBase.hpp>
#include "NoiseBase.hpp"
#include <Nazara/Math/Vector4.hpp> #include <Nazara/Math/Vector4.hpp>
template <typename T> class NzPerlin4D : public NzNoiseBase template <typename T> class NzPerlin4D : public NzNoiseBase
@ -35,6 +36,7 @@ template <typename T> class NzPerlin4D : public NzNoiseBase
typedef NzPerlin4D<float> NzPerlin4Df; typedef NzPerlin4D<float> NzPerlin4Df;
typedef NzPerlin4D<double> NzPerlin4Dd; typedef NzPerlin4D<double> NzPerlin4Dd;
#include <Nazara/Noise/Perlin4D.inl> //#include <Nazara/Noise/Perlin4D.inl>
#include "Perlin4D.inl"
#endif // PERLIN4D_H #endif // PERLIN4D_H

View File

@ -2,9 +2,9 @@
// This file is part of the "Nazara Engine". // This file is part of the "Nazara Engine".
// 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/Error.hpp> //#include <Nazara/Noise/Error.hpp>
#include <Nazara/Noise/Config.hpp> //#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Debug.hpp> //#include <Nazara/Noise/Debug.hpp>
template <typename T> template <typename T>
NzPerlin4D<T>::NzPerlin4D() NzPerlin4D<T>::NzPerlin4D()

View File

@ -8,7 +8,8 @@
#define SIMPLEX2D_H #define SIMPLEX2D_H
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Noise/NoiseBase.hpp> //#include <Nazara/Noise/NoiseBase.hpp>
#include "NoiseBase.hpp"
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
@ -37,7 +38,8 @@ template <typename T> class NzSimplex2D : public NzNoiseBase
typedef NzSimplex2D<float> NzSimplex2Df; typedef NzSimplex2D<float> NzSimplex2Df;
typedef NzSimplex2D<double> NzSimplex2Dd; typedef NzSimplex2D<double> NzSimplex2Dd;
#include <Nazara/Noise/Simplex2D.inl> //#include <Nazara/Noise/Simplex2D.inl>
#include "Simplex2D.inl"
#endif // SIMPLEX2D_H #endif // SIMPLEX2D_H

View File

@ -2,9 +2,9 @@
// This file is part of the "Nazara Engine". // This file is part of the "Nazara Engine".
// 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/Error.hpp> //#include <Nazara/Noise/Error.hpp>
#include <Nazara/Noise/Config.hpp> //#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Debug.hpp> //#include <Nazara/Noise/Debug.hpp>
template <typename T> template <typename T>
NzSimplex2D<T>::NzSimplex2D() NzSimplex2D<T>::NzSimplex2D()

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

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

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

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

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

@ -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". // This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp

View File

@ -54,6 +54,42 @@ void NzNoiseBase::ShufflePermutationTable()
perm[i] = perm[i & 255]; perm[i] = perm[i & 255];
} }
int NzNoiseBase::fastfloor(float n)
{
if(n >= 0)
return static_cast<int>(n);
else
return static_cast<int>(n-1);
}
int NzNoiseBase::JenkinsHash(int a, int b, int c)
{
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 13);
b = b-c; b = b - a; b = b^(a << 8);
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 13);
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 12);
b = b-c; b = b - a; b = b^(a << 16);
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 5);
a = a-b; a = a - c; a = a^(static_cast<unsigned int>(c) >> 3);
b = b-c; b = b - a; b = b^(a << 10);
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(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() NzNoiseBase::~NzNoiseBase()
{ {
//dtor //dtor

View File

@ -35,9 +35,6 @@ NzNoiseMachine::NzNoiseMachine(int seed)
for(int j(0) ; j < 4 ; ++j) for(int j(0) ; j < 4 ; ++j)
lookupTable4D[i][j] = lookupTemp4D[i][j]; lookupTable4D[i][j] = lookupTemp4D[i][j];
gradient1[0] = 1;
gradient1[1] = -1;
float unit = 1.0/sqrt(2); float unit = 1.0/sqrt(2);
float grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit}, float grad2Temp[][2] = {{unit,unit},{-unit,unit},{unit,-unit},{-unit,-unit},
{1,0},{-1,0},{0,1},{0,-1}}; {1,0},{-1,0},{0,1},{0,-1}};
@ -87,29 +84,6 @@ NzNoiseMachine::~NzNoiseMachine()
//------------------------------ PERLIN ------------------------------ //------------------------------ PERLIN ------------------------------
float NzNoiseMachine::Get1DPerlinNoiseValue(float x, float res)
{
nx = x/res;
x0 = static_cast<int>(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) float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res)
{ {
nx = x/res; nx = x/res;
@ -372,10 +346,10 @@ float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w,
//------------------------------ SIMPLEX ------------------------------ //------------------------------ SIMPLEX ------------------------------
float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution) float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res)
{ {
x /= resolution; x /= res;
y /= resolution; y /= res;
Origin.x = fastfloor(x + (x + y) * SkewCoeff2D); Origin.x = fastfloor(x + (x + y) * SkewCoeff2D);
@ -410,28 +384,17 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution)
ii = Origin.x & 255; ii = Origin.x & 255;
jj = Origin.y & 255; jj = Origin.y & 255;
gi0 = perm[ii + perm[jj]] % 12; gi0 = perm[ii + perm[jj]] % 8;
gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 12; gi1 = perm[ii + off1.x + perm[jj + off1.y]] % 8;
gi2 = perm[ii + 1 + perm[jj + 1]] % 12; gi2 = perm[ii + 1 + perm[jj + 1]] % 8;
H[0].x = gradient3[gi0][0]; n1 = gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y;
H[0].y = gradient3[gi0][1]; 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]; c1 = 0.5 - d1.x * d1.x - d1.y * d1.y;
H[1].y = gradient3[gi1][1]; c2 = 0.5 - d2.x * d2.x - d2.y * d2.y;
c3 = 0.5 - d3.x * d3.x - d3.y * d3.y;
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;
if(c1 < 0) if(c1 < 0)
c1 = 0; c1 = 0;
@ -447,11 +410,11 @@ float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float resolution)
return (n1+n2+n3)*23.2; 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; x /= res;
y /= resolution; y /= res;
z /= resolution; z /= res;
Origin.x = fastfloor(x + (x + y + z) * SkewCoeff3D); Origin.x = fastfloor(x + (x + y + z) * SkewCoeff3D);
Origin.y = fastfloor(y + (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; 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; n4 = gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z;
lenght = 0.6; 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;
c1 = lenght - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z; c3 = 0.6 - d3.x * d3.x - d3.y * d3.y - d3.z * d3.z;
c2 = lenght - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z; c4 = 0.6 - d4.x * d4.x - d4.y * d4.y - d4.z * d4.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;
if(c1 < 0) if(c1 < 0)
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; 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; x /= res;
y /= resolution; y /= res;
z /= resolution; z /= res;
w /= resolution; w /= res;
Origin.x = fastfloor(x + (x + y + z + w) * SkewCoeff4D); Origin.x = fastfloor(x + (x + y + z + w) * SkewCoeff4D);
Origin.y = fastfloor(y + (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; 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; 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 = 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;
c1 = lenght - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; c3 = 0.6 - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w;
c2 = lenght - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; c4 = 0.6 - d4.x*d4.x - d4.y*d4.y - d4.z*d4.z - d4.w*d4.w;
c3 = lenght - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w; c5 = 0.6 - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.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) if(c1 < 0)
c1 = 0; c1 = 0;
@ -712,7 +671,7 @@ float NzNoiseMachine::Get3DCellNoiseValue(float x, float y, float z, float res)
y0 = static_cast<int>(y); y0 = static_cast<int>(y);
z0 = static_cast<int>(z); z0 = static_cast<int>(z);
return 0; return (this->JenkinsHash(x0,y0,z0) & 255);
} }
float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, float res) float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, float res)
{ {
@ -776,24 +735,6 @@ void NzNoiseMachine::RecomputeExponentArray()
//------------------------------ FBM ------------------------------ //------------------------------ 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) float NzNoiseMachine::Get2DFBMNoiseValue(float x, float y, float res)
{ {
value = 0.0; value = 0.0;
@ -908,11 +849,3 @@ float NzNoiseMachine::Get3DHybridMultiFractalNoiseValue(float x, float y, float
return result; return result;
} }
int NzNoiseMachine::fastfloor(float n)
{
if(n >= 0)
return static_cast<int>(n);
else
return static_cast<int>(n-1);
}