summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-15 14:10:53 +0200
committerAki <please@ignore.pl>2022-05-15 14:12:23 +0200
commit92d04b664e2e182fab41e63c3465aad898386cb0 (patch)
tree5ff7700d36bb50098646255135bb0742c8c2705f
parent04a37fe8ae205afcdfbf83c0452324d4c9362bf3 (diff)
downloadderelict-92d04b664e2e182fab41e63c3465aad898386cb0.zip
derelict-92d04b664e2e182fab41e63c3465aad898386cb0.tar.gz
derelict-92d04b664e2e182fab41e63c3465aad898386cb0.tar.bz2
Separated Projected into own header and renamed to Label
-rw-r--r--Label.h11
-rw-r--r--View.cpp15
-rw-r--r--View.h9
3 files changed, 21 insertions, 14 deletions
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 <raylib.h>
+
+
+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 <raylib.h>
+#include "Label.h"
#include "Source.h"
View::View(std::unique_ptr<Source> 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 <raylib.h>
+#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<Source> m_source;
- std::vector<Projected> m_projected;
+ std::vector<Label> m_labels;
int m_grid;
float m_timer;
};