Basic loading of SRTM data
[tecorrec.git] / geo / tcGlobe.cpp
blobd405aed33e869ac8f647c54f36f554baed24fea4
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 tcGlobe.cpp
22 * @brief Manages data for a globe.
25 #include "tcGlobe.h"
26 #include "tcSrtmCache.h"
27 #include "tcElevationData.h"
29 #include <GL/gl.h>
31 #include <cmath>
34 * Constructors + destructor
37 /// Primary constructor.
38 tcGlobe::tcGlobe(double meanRadius)
39 : m_meanRadius(meanRadius)
40 , m_srtmCache(new tcSrtmCache())
41 , m_data()
43 addDataSet(new tcElevationData(m_srtmCache->loadData(6, 45)));
44 addDataSet(new tcElevationData(m_srtmCache->loadData(7, 45)));
45 addDataSet(new tcElevationData(m_srtmCache->loadData(6, 46)));
46 addDataSet(new tcElevationData(m_srtmCache->loadData(7, 46)));
49 /// Destructor.
50 tcGlobe::~tcGlobe()
55 * Data sets
58 /// Add a dataset to the globe.
59 void tcGlobe::addDataSet(tcGeoData* data)
61 m_data.push_back(data);
65 * Rendering
68 /// Render from the POV of an observer.
69 void tcGlobe::render(tcObserver* observer)
71 glColor3f(0.0f, 1.0f, 0.0f);
73 // Lines of longitude
74 for (int lat = 5; lat < 180; lat += 5)
76 double z = cos(M_PI/180*lat) * m_meanRadius;
77 double xy = sin(M_PI/180*lat) * m_meanRadius;
78 glBegin(GL_LINE_LOOP);
80 for (int lon = 0; lon < 360; ++lon)
82 glVertex3d(xy*sin(M_PI/180*lon), xy*cos(M_PI/180*lon), z);
85 glEnd();
88 // Lines of latitude
89 for (int lon = 0; lon < 360; lon += 5)
91 double x = sin(M_PI/180*lon) * m_meanRadius;
92 double y = cos(M_PI/180*lon) * m_meanRadius;
93 glBegin(GL_LINE_STRIP);
95 for (int lat = 10; lat <= 170; ++lat)
97 double z = cos(M_PI/180*lat) * m_meanRadius;
98 double xy = sin(M_PI/180*lat);
99 glVertex3d(xy*x, xy*y, z);
102 glEnd();
105 foreach(tcGeoData* data, m_data)
107 data->renderSchematic(m_meanRadius);