From 92d04b664e2e182fab41e63c3465aad898386cb0 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 15 May 2022 14:10:53 +0200 Subject: Separated Projected into own header and renamed to Label --- Label.h | 11 +++++++++++ View.cpp | 15 ++++++++------- View.h | 9 ++------- 3 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 Label.h diff --git a/Label.h b/Label.h new file mode 100644 index 0000000..25d9d4f --- /dev/null +++ b/Label.h @@ -0,0 +1,11 @@ +#pragma once + +#include + + +struct Label +{ + Vector2 pos; + Vector2 base; + float depth; +}; diff --git a/View.cpp b/View.cpp index 3aba502..c4b0e5a 100644 --- a/View.cpp +++ b/View.cpp @@ -7,13 +7,14 @@ #include +#include "Label.h" #include "Source.h" View::View(std::unique_ptr source) : m_camera {}, m_source {std::move(source)}, - m_projected {}, + m_labels {}, m_grid {0} { m_camera.position = Vector3{10.0f, 10.0f, 10.0f}; @@ -38,8 +39,8 @@ View::update(const float dt) const int height = GetScreenHeight(); const int width = GetScreenWidth(); const auto killmails = grids.at(m_grid).killmails; - m_projected.clear(); - m_projected.reserve(killmails.size()); + m_labels.clear(); + m_labels.reserve(killmails.size()); for (const auto& km : killmails) { const auto pos = GetWorldToScreen(km.position, m_camera); const float depth = @@ -50,9 +51,9 @@ View::update(const float dt) 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_projected.push_back(Projected{pos, base, depth}); + m_labels.push_back(Label{pos, base, depth}); } - std::sort(m_projected.begin(), m_projected.end(), [](auto& a, auto& b){ return a.depth > b.depth; }); + std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; }); } @@ -64,14 +65,14 @@ View::draw() const BeginMode3D(m_camera); DrawGrid(12, 1.0f); EndMode3D(); - for (const auto& point : m_projected) { + 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_projected) { + 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) diff --git a/View.h b/View.h index 56a50ca..8e247d1 100644 --- a/View.h +++ b/View.h @@ -5,6 +5,7 @@ #include +#include "Label.h" #include "Source.h" @@ -15,15 +16,9 @@ public: void update(float dt); void draw() const; private: - struct Projected - { - Vector2 pos; - Vector2 base; - float depth; - }; Camera m_camera; std::unique_ptr m_source; - std::vector m_projected; + std::vector