summaryrefslogtreecommitdiff
path: root/kurator
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-03 23:53:33 +0100
committerAki <please@ignore.pl>2023-02-03 23:53:33 +0100
commit6b7d0e795bc57856a1bcaaab08229bb0869e8516 (patch)
treef22e1b1cd1499d2c4a5346be0534c305386aca58 /kurator
parentec3ae653a0965c6c19920ed46030a0abde0fee1c (diff)
downloadkurator-6b7d0e795bc57856a1bcaaab08229bb0869e8516.zip
kurator-6b7d0e795bc57856a1bcaaab08229bb0869e8516.tar.gz
kurator-6b7d0e795bc57856a1bcaaab08229bb0869e8516.tar.bz2
Extracted from/to camera viewport transformations to camera itself
Diffstat (limited to 'kurator')
-rw-r--r--kurator/src/Battle.cpp54
1 files changed, 21 insertions, 33 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 40390ee..9bb5dec 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -130,27 +130,24 @@ void
Battle::draw() const
{
ClearBackground(BLACK);
- const int hwidth = GetScreenWidth() / 2;
- const int hheight = GetScreenHeight() / 2;
Grid().draw(camera);
auto& registry = battle->registry();
auto crosses = registry.view<sim::Transform, Cross>();
for (const auto& [entity, transform, cross] : crosses.each()) {
if (cross.timer > cross.phase)
continue;
- const int x = hwidth + (transform.position.x - camera.offset.x) * camera.scale;
- const int y = hheight + (transform.position.y - camera.offset.y) * camera.scale;
+ const auto pos = camera.to_screen(transform.position);
DrawLine(
- x - cross.hlength,
- y - cross.hlength,
- x + cross.hlength,
- y + cross.hlength,
+ pos.x - cross.hlength,
+ pos.y - cross.hlength,
+ pos.x + cross.hlength,
+ pos.y + cross.hlength,
cross.color);
DrawLine(
- x + cross.hlength,
- y - cross.hlength,
- x - cross.hlength,
- y + cross.hlength,
+ pos.x + cross.hlength,
+ pos.y - cross.hlength,
+ pos.x - cross.hlength,
+ pos.y + cross.hlength,
cross.color);
}
auto lines = registry.view<Line>();
@@ -158,35 +155,26 @@ Battle::draw() const
const auto diff = line.end - line.start;
const auto fstart = line.position - line.hlength;
const auto fend = line.position + line.hlength;
- const auto start = line.start + diff.scale(fstart > 0.0 ? fstart : 0.0);
- const auto end = line.start + diff.scale(fend > 1.0 ? 1.0 : fend);
- DrawLine(
- hwidth + (start.x - camera.offset.x) * camera.scale,
- hheight + (start.y - camera.offset.y) * camera.scale,
- hwidth + (end.x - camera.offset.x) * camera.scale,
- hheight + (end.y - camera.offset.y) * camera.scale,
- line.color);
+ const auto start = camera.to_screen(line.start + diff.scale(fstart > 0.0 ? fstart : 0.0));
+ const auto end = camera.to_screen(line.start + diff.scale(fend > 1.0 ? 1.0 : fend));
+ DrawLine(start.x, start.y, end.x, end.y, line.color);
}
auto view = registry.view<const Marker, const sim::Transform>();
for (auto [entity, marker, transform] : view.each()) {
- const int x = hwidth + (transform.position.x - camera.offset.x) * camera.scale;
- const int y = hheight + (transform.position.y - camera.offset.y) * camera.scale;
- DrawCircle(x, y, marker.radius, marker.color);
+ const auto pos = camera.to_screen(transform.position);
+ DrawCircle(pos.x, pos.y, marker.radius, marker.color);
DrawLine(
- x,
- y,
- x + marker.radius*std::cos(transform.angle),
- y + marker.radius*std::sin(transform.angle),
+ pos.x,
+ pos.y,
+ pos.x + marker.radius*std::cos(transform.angle),
+ pos.y + marker.radius*std::sin(transform.angle),
WHITE);
- DrawText(marker.name.c_str(), x+10, y-5, 10.0f, GRAY);
+ DrawText(marker.name.c_str(), pos.x+10, pos.y-5, 10.0f, GRAY);
}
auto pops = registry.view<CenteredText, sim::Transform, UIOffset>();
for (const auto& [entity, text, transform, offset] : pops.each()) {
- const int x =
- hwidth + (transform.position.x - camera.offset.x) * camera.scale - text.width/2 + offset.x;
- const int y =
- hheight + (transform.position.y - camera.offset.y) * camera.scale - text.font_size/2 + offset.y;
- DrawText(text.text.c_str(), x, y, text.font_size, text.color);
+ const auto pos = camera.to_screen(transform.position).subtract(text.width/2, text.font_size/2) + offset;
+ DrawText(text.text.c_str(), pos.x, pos.y, text.font_size, text.color);
}
balance.draw();
}