summaryrefslogtreecommitdiffhomepage
path: root/View.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-15 18:01:38 +0200
committerAki <please@ignore.pl>2022-05-15 18:01:38 +0200
commite49474fc0dcff041a9fae2857273938481cc9ec9 (patch)
treeeb0dc5b7eceaa2ef9079385bacddd42c7f6c257c /View.cpp
parent345bb237a7f682670a6107ae75afd948cc1f6ab6 (diff)
downloadderelict-e49474fc0dcff041a9fae2857273938481cc9ec9.zip
derelict-e49474fc0dcff041a9fae2857273938481cc9ec9.tar.gz
derelict-e49474fc0dcff041a9fae2857273938481cc9ec9.tar.bz2
Expanded label rendering
Diffstat (limited to 'View.cpp')
-rw-r--r--View.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/View.cpp b/View.cpp
index 77ab271..debf10c 100644
--- a/View.cpp
+++ b/View.cpp
@@ -13,7 +13,8 @@ View::View(std::vector<Grid> grids) :
m_camera {},
m_grids {grids},
m_labels {},
- m_grid {0}
+ m_grid {0},
+ m_texture {LoadTexture("resources/wreck.png")}
{
m_camera.position = Vector3{10.0f, 10.0f, 10.0f};
m_camera.target = Vector3{0.0f, 0.0f, 0.0f};
@@ -24,6 +25,12 @@ View::View(std::vector<Grid> grids) :
}
+View::~View()
+{
+ UnloadTexture(m_texture);
+}
+
+
void
View::update(const float dt)
{
@@ -40,15 +47,20 @@ View::update(const float dt)
m_labels.reserve(wrecks.size());
for (const auto& wreck : wrecks) {
const auto pos = GetWorldToScreen(wreck.position, m_camera);
+ const auto base = GetWorldToScreen({wreck.position.x, 0.0f, wreck.position.z}, m_camera);
+ if (0 > pos.x || width < pos.x || 0 > pos.y || height < pos.y)
+ if (0 > base.x || width < base.x || 0 > base.y || height < base.y)
+ continue;
const float depth =
std::sqrt(
std::pow(m_camera.position.x - wreck.position.x, 2) +
std::pow(m_camera.position.y - wreck.position.y, 2) +
std::pow(m_camera.position.z - wreck.position.z, 2));
- if (0 > pos.x || width < pos.x || 0 > pos.y || height < pos.y)
- continue;
- const auto base = GetWorldToScreen({wreck.position.x, 0.0f, wreck.position.z}, m_camera);
- m_labels.push_back(Label{pos, base, depth});
+ const float length =
+ std::sqrt(
+ std::pow(pos.x - base.x, 2) +
+ std::pow(pos.y - base.y, 2));
+ m_labels.push_back(Label{pos, base, depth, length});
}
std::sort(m_labels.begin(), m_labels.end(), [](auto& a, auto& b){ return a.depth > b.depth; });
}
@@ -63,17 +75,11 @@ View::draw() const
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);
+ if (point.length > 8)
+ DrawLine(point.base.x, point.base.y, point.pos.x, point.pos.y, DARKGRAY);
+ DrawTexture(m_texture, point.pos.x - 8, point.pos.y - 8, WHITE);
}
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;
- }
+ DrawText(TextFormat("%d", m_labels.size()), 5, 25, 20, DARKGRAY);
EndDrawing();
}