152 lines
5.0 KiB
C++
152 lines
5.0 KiB
C++
#include "polypartiCL.hpp"
|
|
#include "include/raylib-cpp.hpp"
|
|
#include <vector>
|
|
#include "rlgl.h"
|
|
#include <exception>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
string roomName = "rooms/load.room";
|
|
string partName = "particles/load.prtc";
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
const int fps = 60;
|
|
const int screenWidth = 1920;
|
|
const int screenHeight = 1080;
|
|
float angle = 0.05;
|
|
float d_interval_pct = 0.00001;
|
|
bool rotate = false;
|
|
bool drawLines = true;
|
|
bool drawFPS = false;
|
|
bool useShader = true;
|
|
bool paused = false;
|
|
// bool counterclockwise = false;
|
|
//
|
|
for (int i = 0; i < argc; i++) {
|
|
if (argv[i] == "--rotate"s || argv[i] == "-r"s) {
|
|
rotate = true;
|
|
}
|
|
}
|
|
|
|
Polyparti::Room sim(screenWidth, screenHeight, fps);
|
|
|
|
vector<raylib::Vector2> lines;
|
|
cout << "ok-1" << endl;
|
|
|
|
sim.loadRoom(roomName);
|
|
sim.loadParticles(partName);
|
|
sim.addFields();
|
|
for (const auto& item : sim.getCorners()) {
|
|
lines.push_back({item[0], item[1]});
|
|
}
|
|
raylib::Window window(screenWidth, screenHeight, "polypartiCL");
|
|
//raylib::Button::key R(KEY_R);
|
|
|
|
window.SetTargetFPS(fps);
|
|
|
|
raylib::RenderTexture2D renderTarget(screenWidth, screenHeight);
|
|
raylib::RenderTexture2D blur(screenWidth, screenHeight);
|
|
raylib::Shader blurShader("", "shaders/blur2.fs");
|
|
raylib::Vector2 mouse_i, mouse_f, mouse_d;
|
|
raylib::Vector2 midpoint(screenWidth * 0.5, screenHeight * 0.5);
|
|
|
|
int resXY = blurShader.GetLocation("resolution");
|
|
int dirXY = blurShader.GetLocation("direction");
|
|
float resolution[2] = { float(screenWidth), float(screenHeight)};
|
|
blurShader.SetValue(resXY, resolution, RL_SHADER_UNIFORM_VEC2);
|
|
|
|
while(!window.ShouldClose()) {
|
|
if (IsKeyPressed(KEY_R)) rotate = !rotate;
|
|
if (IsKeyPressed(KEY_L)) drawLines = !drawLines;
|
|
if (IsKeyPressed(KEY_F)) drawFPS = !drawFPS;
|
|
if (IsKeyPressed(KEY_D)) angle *= -1;
|
|
if (IsKeyPressed(KEY_B)) useShader = !useShader;
|
|
if (IsKeyPressed(KEY_SPACE)) paused = !paused;
|
|
if (IsKeyPressed(KEY_T)) sim.reverseInterval();
|
|
//if (IsKeyPressed(KEY_UP)) sim.adjustInterval(d_interval_pct);
|
|
//if (IsKeyPressed(KEY_DOWN)) sim.adjustInterval(-d_interval_pct);
|
|
/*if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
|
mouse_f = GetMousePosition();
|
|
mouse_f -= midpoint;
|
|
mouse_d = GetMouseDelta();
|
|
mouse_i = mouse_f - mouse_d;
|
|
angle = mouse_f.DotProduct(mouse_i);
|
|
angle = angle / mouse_f.Length() * mouse_i.Length();
|
|
angle = acos(angle);
|
|
}*/
|
|
if (!paused) {
|
|
sim.updateFields();
|
|
if (rotate) sim.rotateRoom(angle);
|
|
lines.clear();
|
|
}
|
|
for(const auto& item : sim.getCorners()) lines.push_back({item[0], item[1]});
|
|
|
|
if (useShader) {
|
|
renderTarget.BeginMode();
|
|
ClearBackground(BLACK);
|
|
|
|
if(drawLines) {
|
|
for(int i = 0; i < (lines.size() - 1); i++)
|
|
lines[i].DrawLine(lines[i+1], WHITE);
|
|
}
|
|
|
|
for (int i = 0; i < sim.getFieldCount(); i++) {
|
|
auto& field = sim.getField(i);
|
|
int *color = field.getColor();
|
|
rlBegin(RL_LINES);
|
|
rlColor4ub(color[0], color[1], color[2], color[3]);
|
|
for (const auto& p : field.getPositions()) {
|
|
rlVertex2f(p[0],p[1]);
|
|
rlVertex2f(p[0]+1.0f,p[1]+1.0f);
|
|
}
|
|
rlEnd();
|
|
}
|
|
renderTarget.EndMode();
|
|
|
|
float dirH[2] = {1.0f, 0.0f};
|
|
float dirV[2] = {0.0f, 1.0f};
|
|
|
|
blurShader.SetValue(dirXY, dirH, SHADER_UNIFORM_VEC2);
|
|
|
|
blur.BeginMode();
|
|
ClearBackground(BLACK);
|
|
blurShader.BeginMode();
|
|
DrawTextureRec(renderTarget.texture, {0, 0, resolution[0], -resolution[1]},
|
|
{0, 0}, WHITE);
|
|
blurShader.EndMode();
|
|
blur.EndMode();
|
|
|
|
blurShader.SetValue(dirXY, dirV, SHADER_UNIFORM_VEC2);
|
|
}
|
|
while(window.Drawing()) {
|
|
window.ClearBackground(BLACK);
|
|
|
|
if (useShader) {
|
|
blurShader.BeginMode();
|
|
DrawTextureRec(blur.texture, {0, 0, resolution[0], -resolution[1]}, {0,0}, WHITE);
|
|
blurShader.EndMode();
|
|
} else {
|
|
for (int i = 0; i < (int)lines.size() - 1; i++) {
|
|
lines[i].DrawLine(lines[i+1], WHITE);
|
|
}
|
|
|
|
for (int i = 0; i < sim.getFieldCount(); i++) {
|
|
auto& field = sim.getField(i);
|
|
int *color = field.getColor();
|
|
rlBegin(RL_LINES);
|
|
rlColor4ub(color[0], color[1], color[2], color[3]);
|
|
for (const auto& p : field.getPositions()) {
|
|
rlVertex2f(p[0],p[1]);
|
|
rlVertex2f(p[0]+1.0f,p[1]+1.0f);
|
|
}
|
|
rlEnd();
|
|
}
|
|
}
|
|
if(drawFPS) window.DrawFPS(10,10);
|
|
}
|
|
|
|
}
|
|
}
|