68 lines
1.4 KiB
C++
68 lines
1.4 KiB
C++
#include <array>
|
|
|
|
#include "App.hpp"
|
|
#include "Math.hpp"
|
|
|
|
#include "raylib.h"
|
|
#include "raymath.h"
|
|
|
|
void App::init(int screenWidth, int screenHeight)
|
|
{
|
|
this->screenWidth = screenWidth;
|
|
this->screenHeight = screenHeight;
|
|
canvases.assign(2, {});
|
|
|
|
for (auto &&canvas : canvases)
|
|
{
|
|
canvas.init(screenWidth);
|
|
canvas.newGen();
|
|
}
|
|
|
|
float posY = (screenHeight - screenWidth) / 2;
|
|
destA = {0, posY, (float)screenWidth, (float)screenWidth};
|
|
destB = destA;
|
|
}
|
|
|
|
void App::update()
|
|
{
|
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
|
{
|
|
mouseStart = GetMousePosition();
|
|
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);
|
|
destA.x = newCenter.x + mousePosition.x;
|
|
destA.y = newCenter.y + mousePosition.y;
|
|
}
|
|
|
|
if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
|
|
{
|
|
canvases[1 - pos].newGen();
|
|
pos = 1 - pos;
|
|
rotation = 0.0f;
|
|
destA = destB;
|
|
}
|
|
}
|
|
|
|
void App::draw()
|
|
{
|
|
ClearBackground(RED);
|
|
canvases[pos].draw(destB, 0.0f);
|
|
canvases[1 - pos].draw(destA, rotation);
|
|
}
|
|
|
|
void App::deinit()
|
|
{
|
|
for (size_t i = 0; i < canvases.size(); i++)
|
|
{
|
|
canvases[i].deinit();
|
|
}
|
|
} |