summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/include/kurator/engine/Camera.h3
-rw-r--r--engine/src/Camera.cpp21
-rw-r--r--kurator/src/Grid.cpp36
3 files changed, 46 insertions, 14 deletions
diff --git a/engine/include/kurator/engine/Camera.h b/engine/include/kurator/engine/Camera.h
index 2eb192a..d5253df 100644
--- a/engine/include/kurator/engine/Camera.h
+++ b/engine/include/kurator/engine/Camera.h
@@ -15,6 +15,9 @@ struct Camera
double scale = 1.0;
Point to_world(const Point& screen) const;
Point to_screen(const Point& world) const;
+ Point top_left() const;
+ Point center() const;
+ Point bottom_right() const;
};
diff --git a/engine/src/Camera.cpp b/engine/src/Camera.cpp
index 41cc5ab..4a95ad8 100644
--- a/engine/src/Camera.cpp
+++ b/engine/src/Camera.cpp
@@ -29,6 +29,27 @@ Camera::to_screen(const Point& world) const
Point
+Camera::top_left() const
+{
+ return to_world({0.0, 0.0});
+}
+
+
+Point
+Camera::center() const
+{
+ return to_world(viewport().scale(0.5));
+}
+
+
+Point
+Camera::bottom_right() const
+{
+ return to_world(viewport());
+}
+
+
+Point
viewport()
{
return {static_cast<double>(GetScreenWidth()), static_cast<double>(GetScreenHeight())};
diff --git a/kurator/src/Grid.cpp b/kurator/src/Grid.cpp
index 4243bc9..633b906 100644
--- a/kurator/src/Grid.cpp
+++ b/kurator/src/Grid.cpp
@@ -1,5 +1,7 @@
#include "Grid.h"
+#include <cmath>
+
#include <raylib.h>
#include <kurator/engine/Camera.h>
@@ -9,23 +11,29 @@ namespace kurator
{
+constexpr Color GRID {0x11, 0x11, 0x11, 0xff};
+constexpr Color CENTER {0x31, 0x31, 0x31, 0xff};
+
+
void
Grid::draw(const engine::Camera& camera) const
{
- const int width = GetScreenWidth();
- const int height = GetScreenHeight();
- DrawLine(
- width/2 - camera.offset.x*camera.scale,
- 0,
- width/2 - camera.offset.x*camera.scale,
- height,
- DARKGRAY);
- DrawLine(
- 0,
- height/2 - camera.offset.y*camera.scale,
- width,
- height/2 - camera.offset.y*camera.scale,
- DARKGRAY);
+ constexpr double step = 1000.0;
+ auto start = camera.top_left();
+ start.x = std::round(start.x / step) * step;
+ start.y = std::round(start.y / step) * step;
+ const auto end = camera.bottom_right();
+ auto point = start;
+ while (point.x < end.x || point.y < end.y) {
+ const auto projected = camera.to_screen(point);
+ DrawLine(projected.x, 0, projected.x, GetScreenHeight(), GRID);
+ DrawLine(0, projected.y, GetScreenWidth(), projected.y, GRID);
+ point.x += step;
+ point.y += step;
+ }
+ const auto center = camera.to_screen({0.0, 0.0});
+ DrawLine(center.x, 0, center.x, GetScreenHeight(), CENTER);
+ DrawLine(0, center.y, GetScreenWidth(), center.y, CENTER);
}