]> git.localhorst.tv Git - blank.git/commitdiff
move RandomWalk into new "ai" module
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 4 Aug 2015 16:30:29 +0000 (18:30 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 4 Aug 2015 16:30:29 +0000 (18:30 +0200)
src/ai/RandomWalk.cpp [new file with mode: 0644]
src/ai/RandomWalk.hpp [new file with mode: 0644]
src/app/Application.hpp
src/app/FPSController.cpp [new file with mode: 0644]
src/app/RandomWalk.hpp [deleted file]
src/app/controller.cpp [deleted file]

diff --git a/src/ai/RandomWalk.cpp b/src/ai/RandomWalk.cpp
new file mode 100644 (file)
index 0000000..32fc29f
--- /dev/null
@@ -0,0 +1,57 @@
+#include "RandomWalk.hpp"
+
+#include "../world/Entity.hpp"
+
+
+namespace blank {
+
+RandomWalk::RandomWalk(Entity &e) noexcept
+: entity(e)
+, time_left(0) {
+
+}
+
+
+void RandomWalk::Update(int dt) noexcept {
+       time_left -= dt;
+       if (time_left > 0) return;
+       time_left += 2500 + (rand() % 5000);
+
+       constexpr float move_vel = 0.0005f;
+
+       glm::vec3 new_vel = entity.Velocity();
+
+       switch (rand() % 9) {
+               case 0:
+                       new_vel.x = -move_vel;
+                       break;
+               case 1:
+                       new_vel.x = 0.0f;
+                       break;
+               case 2:
+                       new_vel.x = move_vel;
+                       break;
+               case 3:
+                       new_vel.y = -move_vel;
+                       break;
+               case 4:
+                       new_vel.y = 0.0f;
+                       break;
+               case 5:
+                       new_vel.y = move_vel;
+                       break;
+               case 6:
+                       new_vel.z = -move_vel;
+                       break;
+               case 7:
+                       new_vel.z = 0.0f;
+                       break;
+               case 8:
+                       new_vel.z = move_vel;
+                       break;
+       }
+
+       entity.Velocity(new_vel);
+}
+
+}
diff --git a/src/ai/RandomWalk.hpp b/src/ai/RandomWalk.hpp
new file mode 100644 (file)
index 0000000..0a61974
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef BLANK_APP_RANDOMWALK_HPP_
+#define BLANK_APP_RANDOMWALK_HPP_
+
+#include <glm/glm.hpp>
+
+
+namespace blank {
+
+class Entity;
+
+/// Randomly start or stop moving in axis directions every now and then.
+class RandomWalk {
+
+public:
+       explicit RandomWalk(Entity &) noexcept;
+
+       void Update(int dt) noexcept;
+
+private:
+       Entity &entity;
+
+       int time_left;
+
+};
+
+}
+
+#endif
index 5909e3ba1437500497b69cee79925b4c5e267059..9644794c1e7d54a9ff5bade9b0c9a0f9c155a5d5 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "Assets.hpp"
 #include "FrameCounter.hpp"
-#include "RandomWalk.hpp"
+#include "../ai/RandomWalk.hpp"
 #include "../audio/Audio.hpp"
 #include "../graphics/Viewport.hpp"
 #include "../ui/Interface.hpp"
diff --git a/src/app/FPSController.cpp b/src/app/FPSController.cpp
new file mode 100644 (file)
index 0000000..9c7820c
--- /dev/null
@@ -0,0 +1,49 @@
+#include "FPSController.hpp"
+
+#include <glm/gtx/euler_angles.hpp>
+#include <glm/gtx/rotate_vector.hpp>
+
+
+namespace blank {
+
+FPSController::FPSController(Entity &entity) noexcept
+: entity(entity)
+, pitch(0)
+, yaw(0) {
+
+}
+
+
+void FPSController::Pitch(float p) noexcept {
+       pitch = p;
+       if (pitch > PI / 2) {
+               pitch = PI / 2;
+       } else if (pitch < -PI / 2) {
+               pitch = -PI / 2;
+       }
+}
+
+void FPSController::RotatePitch(float delta) noexcept {
+       Pitch(pitch + delta);
+}
+
+void FPSController::Yaw(float y) noexcept {
+       yaw = y;
+       if (yaw > PI) {
+               yaw -= PI * 2;
+       } else if (yaw < -PI) {
+               yaw += PI * 2;
+       }
+}
+
+void FPSController::RotateYaw(float delta) noexcept {
+       Yaw(yaw + delta);
+}
+
+
+void FPSController::Update(int dt) noexcept {
+       entity.Rotation(glm::eulerAngleYX(yaw, pitch));
+       entity.Velocity(glm::rotateY(velocity, yaw));
+}
+
+}
diff --git a/src/app/RandomWalk.hpp b/src/app/RandomWalk.hpp
deleted file mode 100644 (file)
index 0a61974..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef BLANK_APP_RANDOMWALK_HPP_
-#define BLANK_APP_RANDOMWALK_HPP_
-
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-class Entity;
-
-/// Randomly start or stop moving in axis directions every now and then.
-class RandomWalk {
-
-public:
-       explicit RandomWalk(Entity &) noexcept;
-
-       void Update(int dt) noexcept;
-
-private:
-       Entity &entity;
-
-       int time_left;
-
-};
-
-}
-
-#endif
diff --git a/src/app/controller.cpp b/src/app/controller.cpp
deleted file mode 100644 (file)
index 9cf2d6c..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#include "FPSController.hpp"
-#include "RandomWalk.hpp"
-
-#include <glm/gtx/euler_angles.hpp>
-#include <glm/gtx/rotate_vector.hpp>
-
-
-namespace blank {
-
-FPSController::FPSController(Entity &entity) noexcept
-: entity(entity)
-, pitch(0)
-, yaw(0) {
-
-}
-
-
-void FPSController::Pitch(float p) noexcept {
-       pitch = p;
-       if (pitch > PI / 2) {
-               pitch = PI / 2;
-       } else if (pitch < -PI / 2) {
-               pitch = -PI / 2;
-       }
-}
-
-void FPSController::RotatePitch(float delta) noexcept {
-       Pitch(pitch + delta);
-}
-
-void FPSController::Yaw(float y) noexcept {
-       yaw = y;
-       if (yaw > PI) {
-               yaw -= PI * 2;
-       } else if (yaw < -PI) {
-               yaw += PI * 2;
-       }
-}
-
-void FPSController::RotateYaw(float delta) noexcept {
-       Yaw(yaw + delta);
-}
-
-
-void FPSController::Update(int dt) noexcept {
-       entity.Rotation(glm::eulerAngleYX(yaw, pitch));
-       entity.Velocity(glm::rotateY(velocity, yaw));
-}
-
-
-RandomWalk::RandomWalk(Entity &e) noexcept
-: entity(e)
-, time_left(0) {
-
-}
-
-
-void RandomWalk::Update(int dt) noexcept {
-       time_left -= dt;
-       if (time_left > 0) return;
-       time_left += 2500 + (rand() % 5000);
-
-       constexpr float move_vel = 0.0005f;
-
-       glm::vec3 new_vel = entity.Velocity();
-
-       switch (rand() % 9) {
-               case 0:
-                       new_vel.x = -move_vel;
-                       break;
-               case 1:
-                       new_vel.x = 0.0f;
-                       break;
-               case 2:
-                       new_vel.x = move_vel;
-                       break;
-               case 3:
-                       new_vel.y = -move_vel;
-                       break;
-               case 4:
-                       new_vel.y = 0.0f;
-                       break;
-               case 5:
-                       new_vel.y = move_vel;
-                       break;
-               case 6:
-                       new_vel.z = -move_vel;
-                       break;
-               case 7:
-                       new_vel.z = 0.0f;
-                       break;
-               case 8:
-                       new_vel.z = move_vel;
-                       break;
-       }
-
-       entity.Velocity(new_vel);
-}
-
-}