added movement and zoom
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
#define DEFAULT_Z_DISTANCE -5.0
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
@@ -12,6 +15,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) :
|
||||
m_dataEngine(0)
|
||||
{
|
||||
setFocus();
|
||||
m_translation.setZ(DEFAULT_Z_DISTANCE);
|
||||
}
|
||||
|
||||
OglViewerWidget::~OglViewerWidget()
|
||||
@@ -63,13 +67,35 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
// request an update
|
||||
update();
|
||||
}
|
||||
else if (m_mouse.right)
|
||||
{
|
||||
// get the difference between last press and now
|
||||
QVector2D diff = QVector2D(e->localPos()) - m_mouse.position;
|
||||
|
||||
// update the new position
|
||||
m_mouse.position = QVector2D(e->localPos());
|
||||
|
||||
// calculate the translation
|
||||
m_translation += {(float)(diff.x() * 0.01), (float)(diff.y() * -0.01), 0.0};
|
||||
|
||||
// request an update
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void OglViewerWidget::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
m_translation += {0.0, 0.0, (float)e->angleDelta().y() / 240};
|
||||
update();
|
||||
}
|
||||
|
||||
void OglViewerWidget::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
if (e->key() == Qt::Key_Space)
|
||||
{
|
||||
m_rotation = QQuaternion();
|
||||
|
||||
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -97,7 +123,7 @@ void OglViewerWidget::resizeGL(int w, int h)
|
||||
qreal aspect = qreal(w) / qreal(h ? h : 1);
|
||||
|
||||
// Set near plane to 3.0, far plane to 7.0, field of view 45 degrees
|
||||
const qreal zNear = 3.0, zFar = 7.0, fov = 45.0;
|
||||
const qreal zNear = 0.1, zFar = 100.0, fov = 45.0;
|
||||
|
||||
// Reset projection
|
||||
m_projection.setToIdentity();
|
||||
@@ -113,7 +139,7 @@ void OglViewerWidget::paintGL()
|
||||
|
||||
// Calculate model view transformation
|
||||
QMatrix4x4 view;
|
||||
view.translate(0.0, 0.0, -5.0);
|
||||
view.translate(m_translation);
|
||||
view.rotate(m_rotation);
|
||||
|
||||
// Set modelview-projection matrix
|
||||
|
||||
Reference in New Issue
Block a user