aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/AI.cpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-09 11:28:06 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-09 11:28:06 +0100
commit6cee1cff083fc50eeedf88537965d3c79e7b790a (patch)
tree7e292157b73ab6d10e4ff3a63ddc5d5a909d009d /src/crepe/api/AI.cpp
parent33a072db28d71ba65e59f9491abd42dbf9695fc4 (diff)
Added Doxygen
Diffstat (limited to 'src/crepe/api/AI.cpp')
-rw-r--r--src/crepe/api/AI.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/crepe/api/AI.cpp b/src/crepe/api/AI.cpp
index d785bb5..49f6b92 100644
--- a/src/crepe/api/AI.cpp
+++ b/src/crepe/api/AI.cpp
@@ -4,4 +4,27 @@ namespace crepe {
AI::AI(game_object_id_t id, float max_force) : Component(id), max_force(max_force) {}
+void AI::make_circle_path(float radius, vec2 center, float start_angle, bool clockwise) {
+ // The step size is determined by the radius (step size is in radians)
+ float step = 400.0f / radius;
+ // Force at least 16 steps (in case of a small radius)
+ if (step > 2 * M_PI / 16) {
+ step = 2 * M_PI / 16;
+ }
+ // The path node distance is determined by the step size and the radius
+ path_node_distance = radius * step * 0.75f;
+
+ if (clockwise) {
+ for (float i = start_angle; i < 2 * M_PI + start_angle; i += step) {
+ path.push_back(vec2{static_cast<float>(center.x + radius * cos(i)),
+ static_cast<float>(center.y + radius * sin(i))});
+ }
+ } else {
+ for (float i = start_angle; i > start_angle - 2 * M_PI; i -= step) {
+ path.push_back(vec2{static_cast<float>(center.x + radius * cos(i)),
+ static_cast<float>(center.y + radius * sin(i))});
+ }
+ }
+}
+
} // namespace crepe