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.
20
#include "Navigator.hpp"
21
#include "StelUtils.hpp"
22
#include "SolarSystem.hpp"
23
#include "InitParser.hpp"
24
#include "Observer.hpp"
26
////////////////////////////////////////////////////////////////////////////////
27
Navigator::Navigator(Observer* obs) : time_speed(JD_SECOND), JDay(0.), position(obs)
31
printf("ERROR : Can't create a Navigator without a valid Observator\n");
34
local_vision=Vec3d(1.,0.,0.);
35
equ_vision=Vec3d(1.,0.,0.);
36
prec_equ_vision=Vec3d(1.,0.,0.); // not correct yet...
37
viewing_mode = VIEW_HORIZON; // default
41
Navigator::~Navigator()
44
const Planet *Navigator::getHomePlanet(void) const
46
return position->getHomePlanet();
49
void Navigator::init(const InitParser& conf)
52
setLocalVision(Vec3f(1,1e-05,0.2));
53
// Compute transform matrices between coordinates systems
54
updateTransformMatrices();
56
string tmpstr = conf.get_str("navigation:viewing_mode");
57
if (tmpstr=="equator")
58
setViewingMode(Navigator::VIEW_EQUATOR);
61
if (tmpstr=="horizon")
62
setViewingMode(Navigator::VIEW_HORIZON);
65
cerr << "ERROR : Unknown viewing mode type : " << tmpstr << endl;
69
initViewPos = StelUtils::str_to_vec3f(conf.get_str("navigation:init_view_pos"));
70
setLocalVision(initViewPos);
73
PresetSkyTime = conf.get_double ("navigation","preset_sky_time",2451545.);
74
StartupTimeMode = conf.get_str("navigation:startup_time_mode"); // Can be "now" or "preset"
75
if (StartupTimeMode=="preset" || StartupTimeMode=="Preset")
76
setJDay(PresetSkyTime - get_GMT_shift_from_system(PresetSkyTime) * JD_HOUR);
80
//! Set stellarium time to current real world time
81
void Navigator::setTimeNow()
83
setJDay(StelUtils::getJDFromSystem());
86
//! Get whether the current stellarium time is the real world time
87
bool Navigator::getIsTimeNow(void) const
89
// cache last time to prevent to much slow system call
90
static double lastJD = getJDay();
91
static bool previousResult = (fabs(getJDay()-StelUtils::getJDFromSystem())<JD_SECOND);
92
if (fabs(lastJD-getJDay())>JD_SECOND/4)
95
previousResult = (fabs(getJDay()-StelUtils::getJDFromSystem())<JD_SECOND);
97
return previousResult;
101
////////////////////////////////////////////////////////////////////////////////
102
void Navigator::setLocalVision(const Vec3d& _pos)
105
equ_vision=local_to_earth_equ(local_vision);
106
prec_equ_vision = mat_earth_equ_to_j2000*equ_vision;
109
////////////////////////////////////////////////////////////////////////////////
110
void Navigator::setEquVision(const Vec3d& _pos)
113
prec_equ_vision = mat_earth_equ_to_j2000*equ_vision;
114
local_vision = earth_equ_to_local(equ_vision);
117
////////////////////////////////////////////////////////////////////////////////
118
void Navigator::setPrecEquVision(const Vec3d& _pos)
120
prec_equ_vision = _pos;
121
equ_vision = mat_j2000_to_earth_equ*prec_equ_vision;
122
local_vision = earth_equ_to_local(equ_vision);
125
////////////////////////////////////////////////////////////////////////////////
127
void Navigator::updateTime(int delta_time)
129
JDay+=time_speed*(double)delta_time/1000.;
131
// Fix time limits to -100000 to +100000 to prevent bugs
132
if (JDay>38245309.499988) JDay = 38245309.499988;
133
if (JDay<-34803211.500012) JDay = -34803211.500012;
136
////////////////////////////////////////////////////////////////////////////////
137
// The non optimized (more clear version is available on the CVS : before date 25/07/2003)
141
const Mat4d mat_j2000_to_vsop87(
142
Mat4d::xrotation(-23.4392803055555555556*(M_PI/180)) *
143
Mat4d::zrotation(0.0000275*(M_PI/180)));
145
const Mat4d mat_vsop87_to_j2000(mat_j2000_to_vsop87.transpose());
148
void Navigator::updateTransformMatrices(void)
150
mat_local_to_earth_equ = position->getRotLocalToEquatorial(JDay);
151
mat_earth_equ_to_local = mat_local_to_earth_equ.transpose();
153
mat_earth_equ_to_j2000 = mat_vsop87_to_j2000
154
* position->getRotEquatorialToVsop87();
155
mat_j2000_to_earth_equ = mat_earth_equ_to_j2000.transpose();
157
mat_helio_to_earth_equ =
158
mat_j2000_to_earth_equ *
159
mat_vsop87_to_j2000 *
160
Mat4d::translation(-position->getCenterVsop87Pos());
163
// These two next have to take into account the position of the observer on the earth
165
mat_j2000_to_vsop87 *
166
mat_earth_equ_to_j2000 *
167
mat_local_to_earth_equ;
169
mat_local_to_helio = Mat4d::translation(position->getCenterVsop87Pos()) *
171
Mat4d::translation(Vec3d(0.,0., position->getDistanceFromCenter()));
173
mat_helio_to_local = Mat4d::translation(Vec3d(0.,0.,-position->getDistanceFromCenter())) *
175
Mat4d::translation(-position->getCenterVsop87Pos());
178
////////////////////////////////////////////////////////////////////////////////
179
// Update the modelview matrices
180
void Navigator::updateModelViewMat(void)
185
if( viewing_mode == VIEW_EQUATOR)
187
// view will use equatorial coordinates, so that north is always up
192
// view will correct for horizon (always down)
198
Vec3d s(f[1],-f[0],0.);
201
if( viewing_mode == VIEW_EQUATOR)
203
// convert everything back to local coord
206
s = earth_equ_to_local( s );
213
mat_local_to_eye.set(s[0],u[0],-f[0],0.,
219
// mat_local_to_eye = Mat4d::zrotation(0.5*M_PI) * mat_local_to_eye;
221
mat_earth_equ_to_eye = mat_local_to_eye*mat_earth_equ_to_local;
222
mat_helio_to_eye = mat_local_to_eye*mat_helio_to_local;
223
mat_j2000_to_eye = mat_earth_equ_to_eye*mat_j2000_to_earth_equ;
226
////////////////////////////////////////////////////////////////////////////////
227
// Return the observer heliocentric position
228
Vec3d Navigator::getObserverHelioPos(void) const
231
return mat_local_to_helio*v;
236
////////////////////////////////////////////////////////////////////////////////
237
// Set type of viewing mode (align with horizon or equatorial coordinates)
238
void Navigator::setViewingMode(ViewingModeType view_mode)
240
viewing_mode = view_mode;
242
// TODO: include some nice smoothing function trigger here to rotate between