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; }