Proper landsat data projection, although very inefficient
[tecorrec.git] / geo / tcObserver.cpp
blobfb8614ee7f56faf10359f8284265b697da2e3149
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 tcObserver.cpp
22 * @brief Viewing information for an observer.
25 #include "tcObserver.h"
26 #include <glMatrix.h>
28 #include <GL/gl.h>
30 #include <cmath>
33 * Constructors + destructor
36 /// Primary constructor.
37 tcObserver::tcObserver()
38 : m_focus(0.0, 0.0)
39 , m_focusAltitude(1000e3)
40 , m_view(0, M_PI/2)
41 , m_range(100e3)
45 /// Destructor.
46 tcObserver::~tcObserver()
51 * Main interface
54 /// Set up the OpenGL projection matrix for this observer.
55 void tcObserver::setupProjection(double aspect) const
57 glMatrixMode(GL_PROJECTION);
58 glLoadIdentity();
59 #define SIZE 120.0
60 glFrustum(-SIZE*aspect, SIZE*aspect, -SIZE, SIZE, 100.0, 20000e3);
61 glMatrixMode(GL_MODELVIEW);
64 void drawAxes(float size)
66 glPushMatrix();
67 glScalef(size, size, size);
68 glBegin(GL_LINES);
70 glColor3f(1.0f, 1.0f, 1.0f);
71 glVertex3f(0.0f, 0.0f, 0.0f);
72 glColor3f(0.0f, 1.0f, 1.0f);
73 glVertex3f(1.0f, 0.0f, 0.0f);
75 glColor3f(1.0f, 1.0f, 1.0f);
76 glVertex3f(0.0f, 0.0f, 0.0f);
77 glColor3f(1.0f, 0.0f, 1.0f);
78 glVertex3f(0.0f, 1.0f, 0.0f);
80 glColor3f(1.0f, 1.0f, 1.0f);
81 glVertex3f(0.0f, 0.0f, 0.0f);
82 glColor3f(1.0f, 1.0f, 0.0f);
83 glVertex3f(0.0f, 0.0f, 1.0f);
85 glEnd();
87 glPointSize(5);
88 glEnable(GL_POINT_SMOOTH);
89 glBegin(GL_POINTS);
91 glColor3f(1.0f, 1.0f, 1.0f);
92 glVertex3f(0.0f, 0.0f, 0.0f);
94 glColor3f(0.0f, 1.0f, 1.0f);
95 glVertex3f(1.0f, 0.0f, 0.0f);
97 glColor3f(1.0f, 0.0f, 1.0f);
98 glVertex3f(0.0f, 1.0f, 0.0f);
100 glColor3f(1.0f, 1.0f, 0.0f);
101 glVertex3f(0.0f, 0.0f, 1.0f);
103 glEnd();
104 glPointSize(1);
105 glPopMatrix();
108 /// Set up the OpenGL modelview matrix for this observer.
109 void tcObserver::setupModelView() const
111 glLoadIdentity();
113 // Translate to focus
114 glTranslatef(0.0f, 0.0f, -m_range);
116 //drawAxes(50e3f);
118 // Rotate to surface space
119 glMultMatrix(m_view);
121 //drawAxes(50e3f);
123 // Translate to origin
124 glTranslatef(0.0f, 0.0f, -m_focusAltitude);
126 // Rotate to model space
127 glMultMatrix(m_focus);
129 //drawAxes(1000e3f);
133 * Mutators
136 /// Adjust the focus directly.
137 void tcObserver::setFocus(const tcGeo& focus, double altitude)
139 m_focus = focus;
140 m_focusAltitude = altitude;
143 /// Adjust the focus altitude.
144 void tcObserver::setFocusAltitude(double altitude)
146 m_focusAltitude = altitude;
149 /// Make a local transformation of the focus.
150 void tcObserver::moveFocusRelative(double dx, double dy)
152 dx *= 2.0 * m_range / m_focusAltitude;
153 dy *= 2.0 * m_range / m_focusAltitude;
154 m_focus.setLat(m_focus.lat() - sin(m_view.azim()) * dx
155 + cos(m_view.azim()) * dy);
156 m_focus.setLon(m_focus.lon() - cos(m_view.azim()) * dx
157 - sin(m_view.azim()) * dy);
160 /// Adjust the range exponentially.
161 void tcObserver::adjustRange(double x)
163 m_range *= exp(x);
166 /// Adjust the azimuth in radians.
167 void tcObserver::adjustAzimuth(double daz)
169 m_view.setAzim(m_view.azim() + daz);
172 /// Adjust the elevation in radians.
173 void tcObserver::adjustElevation(double del)
175 m_view.setElev(m_view.elev() + del);
179 * Accessors
182 /// Get the current focus position.
183 tcGeo tcObserver::focus() const
185 return m_focus;