From b11865d5ce16e327e07a8d9eb6a875114f10a832 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 14 May 2011 19:57:12 +0100 Subject: Some fixes to previous commit, and simplified normalisation. diff --git a/src/GLView.h b/src/GLView.h index 7516894..5ea3907 100644 --- a/src/GLView.h +++ b/src/GLView.h @@ -68,7 +68,10 @@ private: void initializeGL(); void resizeGL(int w, int h); + void setupPerspective(); + void setupOrtho(); void paintGL(); + void normalizeAngle(GLdouble& angle); #ifdef ENABLE_OPENCSG private slots: diff --git a/src/glview.cc b/src/glview.cc index f2bc282..b989cab 100644 --- a/src/glview.cc +++ b/src/glview.cc @@ -236,16 +236,26 @@ void GLView::setupPerspective() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - if (orthomode) - glOrtho(-w_h_ratio*viewer_distance/10, +w_h_ratio*viewer_distance/10, - -(1/w_h_ratio)*viewer_distance/10, +(1/w_h_ratio)*viewer_distance/10, - -FAR_FAR_AWAY, +FAR_FAR_AWAY); - else - glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY); + glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY); +} + +void GLView::setupOrtho() +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-w_h_ratio*viewer_distance/10, +w_h_ratio*viewer_distance/10, + -(1/w_h_ratio)*viewer_distance/10, +(1/w_h_ratio)*viewer_distance/10, + -FAR_FAR_AWAY, +FAR_FAR_AWAY); } void GLView::paintGL() { + if (orthomode) + setupOrtho(); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + const QColor &bgcol = Preferences::inst()->color(Preferences::BACKGROUND_COLOR); glClearColor(bgcol.redF(), bgcol.greenF(), bgcol.blueF(), 0.0); @@ -253,9 +263,6 @@ void GLView::paintGL() gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - 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); @@ -382,7 +389,8 @@ void GLView::paintGL() glEnd(); //Restore perspective for next paint - setupPerspective(); + if(!orthomode) + setupPerspective(); } if (statusLabel) { @@ -457,6 +465,14 @@ static void mat_rot(double *trg, double angle, double x, double y, double z) trg[i] = m[i]; } +void GLView::normalizeAngle(GLdouble& angle) +{ + while(angle < 0) + angle += 360; + while(angle > 360) + angle -= 360; +} + void GLView::mouseMoveEvent(QMouseEvent *event) { int this_mouse_x = event->globalX(); @@ -468,18 +484,10 @@ void GLView::mouseMoveEvent(QMouseEvent *event) object_rot_y += (this_mouse_x-last_mouse_x) * 0.7; else object_rot_z += (this_mouse_x-last_mouse_x) * 0.7; - while (object_rot_x < 0) - object_rot_x += 360; - while (object_rot_x >= 360) - object_rot_x -= 360; - while (object_rot_y < 0) - object_rot_y += 360; - while (object_rot_y >= 360) - object_rot_y -= 360; - while (object_rot_z < 0) - object_rot_z += 360; - while (object_rot_z >= 360) - object_rot_z -= 360; + + 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; -- cgit v0.10.1