#include "View.h" #include #include #include #include #include #include "Label.h" #include "Source.h" View::View(std::unique_ptr 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(); }