fix view controls
This commit is contained in:
parent
61082c8331
commit
64da1084a0
@ -9,11 +9,12 @@
|
||||
MeshViewer::MeshViewer(QWidget *parent) : QOpenGLWidget(parent) {
|
||||
setMouseTracking(true);
|
||||
setFocus();
|
||||
updateViewMatrix();
|
||||
}
|
||||
|
||||
|
||||
void MeshViewer::updateViewMatrix() {
|
||||
view = trans * zoom * rot;
|
||||
view = zoom * rot * trans;
|
||||
}
|
||||
|
||||
|
||||
@ -121,7 +122,6 @@ void MeshViewer::updateForReal() {
|
||||
void MeshViewer::mousePressEvent(QMouseEvent *e) {
|
||||
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();
|
||||
@ -141,23 +141,26 @@ void MeshViewer::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
void MeshViewer::mouseReleaseEvent(QMouseEvent *e) {
|
||||
(void) e;
|
||||
rot_start = rot;
|
||||
}
|
||||
|
||||
|
||||
void MeshViewer::mouseMoveEvent(QMouseEvent *e) {
|
||||
if (e->buttons() & Qt::MiddleButton) {
|
||||
QPoint delta = e->pos() - mouse_pos;
|
||||
rot = rot_start;
|
||||
mouse_pos = e->pos();
|
||||
if (e->buttons() & Qt::MiddleButton) {
|
||||
rot.rotate(delta.x() / 5., 0, 1, 0);
|
||||
rot.rotate(delta.y() / 5., QVector3D(1, 0, 0) * rot);
|
||||
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.;
|
||||
QMatrix4x4 screen_trans;
|
||||
screen_trans.translate(delta.x() / 1000., -delta.y() / 1000., 0);
|
||||
trans = rot.inverted() * screen_trans * rot * trans;
|
||||
// trans(0, 0) = 1;
|
||||
// trans(0, 1) = 0;
|
||||
// trans(1, 0) = 0;
|
||||
// trans(1, 1) = 1;
|
||||
updateViewMatrix();
|
||||
update();
|
||||
}
|
||||
|
@ -31,9 +31,8 @@ class MeshViewer : public QOpenGLWidget {
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, -1,
|
||||
0, 0, 0, 1);
|
||||
QMatrix4x4 trans, trans_start;
|
||||
QMatrix4x4 rot, rot_start;
|
||||
QMatrix4x4 view = trans * zoom * rot;
|
||||
QMatrix4x4 rot, trans;
|
||||
QMatrix4x4 view;
|
||||
QPoint mouse_pos;
|
||||
void updateViewMatrix();
|
||||
bool is_initialized = false;
|
||||
|
Loading…
Reference in New Issue
Block a user