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

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)
: position(pos), currentRotation(xyOffset)
{
requiredRecalcView = true;
sensitivity = 0.05;
recalcTarget();
}
// Конструктор камеры с проекцией перспективы
@ -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;
}