代码拉取完成,页面将自动刷新
//
// Created by chess on 2021/5/20.
//
#include "InputProcessor.h"
#include "renderer/Director.h"
#include <iostream>
namespace sk {
void InputProcessor::ProcessEvent(GLFWwindow *window, float delta) {
auto director = Director::Instance();
auto position = director->GetCameraPosition();
auto front = director->GetCameraFront();
auto up = director->GetCameraUp();
auto speed = delta * 5;
glm::vec3 camera_position;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
camera_position = position + front*speed;
director->UpdateCameraPosition(camera_position);
} else if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
camera_position = position - front*speed;
director->UpdateCameraPosition(camera_position);
} else if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
auto left_direction = glm::normalize(glm::cross(up, front));
camera_position = position + left_direction * speed;
director->UpdateCameraPosition(camera_position);
} else if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
auto left_direction = glm::normalize(glm::cross(up, front));
camera_position = position - left_direction * speed;
director->UpdateCameraPosition(camera_position);
} else if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
camera_position = position + glm::vec3(0, 1, 0)*speed;
director->UpdateCameraPosition(camera_position);
} else if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS) {
camera_position = position - glm::vec3(0, 1, 0)*speed;
director->UpdateCameraPosition(camera_position);
}
}
void InputProcessor::ProcessCursor(double x, double y) {
//std::cout << "x : " << x << " y : " << y << std::endl;
if (first_enter) {
first_enter = false;
last_x = x;
last_y = y;
return;
}
float delta_x = x - last_x;
float delta_y = - (y - last_y);
last_x = x;
last_y = y;
float sense = 0.02;
delta_x *= sense;
delta_y *= sense;
pitch += delta_y;
yaw += delta_x;
if (pitch > 89) {
pitch = 89;
} else if (pitch < -89) {
pitch = -89;
}
glm::vec3 front;
front.x = glm::cos(glm::radians(pitch)) * glm::cos(glm::radians(yaw));
front.y = glm::sin(glm::radians(pitch));
front.z = glm::cos(glm::radians(pitch)) * glm::sin(glm::radians(yaw));
Director::Instance()->UpdateCameraFront(glm::normalize(front));
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。