Added more lines of latitude and render elevation data as triangle strips
[tecorrec.git] / geo / tcElevationData.cpp
blob7775bd55c99460b1fd510c81f9a9c0b5db445bec
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"
27 #include <glVector.h>
29 #include <GL/gl.h>
31 #include <cmath>
34 * Constructors + destructor
37 /// Initialise from SRTM data.
38 tcElevationData::tcElevationData(tcSrtmData* srtm)
39 : tcGeoData(tcGeoData::ElevationData)
40 , m_srtm(srtm)
44 /// Destructor.
45 tcElevationData::~tcElevationData()
50 * Rendering
53 void tcElevationData::renderSchematic(double meanRadius, tcObserver* const observer)
55 tcGeoData::renderSchematic(meanRadius, observer);
57 const int iskip = 2;
58 const int jskip = 2;
59 for (int i = 0; i < m_srtm->lines()-1; i += iskip)
61 glBegin(GL_TRIANGLE_STRIP);
63 for (int j = 0; j < m_srtm->length(); j += jskip)
65 for (int k = 0; k <= iskip; k += iskip)
67 uint32_t alt = m_srtm->pixelAltitude(i+k,j);
68 if (alt == 32768)
70 alt = 0;
71 glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
73 else
75 glColor4f(1.0f, 1.0f-(float)alt/3278.0f, 0.0f, 1.0f);
77 tcGeo coord = m_srtm->pixelCoordinate(i+k,j);
78 GLvec3d dir = coord;
79 double rad = meanRadius + alt;
80 glVertex3(dir * rad);
84 glEnd();