2017-02-02 17:01:08 +00:00
|
|
|
#include "..\Header\MoveCamera.h"
|
|
|
|
#include <QVector2D>
|
|
|
|
|
|
|
|
|
2017-02-04 14:48:10 +00:00
|
|
|
int sgn(double value)
|
|
|
|
{
|
|
|
|
if (value > 0)
|
|
|
|
return 1;
|
|
|
|
else if (value < 0)
|
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-02 17:01:08 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// constructor/destructor
|
|
|
|
|
|
|
|
MoveCamera::MoveCamera()
|
|
|
|
{
|
|
|
|
resetView();
|
|
|
|
}
|
|
|
|
|
|
|
|
MoveCamera::~MoveCamera()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// functions
|
|
|
|
|
|
|
|
void MoveCamera::rotateAction(QVector2D diff)
|
|
|
|
{
|
2017-02-04 14:48:10 +00:00
|
|
|
QMatrix4x4 rot;
|
|
|
|
rot.rotate(-diff.x() * 0.5f, 0, 1, 0);
|
|
|
|
rot.rotate(-diff.y() * 0.5f, 1, 0, 0);
|
2017-02-02 17:01:08 +00:00
|
|
|
|
2017-02-04 14:48:10 +00:00
|
|
|
m_direction = rot * m_direction;
|
|
|
|
m_direction.normalize();
|
|
|
|
|
|
|
|
m_up = QVector3D::crossProduct(m_direction.toVector3D(), QVector3D::crossProduct(QVector3D(0,1,0), m_direction.toVector3D()));
|
|
|
|
m_up.normalize();
|
2017-02-02 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveCamera::moveAction(QVector2D diff)
|
|
|
|
{
|
2017-02-04 14:48:10 +00:00
|
|
|
QVector3D sideDirection = QVector3D::crossProduct(QVector3D(0, 1, 0), m_direction.toVector3D());
|
|
|
|
|
|
|
|
m_position += sgn(diff.y()) * 0.1 * m_zSpeed * QVector4D(sideDirection, 0);
|
2017-02-02 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveCamera::wheelAction(double value)
|
|
|
|
{
|
2017-02-04 14:48:10 +00:00
|
|
|
m_position -= sgn(value) * 0.1 * m_zSpeed * m_direction;
|
2017-02-02 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveCamera::recalculateMatrix()
|
|
|
|
{
|
2017-02-04 14:48:10 +00:00
|
|
|
m_matrix = QMatrix4x4();
|
2017-02-02 17:01:08 +00:00
|
|
|
|
2017-02-04 14:48:10 +00:00
|
|
|
m_matrix.lookAt(m_position.toVector3D(), m_position.toVector3D() - m_direction.toVector3D(), m_up);
|
2017-02-02 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveCamera::resetView()
|
|
|
|
{
|
2017-02-04 14:48:10 +00:00
|
|
|
m_position = { 0,0,4,1 };
|
|
|
|
m_direction = { 0,0,1,0 };
|
|
|
|
m_up = { 0,1,0 };
|
2017-02-02 17:01:08 +00:00
|
|
|
|
|
|
|
CameraInterface::resetView();
|
|
|
|
}
|