diff --git a/src/mesh_viewer.cpp b/src/mesh_viewer.cpp index bd32d5f..eaebd80 100644 --- a/src/mesh_viewer.cpp +++ b/src/mesh_viewer.cpp @@ -13,7 +13,7 @@ MeshViewer::MeshViewer(QWidget *parent) : QOpenGLWidget(parent) { void MeshViewer::updateViewMatrix() { - view = trans * rot; + view = trans * zoom * rot; } @@ -119,8 +119,9 @@ void MeshViewer::updateForReal() { void MeshViewer::mousePressEvent(QMouseEvent *e) { - if (e->button() == Qt::MiddleButton) { + if (e->button() & Qt::MiddleButton || e->button() & Qt::RightButton) { mouse_pos = e->pos(); + trans_start = trans; } else if (e->button() == Qt::LeftButton) { float x = e->x(); float y = height() - e->y(); @@ -153,12 +154,19 @@ void MeshViewer::mouseMoveEvent(QMouseEvent *e) { updateViewMatrix(); update(); } + if (e->buttons() & Qt::RightButton) { + trans = trans_start; + trans(0, 3) += (e->pos() - mouse_pos).x() / 1000.; + trans(1, 3) -= (e->pos() - mouse_pos).y() / 1000.; + updateViewMatrix(); + update(); + } } void MeshViewer::wheelEvent(QWheelEvent *e) { - trans(2, 3) -= e->angleDelta().y() / 1000. * trans(2, 3); - trans.optimize(); + zoom(2, 3) -= e->angleDelta().y() / 1000. * zoom(2, 3); + zoom.optimize(); updateViewMatrix(); update(); } diff --git a/src/mesh_viewer.h b/src/mesh_viewer.h index 609fe85..e626b78 100644 --- a/src/mesh_viewer.h +++ b/src/mesh_viewer.h @@ -27,12 +27,13 @@ class MeshViewer : public QOpenGLWidget { std::list meshes; QOpenGLShaderProgram program; QMatrix4x4 proj; - QMatrix4x4 trans = QMatrix4x4(1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, -1, - 0, 0, 0, 1); + QMatrix4x4 zoom = QMatrix4x4(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, -1, + 0, 0, 0, 1); + QMatrix4x4 trans, trans_start; QMatrix4x4 rot, rot_start; - QMatrix4x4 view = trans * rot; + QMatrix4x4 view = trans * zoom * rot; QPoint mouse_pos; void updateViewMatrix(); bool is_initialized = false;