added MoveCamera but isn't working well

updated about text,
This commit is contained in:
Anakin
2017-02-04 15:48:10 +01:00
parent 648b805daf
commit 94a2fa59ec
6 changed files with 79 additions and 8 deletions

View File

@@ -2,6 +2,16 @@
#include <QVector2D>
int sgn(double value)
{
if (value > 0)
return 1;
else if (value < 0)
return -1;
else
return 0;
}
/////////////////////////////////////////////////////////////////////////
// constructor/destructor
@@ -21,26 +31,41 @@ MoveCamera::~MoveCamera()
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();
}

View File

@@ -235,6 +235,38 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
{
resetView();
}
else if (e->key() == Qt::Key_W)
{
emit m_camera->wheelAction(1);
if (m_light.headlight)
updateLightPosition();
update();
}
else if (e->key() == Qt::Key_S)
{
emit m_camera->wheelAction(-1);
if (m_light.headlight)
updateLightPosition();
update();
}
else if (e->key() == Qt::Key_A)
{
emit m_camera->moveAction(QVector2D(0, -1));
if (m_light.headlight)
updateLightPosition();
update();
}
else if (e->key() == Qt::Key_D)
{
emit m_camera->moveAction(QVector2D(0, 1));
if (m_light.headlight)
updateLightPosition();
update();
}
else if (e->key() == Qt::Key_Escape)
{
parentWidget()->close();

View File

@@ -27,7 +27,6 @@ void OrbitCamera::rotateAction(QVector2D diff)
m_theta -= diff.y() * 0.01;
m_theta = qMax(qMin(M_PI - 0.0001, m_theta), 0.0001);
}
void OrbitCamera::moveAction(QVector2D diff)
@@ -51,14 +50,14 @@ void OrbitCamera::recalculateMatrix()
tmpPosition.setZ(qCos(m_theta));
m_matrix.lookAt(m_roh * tmpPosition, QVector3D(0,0,0), QVector3D(0, 0, 1));
m_matrix.rotate(90, 90, 0);
m_matrix.rotate(90, 1, 0, 0);
m_matrix.rotate(90, 0, 1, 0);
}
void OrbitCamera::resetView()
{
m_roh = 4;
m_phi = -M_PI_2;
m_phi = 0; //-M_PI_2;
m_theta = M_PI_2;
CameraInterface::resetView();
}