Remove rotating frame

This commit is contained in:
Nikola Petrov 2024-12-25 00:12:31 +01:00
parent 131b4e356f
commit 937f582b47
5 changed files with 16 additions and 70 deletions

View File

@ -13,18 +13,11 @@ public:
void deinit();
private:
int pos = 0;
int screenWidth, screenHeight;
Canvas canvas;
std::array<RenderTexture2D, 2> canvasTexure = {0};
float rotation = 0.0f;
Rectangle destB;
Rectangle destA;
RenderTexture2D canvasTexure = {0};
Rectangle dest;
Dna dna = {0};
Vector2 mouseStart;
float len;
float ofset;
bool validHit = false;
};

View File

@ -1,7 +1,4 @@
#include <raylib.h>
Color ColorLerp(Color c1, Color c2, float amount);
Color ColorAdd(Color c, int add);
Vector2 CalculateVector(float rotation, float offSet, float len);
void drawTexureWithRotation(RenderTexture2D &target, Rectangle &dest, float rotation);
Color ColorAdd(Color c, int add);

View File

@ -26,7 +26,7 @@ void main()\
}\
}";
const char shaders_sun_330_fs[] = {
unsigned char shaders_sun_330_fs[] = {
0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x33, 0x33, 0x30,
0x0a, 0x0a, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x66, 0x72,
0x61, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x3b, 0x0a,

View File

@ -16,64 +16,37 @@ void App::init(int screenWidth, int screenHeight)
mrand::setSeed(1);
for (size_t i = 0; i < canvasTexure.size(); i++)
{
canvasTexure[i] = LoadRenderTexture(screenWidth, screenWidth);
}
canvasTexure = LoadRenderTexture(screenWidth, screenWidth);
newDna(dna);
canvas.newGen(canvasTexure[0], &dna);
newDna(dna);
canvas.newGen(canvasTexure[1], &dna);
canvas.newGen(canvasTexure, &dna);
float posY = (screenHeight - screenWidth) / 2.0f;
destA = {0, posY, (float)screenWidth, (float)screenWidth};
destB = destA;
dest = {0, posY, (float)screenWidth, (float)screenWidth};
}
void App::update()
{
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
{
mouseStart = GetMousePosition();
validHit = CheckCollisionPointRec(mouseStart, destA);
len = Vector2Distance(mouseStart, {destB.x, destB.y});
ofset = std::atan2(destB.x - mouseStart.x, destB.y - mouseStart.y);
}
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && validHit)
{
Vector2 mousePosition = GetMousePosition();
float dist = mousePosition.x - mouseStart.x;
float l = dist / screenWidth;
rotation = Lerp(45.0f, -45.0f, (l + 1) / 2);
Vector2 newCenter = CalculateVector(rotation, ofset, len);
destA.x = newCenter.x + mousePosition.x;
destA.y = newCenter.y + mousePosition.y;
}
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && validHit)
{
newDna(dna);
canvas.newGen(canvasTexure[1 - pos], &dna);
pos = 1 - pos;
rotation = 0.0f;
destA = destB;
canvas.newGen(canvasTexure, &dna);
}
}
void App::draw()
{
ClearBackground(RED);
drawTexureWithRotation(canvasTexure[pos], destB, 0.0f);
drawTexureWithRotation(canvasTexure[1 - pos], destA, rotation);
Rectangle source = {0, 0, (float)canvasTexure.texture.width, (float)-canvasTexure.texture.height};
Vector2 origin = {0.0f, 0.0f};
DrawTexturePro(canvasTexure.texture, source, dest, origin, 0.0f, WHITE);
}
void App::deinit()
{
for (size_t i = 0; i < canvasTexure.size(); i++)
{
UnloadRenderTexture(canvasTexure[i]);
}
UnloadRenderTexture(canvasTexure);
canvas.deinit();
}

View File

@ -23,21 +23,4 @@ Color ColorAdd(Color c, int add)
int b = std::clamp(c.b + add, 0, 255);
return {(unsigned char)r, (unsigned char)g, (unsigned char)b, c.a};
}
Vector2 CalculateVector(float rotation, float offSet, float len)
{
float angle = ((rotation)*PI) / 180.0f;
angle += offSet;
return {
.x = len * std::sin(angle),
.y = len * std::cos(angle)};
}
void drawTexureWithRotation(RenderTexture2D &target, Rectangle &dest, float rotation)
{
Rectangle source = {0, 0, (float)target.texture.width, (float)-target.texture.height};
Vector2 origin = {0.0f, 0.0f};
rotation = 360 - rotation;
DrawTexturePro(target.texture, source, dest, origin, rotation, WHITE);
}