Cleanup after old elevation data which we don't use anymore in favour of elevation...
[tecorrec.git] / tcViewportWidget.cpp
blob6a00e4163e3ce6ea8dff7edd57e1ec757d54cb9b
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcViewportWidget.cpp
22 * @brief OpenGL viewport widget.
25 #include "tcViewportWidget.h"
26 #include <tcObserver.h>
27 #include <tcGlobe.h>
29 #include <QMouseEvent>
31 #include <cmath>
34 * Constructors + destructor
37 /// Primary constructor.
38 tcViewportWidget::tcViewportWidget(QWidget* parent)
39 : QGLWidget(parent)
40 , m_observer(new tcObserver())
41 , m_globe(0)
42 , m_mouseInteracting(false)
43 , m_mousePos()
47 /// Destructor.
48 tcViewportWidget::~tcViewportWidget()
50 delete m_observer;
54 * Modifiers
57 /// Set the globe object.
58 void tcViewportWidget::setGlobe(tcGlobe* globe)
60 m_globe = globe;
61 m_observer->setFocus(tcGeo( 7.0 * M_PI/180, 46.0 * M_PI/180), globe->meanRadius());
65 * Rendering
68 void tcViewportWidget::initializeGL()
70 glClearColor(0.0, 0.0, 0.0, 0.0);
73 void tcViewportWidget::resizeGL(int w, int h)
75 glViewport(0, 0, (GLint)w, (GLint)h);
77 double aspect = (double)w / h;
78 m_observer->setupProjection(aspect);
81 void tcViewportWidget::paintGL()
83 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
84 glEnable(GL_DEPTH_TEST);
85 glEnable(GL_CULL_FACE);
87 glEnable(GL_BLEND);
88 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
91 m_observer->setupModelView();
93 m_globe->render(m_observer);
97 * Mouse events
100 void tcViewportWidget::mouseMoveEvent(QMouseEvent* event)
102 if (m_mouseInteracting)
104 QPointF dpos = event->posF() - m_mousePos;
105 m_mousePos = event->posF();
107 // Pan the scene, adjust the observer focus
108 m_observer->moveFocusRelative(dpos.x() / height(), dpos.y() / width());
110 updateGL();
114 void tcViewportWidget::mousePressEvent(QMouseEvent* event)
116 m_mouseInteracting = true;
117 m_mousePos = event->posF();
120 void tcViewportWidget::mouseReleaseEvent(QMouseEvent* event)
122 m_mouseInteracting = false;
125 void tcViewportWidget::wheelEvent(QWheelEvent* event)
127 float delta = M_PI/180.0 * event->delta()/8;
128 delta *= 0.5f;
129 if (event->orientation() == Qt::Vertical)
131 if (event->modifiers().testFlag(Qt::ControlModifier))
133 m_observer->adjustElevation(-delta);
135 else
137 m_observer->adjustRange(delta);
140 else
142 m_observer->adjustAzimuth(delta);
145 updateGL();