94a2fa59ec
updated about text,
72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
#include "..\Header\MoveCamera.h"
|
|
#include <QVector2D>
|
|
|
|
|
|
int sgn(double value)
|
|
{
|
|
if (value > 0)
|
|
return 1;
|
|
else if (value < 0)
|
|
return -1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// constructor/destructor
|
|
|
|
MoveCamera::MoveCamera()
|
|
{
|
|
resetView();
|
|
}
|
|
|
|
MoveCamera::~MoveCamera()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
// functions
|
|
|
|
void MoveCamera::rotateAction(QVector2D diff)
|
|
{
|
|
QMatrix4x4 rot;
|
|
rot.rotate(-diff.x() * 0.5f, 0, 1, 0);
|
|
rot.rotate(-diff.y() * 0.5f, 1, 0, 0);
|
|
|
|
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();
|
|
}
|
|
|
|
void MoveCamera::moveAction(QVector2D diff)
|
|
{
|
|
QVector3D sideDirection = QVector3D::crossProduct(QVector3D(0, 1, 0), m_direction.toVector3D());
|
|
|
|
m_position += sgn(diff.y()) * 0.1 * m_zSpeed * QVector4D(sideDirection, 0);
|
|
}
|
|
|
|
void MoveCamera::wheelAction(double value)
|
|
{
|
|
m_position -= sgn(value) * 0.1 * m_zSpeed * m_direction;
|
|
}
|
|
|
|
void MoveCamera::recalculateMatrix()
|
|
{
|
|
m_matrix = QMatrix4x4();
|
|
|
|
m_matrix.lookAt(m_position.toVector3D(), m_position.toVector3D() - m_direction.toVector3D(), m_up);
|
|
}
|
|
|
|
void MoveCamera::resetView()
|
|
{
|
|
m_position = { 0,0,4,1 };
|
|
m_direction = { 0,0,1,0 };
|
|
m_up = { 0,1,0 };
|
|
|
|
CameraInterface::resetView();
|
|
}
|