summaryrefslogtreecommitdiff
path: root/engine/src
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 /engine/src
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 'engine/src')
-rw-r--r--engine/src/Camera.cpp39
-rw-r--r--engine/src/Point.cpp16
2 files changed, 54 insertions, 1 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
diff --git a/engine/src/Point.cpp b/engine/src/Point.cpp
index b5ce4eb..f02991c 100644
--- a/engine/src/Point.cpp
+++ b/engine/src/Point.cpp
@@ -57,7 +57,7 @@ Point::normalized() const
Point
Point::operator-(const Point& other) const
{
- return {x - other.x, y - other.y};
+ return subtract(other);
}
@@ -68,5 +68,19 @@ Point::operator+(const Point& other) const
}
+Point
+Point::subtract(const Point& other) const
+{
+ return {x - other.x, y - other.y};
+}
+
+
+Point
+Point::subtract(const double _x, const double _y) const
+{
+ return {x - _x, y - _y};
+}
+
+
} // namespace engine
} // namespace kurator