summaryrefslogtreecommitdiffhomepage
path: root/main.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-03 20:47:59 +0200
committerAki <please@ignore.pl>2022-05-03 20:47:59 +0200
commit313b7a531106c623a28883db515f245a74a5fafb (patch)
treec839eb081a45310cf30d44849bf85097797f944e /main.cpp
parentc610c4b94eda867a3f0b083038502dccb8116170 (diff)
downloadderelict-313b7a531106c623a28883db515f245a74a5fafb.zip
derelict-313b7a531106c623a28883db515f245a74a5fafb.tar.gz
derelict-313b7a531106c623a28883db515f245a74a5fafb.tar.bz2
Moved view functionality into own class
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp66
1 files changed, 4 insertions, 62 deletions
diff --git a/main.cpp b/main.cpp
index 58c7347..f3c16f6 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,23 +1,9 @@
-#include <algorithm>
-#include <cmath>
#include <memory>
-#include <vector>
#include <raylib.h>
#include "ExampleSource.h"
-#include "Source.h"
-
-
-constexpr int AMOUNT {2000};
-
-
-struct Entry
-{
- Vector2 pos;
- Vector2 base;
- float depth;
-};
+#include "View.h"
int
@@ -26,55 +12,11 @@ main(int argc, char* argv[])
InitWindow(800, 600, "Derelict");
SetWindowState(FLAG_WINDOW_RESIZABLE);
SetTargetFPS(60);
- Camera camera {};
- camera.position = Vector3{10.0, 10.0, 10.0};
- camera.target = Vector3{0.0, 0.0, 0.0};
- camera.up = Vector3{0.0, 1.0, 0.0};
- camera.fovy = 45;
- camera.projection = CAMERA_PERSPECTIVE;
- SetCameraMode(camera, CAMERA_ORBITAL);
- std::unique_ptr<Source> source = std::make_unique<ExampleSource>();
- auto killmails = source->all();
- std::vector<Entry> projected;
+ View view(std::make_unique<ExampleSource>());
while (!WindowShouldClose())
{
- UpdateCamera(&camera);
- projected.clear();
- projected.reserve(killmails.size());
- const int height = GetScreenHeight();
- const int width = GetScreenWidth();
- for (const auto& km : killmails) {
- const auto vec2 = GetWorldToScreen(km.position, camera);
- const float d =
- std::sqrt(
- std::pow(camera.position.x - km.position.x, 2) +
- std::pow(camera.position.y - km.position.y, 2) +
- std::pow(camera.position.z - km.position.z, 2));
- if (0 > vec2.x || width < vec2.x || 0 > vec2.y || height < vec2.y)
- continue;
- projected.push_back(Entry{
- vec2, GetWorldToScreen({km.position.x, 0, km.position.z}, camera), d
- });
- }
- std::sort(projected.begin(), projected.end(), [](Entry& a, Entry& b){ return a.depth > b.depth; });
- BeginDrawing();
- ClearBackground(RAYWHITE);
- BeginMode3D(camera);
- DrawGrid(12, 1);
- EndMode3D();
- DrawFPS(5, 5);
- for (const auto& entry : projected) {
- DrawLine(entry.base.x, entry.base.y, entry.pos.x, entry.pos.y, LIGHTGRAY);
- DrawCircle(entry.pos.x, entry.pos.y, 3, RED);
- }
- int y = 25;
- for (const auto& entry : projected) {
- DrawText(TextFormat("%5.1f x %5.1f x %5.1f", entry.pos.x, entry.pos.y, entry.depth), 5, y, 10, DARKGRAY);
- y += 10;
- if (y > height)
- break;
- }
- EndDrawing();
+ view.update(GetFrameTime());
+ view.draw();
}
CloseWindow();
}