Код: Выделить всё
void Camera::matrix(float fov, float nearPlane, float farPlane, Shader &shader, const char* uniform) {
mat4 view = mat4(1.0f);
mat4 proj = mat4(1.0f);
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
front = normalize(direction);
view = lookAt(pos, pos + front, up);
proj = perspective(radians(fov), ((float)width / (float)height), nearPlane, farPlane);
glUniformMatrix4fv(glGetUniformLocation(shader.shaderProgram, uniform), 1, GL_FALSE, glm::value_ptr(proj * view));
}
void Camera::look() {
newMouseX = getMouseX();
newMouseY = getMouseY();
float dx = (float) (newMouseX - oldMouseX) * getDeltaTime();
float dy = (float) (newMouseY - oldMouseY) * getDeltaTime();
yaw += dx * sensitivity;
pitch += dy * sensitivity;
oldMouseX = newMouseX;
oldMouseY = newMouseY;
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... 90-degrees