add right click panning to the view
This commit is contained in:
parent
24dabed48c
commit
61082c8331
@ -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();
|
||||
}
|
||||
|
@ -27,12 +27,13 @@ class MeshViewer : public QOpenGLWidget {
|
||||
std::list<MeshView> meshes;
|
||||
QOpenGLShaderProgram program;
|
||||
QMatrix4x4 proj;
|
||||
QMatrix4x4 trans = QMatrix4x4(1, 0, 0, 0,
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user