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
81
82
|
#include "View.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <utility>
#include <raylib.h>
#include "Label.h"
#include "Source.h"
View::View(std::unique_ptr<Source> source) :
m_camera {},
m_source {std::move(source)},
m_labels {},
m_grid {0}
{
m_camera.position = Vector3{10.0f, 10.0f, 10.0f};
m_camera.target = Vector3{0.0f, 0.0f, 0.0f};
m_camera.up = Vector3{0.0f, 1.0f, 0.0f};
m_camera.fovy = 45;
m_camera.projection = CAMERA_PERSPECTIVE;
SetCameraMode(m_camera, CAMERA_ORBITAL);
}
void
View::update(const float dt)
{
const auto grids = m_source->grids();
if (IsKeyPressed(KEY_SPACE)) {
m_grid++;
if (m_grid >= grids.size())
m_grid = 0;
}
UpdateCamera(&m_camera);
const int height = GetScreenHeight();
const int width = GetScreenWidth();
const auto killmails = grids.at(m_grid).killmails;
m_labels.clear();
m_labels.reserve(killmails.size());
for (const auto& km : killmails) {
const auto pos = GetWorldToScreen(km.position, m_camera);
const float depth =
std::sqrt(
std::pow(m_camera.position.x - km.position.x, 2) +
std::pow(m_camera.position.y - km.position.y, 2) +
std::pow(m_camera.position.z - km.position.z, 2));
if (0 > pos.x || width < pos.x || 0 > pos.y || height < pos.y)
continue;
const auto base = GetWorldToScreen({km.position.x, 0.0f, km.position.z}, m_camera);
m_labels.push_back(Label{pos, base, depth});
}
std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; });
}
void
View::draw() const
{
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(m_camera);
DrawGrid(12, 1.0f);
EndMode3D();
for (const auto& point : m_labels) {
DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, LIGHTGRAY);
DrawCircle(point.pos.x, point.pos.y, 3, RED);
}
DrawFPS(5, 5);
int y = 25;
const int height = GetScreenHeight();
for (const auto& point : m_labels) {
DrawText(TextFormat("%5.1f x %5.1f x %5.1f", point.pos.x, point.pos.y, point.depth), 5, y, 10, DARKGRAY);
y += 10;
if (y > height)
break;
}
EndDrawing();
}
|