Фикс алгоритма поворота

This commit is contained in:
parent a6cdadd004
commit 455b655c53
1 changed files with 10 additions and 5 deletions

View File

@ -7,8 +7,8 @@
Camera::Camera(const glm::vec3 &pos, const glm::vec2 &xyOffset) Camera::Camera(const glm::vec3 &pos, const glm::vec2 &xyOffset)
: position(pos), currentRotation(xyOffset) : position(pos), currentRotation(xyOffset)
{ {
requiredRecalcView = true;
sensitivity = 0.05; sensitivity = 0.05;
recalcTarget();
} }
// Конструктор камеры с проекцией перспективы // Конструктор камеры с проекцией перспективы
@ -17,7 +17,7 @@ Camera::Camera(float aspect, const glm::vec3 &position, const glm::vec2 &xyOffse
{ {
setPerspective(fovy, aspect); setPerspective(fovy, aspect);
} }
// Конструктор ортографической камеры // Конструктор ортографической камеры
Camera::Camera(float width, float height, const glm::vec3 &position, const glm::vec2 &xyOffset) Camera::Camera(float width, float height, const glm::vec3 &position, const glm::vec2 &xyOffset)
: Camera(position, xyOffset) : Camera(position, xyOffset)
@ -31,9 +31,14 @@ Camera::~Camera() { }
// Пересчет цели, на которую смотрит камера // Пересчет цели, на которую смотрит камера
void Camera::recalcTarget() 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.x = cos(glm::radians(currentRotation.x)) * cos(glm::radians(currentRotation.y));
target.y = sin(glm::radians(currentRotation.x)); target.y = sin(glm::radians(currentRotation.y));
target.z = cos(glm::radians(currentRotation.x)) * sin(glm::radians(currentRotation.y)); target.z = sin(glm::radians(currentRotation.x)) * cos(glm::radians(currentRotation.y));
requiredRecalcView = true; requiredRecalcView = true;
} }
@ -41,7 +46,7 @@ void Camera::recalcTarget()
// Пересчет матрицы вида // Пересчет матрицы вида
void Camera::recalcView() void Camera::recalcView()
{ {
view = glm::lookAt(position, target, CAMERA_UP_VECTOR); view = glm::lookAt(position, position + target, CAMERA_UP_VECTOR);
requiredRecalcView = false; requiredRecalcView = false;
} }