diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/glview.cc | 70 |
1 files changed, 10 insertions, 60 deletions
diff --git a/src/glview.cc b/src/glview.cc index 887afea..dd2a3b5 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -266,6 +266,8 @@ void GLView::paintGL() gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); + glTranslated(object_trans_x, object_trans_y, object_trans_z); + glRotated(object_rot_x, 1.0, 0.0, 0.0); glRotated(object_rot_y, 0.0, 1.0, 0.0); glRotated(object_rot_z, 0.0, 0.0, 1.0); @@ -287,8 +289,6 @@ void GLView::paintGL() glEnd(); } - glTranslated(object_trans_x, object_trans_y, object_trans_z); - // Large gray axis cross inline with the model // FIXME: This is always gray - adjust color to keep contrast with background if (showaxes) @@ -431,39 +431,6 @@ void GLView::mousePressEvent(QMouseEvent *event) setFocus(); } -static void mat_id(double *trg) -{ - for (int i = 0; i < 16; i++) - trg[i] = i%5 == 0; -} - -static void mat_mul(double *trg, const double *m1, const double *m2) -{ - double m[16]; - for (int x = 0; x < 4; x++) - for (int y = 0; y < 4; y++) - { - m[x+y*4] = 0; - for (int i = 0; i < 4; i++) - m[x+y*4] += m1[i+y*4] * m2[x+i*4]; - } - for (int i = 0; i < 16; i++) - trg[i] = m[i]; -} - -static void mat_rot(double *trg, double angle, double x, double y, double z) -{ - double s = sin(M_PI*angle/180), c = cos(M_PI*angle/180); - double cc = 1 - c; - double m[16] = { - x*x*cc+c, x*y*cc-z*s, x*z*cc+y*s, 0, - y*x*cc+z*s, y*y*cc+c, y*z*cc-x*s, 0, - x*z*cc-y*s, y*z*cc+x*s, z*z*cc+c, 0, - 0, 0, 0, 1 - }; - for (int i = 0; i < 16; i++) - trg[i] = m[i]; -} void GLView::normalizeAngle(GLdouble& angle) { @@ -477,43 +444,26 @@ void GLView::mouseMoveEvent(QMouseEvent *event) { int this_mouse_x = event->globalX(); int this_mouse_y = event->globalY(); + int dx = (this_mouse_x-last_mouse_x); + int dy = (this_mouse_y-last_mouse_y); if (mouse_drag_active) { if ((event->buttons() & Qt::LeftButton) != 0) { object_rot_x += (this_mouse_y-last_mouse_y) * 0.7; if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0) - object_rot_y += (this_mouse_x-last_mouse_x) * 0.7; + object_rot_y += dx * 0.7; else - object_rot_z += (this_mouse_x-last_mouse_x) * 0.7; + object_rot_z += dx * 0.7; normalizeAngle(object_rot_x); normalizeAngle(object_rot_y); normalizeAngle(object_rot_z); } else { - double mx = +(this_mouse_x-last_mouse_x) * viewer_distance/1000; - double my = -(this_mouse_y-last_mouse_y) * viewer_distance/1000; - double rx[16], ry[16], rz[16], tm[16]; - mat_rot(rx, -object_rot_x, 1.0, 0.0, 0.0); - mat_rot(ry, -object_rot_y, 0.0, 1.0, 0.0); - mat_rot(rz, -object_rot_z, 0.0, 0.0, 1.0); - mat_id(tm); - mat_mul(tm, rx, tm); - mat_mul(tm, ry, tm); - mat_mul(tm, rz, tm); - double vec[16] = { - 0, 0, 0, mx, - 0, 0, 0, 0, - 0, 0, 0, my, - 0, 0, 0, 1 - }; if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0) { - vec[3] = 0; - vec[7] = my; - vec[11] = 0; + viewer_distance += (GLdouble)dy; + } else { + object_trans_x += (GLint)dx; + object_trans_z -= (GLint)dy; } - mat_mul(tm, tm, vec); - object_trans_x += tm[3]; - object_trans_y += tm[7]; - object_trans_z += tm[11]; } updateGL(); emit doAnimateUpdate(); |