1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
21 * @file tcObserver.cpp
22 * @brief Viewing information for an observer.
25 #include "tcObserver.h"
33 * Constructors + destructor
36 /// Primary constructor.
37 tcObserver::tcObserver()
39 , m_focusAltitude(1000e3
)
46 tcObserver::~tcObserver()
54 /// Set up the OpenGL projection matrix for this observer.
55 void tcObserver::setupProjection(double aspect
) const
57 glMatrixMode(GL_PROJECTION
);
60 glFrustum(-SIZE
*aspect
, SIZE
*aspect
, -SIZE
, SIZE
, 100.0, 20000e3
);
61 glMatrixMode(GL_MODELVIEW
);
64 void drawAxes(float size
)
67 glScalef(size
, size
, size
);
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
);
88 glEnable(GL_POINT_SMOOTH
);
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
);
108 /// Set up the OpenGL modelview matrix for this observer.
109 void tcObserver::setupModelView() const
113 // Translate to focus
114 glTranslatef(0.0f
, 0.0f
, -m_range
);
118 // Rotate to surface space
119 glMultMatrix(m_view
);
123 // Translate to origin
124 glTranslatef(0.0f
, 0.0f
, -m_focusAltitude
);
126 // Rotate to model space
127 glMultMatrix(m_focus
);
136 /// Adjust the focus directly.
137 void tcObserver::setFocus(const tcGeo
& focus
, double altitude
)
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
)
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
);
182 /// Get the current focus position.
183 tcGeo
tcObserver::focus() const