Ai
2 Star 0 Fork 0

shark-dynamics/opengl-tutorial-cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
InputProcessor.cpp 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
chessplayer 提交于 2021-05-21 13:43 +08:00 . support point light
//
// 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));
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shark-dynamics/opengl-tutorial-cpp.git
git@gitee.com:shark-dynamics/opengl-tutorial-cpp.git
shark-dynamics
opengl-tutorial-cpp
opengl-tutorial-cpp
10.0_load_obj_model

搜索帮助