Remove rotating frame
This commit is contained in:
parent
131b4e356f
commit
937f582b47
13
inc/App.hpp
13
inc/App.hpp
@ -13,18 +13,11 @@ public:
|
|||||||
void deinit();
|
void deinit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int pos = 0;
|
|
||||||
int screenWidth, screenHeight;
|
int screenWidth, screenHeight;
|
||||||
Canvas canvas;
|
Canvas canvas;
|
||||||
std::array<RenderTexture2D, 2> canvasTexure = {0};
|
RenderTexture2D canvasTexure = {0};
|
||||||
float rotation = 0.0f;
|
|
||||||
Rectangle destB;
|
Rectangle dest;
|
||||||
Rectangle destA;
|
|
||||||
|
|
||||||
Dna dna = {0};
|
Dna dna = {0};
|
||||||
|
|
||||||
Vector2 mouseStart;
|
|
||||||
float len;
|
|
||||||
float ofset;
|
|
||||||
bool validHit = false;
|
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,3 @@
|
|||||||
|
|
||||||
Color ColorLerp(Color c1, Color c2, float amount);
|
Color ColorLerp(Color c1, Color c2, float amount);
|
||||||
Color ColorAdd(Color c, int add);
|
Color ColorAdd(Color c, int add);
|
||||||
Vector2 CalculateVector(float rotation, float offSet, float len);
|
|
||||||
|
|
||||||
void drawTexureWithRotation(RenderTexture2D &target, Rectangle &dest, float rotation);
|
|
@ -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,
|
0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x33, 0x33, 0x30,
|
||||||
0x0a, 0x0a, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x66, 0x72,
|
0x0a, 0x0a, 0x69, 0x6e, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x66, 0x72,
|
||||||
0x61, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x3b, 0x0a,
|
0x61, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x3b, 0x0a,
|
||||||
|
49
src/App.cpp
49
src/App.cpp
@ -16,64 +16,37 @@ void App::init(int screenWidth, int screenHeight)
|
|||||||
|
|
||||||
mrand::setSeed(1);
|
mrand::setSeed(1);
|
||||||
|
|
||||||
for (size_t i = 0; i < canvasTexure.size(); i++)
|
canvasTexure = LoadRenderTexture(screenWidth, screenWidth);
|
||||||
{
|
|
||||||
canvasTexure[i] = LoadRenderTexture(screenWidth, screenWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
newDna(dna);
|
newDna(dna);
|
||||||
canvas.newGen(canvasTexure[0], &dna);
|
canvas.newGen(canvasTexure, &dna);
|
||||||
newDna(dna);
|
|
||||||
canvas.newGen(canvasTexure[1], &dna);
|
|
||||||
|
|
||||||
float posY = (screenHeight - screenWidth) / 2.0f;
|
float posY = (screenHeight - screenWidth) / 2.0f;
|
||||||
destA = {0, posY, (float)screenWidth, (float)screenWidth};
|
dest = {0, posY, (float)screenWidth, (float)screenWidth};
|
||||||
destB = destA;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::update()
|
void App::update()
|
||||||
{
|
{
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
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);
|
newDna(dna);
|
||||||
canvas.newGen(canvasTexure[1 - pos], &dna);
|
canvas.newGen(canvasTexure, &dna);
|
||||||
pos = 1 - pos;
|
|
||||||
rotation = 0.0f;
|
|
||||||
destA = destB;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::draw()
|
void App::draw()
|
||||||
{
|
{
|
||||||
ClearBackground(RED);
|
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()
|
void App::deinit()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < canvasTexure.size(); i++)
|
|
||||||
{
|
UnloadRenderTexture(canvasTexure);
|
||||||
UnloadRenderTexture(canvasTexure[i]);
|
|
||||||
}
|
|
||||||
canvas.deinit();
|
canvas.deinit();
|
||||||
}
|
}
|
17
src/Math.cpp
17
src/Math.cpp
@ -24,20 +24,3 @@ Color ColorAdd(Color c, int add)
|
|||||||
|
|
||||||
return {(unsigned char)r, (unsigned char)g, (unsigned char)b, c.a};
|
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);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user