summaryrefslogtreecommitdiff
path: root/engine/src/Camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/Camera.cpp')
-rw-r--r--engine/src/Camera.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/engine/src/Camera.cpp b/engine/src/Camera.cpp
new file mode 100644
index 0000000..60e8aa1
--- /dev/null
+++ b/engine/src/Camera.cpp
@@ -0,0 +1,39 @@
+#include <kurator/engine/Camera.h>
+
+#include <raylib.h>
+
+#include <kurator/engine/Point.h>
+
+
+namespace kurator
+{
+namespace engine
+{
+
+
+static auto viewport() -> Point;
+
+
+Point
+Camera::to_world(const Point& screen) const
+{
+ return screen - viewport().scale(1.0 / (2.0 * scale)) + offset;
+}
+
+
+Point
+Camera::to_screen(const Point& world) const
+{
+ return (world - offset).scale(scale) + viewport().scale(0.5);
+}
+
+
+Point
+viewport()
+{
+ return {static_cast<double>(GetScreenWidth()), static_cast<double>(GetScreenHeight())};
+}
+
+
+} // namespace engine
+} // namespace kurator