3
* Copyright (C) 2003 Fabien Chereau
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program 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 this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#include "stellarium.h"
25
#include "stel_utility.h"
26
#include "stellastro.h"
27
#include "init_parser.h"
28
#include "observator.h"
29
#include "solarsystem.h"
31
#include "translator.h"
34
Observator::Observator(const SolarSystem &ssystem)
35
:ssystem(ssystem), planet(0),
36
longitude(0.), latitude(0.), altitude(0)
38
name = L"Anonymous_Location";
42
Observator::~Observator()
46
Vec3d Observator::getCenterVsop87Pos(void) const {
47
return planet->get_heliocentric_ecliptic_pos();
50
double Observator::getDistanceFromCenter(void) const {
51
return planet->getRadius() + (altitude/(1000*AU));
54
Mat4d Observator::getRotLocalToEquatorial(double jd) const {
55
double lat = latitude;
56
// TODO: Figure out how to keep continuity in sky as reach poles
57
// otherwise sky jumps in rotation when reach poles in equatorial mode
59
if( lat > 89.5 ) lat = 89.5;
60
if( lat < -89.5 ) lat = -89.5;
61
return Mat4d::zrotation((planet->getSiderealTime(jd)+longitude)*(M_PI/180.))
62
* Mat4d::yrotation((90.-lat)*(M_PI/180.));
65
Mat4d Observator::getRotEquatorialToVsop87(void) const {
66
return planet->getRotEquatorialToVsop87();
69
void Observator::load(const string& file, const string& section)
73
if (!conf.find_entry(section))
75
cerr << "ERROR : Can't find observator section " << section << " in file " << file << endl;
81
bool Observator::setHomePlanet(const string &english_name) {
82
Planet *p = ssystem.searchByEnglishName(english_name);
91
void Observator::load(const InitParser& conf, const string& section)
93
name = _(conf.get_str(section, "name").c_str());
95
for (string::size_type i=0;i<name.length();++i)
97
if (name[i]=='_') name[i]=' ';
100
if (!setHomePlanet(conf.get_str(section, "home_planet", "Earth"))) {
101
planet = ssystem.getEarth();
104
cout << "Loading location: \"" << StelUtility::wstringToString(name) <<"\", on " << planet->getEnglishName();
106
// printf("(home_planet should be: \"%s\" is: \"%s\") ",
107
// conf.get_str(section, "home_planet").c_str(),
108
// planet->getEnglishName().c_str());
109
latitude = get_dec_angle(conf.get_str(section, "latitude"));
110
longitude = get_dec_angle(conf.get_str(section, "longitude"));
111
altitude = conf.get_int(section, "altitude");
112
set_landscape_name(conf.get_str(section, "landscape_name", "sea"));
114
printf(" (landscape is: \"%s\")\n", landscape_name.c_str());
118
void Observator::set_landscape_name(const string s) {
120
// need to lower case name because config file parser lowercases section names
122
transform(x.begin(), x.end(), x.begin(), ::tolower);
126
void Observator::save(const string& file, const string& section) const
128
printf("Saving location %s to file %s\n",StelUtility::wstringToString(name).c_str(), file.c_str());
133
setConf(conf,section);
139
// change settings but don't write to files
140
void Observator::setConf(InitParser & conf, const string& section) const
143
conf.set_str(section + ":name", StelUtility::wstringToString(name));
144
conf.set_str(section + ":home_planet", planet->getEnglishName());
145
conf.set_str(section + ":latitude",
146
StelUtility::wstringToString(
147
StelUtility::printAngleDMS(latitude*M_PI/180.0,
149
conf.set_str(section + ":longitude",
150
StelUtility::wstringToString(
151
StelUtility::printAngleDMS(longitude*M_PI/180.0,
154
conf.set_int(section + ":altitude", altitude);
155
conf.set_str(section + ":landscape_name", landscape_name);
159
// for platforms without built in timegm function
160
// taken from the timegm man page
161
time_t my_timegm (struct tm *tm) {
171
snprintf(tmpstr, 255, "TZ=%s", tz);
182
// move gradually to a new observation location
183
void Observator::move_to(double lat, double lon, double alt, int duration, const wstring& _name)
187
start_lat = latitude;
190
start_lon = longitude;
193
start_alt = altitude;
196
move_to_coef = 1.0f/duration;
200
// printf("coef = %f\n", move_to_coef);
203
wstring Observator::get_name(void) const
208
string Observator::getHomePlanetEnglishName(void) const {
209
return planet ? planet->getEnglishName() : "";
212
wstring Observator::getHomePlanetNameI18(void) const {
213
return planet ? planet->getNameI18() : L"";
216
// for moving observator position gradually
217
// TODO need to work on direction of motion...
218
void Observator::update(int delta_time) {
220
move_to_mult += move_to_coef*delta_time;
222
if( move_to_mult >= 1) {
227
latitude = start_lat - move_to_mult*(start_lat-end_lat);
228
longitude = start_lon - move_to_mult*(start_lon-end_lon);
229
altitude = int(start_alt - move_to_mult*(start_alt-end_alt));