From 937f582b478bcd1432d0886338e08f8a3eb92736 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Wed, 25 Dec 2024 00:12:31 +0100 Subject: [PATCH] Remove rotating frame --- inc/App.hpp | 13 +++---------- inc/Math.hpp | 5 +---- inc/sunShader.hpp | 2 +- src/App.cpp | 49 +++++++++++------------------------------------ src/Math.cpp | 17 ---------------- 5 files changed, 16 insertions(+), 70 deletions(-) diff --git a/inc/App.hpp b/inc/App.hpp index 375e332..d4398ba 100644 --- a/inc/App.hpp +++ b/inc/App.hpp @@ -13,18 +13,11 @@ public: void deinit(); private: - int pos = 0; int screenWidth, screenHeight; Canvas canvas; - std::array 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; }; diff --git a/inc/Math.hpp b/inc/Math.hpp index 27cc60f..4f4fa24 100644 --- a/inc/Math.hpp +++ b/inc/Math.hpp @@ -1,7 +1,4 @@ #include 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); \ No newline at end of file +Color ColorAdd(Color c, int add); \ No newline at end of file diff --git a/inc/sunShader.hpp b/inc/sunShader.hpp index 6791883..1f08777 100644 --- a/inc/sunShader.hpp +++ b/inc/sunShader.hpp @@ -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, diff --git a/src/App.cpp b/src/App.cpp index a27ae6b..0522879 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -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(); } \ No newline at end of file diff --git a/src/Math.cpp b/src/Math.cpp index 609cd66..fefb840 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -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); } \ No newline at end of file