StelNavigator.cpp   StelNavigator.cpp 
skipping to change at line 28 skipping to change at line 28
*/ */
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelObserver.hpp" #include "StelObserver.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelLocation.hpp"
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include <QSettings> #include <QSettings>
#include <QStringList> #include <QStringList>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
// Init statics transfo matrices // Init statics transfo matrices
// See vsop87.doc: // See vsop87.doc:
const Mat4d StelNavigator::matJ2000ToVsop87(Mat4d::xrotation(-23.4392803055 555555556*(M_PI/180)) * Mat4d::zrotation(0.0000275*(M_PI/180))); const Mat4d StelNavigator::matJ2000ToVsop87(Mat4d::xrotation(-23.4392803055 555555556*(M_PI/180)) * Mat4d::zrotation(0.0000275*(M_PI/180)));
const Mat4d StelNavigator::matVsop87ToJ2000(matJ2000ToVsop87.transpose()); const Mat4d StelNavigator::matVsop87ToJ2000(matJ2000ToVsop87.transpose());
const Mat4d StelNavigator::matJ2000ToGalactic(-0.054875539726, 0.4941094533
12, -0.867666135858, 0, -0.873437108010, -0.444829589425, -0.198076386122,
0, -0.483834985808, 0.746982251810, 0.455983795705, 0, 0, 0, 0, 1);
const Mat4d StelNavigator::matGalacticToJ2000(matJ2000ToGalactic.transpose(
));
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
StelNavigator::StelNavigator() : timeSpeed(JD_SECOND), JDay(0.), position(N ULL) StelNavigator::StelNavigator() : timeSpeed(JD_SECOND), JDay(0.), position(N ULL)
{ {
altAzVisionDirection=Vec3d(1.,0.,0.);
earthEquVisionDirection=Vec3d(1.,0.,0.);
J2000EquVisionDirection=Vec3d(1.,0.,0.); // not correct yet...
viewingMode = ViewHorizon; // default
} }
StelNavigator::~StelNavigator() StelNavigator::~StelNavigator()
{ {
delete position; delete position;
position=NULL; position=NULL;
} }
const Planet *StelNavigator::getHomePlanet(void) const
{
return position->getHomePlanet();
}
void StelNavigator::init() void StelNavigator::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
defaultLocationID = conf->value("init_location/location","Paris, Par is, France").toString(); defaultLocationID = conf->value("init_location/location","Paris, Par is, France").toString();
position = new StelObserver(StelApp::getInstance().getLocationMgr(). locationForSmallString(defaultLocationID)); position = new StelObserver(StelApp::getInstance().getLocationMgr(). locationForSmallString(defaultLocationID));
setTimeNow(); setTimeNow();
setAltAzVisionDirection(Vec3f(1,1e-05,0.2));
// Compute transform matrices between coordinates systems // Compute transform matrices between coordinates systems
updateTransformMatrices(); updateTransformMatrices();
updateModelViewMat();
QString tmpstr = conf->value("navigation/viewing_mode", "horizon").t
oString();
if (tmpstr=="equator")
setViewingMode(StelNavigator::ViewEquator);
else
{
if (tmpstr=="horizon")
setViewingMode(StelNavigator::ViewHorizon);
else
{
qDebug() << "ERROR : Unknown viewing mode type : " <
< tmpstr;
Q_ASSERT(0);
}
}
initViewPos = StelUtils::strToVec3f(conf->value("navigation/init_vie
w_pos").toString());
setAltAzVisionDirection(initViewPos);
// we want to be able to handle the old style preset time, recorded as a double // we want to be able to handle the old style preset time, recorded as a double
// jday, or as a more human readable string... // jday, or as a more human readable string...
bool ok; bool ok;
QString presetTimeStr = conf->value("navigation/preset_sky_time",245 1545.).toString(); QString presetTimeStr = conf->value("navigation/preset_sky_time",245 1545.).toString();
presetSkyTime = presetTimeStr.toDouble(&ok); presetSkyTime = presetTimeStr.toDouble(&ok);
if (ok) if (ok)
qDebug() << "navigation/preset_sky_time is a double - treati ng as jday:" << presetSkyTime; qDebug() << "navigation/preset_sky_time is a double - treati ng as jday:" << presetSkyTime;
else else
{ {
skipping to change at line 171 skipping to change at line 147
return previousResult; return previousResult;
} }
void StelNavigator::addSolarDays(double d) void StelNavigator::addSolarDays(double d)
{ {
setJDay(getJDay() + d); setJDay(getJDay() + d);
} }
void StelNavigator::addSiderealDays(double d) void StelNavigator::addSiderealDays(double d)
{ {
const Planet* home = position->getHomePlanet(); const PlanetP& home = position->getHomePlanet();
if (home->getEnglishName() != "Solar System StelObserver") if (home->getEnglishName() != "Solar System StelObserver")
d *= home->getSiderealDay(); d *= home->getSiderealDay();
setJDay(getJDay() + d); setJDay(getJDay() + d);
} }
void StelNavigator::moveObserverToSelected(void) void StelNavigator::moveObserverToSelected(void)
{ {
StelObjectMgr* objmgr = GETSTELMODULE(StelObjectMgr); StelObjectMgr* objmgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(objmgr); Q_ASSERT(objmgr);
if (objmgr->getWasSelected()) if (objmgr->getWasSelected())
{ {
Planet* pl = dynamic_cast<Planet*>(objmgr->getSelectedObject ()[0].get()); Planet* pl = dynamic_cast<Planet*>(objmgr->getSelectedObject ()[0].data());
if (pl) if (pl)
{ {
// We need to move to the selected planet. Try to ge nerate a location from the current one // We need to move to the selected planet. Try to ge nerate a location from the current one
StelLocation loc = getCurrentLocation(); StelLocation loc = getCurrentLocation();
loc.planetName = pl->getEnglishName(); loc.planetName = pl->getEnglishName();
loc.name = "-"; loc.name = "-";
loc.state = ""; loc.state = "";
moveObserverTo(loc); moveObserverTo(loc);
} }
} }
skipping to change at line 214 skipping to change at line 190
// Smoothly move the observer to the given location // Smoothly move the observer to the given location
void StelNavigator::moveObserverTo(const StelLocation& target, double durat ion, double durationIfPlanetChange) void StelNavigator::moveObserverTo(const StelLocation& target, double durat ion, double durationIfPlanetChange)
{ {
double d = (getCurrentLocation().planetName==target.planetName) ? du ration : durationIfPlanetChange; double d = (getCurrentLocation().planetName==target.planetName) ? du ration : durationIfPlanetChange;
if (d>0.) if (d>0.)
{ {
SpaceShipObserver* newObs = new SpaceShipObserver(getCurrent Location(), target, d); SpaceShipObserver* newObs = new SpaceShipObserver(getCurrent Location(), target, d);
delete position; delete position;
position = newObs; position = newObs;
newObs->update(0);
} }
else else
{ {
delete position; delete position;
position = new StelObserver(target); position = new StelObserver(target);
} }
emit(locationChanged(target));
} }
// Get the sideral time shifted by the observer longitude // Get the sideral time shifted by the observer longitude
double StelNavigator::getLocalSideralTime() const double StelNavigator::getLocalSideralTime() const
{ {
return (position->getHomePlanet()->getSiderealTime(JDay)+position->g etCurrentLocation().longitude)*M_PI/180.; return (position->getHomePlanet()->getSiderealTime(JDay)+position->g etCurrentLocation().longitude)*M_PI/180.;
} }
void StelNavigator::setInitViewDirectionToCurrent(void) //! Get the duration of a sideral day for the current observer in day.
double StelNavigator::getLocalSideralDayLength() const
{ {
initViewPos = altAzVisionDirection; return position->getHomePlanet()->getSiderealDay();
QString dirStr = QString("%1,%2,%3").arg(altAzVisionDirection[0]).ar
g(altAzVisionDirection[1]).arg(altAzVisionDirection[2]);
StelApp::getInstance().getSettings()->setValue("navigation/init_view
_pos", dirStr);
} }
//! Increase the time speed //! Increase the time speed
void StelNavigator::increaseTimeSpeed() void StelNavigator::increaseTimeSpeed()
{ {
double s = getTimeRate(); double s = getTimeRate();
if (s>=JD_SECOND) s*=10.; if (s>=JD_SECOND) s*=10.;
else if (s<-JD_SECOND) s/=10.; else if (s<-JD_SECOND) s/=10.;
else if (s>=0. && s<JD_SECOND) s=JD_SECOND; else if (s>=0. && s<JD_SECOND) s=JD_SECOND;
else if (s>=-JD_SECOND && s<0.) s=0.; else if (s>=-JD_SECOND && s<0.) s=0.;
skipping to change at line 257 skipping to change at line 234
void StelNavigator::decreaseTimeSpeed() void StelNavigator::decreaseTimeSpeed()
{ {
double s = getTimeRate(); double s = getTimeRate();
if (s>JD_SECOND) s/=10.; if (s>JD_SECOND) s/=10.;
else if (s<=-JD_SECOND) s*=10.; else if (s<=-JD_SECOND) s*=10.;
else if (s>-JD_SECOND && s<=0.) s=-JD_SECOND; else if (s>-JD_SECOND && s<=0.) s=-JD_SECOND;
else if (s>0. && s<=JD_SECOND) s=0.; else if (s>0. && s<=JD_SECOND) s=0.;
setTimeRate(s); setTimeRate(s);
} }
/////////////////////////////////////////////////////////////////////////// void StelNavigator::increaseTimeSpeedLess()
/////
void StelNavigator::setAltAzVisionDirection(const Vec3d& _pos)
{ {
altAzVisionDirection = _pos; double s = getTimeRate();
earthEquVisionDirection=altAzToEquinoxEqu(altAzVisionDirection); if (s>=JD_SECOND) s*=2.;
J2000EquVisionDirection = matEquinoxEquToJ2000*earthEquVisionDirecti else if (s<-JD_SECOND) s/=2.;
on; else if (s>=0. && s<JD_SECOND) s=JD_SECOND;
updateModelViewMat(); else if (s>=-JD_SECOND && s<0.) s=0.;
setTimeRate(s);
} }
/////////////////////////////////////////////////////////////////////////// void StelNavigator::decreaseTimeSpeedLess()
/////
void StelNavigator::setEquinoxEquVisionDirection(const Vec3d& _pos)
{ {
earthEquVisionDirection = _pos; double s = getTimeRate();
J2000EquVisionDirection = matEquinoxEquToJ2000*earthEquVisionDirecti if (s>JD_SECOND) s/=2.;
on; else if (s<=-JD_SECOND) s*=2.;
altAzVisionDirection = equinoxEquToAltAz(earthEquVisionDirection); else if (s>-JD_SECOND && s<=0.) s=-JD_SECOND;
updateModelViewMat(); else if (s>0. && s<=JD_SECOND) s=0.;
setTimeRate(s);
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
void StelNavigator::setJ2000EquVisionDirection(const Vec3d& _pos) void StelNavigator::lookAtJ2000(const Vec3d& pos, const Vec3d& aup)
{ {
J2000EquVisionDirection = _pos; Vec3d f(j2000ToAltAz(pos));
earthEquVisionDirection = matJ2000ToEquinoxEqu*J2000EquVisionDirecti Vec3d up(j2000ToAltAz(aup));
on; f.normalize();
altAzVisionDirection = equinoxEquToAltAz(earthEquVisionDirection); up.normalize();
updateModelViewMat();
// Update the model view matrix
Vec3d s(f^up); // y vector
s.normalize();
Vec3d u(s^f); // Up vector in AltAz coordinates
u.normalize();
matAltAzModelView.set(s[0],u[0],-f[0],0.,
s[1],u[1],-f[1],0.,
s[2],u[2],-f[2],0.,
0.,0.,0.,1.);
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Increment time // Increment time
void StelNavigator::updateTime(double deltaTime) void StelNavigator::updateTime(double deltaTime)
{ {
JDay+=timeSpeed*deltaTime; JDay+=timeSpeed*deltaTime;
// Fix time limits to -100000 to +100000 to prevent bugs // Fix time limits to -100000 to +100000 to prevent bugs
if (JDay>38245309.499988) JDay = 38245309.499988; if (JDay>38245309.499988) JDay = 38245309.499988;
if (JDay<-34803211.500012) JDay = -34803211.500012; if (JDay<-34803211.500012) JDay = -34803211.500012;
if (position->isObserverLifeOver()) if (position->isObserverLifeOver())
{ {
// Unselect if the new home planet is the previously selecte d object // Unselect if the new home planet is the previously selecte d object
StelObjectMgr* objmgr = GETSTELMODULE(StelObjectMgr); StelObjectMgr* objmgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(objmgr); Q_ASSERT(objmgr);
if (objmgr->getWasSelected() && objmgr->getSelectedObject()[ 0].get()==position->getHomePlanet()) if (objmgr->getWasSelected() && objmgr->getSelectedObject()[ 0].data()==position->getHomePlanet())
{ {
objmgr->unSelect(); objmgr->unSelect();
} }
StelObserver* newObs = position->getNextObserver(); StelObserver* newObs = position->getNextObserver();
delete position; delete position;
position = newObs; position = newObs;
} }
position->update(deltaTime); position->update(deltaTime);
// Position of sun and all the satellites (ie planets)
SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getMod
uleMgr().getModule("SolarSystem");
solsystem->computePositions(getJDay(), position->getHomePlanet()->ge
tHeliocentricEclipticPos());
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// The non optimized (more clear version is available on the CVS : before d ate 25/07/2003) // The non optimized (more clear version is available on the CVS : before d ate 25/07/2003)
void StelNavigator::updateTransformMatrices(void) void StelNavigator::updateTransformMatrices(void)
{ {
matAltAzToEquinoxEqu = position->getRotAltAzToEquatorial(JDay); matAltAzToEquinoxEqu = position->getRotAltAzToEquatorial(JDay);
matEquinoxEquToAltAz = matAltAzToEquinoxEqu.transpose(); matEquinoxEquToAltAz = matAltAzToEquinoxEqu.transpose();
matEquinoxEquToJ2000 = matVsop87ToJ2000 * position->getRotEquatorial ToVsop87(); matEquinoxEquToJ2000 = matVsop87ToJ2000 * position->getRotEquatorial ToVsop87();
matJ2000ToEquinoxEqu = matEquinoxEquToJ2000.transpose(); matJ2000ToEquinoxEqu = matEquinoxEquToJ2000.transpose();
matJ2000ToAltAz = matEquinoxEquToAltAz*matJ2000ToEquinoxEqu; matJ2000ToAltAz = matEquinoxEquToAltAz*matJ2000ToEquinoxEqu;
matHeliocentricEclipticToEquinoxEqu = matJ2000ToEquinoxEqu * matVsop 87ToJ2000 * Mat4d::translation(-position->getCenterVsop87Pos()); matHeliocentricEclipticToEquinoxEqu = matJ2000ToEquinoxEqu * matVsop 87ToJ2000 * Mat4d::translation(-position->getCenterVsop87Pos());
// These two next have to take into account the position of the obse rver on the earth // These two next have to take into account the position of the obse rver on the earth
Mat4d tmp = matJ2000ToVsop87 * matEquinoxEquToJ2000 * matAltAzToEqui noxEqu; Mat4d tmp = matJ2000ToVsop87 * matEquinoxEquToJ2000 * matAltAzToEqui noxEqu;
matAltAzToHeliocentricEcliptic = Mat4d::translation(position->getCe nterVsop87Pos()) * tmp * matAltAzToHeliocentricEcliptic = Mat4d::translation(position->getCe nterVsop87Pos()) * tmp *
Mat4d::translation(Vec3d(0.,0., position->getD istanceFromCenter())); Mat4d::translation(Vec3d(0 .,0., position->getDistanceFromCenter()));
matHeliocentricEclipticToAltAz = Mat4d::translation(Vec3d(0.,0.,-po sition->getDistanceFromCenter())) * tmp.transpose() * matHeliocentricEclipticToAltAz = Mat4d::translation(Vec3d(0.,0.,-po sition->getDistanceFromCenter())) * tmp.transpose() *
Mat4d::translation(-position->getCenterVsop87P os()); Mat4d::translation(-positi on->getCenterVsop87Pos());
} }
void StelNavigator::setStartupTimeMode(const QString& s) void StelNavigator::setStartupTimeMode(const QString& s)
{ {
startupTimeMode = s; startupTimeMode = s;
} }
/////////////////////////////////////////////////////////////////////////// ///// /////////////////////////////////////////////////////////////////////////// /////
// Update the modelview matrices
void StelNavigator::updateModelViewMat(void)
{
Vec3d f;
if( viewingMode == ViewEquator)
{
// view will use equatorial coordinates, so that north is al
ways up
f = earthEquVisionDirection;
}
else
{
// view will correct for horizon (always down)
f = altAzVisionDirection;
}
f.normalize();
Vec3d s(f[1],-f[0],0.);
if( viewingMode == ViewEquator)
{
// convert everything back to local coord
f = altAzVisionDirection;
f.normalize();
s = equinoxEquToAltAz( s );
}
Vec3d u(s^f);
s.normalize();
u.normalize();
matAltAzModelView.set(s[0],u[0],-f[0],0.,
s[1],u[1],-f[1],0.,
s[2],u[2],-f[2],0.,
0.,0.,0.,1.);
}
///////////////////////////////////////////////////////////////////////////
/////
// Return the observer heliocentric position // Return the observer heliocentric position
Vec3d StelNavigator::getObserverHeliocentricEclipticPos(void) const Vec3d StelNavigator::getObserverHeliocentricEclipticPos(void) const
{ {
static const Vec3d v(0); return Vec3d(matAltAzToHeliocentricEcliptic[12], matAltAzToHeliocent
return matAltAzToHeliocentricEcliptic*v; ricEcliptic[13], matAltAzToHeliocentricEcliptic[14]);
} }
void StelNavigator::setPresetSkyTime(QDateTime dt) void StelNavigator::setPresetSkyTime(QDateTime dt)
{ {
setPresetSkyTime(StelUtils::qDateTimeToJd(dt)); setPresetSkyTime(StelUtils::qDateTimeToJd(dt));
} }
///////////////////////////////////////////////////////////////////////////
/////
// Set type of viewing mode (align with horizon or equatorial coordinates)
void StelNavigator::setViewingMode(ViewingModeType viewMode)
{
viewingMode = viewMode;
// TODO: include some nice smoothing function trigger here to rotate
between
// the two modes
}
 End of changes. 25 change blocks. 
105 lines changed or deleted 53 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/