Basic loading of SRTM data
[tecorrec.git] / geo / tcElevationData.cpp
blobe5a530af3bb686c417822c2ac53c2c3af7b3786b
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 tcElevationData.cpp
22 * @brief Terrain elevation data.
25 #include "tcElevationData.h"
26 #include "tcSrtmData.h"
28 #include <GL/gl.h>
30 #include <cmath>
33 * Constructors + destructor
36 /// Initialise from SRTM data.
37 tcElevationData::tcElevationData(tcSrtmData* srtm)
38 : tcGeoData(tcGeoData::ElevationData)
39 , m_srtm(srtm)
43 /// Destructor.
44 tcElevationData::~tcElevationData()
49 * Rendering
52 void tcElevationData::renderSchematic(double meanRadius)
54 tcGeoData::renderSchematic(meanRadius);
56 for (int i = 0; i < m_srtm->lines(); i += 5)
58 glBegin(GL_LINE_STRIP);
60 for (int j = 0; j < m_srtm->length(); j += 1)
62 uint32_t alt = m_srtm->pixelAltitude(i,j);
63 if (alt == 32768)
65 glEnd();
66 glBegin(GL_LINE_STRIP);
67 continue;
69 tcGeo coord = m_srtm->pixelCoordinate(i,j);
70 double rad = meanRadius + alt;
71 double z = cos(coord.lat());
72 double xy = sin(coord.lat());
73 glColor3f(1.0f, 1.0f-(float)alt/3278.0f, 0.0f);
74 glVertex3d(rad*sin(coord.lon())*xy,
75 rad*cos(coord.lon())*xy,
76 rad*z);
79 glEnd();