OpenGL学习(七)摄像机
参考官方文档:https://learnopengl-cn.github.io/01%20Getting%20started/09%20Camera/
OpenGL本身没有摄像机的概念,我们通过把场景中的所有物体往相反方向移动的方式来模拟摄像机。
首先我们设置摄像机的位置:
glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.0f);
摄像机的方向为:
glm::vec3 cameraTarget = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 cameraDirection = glm::normalize(cameraPos - cameraTarget);
我们还需要一个向量为一个右向量,它代表摄像机空间的x轴的正方向。我们先定义上向量,然后上向量和摄像机方向叉乘得到
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 cameraRight = glm::normalize(glm::cross(up, cameraDirection));
然后我们容易得到摄像机的正y轴向量:
glm::vec3 cameraUp = glm::cross(cameraDirection, cameraRight);
然后我们可以创建一个LookAt
矩阵
我们可以把我们的摄像机在场景中旋转:
float radius = 10.0f;
float camX = sin(glfwGetTime()) * radius;
float camZ = cos(glfwGetTime()) * radius;
glm::mat4 view;
view = glm::lookAt(glm::vec3(camX, 0.0, camZ), glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 1.0, 0.0));
根据我们上一节的知识我们很容易实现这个效果,如图
接下来我们要想办法实现自己控制摄像机的移动。
首先定义摄像机变量:
glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.0f);
glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, -1.0f);
glm::vec3 cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
LookAt函数:
view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
修改我们之前就有的键盘响应函数:
void processInput(GLFWwindow *window)
{
...
float cameraSpeed = 0.05f; // adjust accordingly
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
cameraPos += cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
cameraPos -= cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
cameraPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
}
这个效果也不能实现
由于不同的处理器每秒绘制的帧数是不同的,如果我们的移动速度是常量的话,不同的电脑上的移动速度可能就会相差很大。这样我们需要保证它在所有设备上具有相同的移动速度的话,就需要特别的设定移动速度的数值。我们可以跟踪一个时间差变量,它为相邻两帧的时间间隔。
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
移动速度设定为
void processInput(GLFWwindow *window)
{
float cameraSpeed = 2.5f * deltaTime;
...
}
这个也不难做到
但大多数时候我们更希望通过鼠标来控制视角。接下来我们就来实现这个效果。
其中涉及一些相关的数学知识。不知道也问题不大。
我们首先需要GLFW监听鼠标移动事件:
//使光标不显示同时不离开窗口
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
//让GLFW监听鼠标移动事件
//鼠标移动就会调用绑定的函数
glfwSetCursorPosCallback(window, mouse_callback);
相关的响应函数我们可以放在main函数前面:
float lastX = 400, lastY = 300;
bool firstMouse = true;
float yaw = 0.0f, pitch = 0.0f;
void mouse_callback(GLFWwindow* window, double xpos, double ypos) {
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = xpos - lastX;
float yoffset = lastY - ypos;
lastX = xpos;
lastY = ypos;
float sensitivity = 0.05;
xoffset *= sensitivity;
yoffset *= sensitivity;
yaw += xoffset;
pitch += yoffset;
if (pitch > 89.0f)
pitch = 89.0f;
if (pitch < -89.0f)
pitch = -89.0f;
glm::vec3 front;
front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
front.y = sin(glm::radians(pitch));
front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
cameraFront = glm::normalize(front);
}
实际效果是鼠标的移动会改变窗口中物体的视角。
但这样还差一个缩放。常见的操作是利用鼠标滚轮来改变视野。
首先我们要注册鼠标滚轮的回调函数:
glfwSetScrollCallback(window, scroll_callback);
回调函数定义为:
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
if(fov >= 1.0f && fov <= 45.0f)
fov -= yoffset;
if(fov <= 1.0f)
fov = 1.0f;
if(fov >= 45.0f)
fov = 45.0f;
}
我们需要修改投影矩阵的定义:
projection = glm::perspective(glm::radians(fov), 800.0f / 600.0f, 0.1f, 100.0f);
这样就行了。
最后,我们来新建一个Camera类,就像我们前面的Shader类那样,创建一个Camera可以让我们的代码更加的简洁。
camera.h
#ifndef CAMERA_H
#define CAMERA_H
#include <glad/glad.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <vector>
enum Camera_Movement {
FORWARD,BACKWARD,LEFT,RIGHT
};
const float YAW = -90.0f;
const float PITCH = 0.0f;
const float SPEED = 2.5f;
const float SENSITIVITY = 0.1f;
const float ZOOM = 45.0f;
class Camera {
public:
glm::vec3 Position;
glm::vec3 Front;
glm::vec3 Up;
glm::vec3 Right;
glm::vec3 WorldUp;
float Yaw;
float Pitch;
float MovementSpeed;
float MouseSensitivity;
float Zoom;
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM)
{
Position = position;
WorldUp = up;
Yaw = yaw;
Pitch = pitch;
updateCameraVectors();
}
// constructor with scalar values
Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM)
{
Position = glm::vec3(posX, posY, posZ);
WorldUp = glm::vec3(upX, upY, upZ);
Yaw = yaw;
Pitch = pitch;
updateCameraVectors();
}
// returns the view matrix calculated using Euler Angles and the LookAt Matrix
glm::mat4 GetViewMatrix()
{
return glm::lookAt(Position, Position + Front, Up);
}
// processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
void ProcessKeyboard(Camera_Movement direction, float deltaTime)
{
float velocity = MovementSpeed * deltaTime;
if (direction == FORWARD)
Position += Front * velocity;
if (direction == BACKWARD)
Position -= Front * velocity;
if (direction == LEFT)
Position -= Right * velocity;
if (direction == RIGHT)
Position += Right * velocity;
}
// processes input received from a mouse input system. Expects the offset value in both the x and y direction.
void ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch = true)
{
xoffset *= MouseSensitivity;
yoffset *= MouseSensitivity;
Yaw += xoffset;
Pitch += yoffset;
// make sure that when pitch is out of bounds, screen doesn't get flipped
if (constrainPitch)
{
if (Pitch > 89.0f)
Pitch = 89.0f;
if (Pitch < -89.0f)
Pitch = -89.0f;
}
// update Front, Right and Up Vectors using the updated Euler angles
updateCameraVectors();
}
// processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
void ProcessMouseScroll(float yoffset)
{
Zoom -= (float)yoffset;
if (Zoom < 1.0f)
Zoom = 1.0f;
if (Zoom > 45.0f)
Zoom = 45.0f;
}
private:
// calculates the front vector from the Camera's (updated) Euler Angles
void updateCameraVectors()
{
// calculate the new Front vector
glm::vec3 front;
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
front.y = sin(glm::radians(Pitch));
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
Front = glm::normalize(front);
// also re-calculate the Right and Up vector
Right = glm::normalize(glm::cross(Front, WorldUp)); // normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
Up = glm::normalize(glm::cross(Right, Front));
}
};
#endif // !CAMERA_H
main.cpp
#include<iostream>
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#include"shader.h"
#include"stb_image.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include"camera.h"
float transparency = 0.0f;
glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 3.0f);
glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, -1.0f);
glm::vec3 cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
float deltaTime = 0.0f;
float lastTime = 0.0f;
float lastX = 400, lastY = 300;
bool firstMouse = true;
float yaw = 0.0f, pitch = 0.0f;
float fov = 0.0f;
void processInput(GLFWwindow* window);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
Camera camera = Camera();
int main() {
//initialize
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GlAD" << std::endl;
return -1;
}
//Shader类
Shader ourShader("shader.vs", "shader.fs");
float vertices[] = {
// ---- 位置 ---- - 纹理座标 -
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // 右上
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, // 右下
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // 左下
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // 左上
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // 右上
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, // 左下
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // 右上
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // 右下
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // 左下
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, // 左上
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, // 右上
-0.5f, -0.5f,-0.5f, 0.0f, 0.0f, // 左下
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // 右上
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, // 右下
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // 左下
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // 左上
0.5f, -0.5f, 0.5f, 1.0f, 1.0f, // 右上
0.5f, 0.5f,0.5f, 0.0f, 1.0f, // 左下
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // 右上
- 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, // 右下
-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // 左下
-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // 左上
-0.5f, -0.5f, 0.5f, 1.0f, 1.0f, // 右上
-0.5f, 0.5f,0.5f, 0.0f, 1.0f, // 左下
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, // 右上
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, // 右下
-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, // 左下
-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, // 左上
-0.5f, 0.5f, 0.5f, 1.0f, 1.0f, // 右上
0.5f, 0.5f,0.5f, 0.0f, 1.0f, // 左下
0.5f, -0.5f, 0.5f, 0.0f, 1.0f, // 右上
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, // 右下
-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // 左下
-0.5f, -0.5f, -0.5f, 1.0f, 0.0f, // 左上
-0.5f, -0.5f, 0.5f, 1.0f, 1.0f, // 右上
0.5f, -0.5f,0.5f, 0.0f, 1.0f, // 左下
};
unsigned int indices[] = {
0,1,3,
1,2,3
};
/*
glm::mat4 trans = glm::mat4(1.0f);
trans = glm::rotate(trans, glm::radians(90.0f), glm::vec3(0.0, 0.0, 1.0));
trans = glm::scale(trans, glm::vec3(0.5, 0.5, 0.5));
*/
//顶点数组对象VAO,创建
unsigned int VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
//索引缓冲对象
unsigned int EBO;
glGenBuffers(1, &EBO);
//
glBindVertexArray(VAO);
//把顶点数组复制到缓冲中供OpenGL使用
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
//位置属性
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
//颜色属性
//glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
//glEnableVertexAttribArray(1);
//纹理座标
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
//加载并创建纹理
//第一个
unsigned int texture1;
glGenTextures(1, &texture1);
glBindTexture(GL_TEXTURE_2D, texture1);
//环绕方式
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// set texture filtering parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
int width, height, nrChannels;
//下面函数的第一个参数输入本地的图片文件的路径就行了
stbi_set_flip_vertically_on_load(true);
unsigned char* data = stbi_load("C:\\Users\\xhh\\Downloads\\article_phy\\container.jpg", &width, &height, &nrChannels,0);
if (data) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else {
std::cout << "Failed to load texture1" << std::endl;
}
stbi_image_free(data);
//第二个
unsigned int texture2;
glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// set texture filtering parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//下面函数的第一个参数输入本地的图片文件的路径就行了
data = stbi_load("C:\\Users\\xhh\\Downloads\\article_phy\\awesomeface.png", &width, &height, &nrChannels, 0);
if (data) {
//注意这个png文件具有透明度属性,因此有一个alpha信道,要告诉OpenGL数据类型为GL_RGBA
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else {
std::cout << "Failed to load texture2" << std::endl;
}
stbi_image_free(data);
ourShader.use(); // don't forget to activate/use the shader before setting uniforms!
// either set it manually like so:
glUniform1i(glGetUniformLocation(ourShader.ID, "texture1"), 0);
// or set it via the texture class
ourShader.setInt("texture2", 1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
const unsigned int screenWidth = 800, screenHeight = 600;
glViewport(0, 0, screenWidth, screenHeight);
void framebuffer_size_callback(GLFWwindow * window, int width, int height);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
//使光标不显示同时不离开窗口
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
//让GLFW监听鼠标移动事件
//鼠标移动就会调用绑定的函数
glfwSetCursorPosCallback(window, mouse_callback);
//鼠标滚轮的回调函数
glfwSetScrollCallback(window, scroll_callback);
//
glm::vec3 cubePositions[] = {
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(2.0f, 5.0f, -15.0f),
glm::vec3(-1.5f, -2.2f, -2.5f),
glm::vec3(-3.8f, -2.0f, -12.3f),
glm::vec3(2.4f, -0.4f, -3.5f),
glm::vec3(-1.7f, 3.0f, -7.5f),
glm::vec3(1.3f, -2.0f, -2.5f),
glm::vec3(1.5f, 2.0f, -2.5f),
glm::vec3(1.5f, 0.2f, -1.5f),
glm::vec3(-1.3f, 1.0f, -1.5f)
};
while (!glfwWindowShouldClose(window))
{
processInput(window);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
//每次迭代之前清楚深度缓冲和颜色缓冲
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//开启深度测试
glEnable(GL_DEPTH_TEST);
glm::mat4 trans = glm::mat4(1.0f);
trans = glm::rotate(trans, (float)glfwGetTime(), glm::vec3(0.0f, 0.0f, 1.0f));
trans = glm::translate(trans, glm::vec3(0.5f, -0.5f, 0.0f));
//绑定纹理
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture1);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture2);
//激活着色器程序对象
ourShader.use();
//
glm::mat4 model = glm::mat4(1.0f);
model = glm::rotate(model,(float)glfwGetTime()* glm::radians(55.0f), glm::vec3(0.5f, 1.0f, 0.0f));
glm::mat4 view = glm::mat4(1.0f);
view = glm::lookAt(camera.Position, camera.Position + camera.Front, camera.Up);
//view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
//view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f));
glm::mat4 projection = glm::mat4(1.0f);
projection = glm::perspective(glm::radians(camera.Zoom), (float)screenWidth / (float)screenHeight, 0.1f, 100.0f);
int modelLoc = glGetUniformLocation(ourShader.ID, "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
int viewLoc = glGetUniformLocation(ourShader.ID, "view");
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, &view[0][0]);
int projectionLoc = glGetUniformLocation(ourShader.ID, "projection");
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
//
//ourShader.setFloat("delta", 0.5f);
//glDrawArrays(GL_TRIANGLES, 0, 3);
ourShader.setFloat("transparency", transparency);
glBindVertexArray(VAO);
for (unsigned int i = 0; i < 10; i++)
{
glm::mat4 model=glm::mat4(1.0f);
model = glm::translate(model, cubePositions[i]);
float angle = 20.0f * i;
model = glm::rotate(model,(float)glfwGetTime()* glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
ourShader.setMat4("model", model);
glDrawArrays(GL_TRIANGLES, 0, 36);
}
glfwSwapBuffers(window);//交换颜色缓冲,它在每一次迭代中被用来绘制,并作为输出显示在屏幕上
glfwPollEvents();//检测有没有触发什么事件、更新窗口状态,并调用对应的回调函数
}
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &EBO);
ourShader.del();
glfwTerminate();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
}
void processInput(GLFWwindow* window) {
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastTime;
lastTime = currentFrame;
float cameraSpeed = 2.5f * deltaTime; // adjust accordingly
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
else if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) {
if (transparency < 1.0f)
transparency += 0.001f;
//std::cout << transparency << std::endl;
}
else if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) {
if (transparency > 0.0f)
transparency -= 0.001f;
//std::cout << transparency << std::endl;
}
else if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
camera.ProcessKeyboard(FORWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
camera.ProcessKeyboard(BACKWARD, deltaTime);
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
camera.ProcessKeyboard(LEFT, deltaTime);
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
camera.ProcessKeyboard(RIGHT, deltaTime);
}
void mouse_callback(GLFWwindow* window, double xpos, double ypos) {
if (firstMouse)
{
lastX = xpos;
lastY = ypos;
firstMouse = false;
}
float xoffset = xpos - lastX;
float yoffset = lastY - ypos;
lastX = xpos;
lastY = ypos;
camera.ProcessMouseMovement(xoffset, yoffset);
}
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
camera.ProcessMouseScroll(yoffset);
}