diff options
Diffstat (limited to 'sim/src')
-rw-r--r-- | sim/src/BaseBattle.cpp | 2 | ||||
-rw-r--r-- | sim/src/Builder.cpp | 5 | ||||
-rw-r--r-- | sim/src/Point.cpp | 72 | ||||
-rw-r--r-- | sim/src/RandomSpawner.cpp | 4 |
4 files changed, 7 insertions, 76 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 99a0199..3e3815c 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -89,7 +89,7 @@ BaseBattle::keep_at_range() if (!_registry.valid(ai.target)) continue; const auto target = _registry.get<Transform>(ai.target); - const Point offset = target.position - self.position; + const auto offset = target.position - self.position; ai.destination = target.position - offset.normalized().scale(ai.keep_at_range); } } diff --git a/sim/src/Builder.cpp b/sim/src/Builder.cpp index b5762b3..279cd8b 100644 --- a/sim/src/Builder.cpp +++ b/sim/src/Builder.cpp @@ -2,10 +2,10 @@ #include <entt/entity/registry.hpp> +#include <kurator/engine/Point.h> #include <kurator/sim/components.h> #include <kurator/sim/FloatingMovement.h> #include <kurator/sim/HitPoints.h> -#include <kurator/sim/Point.h> #include <kurator/sim/TurretControl.h> #include <kurator/universe/ShipType.h> #include <kurator/universe/TurretType.h> @@ -19,6 +19,9 @@ namespace sim { +using engine::Point; + + Builder::Builder(entt::registry& _registry, Spawner& _spawner) : registry {_registry}, spawner {_spawner} diff --git a/sim/src/Point.cpp b/sim/src/Point.cpp deleted file mode 100644 index 1f49774..0000000 --- a/sim/src/Point.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include <kurator/sim/Point.h> - -#include <cmath> - - -namespace kurator -{ -namespace sim -{ - - -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 sim -} // namespace kurator diff --git a/sim/src/RandomSpawner.cpp b/sim/src/RandomSpawner.cpp index 7b85f21..a0b0f78 100644 --- a/sim/src/RandomSpawner.cpp +++ b/sim/src/RandomSpawner.cpp @@ -2,8 +2,8 @@ #include <cmath> +#include <kurator/engine/Point.h> #include <kurator/sim/components.h> -#include <kurator/sim/Point.h> namespace kurator @@ -30,7 +30,7 @@ RandomSpawner::get(const int team) double facing = clean_angle + M_PI; if (facing > 2 * M_PI) facing -= 2 * M_PI; - const Point position { + const engine::Point position { distance * std::cos(angle), distance * std::sin(angle), }; |