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() {
|
void MeshViewer::updateViewMatrix() {
|
||||||
view = trans * rot;
|
view = trans * zoom * rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -119,8 +119,9 @@ void MeshViewer::updateForReal() {
|
|||||||
|
|
||||||
|
|
||||||
void MeshViewer::mousePressEvent(QMouseEvent *e) {
|
void MeshViewer::mousePressEvent(QMouseEvent *e) {
|
||||||
if (e->button() == Qt::MiddleButton) {
|
if (e->button() & Qt::MiddleButton || e->button() & Qt::RightButton) {
|
||||||
mouse_pos = e->pos();
|
mouse_pos = e->pos();
|
||||||
|
trans_start = trans;
|
||||||
} else if (e->button() == Qt::LeftButton) {
|
} else if (e->button() == Qt::LeftButton) {
|
||||||
float x = e->x();
|
float x = e->x();
|
||||||
float y = height() - e->y();
|
float y = height() - e->y();
|
||||||
@ -153,12 +154,19 @@ void MeshViewer::mouseMoveEvent(QMouseEvent *e) {
|
|||||||
updateViewMatrix();
|
updateViewMatrix();
|
||||||
update();
|
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) {
|
void MeshViewer::wheelEvent(QWheelEvent *e) {
|
||||||
trans(2, 3) -= e->angleDelta().y() / 1000. * trans(2, 3);
|
zoom(2, 3) -= e->angleDelta().y() / 1000. * zoom(2, 3);
|
||||||
trans.optimize();
|
zoom.optimize();
|
||||||
updateViewMatrix();
|
updateViewMatrix();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -27,12 +27,13 @@ class MeshViewer : public QOpenGLWidget {
|
|||||||
std::list<MeshView> meshes;
|
std::list<MeshView> meshes;
|
||||||
QOpenGLShaderProgram program;
|
QOpenGLShaderProgram program;
|
||||||
QMatrix4x4 proj;
|
QMatrix4x4 proj;
|
||||||
QMatrix4x4 trans = QMatrix4x4(1, 0, 0, 0,
|
QMatrix4x4 zoom = QMatrix4x4(1, 0, 0, 0,
|
||||||
0, 1, 0, 0,
|
0, 1, 0, 0,
|
||||||
0, 0, 1, -1,
|
0, 0, 1, -1,
|
||||||
0, 0, 0, 1);
|
0, 0, 0, 1);
|
||||||
|
QMatrix4x4 trans, trans_start;
|
||||||
QMatrix4x4 rot, rot_start;
|
QMatrix4x4 rot, rot_start;
|
||||||
QMatrix4x4 view = trans * rot;
|
QMatrix4x4 view = trans * zoom * rot;
|
||||||
QPoint mouse_pos;
|
QPoint mouse_pos;
|
||||||
void updateViewMatrix();
|
void updateViewMatrix();
|
||||||
bool is_initialized = false;
|
bool is_initialized = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user