Вот моя камера: < /p>
Код: Выделить всё
Camera::Camera(GLFWwindow* window, int width, int height, glm::vec3 position) : width(width), height(height), Position(position)
{
glfwSetCursorPos(window, (width / 2), (height / 2));
}
void Camera::Update(GLFWwindow* window, float FOVdegree, float nearPlane, float farPlane)
{
glfwGetWindowSize(window, &width, &height);
Model = glm::mat4(1.0f);
View = glm::mat4(1.0f);
Projection = glm::mat4(1.0f);
View = glm::lookAt(Position, Position + Orientation, Up);
Projection = glm::perspective(glm::radians(FOVdegree), (float)width / height, nearPlane, farPlane);
CameraMatrix = Projection * View * Model;
}
void Camera::Matrix(const Shader& Shader, const char* uniform)
{
glUniformMatrix4fv(glGetUniformLocation(Shader.programID, uniform), 1, GL_FALSE, glm::value_ptr(CameraMatrix));
}
void Camera::Input(GLFWwindow* window)
{
// Speed calculation
this->Framerate();
speed = this->Speed * deltaTime * (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) ? SprintSpeed : 1.0f);
// Keyboard
{
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
Position += speed * Orientation;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
Position += speed * -glm::normalize(glm::cross(Orientation, Up));
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
Position += speed * -Orientation;
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
Position += speed * glm::normalize(glm::cross(Orientation, Up));
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
Position += speed * Up;
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
Position += speed * Up;
if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
Position += speed * -Up;
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
Position += speed * -Up;
}
// Mouse
{
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
double mouseX, mouseY;
glfwGetCursorPos(window, &mouseX, &mouseY);
float rotateX = sensitivity * (float)(mouseY - (height / 2)) / height;
float rotateY = sensitivity * (float)(mouseX - (width / 2)) / width;
glm::vec3 orientation = glm::rotate(Orientation, glm::radians(-rotateX), glm::normalize(glm::cross(Orientation, Up)));
if (glm::abs(glm::angle(orientation, Up) - glm::radians(90.0f)) toggleDelay)
{
Wireframe();
lastToggleTime = currentTime;
}
}
}
// Other unrelated functions
< /code>
И вот мой полноэкранный код (на случай, если он вам понадобится): < /p>
void Window::Fullscreen()
{
if (glfwGetWindowMonitor(window) == nullptr)
{
glfwGetWindowSize(window, &width, &height);
glfwGetWindowPos(window, &x, &y);
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* videomode = (GLFWvidmode*)glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window, monitor, 0, 0, videomode->width, videomode->height, videomode->refreshRate);
glfwSwapBuffers(window);
}
else
{
glfwSetWindowMonitor(window, nullptr, x, y, width, height, 0);
glfwSwapBuffers(window);
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... n-glfw-glm