#include "manualCameraController.h" #include #include #include #include bool ManualCameraController::handleInput(SDL_Event & e) { switch (e.type) { case SDL_KEYDOWN: switch (e.key.keysym.sym) { case SDLK_LCTRL: case SDLK_RCTRL: ctrl = true; return true; } break; case SDL_KEYUP: switch (e.key.keysym.sym) { case SDLK_LCTRL: case SDLK_RCTRL: ctrl = false; return true; } break; case SDL_MOUSEBUTTONDOWN: switch (e.button.button) { case SDL_BUTTON_RIGHT: SDL_SetRelativeMouseMode(SDL_TRUE); mrb = true; return true; } break; case SDL_MOUSEBUTTONUP: switch (e.button.button) { case SDL_BUTTON_RIGHT: SDL_SetRelativeMouseMode(SDL_FALSE); mrb = false; return true; } break; case SDL_MOUSEMOTION: if (mrb) { if (ctrl) { direction -= 0.01F * e.motion.xrel; pitch = std::clamp(pitch - 0.01F * e.motion.yrel, 0.1F, half_pi); } else { focus.x += cos(direction) * e.motion.xrel + sin(direction) * e.motion.yrel; focus.y += cos(direction) * e.motion.yrel - sin(direction) * e.motion.xrel; } } return true; case SDL_MOUSEWHEEL: dist = std::clamp(dist - e.wheel.y * 4.F, 5.F, 200.F); break; } return false; } void ManualCameraController::updateCamera(Camera * camera) const { const auto rel {glm::normalize(glm::vec3 {sin(direction), -sin(pitch), cos(direction)})}; camera->pos = !focus + up * 3.F - (rel * std::pow(dist, 1.3F)); camera->forward = glm::normalize(rel); camera->up = up; }