3
* Copyright (C) 2002 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
#ifndef _STELNAVIGATOR_HPP_
21
#define _STELNAVIGATOR_HPP_
23
#include "VecMath.hpp"
24
#include "StelLocation.hpp"
31
// Conversion in standar Julian time format
32
#define JD_SECOND 0.000011574074074074074074
33
#define JD_MINUTE 0.00069444444444444444444
34
#define JD_HOUR 0.041666666666666666666
40
//! @class StelNavigator
41
//! Manages a navigation context. This includes:
43
//! - viewing direction/fov
44
//! - observer position
45
//! - coordinate changes
46
class StelNavigator : public QObject
49
Q_PROPERTY(double timeRate READ getTimeRate WRITE setTimeRate)
52
// Create and initialise to default a navigation context
58
void updateTime(double deltaTime);
59
void updateTransformMatrices(void);
61
//! Get vision direction
62
void lookAtJ2000(const Vec3d& pos, const Vec3d& up);
64
//! Get the informations on the current location
65
const StelLocation& getCurrentLocation() const;
67
//! Smoothly move the observer to the given location
68
//! @param target the target location
69
//! @param duration direction of view move duration in s
70
//! @param durationIfPlanetChange direction of view + planet travel move duration in s.
71
//! This is used only if the destination planet is different from the starting one.
72
void moveObserverTo(const StelLocation& target, double duration=1., double durationIfPlanetChange=1.);
74
//! Get the sideral time shifted by the observer longitude
75
//! @return the locale sideral time in radian
76
double getLocalSideralTime() const;
78
//! Get the duration of a sideral day for the current observer in day.
79
double getLocalSideralDayLength() const;
81
//! Return the observer heliocentric ecliptic position
82
Vec3d getObserverHeliocentricEclipticPos() const;
85
Vec3d altAzToEquinoxEqu(const Vec3d& v) const {return matAltAzToEquinoxEqu*v;}
86
Vec3d equinoxEquToAltAz(const Vec3d& v) const {return matEquinoxEquToAltAz*v;}
87
Vec3d equinoxEquToJ2000(const Vec3d& v) const {return matEquinoxEquToJ2000*v;}
88
Vec3d altAzToJ2000(const Vec3d& v) const {return matEquinoxEquToJ2000*matAltAzToEquinoxEqu*v;}
89
Vec3d galacticToJ2000(const Vec3d& v) const {return matGalacticToJ2000*v;}
90
Vec3d j2000ToEquinoxEqu(const Vec3d& v) const {return matJ2000ToEquinoxEqu*v;}
91
Vec3d j2000ToAltAz(const Vec3d& v) const {return matJ2000ToAltAz*v;}
92
Vec3d j2000ToGalactic(const Vec3d& v) const {return matJ2000ToGalactic*v;}
93
//! Transform vector from heliocentric ecliptic coordinate to altazimuthal
94
Vec3d heliocentricEclipticToAltAz(const Vec3d& v) const {return matHeliocentricEclipticToAltAz*v;}
95
//! Transform from heliocentric coordinate to equatorial at current equinox (for the planet where the observer stands)
96
Vec3d heliocentricEclipticToEquinoxEqu(const Vec3d& v) const {return matHeliocentricEclipticToEquinoxEqu*v;}
97
//! Transform vector from heliocentric coordinate to false equatorial : equatorial
98
//! coordinate but centered on the observer position (usefull for objects close to earth)
99
Vec3d heliocentricEclipticToEarthPosEquinoxEqu(const Vec3d& v) const {return matAltAzToEquinoxEqu*matHeliocentricEclipticToAltAz*v;}
101
//! Get the modelview matrix for heliocentric ecliptic (Vsop87) drawing
102
const Mat4d getHeliocentricEclipticModelViewMat() const {return matAltAzModelView*matHeliocentricEclipticToAltAz;}
103
//! Get the modelview matrix for observer-centric ecliptic (Vsop87) drawing
104
const Mat4d getObservercentricEclipticModelViewMat() const {return matAltAzModelView*matJ2000ToAltAz*matVsop87ToJ2000;}
105
//! Get the modelview matrix for observer-centric equatorial at equinox drawing
106
const Mat4d getEquinoxEquModelViewMat() const {return matAltAzModelView*matEquinoxEquToAltAz;}
107
//! Get the modelview matrix for observer-centric altazimuthal drawing
108
const Mat4d& getAltAzModelViewMat() const {return matAltAzModelView;}
109
//! Get the modelview matrix for observer-centric J2000 equatorial drawing
110
const Mat4d getJ2000ModelViewMat() const {return matAltAzModelView*matEquinoxEquToAltAz*matJ2000ToEquinoxEqu;}
111
//! Get the modelview matrix for observer-centric Galactic equatorial drawing
112
const Mat4d getGalacticModelViewMat() const {return getJ2000ModelViewMat()*matGalacticToJ2000;}
114
//! Return the startup mode, can be preset|Preset or anything else
115
QString getStartupTimeMode() {return startupTimeMode;}
116
void setStartupTimeMode(const QString& s);
118
//! Rotation matrix from equatorial J2000 to ecliptic (Vsop87)
119
static const Mat4d matJ2000ToVsop87;
120
//! Rotation matrix from ecliptic (Vsop87) to equatorial J2000
121
static const Mat4d matVsop87ToJ2000;
122
//! Rotation matrix from J2000 to Galactic reference frame, using FITS convention.
123
static const Mat4d matJ2000ToGalactic;
124
//! Rotation matrix from J2000 to Galactic reference frame, using FITS convention.
125
static const Mat4d matGalacticToJ2000;
128
//! Set the current date in Julian Day
129
void setJDay(double JD) {JDay=JD;}
130
//! Get the current date in Julian Day
131
double getJDay() const {return JDay;}
133
//! Return the preset sky time in JD
134
double getPresetSkyTime() const {return presetSkyTime;}
135
//! Set the preset sky time from a JD
136
void setPresetSkyTime(double d) {presetSkyTime=d;}
138
//! Set time speed in JDay/sec
139
void setTimeRate(double ts) {timeSpeed=ts; emit timeRateChanged(timeSpeed);}
140
//! Get time speed in JDay/sec
141
double getTimeRate() const {return timeSpeed;}
143
//! Increase the time speed
144
void increaseTimeSpeed();
145
//! Decrease the time speed
146
void decreaseTimeSpeed();
147
//! Increase the time speed, but not as much as with increaseTimeSpeed()
148
void increaseTimeSpeedLess();
149
//! Decrease the time speed but not as much as with decreaseTimeSpeed()
150
void decreaseTimeSpeedLess();
152
//! Set time speed to 0, i.e. freeze the passage of simulation time
153
void setZeroTimeSpeed() {setTimeRate(0);}
154
//! Set real time speed, i.e. 1 sec/sec
155
void setRealTimeSpeed() {setTimeRate(JD_SECOND);}
156
//! Set real time speed or pause simulation if we are already in realtime speed.
157
void toggleRealTimeSpeed() {(!getRealTimeSpeed()) ? setRealTimeSpeed() : setZeroTimeSpeed();}
158
//! Get whether it is real time speed, i.e. 1 sec/sec
159
bool getRealTimeSpeed() const {return (fabs(timeSpeed-JD_SECOND)<0.0000001);}
161
//! Set stellarium time to current real world time
163
//! Set the time to some value, leaving the day the same.
164
void setTodayTime(const QTime& target);
165
//! Get whether the current stellarium time is the real world time
166
bool getIsTimeNow() const;
168
//! get the initial "today time" from the config file
169
QTime getInitTodayTime(void) {return initTodayTime;}
170
//! set the initial "today time" from the config file
171
void setInitTodayTime(const QTime& t) {initTodayTime=t;}
172
//! Set the preset sky time from a QDateTime
173
void setPresetSkyTime(QDateTime dt);
175
//! Add one [Earth, solar] hour to the current simulation time.
176
void addHour() {addSolarDays(0.04166666666666666667);}
177
//! Add one [Earth, solar] day to the current simulation time.
178
void addDay() {addSolarDays(1.0);}
179
//! Add one [Earth, solar] week to the current simulation time.
180
void addWeek() {addSolarDays(7.0);}
182
//! Add one sidereal day to the simulation time. The length of time depends
183
//! on the current planetary body on which the observer is located.
184
void addSiderealDay() {addSiderealDays(1.0);}
185
//! Add one sidereal week to the simulation time. The length of time depends
186
//! on the current planetary body on which the observer is located.
187
void addSiderealWeek() {addSiderealDays(7.0);}
189
//! Subtract one [Earth, solar] hour to the current simulation time.
190
void subtractHour() {addSolarDays(-0.04166666666666666667);}
191
//! Subtract one [Earth, solar] day to the current simulation time.
192
void subtractDay() {addSolarDays(-1.0);}
193
//! Subtract one [Earth, solar] week to the current simulation time.
194
void subtractWeek() {addSolarDays(-7.0);}
196
//! Subtract one sidereal week to the simulation time. The length of time depends
197
//! on the current planetary body on which the observer is located.
198
void subtractSiderealDay() {addSiderealDays(-1.0);}
199
//! Subtract one sidereal week to the simulation time. The length of time depends
200
//! on the current planetary body on which the observer is located.
201
void subtractSiderealWeek() {addSiderealDays(-7.0);}
203
//! Add a number of Earth Solar days to the current simulation time
204
//! @param d the decimal number of days to add (use negative values to subtract)
205
void addSolarDays(double d);
206
//! Add a number of sidereal days to the current simulation time,
207
//! based on the observer body's rotational period.
208
//! @param d the decimal number of sidereal days to add (use negative values to subtract)
209
void addSiderealDays(double d);
211
//! Move the observer to the selected object. This will only do something if
212
//! the selected object is of the correct type - i.e. a planet.
213
void moveObserverToSelected();
215
//! Get the location used by default at startup
216
QString getDefaultLocationID() const {return defaultLocationID;}
217
//! Set the location to use by default at startup
218
void setDefaultLocationID(const QString& id);
221
//! This signal is emitted when the observer location has changed.
222
void locationChanged(StelLocation);
223
//! This signal is emitted when the time rate has changed
224
void timeRateChanged(double rate);
227
// Matrices used for every coordinate transfo
228
Mat4d matHeliocentricEclipticToAltAz; // Transform from heliocentric ecliptic (Vsop87) to observer-centric altazimuthal coordinate
229
Mat4d matAltAzToHeliocentricEcliptic; // Transform from observer-centric altazimuthal coordinate to heliocentric ecliptic (Vsop87)
230
Mat4d matAltAzToEquinoxEqu; // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
231
Mat4d matEquinoxEquToAltAz; // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
232
Mat4d matHeliocentricEclipticToEquinoxEqu;// Transform from heliocentric ecliptic (Vsop87) to earth equatorial coordinate
233
Mat4d matEquinoxEquToJ2000;
234
Mat4d matJ2000ToEquinoxEqu;
235
Mat4d matJ2000ToAltAz;
237
Mat4d matAltAzModelView; // Modelview matrix for observer-centric altazimuthal drawing
240
double timeSpeed; // Positive : forward, Negative : Backward, 1 = 1sec/sec
241
double JDay; // Curent time in Julian day
243
double presetSkyTime;
245
QString startupTimeMode;
247
// The ID of the default startup location
248
QString defaultLocationID;
250
// Position variables
251
StelObserver* position;
254
#endif // _STELNAVIGATOR_HPP_