Improve background mountens by using perlin_noise again

This commit is contained in:
2024-12-24 17:48:27 +01:00
parent 8d4562edf6
commit ef7ee5d8b6
3 changed files with 461 additions and 13 deletions

View File

@@ -6,6 +6,8 @@
#include "Math.hpp"
#include "values/mrand.hpp"
#include "stb_perlin.h"
#include <raylib.h>
#include <rlgl.h>
#include <raymath.h>
@@ -40,9 +42,9 @@ void BackGround::draw(Dna *dna)
}
drawSun();
drawMounten(20, (int)(mounten1min * canvasSize), (int)(mounten1max * canvasSize), BackGroundColors::MountenColor1);
drawMounten(21, (int)(mounten2min * canvasSize), (int)(mounten2max * canvasSize), BackGroundColors::MountenColor2);
drawMounten(23, (int)(mounten3min * canvasSize), (int)(mounten3max * canvasSize), BackGroundColors::MountenColor3);
drawMounten(150, (int)(mounten1min * canvasSize), (int)(mounten1max * canvasSize), BackGroundColors::MountenColor1, 5);
drawMounten(100, (int)(mounten2min * canvasSize), (int)(mounten2max * canvasSize), BackGroundColors::MountenColor2, 3);
drawMounten(50, (int)(mounten3min * canvasSize), (int)(mounten3max * canvasSize), BackGroundColors::MountenColor3, 1);
}
void BackGround::drawStars()
@@ -109,14 +111,22 @@ void BackGround::drawSun()
Circle::draw(xpos, ypos, r);
}
void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color color)
void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color color, float scale)
{
int x = 0;
int diff = canvasSize / (mountenSegments - 1);
float p = mrand::getFloat(&mountenSeed);
float ny = mrand::getFloat(&mountenSeed);
float nz = mrand::getFloat(&mountenSeed);
int y = Lerp(min, max, p);
int offsetX = mrand::getFloat(&mountenSeed) * 255;
float nx = (float)(0 + offsetX) * (scale / (float)mountenSegments);
float p = stb_perlin_fbm_noise3(nx, ny, nz, 2.0f, 0.5f, 6);
float np = (p + 1.0f) / 2.0f;
int y = Lerp(min, max, np);
rlSetTexture(1);
rlBegin(RL_TRIANGLES);
rlNormal3f(0.0f, 0.0f, 1.0f);
@@ -129,8 +139,18 @@ void BackGround::drawMounten(size_t mountenSegments, int min, int max, Color col
// bottomLeft
rlVertex2f(x, canvasSize);
p = mrand::getFloat(&mountenSeed);
y = Lerp(min, max, p);
nx = (float)(i + offsetX) * (scale / (float)mountenSegments);
p = stb_perlin_fbm_noise3(nx, ny, nz, 2.0f, 0.5f, 6);
if (p < -1.0f)
p = -1.0f;
if (p > 1.0f)
p = 1.0f;
np = (p + 1.0f) / 2.0f;
y = Lerp(min, max, np);
x += diff;
// topRight
rlVertex2f(x, y);