StelCore.cpp   StelCore.cpp 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelNavigator.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelProjectorClasses.hpp" #include "StelProjectorClasses.hpp"
#include "StelToneReproducer.hpp" #include "StelToneReproducer.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelGeodesicGrid.hpp" #include "StelGeodesicGrid.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelLocationMgr.hpp"
#include "StelObserver.hpp"
#include "StelObjectMgr.hpp"
#include "Planet.hpp"
#include "SolarSystem.hpp"
#include <QtOpenGL> #include <QtOpenGL>
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QMetaEnum> #include <QMetaEnum>
/************************************************************************* // Init statics transfo matrices
Constructor // See vsop87.doc:
*************************************************************************/ const Mat4d StelCore::matJ2000ToVsop87(Mat4d::xrotation(-23.439280305555555
StelCore::StelCore() : navigation(NULL), movementMgr(NULL), geodesicGrid(NU 5556*(M_PI/180)) * Mat4d::zrotation(0.0000275*(M_PI/180)));
LL), currentProjectionType(ProjectionStereographic) const Mat4d StelCore::matVsop87ToJ2000(matJ2000ToVsop87.transpose());
const Mat4d StelCore::matJ2000ToGalactic(-0.054875539726, 0.494109453312, -
0.867666135858, 0, -0.873437108010, -0.444829589425, -0.198076386122, 0, -0
.483834985808, 0.746982251810, 0.455983795705, 0, 0, 0, 0, 1);
const Mat4d StelCore::matGalacticToJ2000(matJ2000ToGalactic.transpose());
const double StelCore::JD_SECOND=0.000011574074074074074074;
const double StelCore::JD_MINUTE=0.00069444444444444444444;
const double StelCore::JD_HOUR =0.041666666666666666666;
const double StelCore::JD_DAY =1.;
StelCore::StelCore() : movementMgr(NULL), geodesicGrid(NULL), currentProjec
tionType(ProjectionStereographic), position(NULL), timeSpeed(JD_SECOND), JD
ay(0.)
{ {
toneConverter = new StelToneReproducer(); toneConverter = new StelToneReproducer();
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
// Create and initialize the default projector params // Create and initialize the default projector params
QString tmpstr = conf->value("projection/viewport").toString(); QString tmpstr = conf->value("projection/viewport").toString();
currentProjectorParams.maskType = StelProjector::stringToMaskType(tm pstr); currentProjectorParams.maskType = StelProjector::stringToMaskType(tm pstr);
const int viewport_width = conf->value("projection/viewport_width", currentProjectorParams.viewportXywh[2]).toInt(); const int viewport_width = conf->value("projection/viewport_width", currentProjectorParams.viewportXywh[2]).toInt();
const int viewport_height = conf->value("projection/viewport_height" , currentProjectorParams.viewportXywh[3]).toInt(); const int viewport_height = conf->value("projection/viewport_height" , currentProjectorParams.viewportXywh[3]).toInt();
const int viewport_x = conf->value("projection/viewport_x", 0).toInt (); const int viewport_x = conf->value("projection/viewport_x", 0).toInt ();
skipping to change at line 64 skipping to change at line 78
const float viewportCenterX = conf->value("projection/viewport_cente r_x",0.5f*viewport_width).toFloat(); const float viewportCenterX = conf->value("projection/viewport_cente r_x",0.5f*viewport_width).toFloat();
const float viewportCenterY = conf->value("projection/viewport_cente r_y",0.5f*viewport_height).toFloat(); const float viewportCenterY = conf->value("projection/viewport_cente r_y",0.5f*viewport_height).toFloat();
currentProjectorParams.viewportCenter.set(viewportCenterX, viewportC enterY); currentProjectorParams.viewportCenter.set(viewportCenterX, viewportC enterY);
currentProjectorParams.viewportFovDiameter = conf->value("projection /viewport_fov_diameter", qMin(viewport_width,viewport_height)).toFloat(); currentProjectorParams.viewportFovDiameter = conf->value("projection /viewport_fov_diameter", qMin(viewport_width,viewport_height)).toFloat();
currentProjectorParams.flipHorz = conf->value("projection/flip_horz" ,false).toBool(); currentProjectorParams.flipHorz = conf->value("projection/flip_horz" ,false).toBool();
currentProjectorParams.flipVert = conf->value("projection/flip_vert" ,false).toBool(); currentProjectorParams.flipVert = conf->value("projection/flip_vert" ,false).toBool();
currentProjectorParams.gravityLabels = conf->value("viewing/flag_gra vity_labels").toBool(); currentProjectorParams.gravityLabels = conf->value("viewing/flag_gra vity_labels").toBool();
} }
/*************************************************************************
Destructor
*************************************************************************/
StelCore::~StelCore() StelCore::~StelCore()
{ {
delete navigation; navigation=NULL;
delete toneConverter; toneConverter=NULL; delete toneConverter; toneConverter=NULL;
delete geodesicGrid; geodesicGrid=NULL; delete geodesicGrid; geodesicGrid=NULL;
delete skyDrawer; skyDrawer=NULL; delete skyDrawer; skyDrawer=NULL;
delete position; position=NULL;
} }
/************************************************************************* /*************************************************************************
Load core data and initialize with default values Load core data and initialize with default values
*************************************************************************/ *************************************************************************/
void StelCore::init() void StelCore::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
// StelNavigator defaultLocationID = conf->value("init_location/location","error").to
navigation = new StelNavigator(); String();
navigation->init(); bool ok;
StelLocation location = StelApp::getInstance().getLocationMgr().loca
tionForString(defaultLocationID, &ok);
if (!ok)
{
qWarning() << "Warning: location" << defaultLocationID << "i
s unknown.";
}
position = new StelObserver(location);
// Time stuff
setTimeNow();
// We want to be able to handle the old style preset time, recorded
as a double
// jday, or as a more human readable string...
QString presetTimeStr = conf->value("navigation/preset_sky_time",245
1545.).toString();
presetSkyTime = presetTimeStr.toDouble(&ok);
if (ok)
qDebug() << "navigation/preset_sky_time is a double - treati
ng as jday:" << presetSkyTime;
else
{
qDebug() << "navigation/preset_sky_time was not a double, tr
eating as string date:" << presetTimeStr;
presetSkyTime = StelUtils::qDateTimeToJd(QDateTime::fromStri
ng(presetTimeStr));
}
setInitTodayTime(QTime::fromString(conf->value("navigation/today_tim
e", "22:00").toString()));
startupTimeMode = conf->value("navigation/startup_time_mode", "actua
l").toString().toLower();
if (startupTimeMode=="preset")
setJDay(presetSkyTime - StelUtils::getGMTShiftFromQT(presetS
kyTime) * JD_HOUR);
else if (startupTimeMode=="today")
setTodayTime(getInitTodayTime());
// Compute transform matrices between coordinates systems
updateTransformMatrices();
movementMgr = new StelMovementMgr(this); movementMgr = new StelMovementMgr(this);
movementMgr->init(); movementMgr->init();
currentProjectorParams.fov = movementMgr->getInitFov(); currentProjectorParams.fov = movementMgr->getInitFov();
StelApp::getInstance().getModuleMgr().registerModule(movementMgr); StelApp::getInstance().getModuleMgr().registerModule(movementMgr);
QString tmpstr = conf->value("projection/type", "stereographic").toS
tring();
setCurrentProjectionTypeKey(tmpstr);
skyDrawer = new StelSkyDrawer(this); skyDrawer = new StelSkyDrawer(this);
skyDrawer->init(); skyDrawer->init();
QString tmpstr = conf->value("projection/type", "stereographic").toS
tring();
setCurrentProjectionTypeKey(tmpstr);
} }
// Get the shared instance of StelGeodesicGrid. // Get the shared instance of StelGeodesicGrid.
// The returned instance is garanteed to allow for at least maxLevel levels // The returned instance is garanteed to allow for at least maxLevel levels
const StelGeodesicGrid* StelCore::getGeodesicGrid(int maxLevel) const const StelGeodesicGrid* StelCore::getGeodesicGrid(int maxLevel) const
{ {
if (geodesicGrid==NULL) if (geodesicGrid==NULL)
{ {
geodesicGrid = new StelGeodesicGrid(maxLevel); geodesicGrid = new StelGeodesicGrid(maxLevel);
} }
skipping to change at line 121 skipping to change at line 161
return geodesicGrid; return geodesicGrid;
} }
StelProjectorP StelCore::getProjection2d() const StelProjectorP StelCore::getProjection2d() const
{ {
StelProjectorP prj(new StelProjector2d()); StelProjectorP prj(new StelProjector2d());
prj->init(currentProjectorParams); prj->init(currentProjectorParams);
return prj; return prj;
} }
// Get an instance of projector using the current display parameters from N StelProjectorP StelCore::getProjection(StelProjector::ModelViewTranformP mo
avigation, StelMovementMgr delViewTransform, ProjectionType projType) const
// and using the given modelview matrix
StelProjectorP StelCore::getProjection(const Mat4d& modelViewMat, Projectio
nType projType) const
{ {
if (projType==1000) if (projType==1000)
projType = currentProjectionType; projType = currentProjectionType;
StelProjectorP prj; StelProjectorP prj;
switch (projType) switch (projType)
{ {
case ProjectionPerspective: case ProjectionPerspective:
prj = StelProjectorP(new StelProjectorPerspective(mo delViewMat)); prj = StelProjectorP(new StelProjectorPerspective(mo delViewTransform));
break; break;
case ProjectionEqualArea: case ProjectionEqualArea:
prj = StelProjectorP(new StelProjectorEqualArea(mode lViewMat)); prj = StelProjectorP(new StelProjectorEqualArea(mode lViewTransform));
break; break;
case ProjectionStereographic: case ProjectionStereographic:
prj = StelProjectorP(new StelProjectorStereographic( modelViewMat)); prj = StelProjectorP(new StelProjectorStereographic( modelViewTransform));
break; break;
case ProjectionFisheye: case ProjectionFisheye:
prj = StelProjectorP(new StelProjectorFisheye(modelV iewMat)); prj = StelProjectorP(new StelProjectorFisheye(modelV iewTransform));
break; break;
case ProjectionHammer: case ProjectionHammer:
prj = StelProjectorP(new StelProjectorHammer(modelVi ewMat)); prj = StelProjectorP(new StelProjectorHammer(modelVi ewTransform));
break; break;
case ProjectionCylinder: case ProjectionCylinder:
prj = StelProjectorP(new StelProjectorCylinder(model ViewMat)); prj = StelProjectorP(new StelProjectorCylinder(model ViewTransform));
break; break;
case ProjectionMercator: case ProjectionMercator:
prj = StelProjectorP(new StelProjectorMercator(model ViewMat)); prj = StelProjectorP(new StelProjectorMercator(model ViewTransform));
break; break;
case ProjectionOrthographic: case ProjectionOrthographic:
prj = StelProjectorP(new StelProjectorOrthographic(m odelViewMat)); prj = StelProjectorP(new StelProjectorOrthographic(m odelViewTransform));
break; break;
default: default:
qWarning() << "Unknown projection type: " << (int)(p rojType) << "using ProjectionStereographic instead"; qWarning() << "Unknown projection type: " << (int)(p rojType) << "using ProjectionStereographic instead";
prj = StelProjectorP(new StelProjectorStereographic( modelViewMat)); prj = StelProjectorP(new StelProjectorStereographic( modelViewTransform));
Q_ASSERT(0); Q_ASSERT(0);
} }
prj->init(currentProjectorParams); prj->init(currentProjectorParams);
return prj; return prj;
} }
// Get an instance of projector using the current display parameters from N avigation, StelMovementMgr // Get an instance of projector using the current display parameters from N avigation, StelMovementMgr
StelProjectorP StelCore::getProjection(FrameType frameType, ProjectionType projType) const StelProjectorP StelCore::getProjection(FrameType frameType, RefractionMode refractionMode) const
{ {
switch (frameType) switch (frameType)
{ {
case FrameAltAz: case FrameAltAz:
return getProjection(navigation->getAltAzModelViewMa t(), projType); return getProjection(getAltAzModelViewTransform(refr actionMode));
case FrameHeliocentricEcliptic: case FrameHeliocentricEcliptic:
return getProjection(navigation->getHeliocentricEcli pticModelViewMat(), projType); return getProjection(getHeliocentricEclipticModelVie wTransform(refractionMode));
case FrameObservercentricEcliptic: case FrameObservercentricEcliptic:
return getProjection(navigation->getObservercentricE clipticModelViewMat(), projType); return getProjection(getObservercentricEclipticModel ViewTransform(refractionMode));
case FrameEquinoxEqu: case FrameEquinoxEqu:
return getProjection(navigation->getEquinoxEquModelV iewMat(), projType); return getProjection(getEquinoxEquModelViewTransform (refractionMode));
case FrameJ2000: case FrameJ2000:
return getProjection(navigation->getJ2000ModelViewMa t(), projType); return getProjection(getJ2000ModelViewTransform(refr actionMode));
case FrameGalactic: case FrameGalactic:
return getProjection(navigation->getGalacticModelVi ewMat(), projType); return getProjection(getGalacticModelViewTransform( refractionMode));
default: default:
qDebug() << "Unknown reference frame type: " << (int )frameType << "."; qDebug() << "Unknown reference frame type: " << (int )frameType << ".";
} }
Q_ASSERT(0); Q_ASSERT(0);
return getProjection2d(); return getProjection2d();
} }
// Handle the resizing of the window // Handle the resizing of the window
void StelCore::windowHasBeenResized(float x, float y, float width, float he ight) void StelCore::windowHasBeenResized(float x, float y, float width, float he ight)
{ {
skipping to change at line 203 skipping to change at line 241
currentProjectorParams.viewportCenter.set(x+0.5*width, y+0.5*height) ; currentProjectorParams.viewportCenter.set(x+0.5*width, y+0.5*height) ;
currentProjectorParams.viewportFovDiameter = qMin(width,height); currentProjectorParams.viewportFovDiameter = qMin(width,height);
} }
/************************************************************************* /*************************************************************************
Update all the objects in function of the time Update all the objects in function of the time
*************************************************************************/ *************************************************************************/
void StelCore::update(double deltaTime) void StelCore::update(double deltaTime)
{ {
// Update the position of observation and time and recompute planet positions etc... // Update the position of observation and time and recompute planet positions etc...
navigation->updateTime(deltaTime); updateTime(deltaTime);
// Transform matrices between coordinates systems // Transform matrices between coordinates systems
navigation->updateTransformMatrices(); updateTransformMatrices();
// Update direction of vision/Zoom level // Update direction of vision/Zoom level
movementMgr->updateMotion(deltaTime); movementMgr->updateMotion(deltaTime);
currentProjectorParams.fov = movementMgr->getCurrentFov(); currentProjectorParams.fov = movementMgr->getCurrentFov();
skyDrawer->update(deltaTime); skyDrawer->update(deltaTime);
} }
/************************************************************************* /*************************************************************************
skipping to change at line 247 skipping to change at line 285
{ {
StelPainter sPainter(getProjection(StelCore::FrameJ2000)); StelPainter sPainter(getProjection(StelCore::FrameJ2000));
sPainter.drawViewportShape(); sPainter.drawViewportShape();
} }
void StelCore::setCurrentProjectionType(ProjectionType type) void StelCore::setCurrentProjectionType(ProjectionType type)
{ {
currentProjectionType=type; currentProjectionType=type;
const double savedFov = currentProjectorParams.fov; const double savedFov = currentProjectorParams.fov;
currentProjectorParams.fov = 0.0001; // Avoid crash currentProjectorParams.fov = 0.0001; // Avoid crash
double newMaxFov = getProjection(Mat4d::identity())->getMaxFov(); double newMaxFov = getProjection(StelProjector::ModelViewTranformP(n ew StelProjector::Mat4dTransform(Mat4d::identity())))->getMaxFov();
movementMgr->setMaxFov(newMaxFov); movementMgr->setMaxFov(newMaxFov);
currentProjectorParams.fov = qMin(newMaxFov, savedFov); currentProjectorParams.fov = qMin(newMaxFov, savedFov);
} }
//! Set the current projection type to use //! Set the current projection type to use
void StelCore::setCurrentProjectionTypeKey(QString key) void StelCore::setCurrentProjectionTypeKey(QString key)
{ {
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf Enumerator("ProjectionType")); const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf Enumerator("ProjectionType"));
ProjectionType newType = (ProjectionType)en.keyToValue(key.toAscii() .data()); ProjectionType newType = (ProjectionType)en.keyToValue(key.toAscii() .data());
if (newType<0) if (newType<0)
skipping to change at line 285 skipping to change at line 323
QStringList l; QStringList l;
for (int i=0;i<en.keyCount();++i) for (int i=0;i<en.keyCount();++i)
l << en.key(i); l << en.key(i);
return l; return l;
} }
//! Get the translated projection name from its TypeKey for the current loc ale //! Get the translated projection name from its TypeKey for the current loc ale
QString StelCore::projectionTypeKeyToNameI18n(const QString& key) const QString StelCore::projectionTypeKeyToNameI18n(const QString& key) const
{ {
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf Enumerator("ProjectionType")); const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf Enumerator("ProjectionType"));
QString s(getProjection(StelCore::FrameJ2000, (ProjectionType)en.key sToValue(key.toAscii()))->getNameI18()); QString s(getProjection(StelProjector::ModelViewTranformP(new StelPr ojector::Mat4dTransform(Mat4d::identity())), (ProjectionType)en.keyToValue( key.toAscii()))->getNameI18());
return s; return s;
} }
//! Get the projection TypeKey from its translated name for the current loc ale //! Get the projection TypeKey from its translated name for the current loc ale
QString StelCore::projectionNameI18nToTypeKey(const QString& nameI18n) cons t QString StelCore::projectionNameI18nToTypeKey(const QString& nameI18n) cons t
{ {
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf Enumerator("ProjectionType")); const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf Enumerator("ProjectionType"));
for (int i=0;i<en.keyCount();++i) for (int i=0;i<en.keyCount();++i)
{ {
if (getProjection(StelCore::FrameJ2000, (ProjectionType)i)-> getNameI18()==nameI18n) if (getProjection(StelProjector::ModelViewTranformP(new Stel Projector::Mat4dTransform(Mat4d::identity())), (ProjectionType)i)->getNameI 18()==nameI18n)
return en.valueToKey(i); return en.valueToKey(i);
} }
// Unknown translated name // Unknown translated name
Q_ASSERT(0); Q_ASSERT(0);
return en.valueToKey(ProjectionStereographic); return en.valueToKey(ProjectionStereographic);
} }
void StelCore::lookAtJ2000(const Vec3d& pos, const Vec3d& aup)
{
Vec3d f(j2000ToAltAz(pos, RefractionOff));
Vec3d up(j2000ToAltAz(aup, RefractionOff));
f.normalize();
up.normalize();
// 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.);
invertMatAltAzModelView = matAltAzModelView.inverse();
}
void StelCore::updateTransformMatrices()
{
matAltAzToEquinoxEqu = position->getRotAltAzToEquatorial(JDay);
matEquinoxEquToAltAz = matAltAzToEquinoxEqu.transpose();
matEquinoxEquToJ2000 = matVsop87ToJ2000 * position->getRotEquatorial
ToVsop87();
matJ2000ToEquinoxEqu = matEquinoxEquToJ2000.transpose();
matJ2000ToAltAz = matEquinoxEquToAltAz*matJ2000ToEquinoxEqu;
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
Mat4d tmp = matJ2000ToVsop87 * matEquinoxEquToJ2000 * matAltAzToEqui
noxEqu;
matAltAzToHeliocentricEcliptic = Mat4d::translation(position->getCe
nterVsop87Pos()) * tmp *
Mat4d::translation(Vec3d(0
.,0., position->getDistanceFromCenter()));
matHeliocentricEclipticToAltAz = Mat4d::translation(Vec3d(0.,0.,-po
sition->getDistanceFromCenter())) * tmp.transpose() *
Mat4d::translation(-positi
on->getCenterVsop87Pos());
}
// Return the observer heliocentric position
Vec3d StelCore::getObserverHeliocentricEclipticPos() const
{
return Vec3d(matAltAzToHeliocentricEcliptic[12], matAltAzToHeliocent
ricEcliptic[13], matAltAzToHeliocentricEcliptic[14]);
}
// Set the location to use by default at startup
void StelCore::setDefaultLocationID(const QString& id)
{
defaultLocationID = id;
StelApp::getInstance().getLocationMgr().locationForSmallString(id);
QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
conf->setValue("init_location/location", id);
}
void StelCore::moveObserverToSelected()
{
StelObjectMgr* objmgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(objmgr);
if (objmgr->getWasSelected())
{
Planet* pl = dynamic_cast<Planet*>(objmgr->getSelectedObject
()[0].data());
if (pl)
{
// We need to move to the selected planet. Try to ge
nerate a location from the current one
StelLocation loc = getCurrentLocation();
loc.planetName = pl->getEnglishName();
loc.name = "-";
loc.state = "";
moveObserverTo(loc);
}
}
StelMovementMgr* mmgr = GETSTELMODULE(StelMovementMgr);
Q_ASSERT(mmgr);
mmgr->setFlagTracking(false);
}
// Get the informations on the current location
const StelLocation& StelCore::getCurrentLocation() const
{
return position->getCurrentLocation();
}
// Smoothly move the observer to the given location
void StelCore::moveObserverTo(const StelLocation& target, double duration,
double durationIfPlanetChange)
{
double d = (getCurrentLocation().planetName==target.planetName) ? du
ration : durationIfPlanetChange;
if (d>0.)
{
StelLocation curLoc = getCurrentLocation();
if (position->isTraveling())
{
// Avoid using a temporary location name to create a
nother temporary one (otherwise it looks like loc1 -> loc2 -> loc3 etc..)
curLoc.name = ".";
}
SpaceShipObserver* newObs = new SpaceShipObserver(curLoc, ta
rget, d);
delete position;
position = newObs;
newObs->update(0);
}
else
{
delete position;
position = new StelObserver(target);
}
emit(locationChanged(target));
}
//! Set stellarium time to current real world time
void StelCore::setTimeNow()
{
setJDay(StelUtils::getJDFromSystem());
}
void StelCore::setTodayTime(const QTime& target)
{
QDateTime dt = QDateTime::currentDateTime();
if (target.isValid())
{
dt.setTime(target);
// don't forget to adjust for timezone / daylight savings.
setJDay(StelUtils::qDateTimeToJd(dt)-(StelUtils::getGMTShift
FromQT(StelUtils::getJDFromSystem()) * JD_HOUR));
}
else
{
qWarning() << "WARNING - time passed to StelCore::setTodayTi
me is not valid. The system time will be used." << target;
setTimeNow();
}
}
//! Get whether the current stellarium time is the real world time
bool StelCore::getIsTimeNow(void) const
{
// cache last time to prevent to much slow system call
static double lastJD = getJDay();
static bool previousResult = (fabs(getJDay()-StelUtils::getJDFromSys
tem())<JD_SECOND);
if (fabs(lastJD-getJDay())>JD_SECOND/4)
{
lastJD = getJDay();
previousResult = (fabs(getJDay()-StelUtils::getJDFromSystem(
))<JD_SECOND);
}
return previousResult;
}
void StelCore::addSolarDays(double d)
{
setJDay(getJDay() + d);
}
void StelCore::addSiderealDays(double d)
{
const PlanetP& home = position->getHomePlanet();
if (home->getEnglishName() != "Solar System StelObserver")
d *= home->getSiderealDay();
setJDay(getJDay() + d);
}
// Get the sideral time shifted by the observer longitude
double StelCore::getLocalSideralTime() const
{
return (position->getHomePlanet()->getSiderealTime(JDay)+position->g
etCurrentLocation().longitude)*M_PI/180.;
}
//! Get the duration of a sideral day for the current observer in day.
double StelCore::getLocalSideralDayLength() const
{
return position->getHomePlanet()->getSiderealDay();
}
//! Increase the time speed
void StelCore::increaseTimeSpeed()
{
double s = getTimeRate();
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>=-JD_SECOND && s<0.) s=0.;
setTimeRate(s);
}
//! Decrease the time speed
void StelCore::decreaseTimeSpeed()
{
double s = getTimeRate();
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>0. && s<=JD_SECOND) s=0.;
setTimeRate(s);
}
void StelCore::increaseTimeSpeedLess()
{
double s = getTimeRate();
if (s>=JD_SECOND) s*=2.;
else if (s<-JD_SECOND) s/=2.;
else if (s>=0. && s<JD_SECOND) s=JD_SECOND;
else if (s>=-JD_SECOND && s<0.) s=0.;
setTimeRate(s);
}
void StelCore::decreaseTimeSpeedLess()
{
double s = getTimeRate();
if (s>JD_SECOND) s/=2.;
else if (s<=-JD_SECOND) s*=2.;
else if (s>-JD_SECOND && s<=0.) s=-JD_SECOND;
else if (s>0. && s<=JD_SECOND) s=0.;
setTimeRate(s);
}
///////////////////////////////////////////////////////////////////////////
/////
// Increment time
void StelCore::updateTime(double deltaTime)
{
JDay+=timeSpeed*deltaTime;
// Fix time limits to -100000 to +100000 to prevent bugs
if (JDay>38245309.499988) JDay = 38245309.499988;
if (JDay<-34803211.500012) JDay = -34803211.500012;
if (position->isObserverLifeOver())
{
// Unselect if the new home planet is the previously selecte
d object
StelObjectMgr* objmgr = GETSTELMODULE(StelObjectMgr);
Q_ASSERT(objmgr);
if (objmgr->getWasSelected() && objmgr->getSelectedObject()[
0].data()==position->getHomePlanet())
{
objmgr->unSelect();
}
StelObserver* newObs = position->getNextObserver();
delete position;
position = newObs;
}
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());
}
void StelCore::setStartupTimeMode(const QString& s)
{
startupTimeMode = s;
}
void StelCore::setPresetSkyTime(QDateTime dt)
{
setPresetSkyTime(StelUtils::qDateTimeToJd(dt));
}
 End of changes. 32 change blocks. 
43 lines changed or deleted 95 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/