FPSController::FPSController(Entity &entity)
: entity(entity)
, pitch(0)
-, yaw(0)
-, move_velocity(0.005f)
-, pitch_sensitivity(-0.0025f)
-, yaw_sensitivity(-0.001f)
-, front(false)
-, back(false)
-, left(false)
-, right(false)
-, up(false)
-, down(false) {
+, yaw(0) {
}
}
-void FPSController::HandleKeyboard(const SDL_KeyboardEvent &event) {
- switch (event.keysym.sym) {
- case SDLK_w:
- front = event.state == SDL_PRESSED;
+void FPSController::Update(int dt) {
+ entity.Rotation(glm::eulerAngleYX(yaw, pitch));
+ entity.Velocity(glm::rotateY(velocity, yaw));
+}
+
+
+RandomWalk::RandomWalk(Entity &e)
+: entity(e)
+, time_left(0) {
+
+}
+
+
+void RandomWalk::Update(int dt) {
+ 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 SDLK_s:
- back = event.state == SDL_PRESSED;
+ case 1:
+ new_vel.x = 0.0f;
break;
- case SDLK_a:
- left = event.state == SDL_PRESSED;
+ case 2:
+ new_vel.x = move_vel;
break;
- case SDLK_d:
- right = event.state == SDL_PRESSED;
+ case 3:
+ new_vel.y = -move_vel;
break;
- case SDLK_q:
- case SDLK_SPACE:
- up = event.state == SDL_PRESSED;
+ case 4:
+ new_vel.y = 0.0f;
break;
- case SDLK_e:
- case SDLK_LSHIFT:
- down = event.state == SDL_PRESSED;
+ 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;
}
-}
-
-void FPSController::HandleMouse(const SDL_MouseMotionEvent &event) {
- RotateYaw(event.xrel * yaw_sensitivity);
- RotatePitch(event.yrel * pitch_sensitivity);
-}
-
-void FPSController::Update(int dt) {
- glm::vec3 vel;
- if (right && !left) {
- vel.x = move_velocity;
- } else if (left && !right) {
- vel.x = -move_velocity;
- }
- if (up && !down) {
- vel.y = move_velocity;
- } else if (down && !up) {
- vel.y = -move_velocity;
- }
- if (back && !front) {
- vel.z = move_velocity;
- } else if (front && !back) {
- vel.z = -move_velocity;
- }
- entity.Rotation(glm::eulerAngleYX(yaw, pitch));
- entity.Velocity(glm::rotateY(vel, yaw));
+ entity.Velocity(new_vel);
}
}