summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-03 22:00:28 +0100
committerAki <please@ignore.pl>2023-02-03 22:00:28 +0100
commit9b453277059fd015703873172d0dc87b4a29cb55 (patch)
tree3df0415c5b8160f9d97dae12f0c7adb55c4a23db /engine
parentb5a71a9c776386805a12a722be23bf8d7b7e25fe (diff)
downloadkurator-9b453277059fd015703873172d0dc87b4a29cb55.zip
kurator-9b453277059fd015703873172d0dc87b4a29cb55.tar.gz
kurator-9b453277059fd015703873172d0dc87b4a29cb55.tar.bz2
Created engine module right now containing only Point
This might be a bit too generic of a name, but the intent is to get the main shared abstracts for gameplay loop and/or simulation outside of the game executable implementation to redirect dependencies.
Diffstat (limited to 'engine')
-rw-r--r--engine/CMakeLists.txt9
-rw-r--r--engine/include/kurator/engine/Point.h26
-rw-r--r--engine/src/Point.cpp72
3 files changed, 107 insertions, 0 deletions
diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt
new file mode 100644
index 0000000..041965a
--- /dev/null
+++ b/engine/CMakeLists.txt
@@ -0,0 +1,9 @@
+project(engine)
+add_library(
+ ${PROJECT_NAME} STATIC
+ src/Point.cpp
+)
+target_include_directories(
+ ${PROJECT_NAME}
+ PUBLIC include
+)
diff --git a/engine/include/kurator/engine/Point.h b/engine/include/kurator/engine/Point.h
new file mode 100644
index 0000000..0e9f0ab
--- /dev/null
+++ b/engine/include/kurator/engine/Point.h
@@ -0,0 +1,26 @@
+#pragma once
+
+
+namespace kurator
+{
+namespace engine
+{
+
+
+struct Point
+{
+ double x;
+ double y;
+ double magnitude() const;
+ double distance(const Point& other) const;
+ double angle() const;
+ Point rotate(double angle) const;
+ Point scale(double _scale) const;
+ Point normalized() const;
+ Point operator-(const Point& other) const;
+ Point operator+(const Point& other) const;
+};
+
+
+} // namespace engine
+} // namespace kurator
diff --git a/engine/src/Point.cpp b/engine/src/Point.cpp
new file mode 100644
index 0000000..b5ce4eb
--- /dev/null
+++ b/engine/src/Point.cpp
@@ -0,0 +1,72 @@
+#include <kurator/engine/Point.h>
+
+#include <cmath>
+
+
+namespace kurator
+{
+namespace engine
+{
+
+
+double
+Point::magnitude() const
+{
+ return std::sqrt(std::pow(x, 2) + std::pow(y, 2));
+}
+
+
+double
+Point::distance(const Point& other) const
+{
+ return std::sqrt(std::pow(other.x - x, 2) + std::pow(other.y - y, 2));
+}
+
+
+double
+Point::angle() const
+{
+ return std::atan2(y, x); // (+x, _) is 0
+}
+
+
+Point
+Point::rotate(const double angle) const
+{
+ return {
+ x * std::cos(angle) - y * std::sin(angle),
+ x * std::sin(angle) + y * std::cos(angle),
+ };
+}
+
+
+Point
+Point::scale(const double _scale) const
+{
+ return {x * _scale, y * _scale};
+}
+
+
+Point
+Point::normalized() const
+{
+ return scale(1.0 / magnitude());
+}
+
+
+Point
+Point::operator-(const Point& other) const
+{
+ return {x - other.x, y - other.y};
+}
+
+
+Point
+Point::operator+(const Point& other) const
+{
+ return {x + other.x, y + other.y};
+}
+
+
+} // namespace engine
+} // namespace kurator