From 455b655c53540df602ee326548054dc194dde4ae Mon Sep 17 00:00:00 2001 From: "re.kovalev" Date: Tue, 26 Jul 2022 18:23:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B0=D0=BB=D0=B3?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D1=82=D0=BC=D0=B0=20=D0=BF=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Camera.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Camera.cpp b/src/Camera.cpp index 6636308..2a62b32 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -7,8 +7,8 @@ Camera::Camera(const glm::vec3 &pos, const glm::vec2 &xyOffset) : position(pos), currentRotation(xyOffset) { - requiredRecalcView = true; sensitivity = 0.05; + recalcTarget(); } // Конструктор камеры с проекцией перспективы @@ -17,7 +17,7 @@ Camera::Camera(float aspect, const glm::vec3 &position, const glm::vec2 &xyOffse { setPerspective(fovy, aspect); } - + // Конструктор ортографической камеры Camera::Camera(float width, float height, const glm::vec3 &position, const glm::vec2 &xyOffset) : Camera(position, xyOffset) @@ -31,9 +31,14 @@ Camera::~Camera() { } // Пересчет цели, на которую смотрит камера void Camera::recalcTarget() { + if(currentRotation.y > 89.0f) + currentRotation.y = 89.0f; + if(currentRotation.y < -89.0f) + currentRotation.y = -89.0f; + target.x = cos(glm::radians(currentRotation.x)) * cos(glm::radians(currentRotation.y)); - target.y = sin(glm::radians(currentRotation.x)); - target.z = cos(glm::radians(currentRotation.x)) * sin(glm::radians(currentRotation.y)); + target.y = sin(glm::radians(currentRotation.y)); + target.z = sin(glm::radians(currentRotation.x)) * cos(glm::radians(currentRotation.y)); requiredRecalcView = true; } @@ -41,7 +46,7 @@ void Camera::recalcTarget() // Пересчет матрицы вида void Camera::recalcView() { - view = glm::lookAt(position, target, CAMERA_UP_VECTOR); + view = glm::lookAt(position, position + target, CAMERA_UP_VECTOR); requiredRecalcView = false; }