2017-02-02 17:01:08 +00:00
|
|
|
#include "..\Header\MoveCamera.h"
|
|
|
|
#include <QVector2D>
|
2017-02-05 11:34:24 +00:00
|
|
|
#include <qmath.h>
|
2017-02-02 17:01:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// constructor/destructor
|
|
|
|
|
|
|
|
MoveCamera::MoveCamera()
|
|
|
|
{
|
|
|
|
resetView();
|
|
|
|
}
|
|
|
|
|
|
|
|
MoveCamera::~MoveCamera()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// functions
|
|
|
|
|
|
|
|
void MoveCamera::rotateAction(QVector2D diff)
|
|
|
|
{
|
2017-02-05 11:34:24 +00:00
|
|
|
m_phi -= diff.x() * 0.01;
|
|
|
|
m_theta += diff.y() * 0.01;
|
2017-02-02 17:01:08 +00:00
|
|
|
|
2017-02-05 11:34:24 +00:00
|
|
|
m_theta = qMax(qMin(M_PI - 0.0001, m_theta), 0.0001);
|
2017-02-02 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveCamera::moveAction(QVector2D diff)
|
|
|
|
{
|
2017-02-05 11:34:24 +00:00
|
|
|
if (diff.y() > 0)
|
|
|
|
m_sidewardSpeed = 1;
|
|
|
|
else if (diff.y() < 0)
|
|
|
|
m_sidewardSpeed = -1;
|
|
|
|
else
|
|
|
|
m_sidewardSpeed = 0;
|
2017-02-02 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveCamera::wheelAction(double value)
|
|
|
|
{
|
2017-02-05 11:34:24 +00:00
|
|
|
if (value > 0)
|
|
|
|
m_forwardSpeed = 1;
|
|
|
|
else if (value < 0)
|
|
|
|
m_forwardSpeed = -1;
|
|
|
|
else
|
|
|
|
m_forwardSpeed = 0;
|
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-05 11:34:24 +00:00
|
|
|
// different coordinate (spherical -> world) X->Z | Y->X | Z->Y
|
|
|
|
QVector3D tmpdirection(
|
|
|
|
qSin(m_theta) * qSin(m_phi),
|
|
|
|
qCos(m_theta),
|
|
|
|
qSin(m_theta) * qCos(m_phi)
|
|
|
|
);
|
|
|
|
|
|
|
|
QVector3D tmpRight(
|
|
|
|
qSin(m_phi - M_PI_2),
|
|
|
|
0,
|
|
|
|
qCos(m_phi - M_PI_2)
|
|
|
|
);
|
|
|
|
|
|
|
|
m_position += m_forwardSpeed * m_zSpeed * 0.1 * tmpdirection;
|
|
|
|
m_position += m_sidewardSpeed * m_zSpeed * 0.1 * tmpRight;
|
|
|
|
|
|
|
|
m_matrix.lookAt(m_position, m_position + tmpdirection, QVector3D::crossProduct(tmpRight, tmpdirection));
|
2017-02-02 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MoveCamera::resetView()
|
|
|
|
{
|
2017-02-05 11:34:24 +00:00
|
|
|
m_position = { 0,0,4 };
|
|
|
|
m_phi = M_PI;
|
|
|
|
m_theta = M_PI_2;
|
|
|
|
m_forwardSpeed = 0;
|
|
|
|
m_sidewardSpeed = 0;
|
2017-02-02 17:01:08 +00:00
|
|
|
CameraInterface::resetView();
|
|
|
|
}
|