summaryrefslogtreecommitdiffhomepage
path: root/main.cpp
blob: 58c73470b9c6f28b0fb5c1dd73877f157f674151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#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;
};


int
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;
    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();
    }
    CloseWindow();
}