summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battles/include/kurator/battles/Point.h1
-rw-r--r--battles/src/BaseBattle.cpp1
-rw-r--r--battles/src/Point.cpp7
3 files changed, 9 insertions, 0 deletions
diff --git a/battles/include/kurator/battles/Point.h b/battles/include/kurator/battles/Point.h
index b6be651..ba9ab63 100644
--- a/battles/include/kurator/battles/Point.h
+++ b/battles/include/kurator/battles/Point.h
@@ -13,6 +13,7 @@ struct Point
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;
diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp
index eb75464..0de18d5 100644
--- a/battles/src/BaseBattle.cpp
+++ b/battles/src/BaseBattle.cpp
@@ -104,6 +104,7 @@ BaseBattle::floating_movement(const float dt)
const auto speed = movement.speed.scale(dt);
transform.position.x += speed.x;
transform.position.y += speed.y;
+ transform.angle = speed.angle();
}
}
diff --git a/battles/src/Point.cpp b/battles/src/Point.cpp
index 9ffa81c..31aecae 100644
--- a/battles/src/Point.cpp
+++ b/battles/src/Point.cpp
@@ -23,6 +23,13 @@ Point::distance(const Point& other) const
}
+double
+Point::angle() const
+{
+ return std::atan2(y, x); // (+x, _) is 0
+}
+
+
Point
Point::rotate(const double angle) const
{