Skip to content

Commit

Permalink
refactor processKey
Browse files Browse the repository at this point in the history
  • Loading branch information
yknishidate committed Feb 14, 2024
1 parent cc9610e commit 0459373
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion include/reactive/Scene/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class Camera {
}
}

void processKey(int key);
// キー入力は関数内で rv::Window から直接取得する
void processKey();

// マウス入力は rv::Window 以外で計測される場合もあるため
// 外部から引数で受け取る
void processMouseDragLeft(glm::vec2 dragDelta);
void processMouseDragRight(glm::vec2 dragDelta);
void processMouseScroll(float scroll);
Expand Down
13 changes: 7 additions & 6 deletions src/Scene/Camera.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#include "Scene/Camera.hpp"
#include "App.hpp"
#include "Window.hpp"

#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>

namespace rv {
void Camera::processKey(int key) {
void Camera::processKey() {
if (type == Type::FirstPerson) {
auto& _params = std::get<FirstPersonParams>(params);
glm::vec3 front = getFront();
glm::vec3 right = getRight();
if (key == GLFW_KEY_W) {
if (Window::isKeyDown(GLFW_KEY_W)) {
_params.position += front * 0.15f * _params.speed;
}
if (key == GLFW_KEY_S) {
if (Window::isKeyDown(GLFW_KEY_S)) {
_params.position -= front * 0.15f * _params.speed;
}
if (key == GLFW_KEY_D) {
if (Window::isKeyDown(GLFW_KEY_D)) {
_params.position += right * 0.1f * _params.speed;
}
if (key == GLFW_KEY_A) {
if (Window::isKeyDown(GLFW_KEY_A)) {
_params.position -= right * 0.1f * _params.speed;
}
if (key == GLFW_KEY_SPACE) {
if (Window::isKeyDown(GLFW_KEY_SPACE)) {
_params.position += glm::vec3{0, 1, 0} * 0.05f * _params.speed;
}
}
Expand Down

0 comments on commit 0459373

Please sign in to comment.