Resolved conflicts
Former-commit-id: 4bd4e4f8435d701d16d3864dd030a6c1cff48c47
This commit is contained in:
commit
780da2cfa5
|
|
@ -1,39 +1,14 @@
|
|||
#include <Nazara/3D/Model.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
// Une structure pour contenir nos informations (Cette structure est très simpliste)
|
||||
struct Model
|
||||
{
|
||||
NzMatrix4f matrix; // Les transformations subies par le modèle
|
||||
NzMesh mesh; // Le mesh
|
||||
NzTexture texture; // Sa texture
|
||||
};
|
||||
|
||||
struct AnimatedModel : public Model
|
||||
{
|
||||
// Quelques variables pour l'animation
|
||||
const NzSequence* currentSequence = nullptr; // La séquence en cours
|
||||
float interpolation = 0.f; // La valeur de l'interpolation ([0..1], si dépasse 1, on passe à la frame suivante)
|
||||
unsigned int currentFrame = 0; // La première frame
|
||||
unsigned int nextFrame; // La seconde frame, l'animation est interpollée entre ces deux-là
|
||||
};
|
||||
|
||||
void AnimateModel(AnimatedModel& moedel, float elapsed);
|
||||
bool CreateCheckerTexture(NzTexture* texture);
|
||||
bool CreateFloorMesh(NzMesh* mesh);
|
||||
void DrawModel(const Model& model);
|
||||
void SetSequence(AnimatedModel& model, const NzString& name);
|
||||
bool CreateCheckerMaterial(NzMaterial* material);
|
||||
bool CreateFloorModel(NzModel* model);
|
||||
void DrawModel(const NzModel& model);
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
@ -57,6 +32,8 @@ int main()
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
NzDebugDrawer::Initialize();
|
||||
|
||||
// Maintenant nous pouvons utiliser le moteur comme bon nous semble, tout d'abord nous allons charger les ressources
|
||||
|
||||
// Charger une ressource se fait actuellement manuellement, mais un ResourceManager est à venir
|
||||
|
|
@ -70,22 +47,22 @@ int main()
|
|||
// qu'elles sont fourniees avec le mesh.
|
||||
// -Pour les animations squelettiques, le loader ne fera que charger automatiquement l'animation associée au mesh s'il le peut
|
||||
// Dans les deux cas, les paramètres d'animations (parameters.animation) seront utilisés
|
||||
parameters.loadAnimations = true; // Vaut true par défaut
|
||||
parameters.animated = true; // Vaut true par défaut
|
||||
|
||||
// Pour qu'un mesh puisse être rendu, il doit être stocké du côté de la carte graphique (Hardware), mais il est parfois utile de
|
||||
// le stocker côté RAM, par exemple pour le moteur physique. En sachant qu'il est facile de changer le stockage d'un buffer.
|
||||
parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut
|
||||
parameters.storage = nzBufferStorage_Hardware; // Vaut nzBufferStorage_Hardware par défaut si possible et nzBufferStorage_Software autrement.
|
||||
|
||||
AnimatedModel drfreak;
|
||||
if (!drfreak.mesh.LoadFromFile("resources/drfreak.md2", parameters)) // On charge notre bon vieux docteur avec les paramètres de chargement.
|
||||
NzModel drfreak;
|
||||
if (!drfreak.LoadFromFile("resources/drfreak.md2")) // On charge notre bon vieux docteur avec les paramètres de chargement.
|
||||
{
|
||||
// Le chargement n'a pas fonctionné, le modèle est peut-être corrompu/non-supporté, ou alors n'existe pas.
|
||||
std::cout << "Failed to load mesh" << std::endl;
|
||||
std::cout << "Failed to load Dr. Freak" << std::endl;
|
||||
std::getchar(); // On laise le temps de voir l'erreur
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!drfreak.mesh.HasAnimation()) // Le mesh possède-t-il des animations ?
|
||||
if (!drfreak.HasAnimation()) // Le mesh possède-t-il des animations ?
|
||||
{
|
||||
// Cette démo n'a aucun intérêt sans animations
|
||||
std::cout << "Mesh has no animation" << std::endl;
|
||||
|
|
@ -93,49 +70,15 @@ int main()
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
SetSequence(drfreak, "stand");
|
||||
|
||||
// Il est possible que le mesh possède un ou plusieurs skin, nous utiliserons cette information pour charger une texture
|
||||
if (drfreak.mesh.HasSkin())
|
||||
{
|
||||
// Contrairement aux autres ressources, la texture n'est pas critique
|
||||
if (drfreak.texture.LoadFromFile("resources/" + drfreak.mesh.GetSkin()))
|
||||
drfreak.texture.SetFilterMode(nzTextureFilter_Bilinear); // Appliquons-lui un filtrage bilinéaire
|
||||
else
|
||||
std::cout << "Failed to load texture" << std::endl;
|
||||
}
|
||||
|
||||
if (!drfreak.texture.IsValid()) // Les méthodes Resource::IsValid indiquent si la ressource a été correctement créée
|
||||
{
|
||||
std::cout << "Creating checker texture for mesh" << std::endl;
|
||||
|
||||
if (!CreateCheckerTexture(&drfreak.texture))
|
||||
{
|
||||
std::cout << "Failed to create mesh texture" << std::endl;
|
||||
std::getchar();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Nous créons maintenant notre sol
|
||||
Model floor;
|
||||
if (!CreateFloorMesh(&floor.mesh))
|
||||
NzModel floor;
|
||||
if (!CreateFloorModel(&floor))
|
||||
{
|
||||
std::cout << "Failed to create floor" << std::endl;
|
||||
std::getchar();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!CreateCheckerTexture(&floor.texture))
|
||||
{
|
||||
std::cout << "Failed to create floor texture" << std::endl;
|
||||
std::getchar();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Le sol ne subit aucune transformation
|
||||
floor.matrix.MakeIdentity();
|
||||
|
||||
// Pour effectuer un rendu, il faut que la carte graphique sache comment le faire.
|
||||
// Les shaders sont de petits programmes qui donnent des instructions à la carte graphique lors de son pipeline.
|
||||
// Ils sont aujourd'hui indispensables pour un rendu 3D, mais sont très utiles pour divers effets !
|
||||
|
|
@ -189,12 +132,15 @@ int main()
|
|||
// Un VideoMode est une structure contenant une longueur (width), une largeur (height) et le nombre de bits par pixels (bitsPerPixel)
|
||||
NzVideoMode mode = NzVideoMode::GetDesktopMode(); // Nous récupérons le mode actuellement utilisé par le bureau
|
||||
|
||||
// Nous divisons sa longueur et sa largeur par deux
|
||||
mode.width /= 2;
|
||||
mode.height /= 2;
|
||||
// Nous allons prendre les trois quarts de la résolution du bureau pour notre fenêtre
|
||||
//mode.width *= 3.f/4.f;
|
||||
//mode.height *= 3.f/4.f;
|
||||
mode.width = 1280;
|
||||
mode.height = 720;
|
||||
// 720p power !
|
||||
|
||||
// Maintenant le titre, rien de plus simple...
|
||||
NzString windowTitle = "Nazara Demo - AnimatedMesh";
|
||||
NzString windowTitle = "Nazara Demo - Skeletal mesh test";
|
||||
|
||||
// Nous pouvons créer notre fenêtre ! (Via le constructeur directement ou par la méthode Create)
|
||||
NzRenderWindow window;
|
||||
|
|
@ -217,32 +163,26 @@ int main()
|
|||
window.SetCursor(nzWindowCursor_None);
|
||||
|
||||
// Nous limitons les FPS à 100
|
||||
window.SetFramerateLimit(100);
|
||||
//window.SetFramerateLimit(100);
|
||||
|
||||
// La matrice de projection définit la transformation du vertice 3D à un point 2D
|
||||
NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast<float>(window.GetWidth())/window.GetHeight(), 1.f, 1000.f));
|
||||
NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast<float>(window.GetWidth())/window.GetHeight(), 1.f, 10000.f));
|
||||
|
||||
// Notre fenêtre est créée, cependant il faut s'occuper d'elle, pour le rendu et les évènements
|
||||
NzClock secondClock, updateClock; // Des horloges pour gérer le temps
|
||||
unsigned int fps = 0; // Compteur de FPS
|
||||
|
||||
// Quelques variables pour notre improvisation de physique
|
||||
float groundPos = drfreak.mesh.GetAABB().GetMinimum().y; // Les coordonnées locales du "bas" du modèle
|
||||
NzVector3f modelPos(0.f, -groundPos, -50.f);
|
||||
NzVector3f modelVel(0.f, 0.f, 0.f);
|
||||
NzQuaternionf modelOrient(NzQuaternionf::Identity());
|
||||
NzEulerAnglesf modelRot(0.f, 0.f, 0.f);
|
||||
float modelSpeed = 150.f;
|
||||
|
||||
// Nous initialisons la matrice
|
||||
drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos);
|
||||
float modelSpeed = 250.f;
|
||||
|
||||
// Notre caméra
|
||||
NzVector3f camPos(0.f, 25.f, -20.f);
|
||||
NzQuaternionf camOrient(NzQuaternionf::Identity());
|
||||
NzEulerAnglesf camRot(0.f, 0.f, 0.f); // Les angles d'eulers sont bien plus facile à utiliser
|
||||
NzMatrix4f camMatrix = NzMatrix4f::Translate(camPos);
|
||||
float camSpeed = 100.f;
|
||||
NzEulerAnglesf camRot(0.f, 180.f, 0.f); // Les angles d'eulers sont bien plus facile à utiliser
|
||||
|
||||
NzNode camera;
|
||||
camera.SetTranslation(0.f, 50.f, -50.f);
|
||||
camera.SetRotation(camRot);
|
||||
|
||||
NzVector3f camSpeed(100.f);
|
||||
float sensitivity = 0.8f;
|
||||
|
||||
// Quelques variables
|
||||
|
|
@ -251,6 +191,40 @@ int main()
|
|||
bool thirdPerson = false;
|
||||
bool windowOpen = true;
|
||||
|
||||
NzClock loadClock;
|
||||
|
||||
NzModel hellknight;
|
||||
//if (!LoadModel("resources/mm/snoutx10k.md5mesh", params, &hellknight))
|
||||
//if (!LoadModel("resources/Boblamp/boblampclean.md5mesh", params, &hellknight))
|
||||
if (!hellknight.LoadFromFile("resources/hellknight.md5mesh"))
|
||||
{
|
||||
std::cout << "Failed to load mesh" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
NzAnimation* hellknightAnimation = new NzAnimation;
|
||||
//if (!hellknightAnimation.LoadFromFile("resources/mm/idle.md5anim"))
|
||||
//if (!hellknightAnimation.LoadFromFile("resources/Boblamp/boblampclean.md5anim"))0
|
||||
if (!hellknightAnimation->LoadFromFile("resources/hellknight/walk7.md5anim"))
|
||||
{
|
||||
std::cout << "Failed to load animation" << std::endl;
|
||||
delete hellknightAnimation;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
hellknightAnimation->SetPersistent(false, false);
|
||||
hellknight.SetAnimation(hellknightAnimation);
|
||||
|
||||
std::cout << "Loaded in " << loadClock.GetSeconds() << std::endl;
|
||||
|
||||
bool drawAabb = false;
|
||||
bool drawSkeleton = false;
|
||||
bool drawHellknight = true;
|
||||
bool drawWireframe = false;
|
||||
|
||||
NzClock secondClock, updateClock; // Des horloges pour gérer le temps
|
||||
|
||||
// On peut commencer la boucle du programme
|
||||
while (windowOpen)
|
||||
{
|
||||
|
|
@ -280,8 +254,7 @@ int main()
|
|||
|
||||
// La matrice vue représente les transformations effectuées par la caméra
|
||||
// On recalcule la matrice de la caméra et on l'envoie au renderer
|
||||
camOrient = camRot; // Conversion des angles d'euler en quaternion
|
||||
NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward()));
|
||||
camera.SetRotation(camRot); // Conversion des angles d'euler en quaternion
|
||||
|
||||
// Pour éviter que le curseur ne sorte de l'écran, nous le renvoyons au centre de la fenêtre
|
||||
NzMouse::SetPosition(window.GetWidth()/2, window.GetHeight()/2, window);
|
||||
|
|
@ -309,10 +282,11 @@ int main()
|
|||
if (thirdPerson)
|
||||
{
|
||||
// On arrête le mouvement
|
||||
SetSequence(drfreak, "stand");
|
||||
drfreak.SetSequence("stand");
|
||||
|
||||
// Afin de synchroniser le quaternion avec les angles d'euler
|
||||
camRot = camOrient.ToEulerAngles();
|
||||
camRot = camera.GetDerivedRotation().ToEulerAngles();
|
||||
|
||||
thirdPerson = false;
|
||||
}
|
||||
else
|
||||
|
|
@ -324,25 +298,75 @@ int main()
|
|||
NzRenderer::SetViewport(NzRectui(0, 0, event.size.width, event.size.height)); // Adaptons l'affichage
|
||||
|
||||
// Il nous faut aussi mettre à jour notre matrice de projection
|
||||
NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast<float>(event.size.width)/event.size.height, 1.f, 1000.f));
|
||||
NzRenderer::SetMatrix(nzMatrixType_Projection, NzMatrix4f::Perspective(NzDegrees(70.f), static_cast<float>(event.size.width)/event.size.height, 1.f, 10000.f));
|
||||
break;
|
||||
|
||||
case nzEventType_KeyPressed: // Une touche du clavier vient d'être enfoncée
|
||||
if (thirdPerson &&
|
||||
(event.key.code == NzKeyboard::Z || // Est-ce la touche Z ?
|
||||
event.key.code == NzKeyboard::S || // Ou bien la touche S ?
|
||||
event.key.code == NzKeyboard::Q || // Ou encore la touche Q ?
|
||||
event.key.code == NzKeyboard::D)) // Et pourquoi pas la touche D ?
|
||||
{
|
||||
switch (event.key.code)
|
||||
{
|
||||
// Si une touche concernant le déplacement est appuyée
|
||||
SetSequence(drfreak, "run"); // On anime le personnage pour qu'il ait une animation de déplacement
|
||||
case NzKeyboard::Z:
|
||||
case NzKeyboard::S:
|
||||
case NzKeyboard::Q:
|
||||
case NzKeyboard::D:
|
||||
if (thirdPerson)
|
||||
drfreak.SetSequence("run");
|
||||
break;
|
||||
|
||||
case NzKeyboard::Escape:
|
||||
windowOpen = false;
|
||||
break;
|
||||
|
||||
case NzKeyboard::P:
|
||||
paused = !paused;
|
||||
break;
|
||||
|
||||
case NzKeyboard::F1:
|
||||
if (drawWireframe)
|
||||
{
|
||||
drawWireframe = false;
|
||||
NzRenderer::SetFaceFilling(nzFaceFilling_Fill);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawWireframe = true;
|
||||
NzRenderer::SetFaceFilling(nzFaceFilling_Line);
|
||||
}
|
||||
break;
|
||||
|
||||
case NzKeyboard::F2:
|
||||
drawAabb = !drawAabb;
|
||||
break;
|
||||
|
||||
case NzKeyboard::F3:
|
||||
drawSkeleton = !drawSkeleton;
|
||||
break;
|
||||
|
||||
case NzKeyboard::F4:
|
||||
drawHellknight = !drawHellknight;
|
||||
break;
|
||||
|
||||
/*case NzKeyboard::F5:
|
||||
{
|
||||
NzString animationName;
|
||||
std::cin >> animationName;
|
||||
if (!hellknightAnimation.LoadFromFile("resources/mm/" + animationName + ".md5anim"))
|
||||
{
|
||||
std::cout << "Failed to load animation" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
SetSequence(hellknight, 0);
|
||||
|
||||
break;
|
||||
}*/
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
else if (event.key.code == NzKeyboard::Escape)
|
||||
windowOpen = false;
|
||||
else if (event.key.code == NzKeyboard::P)
|
||||
paused = !paused;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nzEventType_KeyReleased: // Une touche du clavier vient d'être relachée
|
||||
if (thirdPerson &&
|
||||
|
|
@ -352,7 +376,7 @@ int main()
|
|||
!NzKeyboard::IsKeyPressed(NzKeyboard::D)) // Etc..
|
||||
{
|
||||
// Si plus aucune touche de déplacement n'est enfoncée
|
||||
SetSequence(drfreak, "stand");
|
||||
drfreak.SetSequence("stand");
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -380,68 +404,71 @@ int main()
|
|||
// Nous déplaçons le personnage en fonction des touches pressées
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::Z))
|
||||
modelPos += modelOrient * forward * modelSpeed * elapsedTime;
|
||||
drfreak.Translate(forward * modelSpeed * elapsedTime);
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::S))
|
||||
modelPos -= modelOrient * forward * modelSpeed * elapsedTime;
|
||||
drfreak.Translate(-forward * modelSpeed * elapsedTime);
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::Q))
|
||||
modelRot.yaw += camSpeed * elapsedTime;
|
||||
drfreak.Rotate(NzEulerAnglesf(0.f, modelSpeed * elapsedTime, 0.f));
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::D))
|
||||
modelRot.yaw -= camSpeed * elapsedTime;
|
||||
|
||||
modelOrient = modelRot;
|
||||
drfreak.Rotate(NzEulerAnglesf(0.f, -modelSpeed * elapsedTime, 0.f));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sinon, c'est la caméra qui se déplace (en fonction des mêmes touches)
|
||||
|
||||
// Un boost en maintenant le shift gauche
|
||||
float speed = (NzKeyboard::IsKeyPressed(NzKeyboard::Key::LShift)) ? camSpeed*5 : camSpeed;
|
||||
NzVector3f speed = (NzKeyboard::IsKeyPressed(NzKeyboard::Key::LShift)) ? camSpeed*5 : camSpeed;
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::Z))
|
||||
camPos += camOrient * forward * speed * elapsedTime;
|
||||
camera.Translate(forward * speed * elapsedTime);
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::S))
|
||||
camPos -= camOrient * forward * speed * elapsedTime;
|
||||
camera.Translate(-forward * speed * elapsedTime);
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::Q))
|
||||
camPos += camOrient * left * speed * elapsedTime;
|
||||
camera.Translate(left * speed * elapsedTime);
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::D))
|
||||
camPos -= camOrient * left * speed * elapsedTime;
|
||||
camera.Translate(-left * speed * elapsedTime);
|
||||
|
||||
// En revanche, ici la hauteur est toujours la même, peu importe notre orientation
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::Space))
|
||||
camPos += up * speed * elapsedTime;
|
||||
camera.Translate(up * speed * elapsedTime, nzCoordSys_Global);
|
||||
|
||||
if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl))
|
||||
camPos -= up * speed * elapsedTime;
|
||||
camera.Translate(up * speed * elapsedTime, nzCoordSys_Global);
|
||||
}
|
||||
|
||||
// Oui les quaternions et les matrices sont calculés même si la caméra ne bouge pas
|
||||
// C'est une limitation de mon implémentation, qui ne sera pas présente une fois les NzSceneNode intégrés
|
||||
if (thirdPerson)
|
||||
{
|
||||
static NzQuaternionf rotDown(NzEulerAnglesf(-15.f, 0.f, 0.f)); // Une rotation pour regarder vers le bas
|
||||
camOrient = modelOrient * rotDown;
|
||||
static NzQuaternionf rotDown(NzEulerAnglesf(-35.f, 0.f, 0.f)); // Une rotation pour regarder vers le bas
|
||||
camera.SetRotation(drfreak.GetDerivedRotation() * rotDown);
|
||||
|
||||
camPos = modelPos + camOrient * NzVector3f(0.f, 25.f, 60.f);
|
||||
camera.SetTranslation(drfreak.GetDerivedTranslation() + camera.GetDerivedRotation() * NzVector3f(0.f, 30.f, 50.f));
|
||||
}
|
||||
|
||||
NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camPos, camPos + camOrient * NzVector3f::Forward()));
|
||||
|
||||
// Mise à jour de la matrice du personnage
|
||||
drfreak.matrix = NzMatrix4f::Rotate(modelOrient) * NzMatrix4f::Translate(modelPos);
|
||||
|
||||
// Animation
|
||||
if (!paused)
|
||||
AnimateModel(drfreak, elapsedTime);
|
||||
{
|
||||
drfreak.Update(elapsedTime);
|
||||
hellknight.Update(elapsedTime);
|
||||
/*AnimateModel(hellknight, elapsedTime);
|
||||
hellknight.mesh.GetSkeleton()->GetJoint("luparm")->SetScale(2.f);
|
||||
hellknight.mesh.Skin(hellknight.mesh.GetSkeleton());*/
|
||||
}
|
||||
|
||||
updateClock.Restart();
|
||||
}
|
||||
|
||||
NzRenderer::SetMatrix(nzMatrixType_View, NzMatrix4f::LookAt(camera.GetDerivedTranslation(), camera.GetDerivedTranslation() + camera.GetDerivedRotation() * NzVector3f::Forward()));
|
||||
|
||||
NzVector3f translation = drfreak.GetTranslation();
|
||||
translation.y = -drfreak.GetMesh()->GetAABB().GetMinimum().y;
|
||||
drfreak.SetTranslation(translation);
|
||||
|
||||
// On active le shader et paramètrons le rendu
|
||||
NzRenderer::SetShader(&shader);
|
||||
|
||||
|
|
@ -457,11 +484,39 @@ int main()
|
|||
// Affichage des meshs
|
||||
DrawModel(floor);
|
||||
|
||||
// Notre Dr. Freak possède des normales, nous pouvons alors éliminer les faces qu'on ne voit pas
|
||||
// On élimine les faces qu'on ne voit pas
|
||||
NzRenderer::Enable(nzRendererParameter_FaceCulling, true);
|
||||
|
||||
DrawModel(drfreak);
|
||||
|
||||
if (drawHellknight)
|
||||
DrawModel(hellknight);
|
||||
|
||||
if (drawSkeleton)
|
||||
{
|
||||
NzDebugDrawer::SetDepthTest(false);
|
||||
NzDebugDrawer::SetPrimaryColor(NzColor::Blue);
|
||||
NzDebugDrawer::Draw(hellknight.GetSkeleton());
|
||||
}
|
||||
|
||||
if (drawAabb)
|
||||
{
|
||||
/* NzDebugDrawer::SetDepthTest(true);
|
||||
NzDebugDrawer::SetPrimaryColor(NzColor::Red);
|
||||
NzDebugDrawer::Draw(hellknight.mesh.GetAABB());*/
|
||||
|
||||
NzAxisAlignedBox aabb(drfreak.GetMesh()->GetAABB());
|
||||
aabb.Transform(drfreak.GetTransformMatrix());
|
||||
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Translate(drfreak.GetDerivedTranslation()));
|
||||
NzDebugDrawer::SetPrimaryColor(NzColor::Red);
|
||||
NzDebugDrawer::Draw(aabb);
|
||||
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, drfreak.GetTransformMatrix());
|
||||
NzDebugDrawer::SetPrimaryColor(NzColor::Blue);
|
||||
NzDebugDrawer::Draw(drfreak.GetMesh()->GetAABB());
|
||||
}
|
||||
|
||||
NzRenderer::Enable(nzRendererParameter_FaceCulling, false);
|
||||
|
||||
// Nous mettons à jour l'écran
|
||||
|
|
@ -478,32 +533,19 @@ int main()
|
|||
}
|
||||
}
|
||||
|
||||
NzDebugDrawer::Uninitialize();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void AnimateModel(AnimatedModel& model, float elapsed)
|
||||
{
|
||||
model.interpolation += model.currentSequence->framePerSecond * elapsed;
|
||||
while (model.interpolation > 1.f)
|
||||
{
|
||||
model.interpolation -= 1.f;
|
||||
|
||||
model.currentFrame = model.nextFrame;
|
||||
if (++model.nextFrame > model.currentSequence->lastFrame)
|
||||
model.nextFrame = model.currentSequence->firstFrame;
|
||||
}
|
||||
|
||||
model.mesh.Animate(model.currentFrame, model.nextFrame, (NzKeyboard::IsKeyPressed(NzKeyboard::A)) ? 0.f : model.interpolation);
|
||||
}
|
||||
|
||||
bool CreateCheckerTexture(NzTexture* texture)
|
||||
bool CreateCheckerMaterial(NzMaterial* material)
|
||||
{
|
||||
NzImage image;
|
||||
// Nous crééons une image 2D, au format RGBA8 de dimensions 128*128 (8 blocs de 16 pixels de côté)
|
||||
if (!image.Create(nzImageType_2D, nzPixelFormat_RGBA8, 8*16, 8*16))
|
||||
{
|
||||
// Ne devrait pas arriver (La création d'une image ne peut échouer que si l'un des argument est incorrect)
|
||||
std::cout << "Failed to create image, this means a bug has been found in Nazara" << std::endl;
|
||||
std::cout << "Failed to create image, this means that a bug has been found in Nazara" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -522,6 +564,7 @@ bool CreateCheckerTexture(NzTexture* texture)
|
|||
}
|
||||
}
|
||||
|
||||
NzTexture* texture = new NzTexture;
|
||||
if (!texture->LoadFromImage(image)) // Nous créons notre texture depuis notre image
|
||||
{
|
||||
// Nous n'avons vraiment pas beaucoup de chance..
|
||||
|
|
@ -532,18 +575,24 @@ bool CreateCheckerTexture(NzTexture* texture)
|
|||
texture->SetAnisotropyLevel(NzRenderer::GetMaxAnisotropyLevel()); // Un filtrage anisotropique pour la texture
|
||||
texture->SetWrapMode(nzTextureWrap_Repeat); // Si les coordonnées de texture dépassent 1.f, la texture sera répétée
|
||||
|
||||
material->SetDiffuseMap(texture);
|
||||
|
||||
texture->SetPersistent(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CreateFloorMesh(NzMesh* mesh)
|
||||
bool CreateFloorModel(NzModel* model)
|
||||
{
|
||||
// Cette fonction créé un mesh statique simpliste pour servir de sol
|
||||
|
||||
NzMesh* mesh = new NzMesh;
|
||||
// Nous créons un mesh statique
|
||||
if (!mesh->Create(nzAnimationType_Static))
|
||||
if (!mesh->CreateStatic())
|
||||
{
|
||||
// L'échec est techniquement impossible mais le moteur étant en constante évolution ...
|
||||
std::cout << "Failed to create mesh" << std::endl;
|
||||
delete mesh;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -575,7 +624,7 @@ bool CreateFloorMesh(NzMesh* mesh)
|
|||
|
||||
// Nous créons ensuite un buffer de 4 vertices (le second argument précise l'espace pris par chaque vertex), le stockage
|
||||
// Et nous indiquons que nous n'y toucherons plus
|
||||
NzVertexBuffer* buffer = new NzVertexBuffer(4, declaration->GetStride(nzElementStream_VertexData), nzBufferStorage_Hardware, nzBufferUsage_Static);
|
||||
NzVertexBuffer* buffer = new NzVertexBuffer(declaration, 4, nzBufferStorage_Hardware, nzBufferUsage_Static);
|
||||
|
||||
// Doit respecter la declaration
|
||||
float vertices[] =
|
||||
|
|
@ -605,16 +654,18 @@ bool CreateFloorMesh(NzMesh* mesh)
|
|||
}
|
||||
|
||||
NzStaticMesh* subMesh = new NzStaticMesh(mesh);
|
||||
if (!subMesh->Create(declaration, buffer))
|
||||
if (!subMesh->Create(buffer))
|
||||
{
|
||||
std::cout << "Failed to create subMesh" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
subMesh->SetMaterialIndex(0);
|
||||
subMesh->SetPrimitiveType(nzPrimitiveType_TriangleStrip);
|
||||
|
||||
// On ajoute le submesh au mesh
|
||||
mesh->AddSubMesh(subMesh);
|
||||
mesh->SetMaterialCount(1);
|
||||
|
||||
// Nos ressources sont notifiées utilisées par le mesh et le submesh, nous pouvons les rendre éphèmères.
|
||||
// Les ressources seront donc automatiquement libérées lorsqu'elles ne seront plus référencées par une classe
|
||||
|
|
@ -622,46 +673,46 @@ bool CreateFloorMesh(NzMesh* mesh)
|
|||
declaration->SetPersistent(false);
|
||||
subMesh->SetPersistent(false); // Pour le submesh, c'est déjà le comportement par défaut
|
||||
|
||||
NzModelParameters params;
|
||||
params.loadAnimation = false;
|
||||
params.loadMaterials = false;
|
||||
|
||||
model->SetMesh(mesh, params);
|
||||
mesh->SetPersistent(false);
|
||||
|
||||
NzMaterial* material = new NzMaterial;
|
||||
CreateCheckerMaterial(material);
|
||||
|
||||
model->SetMaterial(0, material);
|
||||
material->SetPersistent(false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DrawModel(const Model& model)
|
||||
void DrawModel(const NzModel& model)
|
||||
{
|
||||
// La matrice world est celle qui représente les transformations du modèle
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, model.matrix);
|
||||
|
||||
NzShader* shader = NzRenderer::GetShader();// On récupère le shader du rendu
|
||||
shader->SendTexture(shader->GetUniformLocation("texture"), &model.texture);
|
||||
NzRenderer::SetMatrix(nzMatrixType_World, model.GetTransformMatrix());
|
||||
|
||||
// Un mesh est divisé en plusieurs submeshes
|
||||
unsigned int subMeshCount = model.mesh.GetSubMeshCount();
|
||||
unsigned int subMeshCount = model.GetMesh()->GetSubMeshCount();
|
||||
for (unsigned int i = 0; i < subMeshCount; ++i)
|
||||
{
|
||||
// On récupère le submesh
|
||||
const NzSubMesh* subMesh = model.mesh.GetSubMesh(i);
|
||||
const NzSubMesh* subMesh = model.GetMesh()->GetSubMesh(i);
|
||||
|
||||
NzRenderer::ApplyMaterial(model.GetMaterial(i));
|
||||
|
||||
// On paramètre le Renderer avec ses données
|
||||
NzRenderer::SetIndexBuffer(subMesh->GetIndexBuffer());
|
||||
NzRenderer::SetVertexBuffer(subMesh->GetVertexBuffer());
|
||||
NzRenderer::SetVertexDeclaration(subMesh->GetVertexDeclaration());
|
||||
|
||||
// On fait le rendu
|
||||
NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount());
|
||||
}
|
||||
}
|
||||
|
||||
void SetSequence(AnimatedModel& model, const NzString& sequenceName)
|
||||
{
|
||||
// On récupère l'animation du mesh
|
||||
const NzAnimation* animation = model.mesh.GetAnimation();
|
||||
|
||||
// Nous nous basons sur l'assertion que la séquence existe (Chose que nous pouvons tester avec HasSequence())
|
||||
const NzSequence* sequence = animation->GetSequence(sequenceName);
|
||||
if (model.currentSequence != sequence)
|
||||
{
|
||||
model.currentSequence = sequence;
|
||||
|
||||
// Pour avoir une interpolation entre la séquence précédente et celle-ci, nous n'affectons que nextFrame
|
||||
model.nextFrame = model.currentSequence->firstFrame;
|
||||
const NzIndexBuffer* indexBuffer = subMesh->GetIndexBuffer();
|
||||
if (indexBuffer)
|
||||
{
|
||||
NzRenderer::SetIndexBuffer(indexBuffer);
|
||||
NzRenderer::DrawIndexedPrimitives(subMesh->GetPrimitiveType(), 0, indexBuffer->GetIndexCount());
|
||||
}
|
||||
else
|
||||
NzRenderer::DrawPrimitives(subMesh->GetPrimitiveType(), 0, subMesh->GetVertexCount());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
varying vec2 TexCoord;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(texture, TexCoord);
|
||||
gl_FragColor = texture2D(diffuseMap, TexCoord);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/Format.hpp>
|
||||
#include <Nazara/Core/Functor.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/Hash.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
|
|
@ -61,6 +62,7 @@
|
|||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/TaskScheduler.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Core/Tuple.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
// 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 NAZARA_ABSTRACT2DNOISE_HPP
|
||||
#define NAZARA_ABSTRACT2DNOISE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
|
||||
class NAZARA_API NzAbstract2DNoise : public NzMappedNoiseBase
|
||||
{
|
||||
public:
|
||||
float GetBasicValue(float x, float y);
|
||||
float GetMappedValue(float x, float y);
|
||||
virtual float GetValue(float x, float y, float resolution) = 0;
|
||||
};
|
||||
|
||||
#endif // NAZARA_ABSTRACT2DNOISE_HPP
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// 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 NAZARA_ABSTRACT3DNOISE_HPP
|
||||
#define NAZARA_ABSTRACT3DNOISE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
|
||||
class NAZARA_API NzAbstract3DNoise : public NzMappedNoiseBase
|
||||
{
|
||||
public:
|
||||
float GetBasicValue(float x, float y, float z);
|
||||
float GetMappedValue(float x, float y, float z);
|
||||
virtual float GetValue(float x, float y, float z, float resolution) = 0;
|
||||
};
|
||||
|
||||
#endif // NAZARA_ABSTRACT3DNOISE_HPP
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// 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 NAZARA_ABSTRACT4DNOISE_HPP
|
||||
#define NAZARA_ABSTRACT4DNOISE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
|
||||
class NAZARA_API NzAbstract4DNoise : public NzMappedNoiseBase
|
||||
{
|
||||
public:
|
||||
float GetBasicValue(float x, float y, float z, float w);
|
||||
float GetMappedValue(float x, float y, float z, float w);
|
||||
virtual float GetValue(float x, float y, float z, float w, float resolution) = 0;
|
||||
};
|
||||
|
||||
#endif // NAZARA_ABSTRACT4DNOISE_HPP
|
||||
|
|
@ -8,16 +8,19 @@
|
|||
#define COMPLEXNOISEBASE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <array>
|
||||
|
||||
class NAZARA_API NzComplexNoiseBase : public NzNoiseBase
|
||||
class NAZARA_API NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzComplexNoiseBase();
|
||||
~NzComplexNoiseBase() = default;
|
||||
|
||||
void SetLacunarity(float lacunarity);
|
||||
float GetHurstParameter() const;
|
||||
float GetLacunarity() const;
|
||||
float GetOctaveNumber() const;
|
||||
void SetHurstParameter(float h);
|
||||
void SetLacunarity(float lacunarity);
|
||||
void SetOctavesNumber(float octaves);
|
||||
void RecomputeExponentArray();
|
||||
|
||||
|
|
@ -25,11 +28,10 @@ class NAZARA_API NzComplexNoiseBase : public NzNoiseBase
|
|||
float m_lacunarity;
|
||||
float m_hurst;
|
||||
float m_octaves;
|
||||
float exponent_array[30];
|
||||
std::array<float, 30> m_exponent_array;
|
||||
float m_sum;
|
||||
private:
|
||||
bool m_parametersModified;
|
||||
|
||||
};
|
||||
|
||||
#endif // COMPLEXNOISEBASE_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
// 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 FBM2D_HPP
|
||||
#define FBM2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
|
||||
class NAZARA_API NzFBM2D : public NzAbstract2DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzFBM2D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
~NzFBM2D();
|
||||
protected:
|
||||
private:
|
||||
NzAbstract2DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
nzNoises m_noiseType;
|
||||
};
|
||||
|
||||
#endif // FBM2D_HPP
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
// 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 FBM3D_HPP
|
||||
#define FBM3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
|
||||
class NAZARA_API NzFBM3D : public NzAbstract3DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzFBM3D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzFBM3D();
|
||||
protected:
|
||||
private:
|
||||
NzAbstract3DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
nzNoises m_noiseType;
|
||||
};
|
||||
|
||||
#endif // FBM3D_HPP
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
// 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 FBM4D_HPP
|
||||
#define FBM4D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
|
||||
class NAZARA_API NzFBM4D : public NzAbstract4DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzFBM4D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzFBM4D();
|
||||
protected:
|
||||
private:
|
||||
NzAbstract4DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
nzNoises m_noiseType;
|
||||
};
|
||||
|
||||
#endif // FBM4D_HPP
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// 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 HYBRIDMULTIFRACTAL3D_HPP
|
||||
#define HYBRIDMULTIFRACTAL3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
|
||||
class NAZARA_API NzHybridMultiFractal3D : public NzAbstract3DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzHybridMultiFractal3D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzHybridMultiFractal3D();
|
||||
protected:
|
||||
private:
|
||||
NzAbstract3DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
nzNoises m_noiseType;
|
||||
};
|
||||
|
||||
#endif // HYBRIDMULTIFRACTAL3D_HPP
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// 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 HYBRIDMULTIFRACTAL4D_HPP
|
||||
#define HYBRIDMULTIFRACTAL4D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
|
||||
class NAZARA_API NzHybridMultiFractal4D : public NzAbstract4DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzHybridMultiFractal4D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzHybridMultiFractal4D();
|
||||
protected:
|
||||
private:
|
||||
NzAbstract4DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
nzNoises m_noiseType;
|
||||
};
|
||||
|
||||
#endif // HYBRIDMULTIFRACTAL4D_HPP
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// 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 HYBRIDMULTIFRACTAL2D_HPP
|
||||
#define HYBRIDMULTIFRACTAL2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
|
||||
class NAZARA_API NzHybridMultiFractal2D : public NzAbstract2DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzHybridMultiFractal2D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
~NzHybridMultiFractal2D();
|
||||
protected:
|
||||
private:
|
||||
NzAbstract2DNoise* m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
nzNoises m_noiseType;
|
||||
};
|
||||
|
||||
#endif // HYBRIDMULTIFRACTAL2D_HPP
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// 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 NAZARA_MAPPEDNOISEBASE_HPP
|
||||
#define NAZARA_MAPPEDNOISEBASE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
|
||||
class NAZARA_API NzMappedNoiseBase : public NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzMappedNoiseBase();
|
||||
~NzMappedNoiseBase() = default;
|
||||
|
||||
float GetGain() const;
|
||||
float GetOffset() const;
|
||||
float GetResolution() const;
|
||||
void SetGain(float gain);
|
||||
void SetOffset(float offset);
|
||||
void SetResolution(float resolution);
|
||||
protected:
|
||||
float m_gain;
|
||||
float m_offset;
|
||||
float m_resolution;
|
||||
};
|
||||
|
||||
#endif // NAZARA_MAPPEDNOISEBASE_HPP
|
||||
|
|
@ -9,24 +9,33 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
enum nzNoises
|
||||
{
|
||||
PERLIN,
|
||||
SIMPLEX,
|
||||
CELL
|
||||
};
|
||||
|
||||
class NAZARA_API NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzNoiseBase(int seed = 0);
|
||||
NzNoiseBase(unsigned int seed = 0);
|
||||
~NzNoiseBase() = default;
|
||||
|
||||
void SetNewSeed(int seed);
|
||||
int GetUniformRandomValue();
|
||||
void SetNewSeed(unsigned int seed);
|
||||
|
||||
void ShufflePermutationTable();
|
||||
|
||||
unsigned int GetUniformRandomValue();
|
||||
|
||||
int fastfloor(float n);
|
||||
int JenkinsHash(int a, int b, int c);
|
||||
protected:
|
||||
int perm[512];
|
||||
unsigned int perm[512];
|
||||
private:
|
||||
int Ua, Uc, Um;
|
||||
int UcurrentSeed;
|
||||
int Uprevious, Ulast;
|
||||
unsigned int Ua, Uc, Um;
|
||||
unsigned int UcurrentSeed;
|
||||
unsigned int Uprevious, Ulast;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,93 +0,0 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NOISEMACHINE_HPP
|
||||
#define NOISEMACHINE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
class NAZARA_API NzNoiseMachine : public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzNoiseMachine(int seed = 0);
|
||||
~NzNoiseMachine() = default;
|
||||
|
||||
float Get2DPerlinNoiseValue (float x, float y, float res);
|
||||
float Get3DPerlinNoiseValue (float x, float y, float z, float res);
|
||||
float Get4DPerlinNoiseValue (float x, float y, float z, float w, float res);
|
||||
|
||||
float Get2DSimplexNoiseValue(float x, float y, float res);
|
||||
float Get3DSimplexNoiseValue(float x, float y, float z, float res);
|
||||
float Get4DSimplexNoiseValue(float x, float y, float z, float w, float res);
|
||||
|
||||
float Get2DCellNoiseValue(float x, float y, float res);
|
||||
float Get3DCellNoiseValue(float x, float y, float z, float res);
|
||||
float Get4DCellNoiseValue(float x, float y, float z, float w, float res);
|
||||
|
||||
float Get2DFBMNoiseValue(float x, float y, float res);
|
||||
float Get3DFBMNoiseValue(float x, float y, float z, float res);
|
||||
|
||||
float Get2DHybridMultiFractalNoiseValue(float x, float y, float res);
|
||||
float Get3DHybridMultiFractalNoiseValue(float x, float y, float z, float res);
|
||||
|
||||
protected:
|
||||
private:
|
||||
|
||||
float gradient2[8][2];
|
||||
int gradient3[16][3];
|
||||
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;
|
||||
|
||||
|
||||
float c1,c2,c3,c4,c5,c6;
|
||||
int c;
|
||||
|
||||
float SkewCoeff2D;
|
||||
float UnskewCoeff2D;
|
||||
|
||||
float SkewCoeff3D;
|
||||
float UnskewCoeff3D;
|
||||
|
||||
float SkewCoeff4D;
|
||||
float UnskewCoeff4D;
|
||||
|
||||
float sum;
|
||||
|
||||
//----------------------- Perlin Variables -------------------------------------
|
||||
|
||||
int x0,y0,z0,w0;
|
||||
float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14;
|
||||
float s[4],t[4],u[4],v[4];
|
||||
float Cx, Cy, Cz, Cw;
|
||||
NzVector4f temp;
|
||||
float tmp;
|
||||
|
||||
//---------------------- Complex Noise Variables --------------------------------
|
||||
|
||||
|
||||
bool first;
|
||||
float value;
|
||||
float remainder;
|
||||
float smax;
|
||||
float smin;
|
||||
|
||||
};
|
||||
|
||||
#endif // NOISEMACHINE_HPP
|
||||
|
|
@ -9,30 +9,27 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
template <typename T> class NAZARA_API NzPerlin2D : public NzNoiseBase
|
||||
class NAZARA_API NzPerlin2D : public NzAbstract2DNoise
|
||||
{
|
||||
public:
|
||||
NzPerlin2D();
|
||||
T GetValue(T x, T y, T res);
|
||||
NzPerlin2D(unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
~NzPerlin2D() = default;
|
||||
protected:
|
||||
private:
|
||||
int x0, y0;
|
||||
int gi0,gi1,gi2,gi3;
|
||||
int ii, jj;
|
||||
T gradient2[8][2];
|
||||
T s,t,u,v;
|
||||
T Cx,Cy;
|
||||
T Li1, Li2;
|
||||
NzVector2<T> temp;
|
||||
float gradient2[8][2];
|
||||
float s,t,u,v;
|
||||
float Cx,Cy;
|
||||
float Li1, Li2;
|
||||
NzVector2<float> temp;
|
||||
};
|
||||
|
||||
typedef NzPerlin2D<float> NzPerlin2Df;
|
||||
typedef NzPerlin2D<double> NzPerlin2Dd;
|
||||
|
||||
#include <Nazara/Noise/Perlin2D.inl>
|
||||
|
||||
#endif // PERLIN2D_HPP
|
||||
|
||||
|
|
|
|||
|
|
@ -9,32 +9,28 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
template <typename T> class NAZARA_API NzPerlin3D : public NzNoiseBase
|
||||
class NAZARA_API NzPerlin3D : public NzAbstract3DNoise
|
||||
{
|
||||
public:
|
||||
NzPerlin3D();
|
||||
T GetValue(T x, T y, T z, T res);
|
||||
NzPerlin3D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzPerlin3D() = default;
|
||||
protected:
|
||||
private:
|
||||
int x0,y0,z0;
|
||||
int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7;
|
||||
int ii,jj,kk;
|
||||
int gradient3[16][3];
|
||||
T Li1,Li2,Li3,Li4,Li5,Li6;
|
||||
T s[2],t[2],u[2],v[2];
|
||||
T Cx,Cy,Cz;
|
||||
T nx,ny,nz;
|
||||
T tmp;
|
||||
NzVector3<T> temp;
|
||||
|
||||
float gradient3[16][3];
|
||||
float Li1,Li2,Li3,Li4,Li5,Li6;
|
||||
float s[2],t[2],u[2],v[2];
|
||||
float Cx,Cy,Cz;
|
||||
float nx,ny,nz;
|
||||
float tmp;
|
||||
NzVector3<float> temp;
|
||||
};
|
||||
|
||||
typedef NzPerlin3D<float> NzPerlin3Df;
|
||||
typedef NzPerlin3D<double> NzPerlin3Dd;
|
||||
|
||||
#include <Nazara/Noise/Perlin3D.inl>
|
||||
|
||||
#endif // PERLIN3D_HPP
|
||||
|
|
|
|||
|
|
@ -9,32 +9,27 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
template <typename T> class NAZARA_API NzPerlin4D : public NzNoiseBase
|
||||
class NAZARA_API NzPerlin4D : public NzAbstract4DNoise
|
||||
{
|
||||
public:
|
||||
NzPerlin4D();
|
||||
T GetValue(T x, T y, T z, T w, T res);
|
||||
NzPerlin4D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzPerlin4D() = default;
|
||||
protected:
|
||||
private:
|
||||
int x0,y0,z0,w0;
|
||||
int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15;
|
||||
int ii,jj,kk,ll;
|
||||
int gradient4[32][4];
|
||||
T Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14;
|
||||
T s[4],t[4],u[4],v[4];
|
||||
T Cx,Cy,Cz,Cw;
|
||||
T nx,ny,nz,nw;
|
||||
T tmp;
|
||||
NzVector4<T> temp;
|
||||
|
||||
float gradient4[32][4];
|
||||
float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14;
|
||||
float s[4],t[4],u[4],v[4];
|
||||
float Cx,Cy,Cz,Cw;
|
||||
float tmp;
|
||||
NzVector4<float> temp;
|
||||
};
|
||||
|
||||
typedef NzPerlin4D<float> NzPerlin4Df;
|
||||
typedef NzPerlin4D<double> NzPerlin4Dd;
|
||||
|
||||
#include <Nazara/Noise/Perlin4D.inl>
|
||||
|
||||
#endif // PERLIN4D_HPP
|
||||
|
|
|
|||
|
|
@ -9,35 +9,30 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
template <typename T> class NAZARA_API NzSimplex2D : public NzNoiseBase
|
||||
class NAZARA_API NzSimplex2D : public NzAbstract2DNoise
|
||||
{
|
||||
public:
|
||||
NzSimplex2D();
|
||||
T GetValue(T x, T y, T res);
|
||||
~NzSimplex2D() = default;
|
||||
NzSimplex2D(unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
virtual ~NzSimplex2D() = default;
|
||||
protected:
|
||||
private:
|
||||
int ii,jj;
|
||||
int gi0,gi1,gi2;
|
||||
NzVector2i skewedCubeOrigin,off1;
|
||||
T n1,n2,n3;
|
||||
T c1,c2,c3;
|
||||
T gradient2[8][2];
|
||||
T UnskewCoeff2D;
|
||||
T SkewCoeff2D;
|
||||
T sum;
|
||||
NzVector2<T> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
NzVector2<T> d1,d2,d3;
|
||||
|
||||
|
||||
float n1,n2,n3;
|
||||
float c1,c2,c3;
|
||||
float gradient2[8][2];
|
||||
float UnskewCoeff2D;
|
||||
float SkewCoeff2D;
|
||||
float sum;
|
||||
NzVector2<float> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
NzVector2<float> d1,d2,d3;
|
||||
};
|
||||
|
||||
typedef NzSimplex2D<float> NzSimplex2Df;
|
||||
typedef NzSimplex2D<double> NzSimplex2Dd;
|
||||
|
||||
#include <Nazara/Noise/Simplex2D.inl>
|
||||
|
||||
#endif // SIMPLEX2D_HPP
|
||||
|
||||
|
|
|
|||
|
|
@ -9,35 +9,30 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
template <typename T> class NAZARA_API NzSimplex3D : public NzNoiseBase
|
||||
class NAZARA_API NzSimplex3D : public NzAbstract3DNoise
|
||||
{
|
||||
public:
|
||||
NzSimplex3D();
|
||||
T GetValue(T x, T y, T z, T res);
|
||||
NzSimplex3D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzSimplex3D() = default;
|
||||
protected:
|
||||
private:
|
||||
int ii,jj,kk;
|
||||
int gi0,gi1,gi2,gi3;
|
||||
NzVector3i skewedCubeOrigin,off1,off2;
|
||||
T n1,n2,n3,n4;
|
||||
T c1,c2,c3,c4;
|
||||
T gradient3[12][3];
|
||||
T UnskewCoeff3D;
|
||||
T SkewCoeff3D;
|
||||
T sum;
|
||||
NzVector3<T> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
NzVector3<T> d1,d2,d3,d4;
|
||||
|
||||
|
||||
float n1,n2,n3,n4;
|
||||
float c1,c2,c3,c4;
|
||||
float gradient3[12][3];
|
||||
float UnskewCoeff3D;
|
||||
float SkewCoeff3D;
|
||||
float sum;
|
||||
NzVector3<float> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
NzVector3<float> d1,d2,d3,d4;
|
||||
};
|
||||
|
||||
typedef NzSimplex3D<float> NzSimplex3Df;
|
||||
typedef NzSimplex3D<double> NzSimplex3Dd;
|
||||
|
||||
#include <Nazara/Noise/Simplex3D.inl>
|
||||
|
||||
#endif // SIMPLEX3D_HPP
|
||||
|
||||
|
|
|
|||
|
|
@ -9,37 +9,32 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Noise/NoiseBase.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
template <typename T> class NAZARA_API NzSimplex4D : public NzNoiseBase
|
||||
class NAZARA_API NzSimplex4D : public NzAbstract4DNoise
|
||||
{
|
||||
public:
|
||||
NzSimplex4D();
|
||||
T GetValue(T x, T y, T z, T w, T res);
|
||||
NzSimplex4D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzSimplex4D() = default;
|
||||
protected:
|
||||
private:
|
||||
int ii,jj,kk,ll;
|
||||
int gi0,gi1,gi2,gi3,gi4;
|
||||
NzVector4i skewedCubeOrigin,off1,off2,off3;
|
||||
T n1,n2,n3,n4,n5;
|
||||
T c1,c2,c3,c4,c5,c6;
|
||||
T gradient4[32][4];
|
||||
int lookupTable4D[64][4];
|
||||
int c;
|
||||
T UnskewCoeff4D;
|
||||
T SkewCoeff4D;
|
||||
T sum;
|
||||
NzVector4<T> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
NzVector4<T> d1,d2,d3,d4,d5;
|
||||
|
||||
|
||||
float n1,n2,n3,n4,n5;
|
||||
float c1,c2,c3,c4,c5,c6;
|
||||
float gradient4[32][4];
|
||||
float UnskewCoeff4D;
|
||||
float SkewCoeff4D;
|
||||
float sum;
|
||||
NzVector4<float> unskewedCubeOrigin, unskewedDistToOrigin;
|
||||
NzVector4<float> d1,d2,d3,d4,d5;
|
||||
};
|
||||
|
||||
typedef NzSimplex4D<float> NzSimplex4Df;
|
||||
typedef NzSimplex4D<double> NzSimplex4Dd;
|
||||
|
||||
#include <Nazara/Noise/Simplex4D.inl>
|
||||
|
||||
#endif // SIMPLEX4D_H
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/DebugDrawer.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Renderer/Material.hpp>
|
||||
#include <Nazara/Renderer/OcclusionQuery.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
|
|
@ -42,6 +43,7 @@
|
|||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_RENDERER_HPP
|
||||
|
|
|
|||
|
|
@ -158,7 +158,9 @@ enum nzTextureFilter
|
|||
nzTextureFilter_Nearest,
|
||||
nzTextureFilter_Trilinear,
|
||||
|
||||
nzTextureFilter_Max = nzTextureFilter_Trilinear
|
||||
nzTextureFilter_Default,
|
||||
|
||||
nzTextureFilter_Max = nzTextureFilter_Default
|
||||
};
|
||||
|
||||
enum nzTextureWrap
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class NAZARA_API NzMaterial : public NzResource
|
|||
NzColor GetSpecularColor() const;
|
||||
const NzTexture* GetSpecularMap() const;
|
||||
nzBlendFunc GetSrcBlend() const;
|
||||
nzTextureFilter GetTextureFilter() const;
|
||||
nzRendererComparison GetZTestCompare() const;
|
||||
|
||||
bool IsAlphaBlendingEnabled() const;
|
||||
|
|
@ -69,6 +70,8 @@ class NAZARA_API NzMaterial : public NzResource
|
|||
void SetSpecularColor(const NzColor& specular);
|
||||
void SetSpecularMap(const NzTexture* map);
|
||||
void SetSrcBlend(nzBlendFunc func);
|
||||
void SetTextureFilter(nzTextureFilter filter);
|
||||
void SetTextureWrap(nzTextureWrap wrapMode);
|
||||
void SetZTestCompare(nzRendererComparison compareFunc);
|
||||
|
||||
static const NzMaterial* GetDefault();
|
||||
|
|
@ -79,6 +82,8 @@ class NAZARA_API NzMaterial : public NzResource
|
|||
nzFaceCulling m_faceCulling;
|
||||
nzFaceFilling m_faceFilling;
|
||||
nzRendererComparison m_zTestCompareFunc;
|
||||
nzTextureFilter m_textureFilter;
|
||||
nzTextureWrap m_textureWrap;
|
||||
NzColor m_ambientColor;
|
||||
NzColor m_diffuseColor;
|
||||
NzColor m_specularColor;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
|||
unsigned int GetWidth() const;
|
||||
nzTextureWrap GetWrapMode() const;
|
||||
|
||||
bool HasMipmaps() const;
|
||||
|
||||
bool IsCompressed() const;
|
||||
bool IsCubemap() const;
|
||||
bool IsTarget() const;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
// 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/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
#include <Nazara/Noise/Abstract2DNoise.hpp>
|
||||
|
||||
float NzAbstract2DNoise::GetBasicValue(float x, float y)
|
||||
{
|
||||
return this->GetValue(x,y,m_resolution);
|
||||
}
|
||||
|
||||
float NzAbstract2DNoise::GetMappedValue(float x, float y)
|
||||
{
|
||||
return (this->GetValue(x,y,m_resolution) + m_offset) * m_gain;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// 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/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
#include <Nazara/Noise/Abstract3DNoise.hpp>
|
||||
|
||||
float NzAbstract3DNoise::GetBasicValue(float x, float y, float z)
|
||||
{
|
||||
return this->GetValue(x,y,z,m_resolution);
|
||||
}
|
||||
|
||||
float NzAbstract3DNoise::GetMappedValue(float x, float y, float z)
|
||||
{
|
||||
return (this->GetValue(x,y,z,m_resolution) + m_offset) * m_gain ;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// 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/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
#include <Nazara/Noise/Abstract4DNoise.hpp>
|
||||
|
||||
float NzAbstract4DNoise::GetBasicValue(float x, float y, float z, float w)
|
||||
{
|
||||
return this->GetValue(x,y,z,w,m_resolution);
|
||||
}
|
||||
|
||||
float NzAbstract4DNoise::GetMappedValue(float x, float y, float z, float w)
|
||||
{
|
||||
return (this->GetValue(x,y,z,w,m_resolution) + m_offset) * m_gain ;
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// 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/ComplexNoiseBase.hpp>
|
||||
#include <cmath>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
#include <Nazara/Noise/ComplexNoiseBase.hpp>
|
||||
|
||||
NzComplexNoiseBase::NzComplexNoiseBase()
|
||||
{
|
||||
|
|
@ -14,33 +14,52 @@ NzComplexNoiseBase::NzComplexNoiseBase()
|
|||
m_lacunarity = 5.0f;
|
||||
m_hurst = 1.2f;
|
||||
m_octaves = 3.0f;
|
||||
|
||||
for (int i(0) ; i < m_octaves; ++i)
|
||||
{
|
||||
m_exponent_array[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
float NzComplexNoiseBase::GetLacunarity() const
|
||||
{
|
||||
|
||||
return m_lacunarity;
|
||||
}
|
||||
|
||||
float NzComplexNoiseBase::GetHurstParameter() const
|
||||
{
|
||||
return m_hurst;
|
||||
}
|
||||
|
||||
float NzComplexNoiseBase::GetOctaveNumber() const
|
||||
{
|
||||
return m_octaves;
|
||||
}
|
||||
|
||||
void NzComplexNoiseBase::SetLacunarity(float lacunarity)
|
||||
{
|
||||
if(lacunarity != m_lacunarity)
|
||||
{
|
||||
m_lacunarity = lacunarity;
|
||||
m_parametersModified = true;
|
||||
}
|
||||
m_lacunarity = lacunarity;
|
||||
m_parametersModified = true;
|
||||
|
||||
}
|
||||
|
||||
void NzComplexNoiseBase::SetHurstParameter(float h)
|
||||
{
|
||||
if(h != m_hurst)
|
||||
{
|
||||
m_hurst = h;
|
||||
m_parametersModified = true;
|
||||
}
|
||||
|
||||
m_hurst = h;
|
||||
m_parametersModified = true;
|
||||
}
|
||||
|
||||
void NzComplexNoiseBase::SetOctavesNumber(float octaves)
|
||||
{
|
||||
if(octaves != m_octaves && octaves < 30)
|
||||
{
|
||||
if(octaves <= 30.0f)
|
||||
m_octaves = octaves;
|
||||
m_parametersModified = true;
|
||||
}
|
||||
else
|
||||
m_octaves = 30.0f;
|
||||
|
||||
m_parametersModified = true;
|
||||
|
||||
}
|
||||
|
||||
void NzComplexNoiseBase::RecomputeExponentArray()
|
||||
|
|
@ -49,12 +68,13 @@ void NzComplexNoiseBase::RecomputeExponentArray()
|
|||
{
|
||||
float frequency = 1.0;
|
||||
m_sum = 0.f;
|
||||
for (int i(0) ; i < m_octaves; ++i)
|
||||
for (int i(0) ; i < static_cast<int>(m_octaves) ; ++i)
|
||||
{
|
||||
exponent_array[i] = std::pow( frequency, -m_hurst );
|
||||
|
||||
m_exponent_array[i] = std::pow( frequency, -m_hurst );
|
||||
frequency *= m_lacunarity;
|
||||
|
||||
m_sum += exponent_array[i];
|
||||
m_sum += m_exponent_array[i];
|
||||
|
||||
}
|
||||
m_parametersModified = false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
// 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/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/FBM2D.hpp>
|
||||
#include <Nazara/Noise/Perlin2D.hpp>
|
||||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzFBM2D::NzFBM2D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new NzPerlin2D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new NzSimplex2D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float NzFBM2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_value = 0.0;
|
||||
|
||||
for (int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
m_value += m_source->GetValue(x,y,resolution) * m_exponent_array[i];
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(!NzNumberEquals(m_remainder, static_cast<float>(0.0)))
|
||||
m_value += m_remainder * m_source->GetValue(x,y,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum;
|
||||
}
|
||||
|
||||
NzFBM2D::~NzFBM2D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// 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/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/FBM3D.hpp>
|
||||
#include <Nazara/Noise/Perlin3D.hpp>
|
||||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzFBM3D::NzFBM3D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new NzPerlin3D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new NzSimplex3D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float NzFBM3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_value = 0.0;
|
||||
|
||||
for (int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
m_value += m_source->GetValue(x,y,z,resolution) * m_exponent_array[i];
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(!NzNumberEquals(m_remainder, static_cast<float>(0.0)))
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum;
|
||||
}
|
||||
|
||||
NzFBM3D::~NzFBM3D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// 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/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/FBM4D.hpp>
|
||||
#include <Nazara/Noise/Perlin4D.hpp>
|
||||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzFBM4D::NzFBM4D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new NzPerlin4D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new NzSimplex4D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float NzFBM4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_value = 0.0;
|
||||
|
||||
for (int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
m_value += m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[i];
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(!NzNumberEquals(m_remainder, static_cast<float>(0.0)))
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum;
|
||||
}
|
||||
|
||||
NzFBM4D::~NzFBM4D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/HybridMultiFractal3D.hpp>
|
||||
#include <Nazara/Noise/Perlin3D.hpp>
|
||||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzHybridMultiFractal3D::NzHybridMultiFractal3D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new NzPerlin3D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new NzSimplex3D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float NzHybridMultiFractal3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_offset = 1.0f;
|
||||
|
||||
m_value = (m_source->GetValue(x,y,z,resolution) + m_offset) * m_exponent_array[0];
|
||||
m_weight = m_value;
|
||||
m_signal = 0.f;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if(m_weight > 1.0)
|
||||
m_weight = 1.0;
|
||||
|
||||
m_signal = (m_source->GetValue(x,y,z,resolution) + m_offset) * m_exponent_array[i];
|
||||
m_value += m_weight * m_signal;
|
||||
|
||||
m_weight *= m_signal;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(remainder != 0)
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum - m_offset;
|
||||
}
|
||||
|
||||
NzHybridMultiFractal3D::~NzHybridMultiFractal3D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/HybridMultiFractal4D.hpp>
|
||||
#include <Nazara/Noise/Perlin4D.hpp>
|
||||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzHybridMultiFractal4D::NzHybridMultiFractal4D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new NzPerlin4D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new NzSimplex4D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float NzHybridMultiFractal4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_offset = 1.0f;
|
||||
|
||||
m_value = (m_source->GetValue(x,y,z,w,resolution) + m_offset) * m_exponent_array[0];
|
||||
m_weight = m_value;
|
||||
m_signal = 0.f;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if(m_weight > 1.0)
|
||||
m_weight = 1.0;
|
||||
|
||||
m_signal = (m_source->GetValue(x,y,z,w,resolution) + m_offset) * m_exponent_array[i];
|
||||
m_value += m_weight * m_signal;
|
||||
|
||||
m_weight *= m_signal;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(remainder != 0)
|
||||
m_value += m_remainder * m_source->GetValue(x,y,z,w,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum - m_offset;
|
||||
}
|
||||
|
||||
NzHybridMultiFractal4D::~NzHybridMultiFractal4D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/HybridMultiFractal2D.hpp>
|
||||
#include <Nazara/Noise/Perlin2D.hpp>
|
||||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzHybridMultiFractal2D::NzHybridMultiFractal2D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
case PERLIN:
|
||||
m_source = new NzPerlin2D();
|
||||
break;
|
||||
|
||||
default:
|
||||
m_source = new NzSimplex2D();
|
||||
break;
|
||||
}
|
||||
m_source->SetNewSeed(seed);
|
||||
m_source->ShufflePermutationTable();
|
||||
m_noiseType = source;
|
||||
}
|
||||
|
||||
float NzHybridMultiFractal2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
this->RecomputeExponentArray();
|
||||
|
||||
m_offset = 1.0f;
|
||||
|
||||
m_value = (m_source->GetValue(x,y,resolution) + m_offset) * m_exponent_array[0];
|
||||
m_weight = m_value;
|
||||
m_signal = 0.f;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if(m_weight > 1.0)
|
||||
m_weight = 1.0;
|
||||
|
||||
m_signal = (m_source->GetValue(x,y,resolution) + m_offset) * m_exponent_array[i];
|
||||
m_value += m_weight * m_signal;
|
||||
|
||||
m_weight *= m_signal;
|
||||
|
||||
resolution *= m_lacunarity;
|
||||
}
|
||||
|
||||
m_remainder = m_octaves - static_cast<int>(m_octaves);
|
||||
|
||||
if(remainder != 0)
|
||||
m_value += m_remainder * m_source->GetValue(x,y,resolution) * m_exponent_array[static_cast<int>(m_octaves-1)];
|
||||
|
||||
return m_value/this->m_sum - m_offset;
|
||||
}
|
||||
|
||||
NzHybridMultiFractal2D::~NzHybridMultiFractal2D()
|
||||
{
|
||||
delete m_source;
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
// 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/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
#include <Nazara/Noise/MappedNoiseBase.hpp>
|
||||
|
||||
NzMappedNoiseBase::NzMappedNoiseBase() : m_gain(1.f), m_offset(0.f), m_resolution(30.f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float NzMappedNoiseBase::GetGain() const
|
||||
{
|
||||
return m_gain;
|
||||
}
|
||||
|
||||
float NzMappedNoiseBase::GetOffset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
float NzMappedNoiseBase::GetResolution() const
|
||||
{
|
||||
return m_resolution;
|
||||
}
|
||||
|
||||
void NzMappedNoiseBase::SetGain(float gain)
|
||||
{
|
||||
m_gain = gain;
|
||||
}
|
||||
|
||||
void NzMappedNoiseBase::SetOffset(float offset)
|
||||
{
|
||||
m_offset = offset;
|
||||
}
|
||||
|
||||
void NzMappedNoiseBase::SetResolution(float resolution)
|
||||
{
|
||||
if (NzNumberEquals(resolution, 0.f))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << " : resolution cannot be 0.0f";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
m_resolution = resolution;
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzNoiseBase::NzNoiseBase(int seed)
|
||||
NzNoiseBase::NzNoiseBase(unsigned int seed)
|
||||
{
|
||||
Ua = 16807;
|
||||
Uc = 0;
|
||||
|
|
@ -17,18 +17,18 @@ NzNoiseBase::NzNoiseBase(int seed)
|
|||
|
||||
SetNewSeed(seed);
|
||||
|
||||
for(int i(0) ; i < 256 ; i++)
|
||||
perm[i] = i;
|
||||
for(int i(0) ; i < 512 ; i++)
|
||||
perm[i] = i & 255;
|
||||
|
||||
}
|
||||
|
||||
void NzNoiseBase::SetNewSeed(int seed)
|
||||
void NzNoiseBase::SetNewSeed(unsigned int seed)
|
||||
{
|
||||
Uprevious = seed;
|
||||
UcurrentSeed = seed;
|
||||
}
|
||||
|
||||
int NzNoiseBase::GetUniformRandomValue()
|
||||
unsigned int NzNoiseBase::GetUniformRandomValue()
|
||||
{
|
||||
Ulast = Ua*Uprevious + Uc%Um;
|
||||
Uprevious = Ulast;
|
||||
|
|
@ -40,11 +40,11 @@ void NzNoiseBase::ShufflePermutationTable()
|
|||
int xchanger;
|
||||
unsigned int ncase;
|
||||
|
||||
for(int i(0) ; i < 256 ; i++)
|
||||
for(unsigned int i(0) ; i < 256 ; i++)
|
||||
perm[i] = i;
|
||||
|
||||
for(int j(0) ; j < 20 ; ++j)
|
||||
for (int i(0); i < 256 ; ++i)
|
||||
for(unsigned int j(0) ; j < 20 ; ++j)
|
||||
for (unsigned int i(0); i < 256 ; ++i)
|
||||
{
|
||||
ncase = this->GetUniformRandomValue() & 255;
|
||||
xchanger = perm[i];
|
||||
|
|
@ -52,7 +52,7 @@ void NzNoiseBase::ShufflePermutationTable()
|
|||
perm[ncase] = xchanger;
|
||||
}
|
||||
|
||||
for(int i(256) ; i < 512; ++i)
|
||||
for(unsigned int i(256) ; i < 512; ++i)
|
||||
perm[i] = perm[i & 255];
|
||||
}
|
||||
|
||||
|
|
@ -74,5 +74,3 @@ int NzNoiseBase::JenkinsHash(int a, int b, int c)
|
|||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 15);
|
||||
return c;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -1,762 +0,0 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/NoiseMachine.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzNoiseMachine::NzNoiseMachine(int seed)
|
||||
{
|
||||
SkewCoeff2D = 0.5*(sqrt(3.0) - 1.0);
|
||||
UnskewCoeff2D = (3.0-sqrt(3.0))/6;
|
||||
|
||||
SkewCoeff3D = 1/3;
|
||||
UnskewCoeff3D = 1/6;
|
||||
|
||||
SkewCoeff4D = (sqrt(5) - 1)/4;
|
||||
UnskewCoeff4D = (5 - sqrt(5))/20;
|
||||
|
||||
|
||||
int lookupTemp4D[][4] =
|
||||
{
|
||||
{0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
|
||||
{0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
|
||||
{1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
|
||||
{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
|
||||
{2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
|
||||
{2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 64 ; ++i)
|
||||
for(int j(0) ; j < 4 ; ++j)
|
||||
lookupTable4D[i][j] = lookupTemp4D[i][j];
|
||||
|
||||
float grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1},
|
||||
{1,0},{-1,0},{0,1},{0,-1}};
|
||||
|
||||
for(int i(0) ; i < 8 ; ++i)
|
||||
for(int j(0) ; j < 2 ; ++j)
|
||||
gradient2[i][j] = grad2Temp[i][j];
|
||||
|
||||
int grad3Temp[][3] = {
|
||||
{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0},
|
||||
{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},
|
||||
{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1},
|
||||
{1,1,0},{-1,1,0},{0,-1,1},{0,-1,-1}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 16 ; ++i)
|
||||
for(int j(0) ; j < 3 ; ++j)
|
||||
gradient3[i][j] = grad3Temp[i][j];
|
||||
|
||||
int grad4Temp[][4] =
|
||||
{
|
||||
{0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1},
|
||||
{0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1},
|
||||
{1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1},
|
||||
{-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1},
|
||||
{1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1},
|
||||
{-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1},
|
||||
{1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0},
|
||||
{-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0}
|
||||
};
|
||||
|
||||
for(int i(0) ; i < 32 ; ++i)
|
||||
for(int j(0) ; j < 4 ; ++j)
|
||||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
//------------------------------ PERLIN ------------------------------
|
||||
|
||||
float NzNoiseMachine::Get2DPerlinNoiseValue(float x, float y, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
|
||||
x0 = fastfloor(x);
|
||||
y0 = fastfloor(y);
|
||||
|
||||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj]] & 7;
|
||||
gi1 = perm[ii + 1 + perm[jj]] & 7;
|
||||
gi2 = perm[ii + perm[jj + 1]] & 7;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1]] & 7;
|
||||
|
||||
temp.x = x-x0;
|
||||
temp.y = y-y0;
|
||||
|
||||
Cx = temp.x * temp.x * temp.x * (temp.x * (temp.x * 6 - 15) + 10);
|
||||
Cy = temp.y * temp.y * temp.y * (temp.y * (temp.y * 6 - 15) + 10);
|
||||
|
||||
s[0] = gradient2[gi0][0]*temp.x + gradient2[gi0][1]*temp.y;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[0] = gradient2[gi1][0]*temp.x + gradient2[gi1][1]*temp.y;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[0] = gradient2[gi3][0]*temp.x + gradient2[gi3][1]*temp.y;
|
||||
|
||||
temp.x = x-x0;
|
||||
u[0] = gradient2[gi2][0]*temp.x + gradient2[gi2][1]*temp.y;
|
||||
|
||||
Li1 = s[0] + Cx*(t[0]-s[0]);
|
||||
Li2 = u[0] + Cx*(v[0]-u[0]);
|
||||
|
||||
return Li1 + Cy*(Li2-Li1);
|
||||
}
|
||||
float NzNoiseMachine::Get3DPerlinNoiseValue(float x, float y, float z, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
|
||||
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 ]]] & 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]]] & 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.y = y-(y0+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;
|
||||
|
||||
temp.x = x-(x0+1);
|
||||
t[1] = gradient3[gi5][0]*temp.x + gradient3[gi5][1]*temp.y + gradient3[gi5][2]*temp.z;
|
||||
|
||||
temp.y = y-(y0+1);
|
||||
v[1] = gradient3[gi7][0]*temp.x + gradient3[gi7][1]*temp.y + gradient3[gi7][2]*temp.z;
|
||||
|
||||
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]);
|
||||
|
||||
Li5 = Li1 + Cy*(Li2-Li1);
|
||||
Li6 = Li3 + Cy*(Li4-Li3);
|
||||
|
||||
return Li5 + Cz*(Li6-Li5);
|
||||
}
|
||||
|
||||
float NzNoiseMachine::Get4DPerlinNoiseValue(float x, float y, float z, float w, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
w /= res;
|
||||
|
||||
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 ]]]] & 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 ]]]] & 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]]]] & 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]]]] & 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.y = y-(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 = 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;
|
||||
|
||||
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.y = y-(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 = 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);
|
||||
s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.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.y = y-(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 = 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;
|
||||
|
||||
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.y = y-(y0+1);
|
||||
v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w;
|
||||
|
||||
temp.x = 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]);
|
||||
Li3 = s[1] + Cx*(t[1]-s[1]);
|
||||
Li4 = u[1] + Cx*(v[1]-u[1]);
|
||||
Li5 = s[2] + Cx*(t[2]-s[2]);
|
||||
Li6 = u[2] + Cx*(v[2]-u[2]);
|
||||
Li7 = s[3] + Cx*(t[3]-s[3]);
|
||||
Li8 = u[3] + Cx*(v[3]-u[3]);
|
||||
|
||||
Li9 = Li1 + Cy*(Li2-Li1);
|
||||
Li10 = Li3 + Cy*(Li4-Li3);
|
||||
Li11 = Li5 + Cy*(Li6-Li5);
|
||||
Li12 = Li7 + Cy*(Li8-Li7);
|
||||
|
||||
Li13 = Li9 + Cz*(Li10-Li9);
|
||||
Li14 = Li11 + Cz*(Li12-Li11);
|
||||
|
||||
return Li13 + Cw*(Li14-Li13);
|
||||
}
|
||||
|
||||
//------------------------------ SIMPLEX ------------------------------
|
||||
|
||||
float NzNoiseMachine::Get2DSimplexNoiseValue(float x, float y, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
|
||||
sum = (x + y) * SkewCoeff2D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
skewedCubeOrigin.y = fastfloor(y + sum);
|
||||
|
||||
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;
|
||||
|
||||
if(unskewedDistToOrigin.x > unskewedDistToOrigin.y)
|
||||
{
|
||||
off1.x = 1;
|
||||
off1.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 1;
|
||||
}
|
||||
|
||||
d1 = - unskewedDistToOrigin;
|
||||
|
||||
d2.x = d1.x + off1.x - UnskewCoeff2D;
|
||||
d2.y = d1.y + off1.y - UnskewCoeff2D;
|
||||
|
||||
d3.x = d1.x + 1.0 - 2 * UnskewCoeff2D;
|
||||
d3.y = d1.y + 1.0 - 2 * UnskewCoeff2D;
|
||||
|
||||
ii = skewedCubeOrigin.x & 255;
|
||||
jj = skewedCubeOrigin.y & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj ]] & 7;
|
||||
gi1 = perm[ii + off1.x + perm[jj + off1.y]] & 7;
|
||||
gi2 = perm[ii + 1 + perm[jj + 1 ]] & 7;
|
||||
|
||||
c1 = 0.5 - d1.x * d1.x - d1.y * d1.y;
|
||||
c2 = 0.5 - d2.x * d2.x - d2.y * d2.y;
|
||||
c3 = 0.5 - d3.x * d3.x - d3.y * d3.y;
|
||||
|
||||
if(c1 < 0)
|
||||
n1 = 0;
|
||||
else
|
||||
n1 = c1*c1*c1*c1*(gradient2[gi0][0] * d1.x + gradient2[gi0][1] * d1.y);
|
||||
|
||||
if(c2 < 0)
|
||||
n2 = 0;
|
||||
else
|
||||
n2 = c2*c2*c2*c2*(gradient2[gi1][0] * d2.x + gradient2[gi1][1] * d2.y);
|
||||
|
||||
if(c3 < 0)
|
||||
n3 = 0;
|
||||
else
|
||||
n3 = c3*c3*c3*c3*(gradient2[gi2][0] * d3.x + gradient2[gi2][1] * d3.y);
|
||||
|
||||
return (n1+n2+n3)*70;
|
||||
}
|
||||
|
||||
float NzNoiseMachine::Get3DSimplexNoiseValue(float x, float y, float z, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
|
||||
sum = (x + y + z) * SkewCoeff3D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
skewedCubeOrigin.y = fastfloor(y + sum);
|
||||
skewedCubeOrigin.z = fastfloor(z + sum);
|
||||
|
||||
sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z) * UnskewCoeff3D;
|
||||
unskewedCubeOrigin.x = skewedCubeOrigin.x - sum;
|
||||
unskewedCubeOrigin.y = skewedCubeOrigin.y - sum;
|
||||
unskewedCubeOrigin.z = skewedCubeOrigin.z - sum;
|
||||
|
||||
unskewedDistToOrigin.x = x - unskewedCubeOrigin.x;
|
||||
unskewedDistToOrigin.y = y - unskewedCubeOrigin.y;
|
||||
unskewedDistToOrigin.z = z - unskewedCubeOrigin.z;
|
||||
|
||||
if(unskewedDistToOrigin.x >= unskewedDistToOrigin.y)
|
||||
{
|
||||
if(unskewedDistToOrigin.y >= unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 1;
|
||||
off1.y = 0;
|
||||
off1.z = 0;
|
||||
off2.x = 1;
|
||||
off2.y = 1;
|
||||
off2.z = 0;
|
||||
}
|
||||
else if(unskewedDistToOrigin.x >= unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 1;
|
||||
off1.y = 0;
|
||||
off1.z = 0;
|
||||
off2.x = 1;
|
||||
off2.y = 0;
|
||||
off2.z = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 0;
|
||||
off1.z = 1;
|
||||
off2.x = 1;
|
||||
off2.y = 0;
|
||||
off2.z = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(unskewedDistToOrigin.y < unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 0;
|
||||
off1.z = 1;
|
||||
off2.x = 0;
|
||||
off2.y = 1;
|
||||
off2.z = 1;
|
||||
}
|
||||
else if(unskewedDistToOrigin.x < unskewedDistToOrigin.z)
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 1;
|
||||
off1.z = 0;
|
||||
off2.x = 0;
|
||||
off2.y = 1;
|
||||
off2.z = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
off1.x = 0;
|
||||
off1.y = 1;
|
||||
off1.z = 0;
|
||||
off2.x = 1;
|
||||
off2.y = 1;
|
||||
off2.z = 0;
|
||||
}
|
||||
}
|
||||
|
||||
d1 = unskewedDistToOrigin;
|
||||
|
||||
d2.x = d1.x - off1.x + UnskewCoeff3D;
|
||||
d2.y = d1.y - off1.y + UnskewCoeff3D;
|
||||
d2.z = d1.z - off1.z + UnskewCoeff3D;
|
||||
|
||||
d3.x = d1.x - off2.x + 2*UnskewCoeff3D;
|
||||
d3.y = d1.y - off2.y + 2*UnskewCoeff3D;
|
||||
d3.z = d1.z - off2.z + 2*UnskewCoeff3D;
|
||||
|
||||
d4.x = d1.x - 1.0 + 3*UnskewCoeff3D;
|
||||
d4.y = d1.y - 1.0 + 3*UnskewCoeff3D;
|
||||
d4.z = d1.z - 1.0 + 3*UnskewCoeff3D;
|
||||
|
||||
ii = skewedCubeOrigin.x & 255;
|
||||
jj = skewedCubeOrigin.y & 255;
|
||||
kk = skewedCubeOrigin.z & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk ]]] % 12;
|
||||
gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z]]] % 12;
|
||||
gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z]]] % 12;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 ]]] % 12;
|
||||
|
||||
c1 = 0.6 - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z;
|
||||
c2 = 0.6 - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z;
|
||||
c3 = 0.6 - d3.x * d3.x - d3.y * d3.y - d3.z * d3.z;
|
||||
c4 = 0.6 - d4.x * d4.x - d4.y * d4.y - d4.z * d4.z;
|
||||
|
||||
if(c1 < 0)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
n4 = 0;
|
||||
else
|
||||
n4 = c4*c4*c4*c4*(gradient3[gi3][0] * d4.x + gradient3[gi3][1] * d4.y + gradient3[gi3][2] * d4.z);
|
||||
|
||||
return (n1+n2+n3+n4)*32;
|
||||
}
|
||||
|
||||
float NzNoiseMachine::Get4DSimplexNoiseValue(float x, float y, float z, float w, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
w /= res;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
unskewedDistToOrigin.x = x - unskewedCubeOrigin.x;
|
||||
unskewedDistToOrigin.y = y - unskewedCubeOrigin.y;
|
||||
unskewedDistToOrigin.z = z - unskewedCubeOrigin.z;
|
||||
unskewedDistToOrigin.w = w - unskewedCubeOrigin.w;
|
||||
|
||||
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;
|
||||
off1.y = lookupTable4D[c][1] >= 3 ? 1 : 0;
|
||||
off1.z = lookupTable4D[c][2] >= 3 ? 1 : 0;
|
||||
off1.w = lookupTable4D[c][3] >= 3 ? 1 : 0;
|
||||
|
||||
off2.x = lookupTable4D[c][0] >= 2 ? 1 : 0;
|
||||
off2.y = lookupTable4D[c][1] >= 2 ? 1 : 0;
|
||||
off2.z = lookupTable4D[c][2] >= 2 ? 1 : 0;
|
||||
off2.w = lookupTable4D[c][3] >= 2 ? 1 : 0;
|
||||
|
||||
off3.x = lookupTable4D[c][0] >= 1 ? 1 : 0;
|
||||
off3.y = lookupTable4D[c][1] >= 1 ? 1 : 0;
|
||||
off3.z = lookupTable4D[c][2] >= 1 ? 1 : 0;
|
||||
off3.w = lookupTable4D[c][3] >= 1 ? 1 : 0;
|
||||
|
||||
d1 = 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;
|
||||
|
||||
d3.x = d1.x - off2.x + 2*UnskewCoeff4D;
|
||||
d3.y = d1.y - off2.y + 2*UnskewCoeff4D;
|
||||
d3.z = d1.z - off2.z + 2*UnskewCoeff4D;
|
||||
d3.w = d1.w - off2.w + 2*UnskewCoeff4D;
|
||||
|
||||
d4.x = d1.x - off3.x + 3*UnskewCoeff4D;
|
||||
d4.y = d1.y - off3.y + 3*UnskewCoeff4D;
|
||||
d4.z = d1.z - off3.z + 3*UnskewCoeff4D;
|
||||
d4.w = d1.w - off3.w + 3*UnskewCoeff4D;
|
||||
|
||||
d5.x = d1.x - 1.0 + 4*UnskewCoeff4D;
|
||||
d5.y = d1.y - 1.0 + 4*UnskewCoeff4D;
|
||||
d5.z = d1.z - 1.0 + 4*UnskewCoeff4D;
|
||||
d5.w = d1.w - 1.0 + 4*UnskewCoeff4D;
|
||||
|
||||
ii = skewedCubeOrigin.x & 255;
|
||||
jj = skewedCubeOrigin.y & 255;
|
||||
kk = skewedCubeOrigin.z & 255;
|
||||
ll = skewedCubeOrigin.w & 255;
|
||||
|
||||
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;
|
||||
|
||||
c1 = 0.6 - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w;
|
||||
c2 = 0.6 - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w;
|
||||
c3 = 0.6 - d3.x*d3.x - d3.y*d3.y - d3.z*d3.z - d3.w*d3.w;
|
||||
c4 = 0.6 - d4.x*d4.x - d4.y*d4.y - d4.z*d4.z - d4.w*d4.w;
|
||||
c5 = 0.6 - d5.x*d5.x - d5.y*d5.y - d5.z*d5.z - d5.w*d5.w;
|
||||
|
||||
if(c1 < 0)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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);
|
||||
|
||||
return (n1+n2+n3+n4+n5)*27.0;
|
||||
}
|
||||
|
||||
//------------------------------ CELL ------------------------------
|
||||
|
||||
float NzNoiseMachine::Get2DCellNoiseValue(float x, float y, float res)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float NzNoiseMachine::Get3DCellNoiseValue(float x, float y, float z, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
|
||||
x0 = static_cast<int>(x);
|
||||
y0 = static_cast<int>(y);
|
||||
z0 = static_cast<int>(z);
|
||||
|
||||
return (this->JenkinsHash(x0,y0,z0) & 255);
|
||||
}
|
||||
float NzNoiseMachine::Get4DCellNoiseValue(float x, float y, float z, float w, float res)
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
w /= res;
|
||||
|
||||
x0 = static_cast<int>(x) & 255;
|
||||
y0 = static_cast<int>(y) & 255;
|
||||
z0 = static_cast<int>(z) & 255;
|
||||
w0 = static_cast<int>(w) & 255;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------ FBM ------------------------------
|
||||
|
||||
float NzNoiseMachine::Get2DFBMNoiseValue(float x, float y, float res)
|
||||
{
|
||||
value = 0.0;
|
||||
RecomputeExponentArray();
|
||||
|
||||
for (int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
value += Get2DPerlinNoiseValue(x,y,res) * exponent_array[i];
|
||||
x *= m_lacunarity;
|
||||
y *= m_lacunarity;
|
||||
}
|
||||
remainder = m_octaves - (int)m_octaves;
|
||||
|
||||
if(remainder != 0)
|
||||
value += remainder * Get2DSimplexNoiseValue(x,y,res) * exponent_array[(int)m_octaves-1];
|
||||
|
||||
return value * m_sum;
|
||||
}
|
||||
|
||||
float NzNoiseMachine::Get3DFBMNoiseValue(float x, float y, float z, float res)
|
||||
{
|
||||
value = 0.0;
|
||||
RecomputeExponentArray();
|
||||
|
||||
for(int i(0); i < m_octaves; ++i)
|
||||
{
|
||||
value += Get3DSimplexNoiseValue(x,y,z,res) * exponent_array[i];
|
||||
x *= m_lacunarity;
|
||||
y *= m_lacunarity;
|
||||
z *= m_lacunarity;
|
||||
}
|
||||
remainder = m_octaves - (int)m_octaves;
|
||||
|
||||
if(remainder != 0)
|
||||
value += remainder * Get3DSimplexNoiseValue(x,y,z,res) * exponent_array[(int)m_octaves-1];
|
||||
|
||||
return value * m_sum;
|
||||
}
|
||||
|
||||
//------------------------------ HYBRID MULTIFRACTAL ------------------------------
|
||||
|
||||
float NzNoiseMachine::Get2DHybridMultiFractalNoiseValue(float x, float y, float res)
|
||||
{
|
||||
float result, signal, weight, remainder;
|
||||
float offset = 1;
|
||||
|
||||
RecomputeExponentArray();
|
||||
|
||||
result = (Get2DSimplexNoiseValue(x,y,res) + offset) * exponent_array[0];
|
||||
weight = result;
|
||||
|
||||
x *= m_lacunarity;
|
||||
y *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
if(weight > 1.0)
|
||||
weight = 1.0;
|
||||
|
||||
signal = (Get2DSimplexNoiseValue(x,y,res) + offset) * exponent_array[i];
|
||||
result += weight * signal;
|
||||
|
||||
weight *= signal;
|
||||
|
||||
x *= m_lacunarity;
|
||||
y *= m_lacunarity;
|
||||
|
||||
}
|
||||
|
||||
remainder = m_octaves - (int)m_octaves;
|
||||
|
||||
if(remainder != 0)
|
||||
result += remainder * Get2DSimplexNoiseValue(x,y,res) * exponent_array[(int)m_octaves-1];
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
float NzNoiseMachine::Get3DHybridMultiFractalNoiseValue(float x, float y, float z, float res)
|
||||
{
|
||||
float result, signal, weight, remainder;
|
||||
float offset = 1;
|
||||
|
||||
RecomputeExponentArray();
|
||||
|
||||
result = (Get3DSimplexNoiseValue(x,y,z,res) + offset) * exponent_array[0];
|
||||
weight = result;
|
||||
|
||||
x *= m_lacunarity;
|
||||
y *= m_lacunarity;
|
||||
|
||||
for(int i(1) ; i < m_octaves; ++i)
|
||||
{
|
||||
|
||||
if(weight > 1.0)
|
||||
weight = 1.0;
|
||||
|
||||
signal = ( Get3DSimplexNoiseValue(x,y,z,res) + offset ) * exponent_array[i];
|
||||
result += weight * signal;
|
||||
|
||||
weight *= signal;
|
||||
|
||||
x *= m_lacunarity;
|
||||
y *= m_lacunarity;
|
||||
|
||||
}
|
||||
|
||||
remainder = m_octaves - (int)m_octaves;
|
||||
|
||||
if(remainder != 0)
|
||||
result += remainder * Get3DSimplexNoiseValue(x,y,z,res) * exponent_array[(int)m_octaves-1];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Perlin2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzPerlin2D<T>::NzPerlin2D()
|
||||
NzPerlin2D::NzPerlin2D()
|
||||
{
|
||||
T grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1},
|
||||
int grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1},
|
||||
{1,0},{-1,0},{0,1},{0,-1}};
|
||||
|
||||
for(int i(0) ; i < 8 ; ++i)
|
||||
|
|
@ -17,11 +17,16 @@ NzPerlin2D<T>::NzPerlin2D()
|
|||
gradient2[i][j] = grad2Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzPerlin2D<T>::GetValue(T x, T y, T res)
|
||||
NzPerlin2D::NzPerlin2D(unsigned int seed) : NzPerlin2D()
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float NzPerlin2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
|
||||
x0 = fastfloor(x);
|
||||
y0 = fastfloor(y);
|
||||
|
|
@ -29,9 +34,9 @@ T NzPerlin2D<T>::GetValue(T x, T y, T res)
|
|||
ii = x0 & 255;
|
||||
jj = y0 & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj]] & 7;
|
||||
gi0 = perm[ii + perm[jj]] & 7;
|
||||
gi1 = perm[ii + 1 + perm[jj]] & 7;
|
||||
gi2 = perm[ii + perm[jj + 1]] & 7;
|
||||
gi2 = perm[ii + perm[jj + 1]] & 7;
|
||||
gi3 = perm[ii + 1 + perm[jj + 1]] & 7;
|
||||
|
||||
temp.x = x-x0;
|
||||
|
|
@ -56,5 +61,3 @@ T NzPerlin2D<T>::GetValue(T x, T y, T res)
|
|||
|
||||
return Li1 + Cy*(Li2-Li1);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Perlin3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzPerlin3D<T>::NzPerlin3D()
|
||||
NzPerlin3D::NzPerlin3D()
|
||||
{
|
||||
int grad3Temp[][3] = {
|
||||
float grad3Temp[][3] = {
|
||||
{1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0},
|
||||
{1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1},
|
||||
{0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1},
|
||||
|
|
@ -21,12 +21,17 @@ NzPerlin3D<T>::NzPerlin3D()
|
|||
gradient3[i][j] = grad3Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzPerlin3D<T>::GetValue(T x, T y, T z, T res)
|
||||
NzPerlin3D::NzPerlin3D(unsigned int seed) : NzPerlin3D()
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float NzPerlin3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
x /= resolution;
|
||||
y /= resolution;
|
||||
z /= resolution;
|
||||
|
||||
x0 = fastfloor(x);
|
||||
y0 = fastfloor(y);
|
||||
|
|
@ -36,14 +41,14 @@ T NzPerlin3D<T>::GetValue(T x, T y, T z, T res)
|
|||
jj = y0 & 255;
|
||||
kk = z0 & 255;
|
||||
|
||||
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;
|
||||
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]]] & 15;
|
||||
gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] & 15;
|
||||
gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] & 15;
|
||||
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;
|
||||
|
|
@ -88,5 +93,3 @@ T NzPerlin3D<T>::GetValue(T x, T y, T z, T res)
|
|||
|
||||
return Li5 + Cz*(Li6-Li5);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Perlin4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzPerlin4D<T>::NzPerlin4D()
|
||||
NzPerlin4D::NzPerlin4D()
|
||||
{
|
||||
int grad4Temp[][4] =
|
||||
float grad4Temp[][4] =
|
||||
{
|
||||
{0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1},
|
||||
{0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1},
|
||||
|
|
@ -26,33 +26,38 @@ NzPerlin4D<T>::NzPerlin4D()
|
|||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzPerlin4D<T>::GetValue(T x, T y, T z, T w, T res)
|
||||
NzPerlin4D::NzPerlin4D(unsigned int seed) : NzPerlin4D()
|
||||
{
|
||||
nx = x/res;
|
||||
ny = y/res;
|
||||
nz = z/res;
|
||||
nw = w/res;
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
x0 = fastfloor(nx);
|
||||
y0 = fastfloor(ny);
|
||||
z0 = fastfloor(nz);
|
||||
w0 = fastfloor(nw);
|
||||
float NzPerlin4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
z *= resolution;
|
||||
w *= resolution;
|
||||
|
||||
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 ]]]] & 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;
|
||||
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 ]]]] & 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;
|
||||
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]]]] & 31;
|
||||
gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] & 31;
|
||||
|
|
@ -64,10 +69,10 @@ T NzPerlin4D<T>::GetValue(T x, T y, T z, T w, T res)
|
|||
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;
|
||||
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);
|
||||
|
|
@ -76,55 +81,55 @@ T NzPerlin4D<T>::GetValue(T x, T y, T z, T w, T res)
|
|||
|
||||
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.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.y = ny-(y0+1);
|
||||
temp.y = y-(y0+1);
|
||||
v[0] = gradient4[gi3][0]*temp.x + gradient4[gi3][1]*temp.y + gradient4[gi3][2]*temp.z + gradient4[gi3][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.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 = ny-y0;
|
||||
temp.z = nz-(z0+1);
|
||||
temp.y = y-y0;
|
||||
temp.z = z-(z0+1);
|
||||
s[1] = gradient4[gi4][0]*temp.x + gradient4[gi4][1]*temp.y + gradient4[gi4][2]*temp.z + gradient4[gi4][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.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.y = ny-(y0+1);
|
||||
temp.y = y-(y0+1);
|
||||
v[1] = gradient4[gi7][0]*temp.x + gradient4[gi7][1]*temp.y + gradient4[gi7][2]*temp.z + gradient4[gi7][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.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 = ny-y0;
|
||||
temp.z = nz-z0;
|
||||
temp.w = nw-(w0+1);
|
||||
temp.y = y-y0;
|
||||
temp.z = z-z0;
|
||||
temp.w = w-(w0+1);
|
||||
s[2] = gradient4[gi8][0]*temp.x + gradient4[gi8][1]*temp.y + gradient4[gi8][2]*temp.z + gradient4[gi8][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.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.y = ny-(y0+1);
|
||||
temp.y = y-(y0+1);
|
||||
v[2] = gradient4[gi11][0]*temp.x + gradient4[gi11][1]*temp.y + gradient4[gi11][2]*temp.z + gradient4[gi11][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
temp.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 = ny-y0;
|
||||
temp.z = nz-(z0+1);
|
||||
temp.y = y-y0;
|
||||
temp.z = z-(z0+1);
|
||||
s[3] = gradient4[gi12][0]*temp.x + gradient4[gi12][1]*temp.y + gradient4[gi12][2]*temp.z + gradient4[gi12][3]*temp.w;
|
||||
|
||||
temp.x = nx-(x0+1);
|
||||
temp.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.y = ny-(y0+1);
|
||||
temp.y = y-(y0+1);
|
||||
v[3] = gradient4[gi15][0]*temp.x + gradient4[gi15][1]*temp.y + gradient4[gi15][2]*temp.z + gradient4[gi15][3]*temp.w;
|
||||
|
||||
temp.x = nx-x0;
|
||||
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]);
|
||||
|
|
@ -146,5 +151,3 @@ T NzPerlin4D<T>::GetValue(T x, T y, T z, T w, T res)
|
|||
|
||||
return Li13 + Cw*(Li14-Li13);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzSimplex2D<T>::NzSimplex2D()
|
||||
NzSimplex2D::NzSimplex2D()
|
||||
{
|
||||
T grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1},
|
||||
float grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1},
|
||||
{1,0},{-1,0},{0,1},{0,-1}};
|
||||
|
||||
for(int i(0) ; i < 8 ; ++i)
|
||||
|
|
@ -20,11 +20,16 @@ NzSimplex2D<T>::NzSimplex2D()
|
|||
UnskewCoeff2D = (3.0-sqrt(3.0))/6.;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzSimplex2D<T>::GetValue(T x, T y, T res)
|
||||
NzSimplex2D::NzSimplex2D(unsigned int seed) : NzSimplex2D()
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float NzSimplex2D::GetValue(float x, float y, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
|
||||
sum = (x + y) * SkewCoeff2D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
|
|
@ -84,5 +89,3 @@ T NzSimplex2D<T>::GetValue(T x, T y, T res)
|
|||
|
||||
return (n1+n2+n3)*70;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzSimplex3D<T>::NzSimplex3D()
|
||||
NzSimplex3D::NzSimplex3D()
|
||||
{
|
||||
SkewCoeff3D = 1/3.;
|
||||
UnskewCoeff3D = 1/6.;
|
||||
|
|
@ -21,12 +21,17 @@ NzSimplex3D<T>::NzSimplex3D()
|
|||
gradient3[i][j] = grad3Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzSimplex3D<T>::GetValue(T x, T y, T z, T res)
|
||||
NzSimplex3D::NzSimplex3D(unsigned int seed) : NzSimplex3D()
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float NzSimplex3D::GetValue(float x, float y, float z, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
z *= resolution;
|
||||
|
||||
sum = (x + y + z) * SkewCoeff3D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
|
|
@ -153,5 +158,3 @@ T NzSimplex3D<T>::GetValue(T x, T y, T z, T res)
|
|||
|
||||
return (n1+n2+n3+n4)*32;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
template <typename T>
|
||||
NzSimplex4D<T>::NzSimplex4D()
|
||||
NzSimplex4D::NzSimplex4D()
|
||||
{
|
||||
SkewCoeff4D = (sqrt(5.) - 1.)/4.;
|
||||
UnskewCoeff4D = (5. - sqrt(5.))/20.;
|
||||
|
|
@ -45,13 +45,18 @@ NzSimplex4D<T>::NzSimplex4D()
|
|||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NzSimplex4D<T>::GetValue(T x, T y, T z, T w, T res)
|
||||
NzSimplex4D::NzSimplex4D(unsigned int seed) : NzSimplex4D()
|
||||
{
|
||||
x /= res;
|
||||
y /= res;
|
||||
z /= res;
|
||||
w /= res;
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
}
|
||||
|
||||
float NzSimplex4D::GetValue(float x, float y, float z, float w, float resolution)
|
||||
{
|
||||
x *= resolution;
|
||||
y *= resolution;
|
||||
z *= resolution;
|
||||
w *= resolution;
|
||||
|
||||
sum = (x + y + z + w) * SkewCoeff4D;
|
||||
skewedCubeOrigin.x = fastfloor(x + sum);
|
||||
|
|
@ -120,11 +125,11 @@ T NzSimplex4D<T>::GetValue(T x, T y, T z, T w, T res)
|
|||
kk = skewedCubeOrigin.z & 255;
|
||||
ll = skewedCubeOrigin.w & 255;
|
||||
|
||||
gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31;
|
||||
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;
|
||||
gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32;
|
||||
|
||||
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;
|
||||
|
|
@ -159,5 +164,3 @@ T NzSimplex4D<T>::GetValue(T x, T y, T z, T w, T res)
|
|||
|
||||
return (n1+n2+n3+n4+n5)*27.0;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -148,6 +148,8 @@ void NzMaterial::Reset()
|
|||
m_shininess = 0;
|
||||
m_specularColor = NzColor::White;
|
||||
m_srcBlend = nzBlendFunc_One;
|
||||
m_textureFilter = nzTextureFilter_Default;
|
||||
m_textureWrap = nzTextureWrap_Repeat;
|
||||
m_zTestCompareFunc = nzRendererComparison_LessOrEqual;
|
||||
m_zTestEnabled = true;
|
||||
m_zWriteEnabled = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue