Rename Sun to circle
This commit is contained in:
parent
e630cf49cd
commit
6661a71271
@ -1,6 +1,5 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "canvas/Sun.hpp"
|
|
||||||
#include "values/Dna.hpp"
|
#include "values/Dna.hpp"
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
@ -25,8 +24,6 @@ private:
|
|||||||
uint128 mountenSeed;
|
uint128 mountenSeed;
|
||||||
uint128 starSeed;
|
uint128 starSeed;
|
||||||
|
|
||||||
Sun sun;
|
|
||||||
|
|
||||||
int canvasSize = 0;
|
int canvasSize = 0;
|
||||||
|
|
||||||
constexpr static size_t numOfStarts = 150;
|
constexpr static size_t numOfStarts = 150;
|
||||||
|
26
inc/canvas/Circle.hpp
Normal file
26
inc/canvas/Circle.hpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include <raylib.h>
|
||||||
|
|
||||||
|
class Circle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void init();
|
||||||
|
static void deinit();
|
||||||
|
static void setColor(Color color);
|
||||||
|
static void setSoftEdge(bool soft);
|
||||||
|
static void draw(float x, float y, float size);
|
||||||
|
|
||||||
|
Circle() = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const int sizeTexute = 250;
|
||||||
|
static RenderTexture2D target;
|
||||||
|
static Shader shader;
|
||||||
|
|
||||||
|
static float radius;
|
||||||
|
static float start_transperency;
|
||||||
|
static float c[3];
|
||||||
|
|
||||||
|
static int radius_loc;
|
||||||
|
static int start_transperency_loc;
|
||||||
|
static int colorLoc;
|
||||||
|
};
|
@ -1,26 +0,0 @@
|
|||||||
#include <raylib.h>
|
|
||||||
|
|
||||||
class Sun
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Sun() = default;
|
|
||||||
~Sun() = default;
|
|
||||||
void init();
|
|
||||||
void deinit();
|
|
||||||
void setColor(Color color);
|
|
||||||
void draw(float x, float y, float size);
|
|
||||||
private:
|
|
||||||
const int sizeTexute = 250;
|
|
||||||
RenderTexture2D target = { 0 };
|
|
||||||
Shader shader = { 0 };
|
|
||||||
|
|
||||||
float sun_radius = 0.60f;
|
|
||||||
float start_transperency = 0.40f;
|
|
||||||
float c[3] = { 240.0f / 255.0f, 240.0f / 255.0f, 190.0f / 255.0f };
|
|
||||||
|
|
||||||
int sun_radius_loc = 0;
|
|
||||||
int start_transperency_loc = 0;
|
|
||||||
int colorLoc = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "canvas/BackGround.hpp"
|
#include "canvas/BackGround.hpp"
|
||||||
#include "canvas/BackGroundColors.hpp"
|
#include "canvas/BackGroundColors.hpp"
|
||||||
|
#include "canvas/Circle.hpp"
|
||||||
#include "Math.hpp"
|
#include "Math.hpp"
|
||||||
#include "values/mrand.hpp"
|
#include "values/mrand.hpp"
|
||||||
|
|
||||||
@ -13,12 +14,10 @@
|
|||||||
void BackGround::init(int canvasSize)
|
void BackGround::init(int canvasSize)
|
||||||
{
|
{
|
||||||
this->canvasSize = canvasSize;
|
this->canvasSize = canvasSize;
|
||||||
sun.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackGround::deinit()
|
void BackGround::deinit()
|
||||||
{
|
{
|
||||||
sun.deinit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackGround::draw(Dna *dna)
|
void BackGround::draw(Dna *dna)
|
||||||
@ -93,7 +92,7 @@ void BackGround::drawSun()
|
|||||||
|
|
||||||
if (m_dna->colorSet == 3)
|
if (m_dna->colorSet == 3)
|
||||||
{
|
{
|
||||||
sun.setColor(BackGroundColors::moonColor);
|
Circle::setColor(BackGroundColors::moonColor);
|
||||||
r = ((m_dna->moon.size * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
r = ((m_dna->moon.size * (maxSizeOfMoon - minSizeOfMoon)) + minSizeOfMoon) * canvasSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -104,9 +103,9 @@ void BackGround::drawSun()
|
|||||||
color.b = std::lerp(50, 0, m_dna->moon.y);
|
color.b = std::lerp(50, 0, m_dna->moon.y);
|
||||||
color.a = 255;
|
color.a = 255;
|
||||||
|
|
||||||
sun.setColor(color);
|
Circle::setColor(color);
|
||||||
}
|
}
|
||||||
sun.draw(xpos, ypos, r);
|
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)
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#include "canvas/Canvas.hpp"
|
#include "canvas/Canvas.hpp"
|
||||||
|
#include "canvas/Circle.hpp"
|
||||||
|
|
||||||
void Canvas::init(int size)
|
void Canvas::init(int size)
|
||||||
{
|
{
|
||||||
backGround.init(size);
|
backGround.init(size);
|
||||||
tree.init(size);
|
tree.init(size);
|
||||||
|
Circle::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::newGen(RenderTexture2D &target, Dna *dna)
|
void Canvas::newGen(RenderTexture2D &target, Dna *dna)
|
||||||
@ -20,4 +22,5 @@ void Canvas::newGen(RenderTexture2D &target, Dna *dna)
|
|||||||
void Canvas::deinit()
|
void Canvas::deinit()
|
||||||
{
|
{
|
||||||
backGround.deinit();
|
backGround.deinit();
|
||||||
|
Circle::deinit();
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "canvas/Sun.hpp"
|
#include "canvas/Circle.hpp"
|
||||||
#include "sunShader.hpp"
|
#include "sunShader.hpp"
|
||||||
|
|
||||||
#include "Math.hpp"
|
#include "Math.hpp"
|
||||||
@ -6,7 +6,16 @@
|
|||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <rlgl.h>
|
#include <rlgl.h>
|
||||||
|
|
||||||
void Sun::init()
|
RenderTexture2D Circle::target;
|
||||||
|
Shader Circle::shader;
|
||||||
|
float Circle::radius;
|
||||||
|
float Circle::start_transperency;
|
||||||
|
float Circle::c[3];
|
||||||
|
int Circle::radius_loc;
|
||||||
|
int Circle::start_transperency_loc;
|
||||||
|
int Circle::colorLoc;
|
||||||
|
|
||||||
|
void Circle::init()
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
||||||
shader = LoadShaderFromMemory(0, (const char *)shaders_sun_100_fs);
|
shader = LoadShaderFromMemory(0, (const char *)shaders_sun_100_fs);
|
||||||
@ -15,12 +24,17 @@ void Sun::init()
|
|||||||
#endif
|
#endif
|
||||||
target = LoadRenderTexture(sizeTexute, sizeTexute);
|
target = LoadRenderTexture(sizeTexute, sizeTexute);
|
||||||
|
|
||||||
sun_radius_loc = GetShaderLocation(shader, "sun_radius");
|
radius = 0.6f;
|
||||||
SetShaderValue(shader, sun_radius_loc, &sun_radius, SHADER_UNIFORM_FLOAT);
|
radius_loc = GetShaderLocation(shader, "sun_radius");
|
||||||
|
SetShaderValue(shader, radius_loc, &radius, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
start_transperency = 0.40f;
|
||||||
start_transperency_loc = GetShaderLocation(shader, "start_transperency");
|
start_transperency_loc = GetShaderLocation(shader, "start_transperency");
|
||||||
SetShaderValue(shader, start_transperency_loc, &start_transperency, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shader, start_transperency_loc, &start_transperency, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
c[0] = 1.0f;
|
||||||
|
c[1] = 1.0f;
|
||||||
|
c[2] = 1.0f;
|
||||||
colorLoc = GetShaderLocation(shader, "color");
|
colorLoc = GetShaderLocation(shader, "color");
|
||||||
SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3);
|
SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
@ -29,28 +43,43 @@ void Sun::init()
|
|||||||
rlSetBlendFactorsSeparate(RL_SRC_ALPHA, RL_ONE_MINUS_SRC_ALPHA, RL_ONE, RL_ONE, RL_FUNC_ADD, RL_MAX);
|
rlSetBlendFactorsSeparate(RL_SRC_ALPHA, RL_ONE_MINUS_SRC_ALPHA, RL_ONE, RL_ONE, RL_FUNC_ADD, RL_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sun::deinit()
|
void Circle::deinit()
|
||||||
{
|
{
|
||||||
UnloadShader(shader);
|
UnloadShader(shader);
|
||||||
UnloadRenderTexture(target);
|
UnloadRenderTexture(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sun::setColor(Color color)
|
void Circle::setColor(Color color)
|
||||||
{
|
{
|
||||||
c[0] = color.r / 255.0f;
|
c[0] = color.r / 255.0f;
|
||||||
c[1] = color.g / 255.0f;
|
c[1] = color.g / 255.0f;
|
||||||
c[2] = color.b / 255.0f;
|
c[2] = color.b / 255.0f;
|
||||||
colorLoc = GetShaderLocation(shader, "color");
|
|
||||||
SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3);
|
SetShaderValue(shader, colorLoc, c, SHADER_UNIFORM_VEC3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sun::draw(float x, float y, float size)
|
void Circle::setSoftEdge(bool soft)
|
||||||
|
{
|
||||||
|
if (soft)
|
||||||
|
{
|
||||||
|
radius = 0.6f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
radius = 1.0f;
|
||||||
|
}
|
||||||
|
SetShaderValue(shader, radius_loc, &radius, SHADER_UNIFORM_FLOAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Circle::draw(float x, float y, float size)
|
||||||
{
|
{
|
||||||
Rectangle dest = {x - size, y - size, size * 2, size * 2};
|
Rectangle dest = {x - size, y - size, size * 2, size * 2};
|
||||||
|
Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height};
|
||||||
|
Vector2 origin = {0.0f, 0.0f};
|
||||||
|
|
||||||
// zgorni komentar da se mesanje barv oklopi pravilno
|
// zgorni komentar da se mesanje barv oklopi pravilno
|
||||||
BeginBlendMode(RL_BLEND_CUSTOM_SEPARATE);
|
BeginBlendMode(RL_BLEND_CUSTOM_SEPARATE);
|
||||||
BeginShaderMode(shader);
|
BeginShaderMode(shader);
|
||||||
drawTexureWithRotation(target, dest, 0.0f);
|
DrawTexturePro(target.texture, source, dest, origin, 0.0f, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
EndBlendMode();
|
EndBlendMode();
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ void newDna(Dna &dna)
|
|||||||
{
|
{
|
||||||
dna.moon = {mrand::getFloat(), mrand::getFloat(), mrand::getFloat()};
|
dna.moon = {mrand::getFloat(), mrand::getFloat(), mrand::getFloat()};
|
||||||
dna.colorSet = mrand::getValue(0, 3);
|
dna.colorSet = mrand::getValue(0, 3);
|
||||||
dna.time = std::floor(Remap(mrand::getFloat(), 0, 1, 4, 0));
|
dna.time = std::floor(Remap(dna.moon.y, 0, 1, 4, 0));
|
||||||
|
|
||||||
dna.mountenSeed.a = mrand::getInt();
|
dna.mountenSeed.a = mrand::getInt();
|
||||||
dna.mountenSeed.b = mrand::getInt();
|
dna.mountenSeed.b = mrand::getInt();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user