Доработка камеры

This commit is contained in:
2023-11-13 17:02:07 +03:00
parent 24e509aa1f
commit 95162bf637
2 changed files with 12 additions and 12 deletions

View File

@@ -21,17 +21,17 @@ Camera::Camera(const glm::vec3 &pos, const glm::vec3 &initialRotation) : Node(NU
}
// Конструктор камеры с проекцией перспективы
Camera::Camera(float aspect, const glm::vec3 &position, const glm::vec3 &initialRotation, float fovy)
Camera::Camera(float aspect, const glm::vec3 &position, const glm::vec3 &initialRotation, float fovy, float near, float far)
: Camera(position, initialRotation)
{
setPerspective(fovy, aspect);
setPerspective(fovy, aspect, near, far);
}
// Конструктор ортографической камеры
Camera::Camera(float width, float height, const glm::vec3 &position, const glm::vec3 &initialRotation)
Camera::Camera(float width, float height, const glm::vec3 &position, const glm::vec3 &initialRotation, float near, float far)
: Camera(position, initialRotation)
{
setOrtho(width, height);
setOrtho(width, height, near, far);
}
// Конструктор копирования камеры
@@ -90,19 +90,19 @@ const glm::mat4& Camera::getVP()
}
// Устанавливает заданную матрицу перспективы
void Camera::setPerspective(float fovy, float aspect)
void Camera::setPerspective(float fovy, float aspect, float near, float far)
{
projection = glm::perspective(glm::radians(fovy), aspect, CAMERA_NEAR, CAMERA_FAR);
projection = glm::perspective(glm::radians(fovy), aspect, near, far);
requiredRecalcVP = true;
for (int cascade = 0; cascade < CAMERA_CASCADE_COUNT; cascade++)
cascade_proj[cascade] = glm::perspective(glm::radians(fovy), aspect, camera_cascade_distances[cascade], camera_cascade_distances[cascade+1]);
}
// Устанавливает заданную ортографическую матрицу
void Camera::setOrtho(float width, float height)
void Camera::setOrtho(float width, float height, float near, float far)
{
const float aspect = width / height;
projection = glm::ortho(-1.0f, 1.0f, -1.0f/aspect, 1.0f/aspect, CAMERA_NEAR, CAMERA_FAR);
projection = glm::ortho(-1.0f, 1.0f, -1.0f/aspect, 1.0f/aspect, near, far);
requiredRecalcVP = true;
for (int cascade = 0; cascade < CAMERA_CASCADE_COUNT; cascade++)
cascade_proj[cascade] = glm::ortho(-1.0f, 1.0f, -1.0f/aspect, 1.0f/aspect, camera_cascade_distances[cascade], camera_cascade_distances[cascade+1]);