diff --git a/inc/App.hpp b/inc/App.hpp index 1812245..2c0ce3f 100644 --- a/inc/App.hpp +++ b/inc/App.hpp @@ -16,7 +16,6 @@ private: int pos = 0; int screenWidth, screenHeight; std::vector canvases; - Vector2 center; float rotation = 0.0f; Rectangle destB; Rectangle destA; diff --git a/inc/Math.hpp b/inc/Math.hpp index ce0bea4..032c4df 100644 --- a/inc/Math.hpp +++ b/inc/Math.hpp @@ -1,5 +1,4 @@ #include "raylib.h" Color ColorLerp(Color c1, Color c2, float amount); -Vector2 calculateVector(float rotation, float offSet, float len); -Rectangle calculateRotatedRectangle(Vector2 center, float rotation, float width, float height); \ No newline at end of file +Vector2 calculateVector(float rotation, float offSet, float len); \ No newline at end of file diff --git a/src/App.cpp b/src/App.cpp index db6b35a..f6e84bb 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -18,9 +18,8 @@ void App::init(int screenWidth, int screenHeight) canvas.newGen(); } - center = {(float)screenWidth / 2, (float)screenHeight / 2}; - float rotation = 0.0f; - destA = calculateRotatedRectangle(center, rotation, screenWidth, screenWidth); + float posY = (screenHeight - screenWidth) / 2; + destA = {0, posY, (float)screenWidth, (float)screenWidth}; destB = destA; } @@ -29,24 +28,19 @@ void App::update() if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { mouseStart = GetMousePosition(); - len = Vector2Distance(mouseStart, center); - ofset = std::atan2(center.x - mouseStart.x, center.y - mouseStart.y); + len = Vector2Distance(mouseStart, {destB.x, destB.y}); + ofset = std::atan2(destB.x - mouseStart.x, destB.y - mouseStart.y); } if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) { 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); - newCenter.x += mousePosition.x; - newCenter.y += mousePosition.y; - - destA = calculateRotatedRectangle(newCenter, rotation, screenWidth, screenWidth); + destA.x = newCenter.x + mousePosition.x; + destA.y = newCenter.y + mousePosition.y; } if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) diff --git a/src/Math.cpp b/src/Math.cpp index 4d3355c..9c2bd63 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -19,20 +19,4 @@ Vector2 calculateVector(float rotation, float offSet, float len) return { .x = len * std::sin(angle), .y = len * std::cos(angle)}; -} - -Rectangle calculateRotatedRectangle(Vector2 center, float rotation, float width, float height) -{ - Rectangle ret = {0, 0, width, height}; - - width /= 2; // a - height /= 2; // b - float len = std::sqrt(std::pow(width, 2) + std::pow(height, 2)); // c - float offSet = std::atan2(width, height); // add angle alfa - - Vector2 vec = calculateVector(rotation + 180.0f, offSet, len); - - ret.x = vec.x + center.x; - ret.y = vec.y + center.y; - return ret; } \ No newline at end of file