summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiles Bathgate <gilesbathgate@gmail.com>2011-05-14 19:47:17 (GMT)
committerGiles Bathgate <gilesbathgate@gmail.com>2011-05-14 19:47:17 (GMT)
commitccaf10dcc61cab770f6185b59703f1998b35618f (patch)
treec923478ee5c73fd9145e99c4a2fbf4cf8be284ab /src
parentb11865d5ce16e327e07a8d9eb6a875114f10a832 (diff)
Reduce multiple divisions by 10, and move similar code into single function.
Diffstat (limited to 'src')
-rw-r--r--src/GLView.h2
-rw-r--r--src/glview.cc32
2 files changed, 17 insertions, 17 deletions
diff --git a/src/GLView.h b/src/GLView.h
index 5ea3907..4977abb 100644
--- a/src/GLView.h
+++ b/src/GLView.h
@@ -69,7 +69,7 @@ private:
void initializeGL();
void resizeGL(int w, int h);
void setupPerspective();
- void setupOrtho();
+ void setupOrtho(double distance,bool offset=false);
void paintGL();
void normalizeAngle(GLdouble& angle);
diff --git a/src/glview.cc b/src/glview.cc
index b989cab..887afea 100644
--- a/src/glview.cc
+++ b/src/glview.cc
@@ -239,19 +239,22 @@ void GLView::setupPerspective()
glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY);
}
-void GLView::setupOrtho()
+void GLView::setupOrtho(double distance, bool offset)
{
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,
+ if(offset)
+ glTranslated(-0.8, -0.8, 0);
+ double l = distance/10;
+ glOrtho(-w_h_ratio*l, +w_h_ratio*l,
+ -(1/w_h_ratio)*l, +(1/w_h_ratio)*l,
-FAR_FAR_AWAY, +FAR_FAR_AWAY);
}
void GLView::paintGL()
{
if (orthomode)
- setupOrtho();
+ setupOrtho(viewer_distance);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -293,12 +296,13 @@ void GLView::paintGL()
glLineWidth(1);
glColor3d(0.5, 0.5, 0.5);
glBegin(GL_LINES);
- glVertex3d(-viewer_distance/10, 0, 0);
- glVertex3d(+viewer_distance/10, 0, 0);
- glVertex3d(0, -viewer_distance/10, 0);
- glVertex3d(0, +viewer_distance/10, 0);
- glVertex3d(0, 0, -viewer_distance/10);
- glVertex3d(0, 0, +viewer_distance/10);
+ double l = viewer_distance/10;
+ glVertex3d(-l, 0, 0);
+ glVertex3d(+l, 0, 0);
+ glVertex3d(0, -l, 0);
+ glVertex3d(0, +l, 0);
+ glVertex3d(0, 0, -l);
+ glVertex3d(0, 0, +l);
glEnd();
}
@@ -317,12 +321,8 @@ void GLView::paintGL()
{
glDepthFunc(GL_ALWAYS);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glTranslated(-0.8, -0.8, 0);
- glOrtho(-w_h_ratio*1000/10, +w_h_ratio*1000/10,
- -(1/w_h_ratio)*1000/10, +(1/w_h_ratio)*1000/10,
- -FAR_FAR_AWAY, +FAR_FAR_AWAY);
+ setupOrtho(1000,true);
+
gluLookAt(0.0, -1000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
contact: Jan Huwald // Impressum