StelObserver.cpp   StelObserver.cpp 
skipping to change at line 38 skipping to change at line 38
#include "StelLocationMgr.hpp" #include "StelLocationMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
#include <QStringList> #include <QStringList>
class ArtificialPlanet : public Planet class ArtificialPlanet : public Planet
{ {
public: public:
ArtificialPlanet(const Planet &orig); ArtificialPlanet(const PlanetP& orig);
void setDest(const Planet &dest); void setDest(const PlanetP& dest);
void computeAverage(double f1); void computeAverage(double f1);
private: private:
void setRot(const Vec3d &r); void setRot(const Vec3d &r);
static Vec3d GetRot(const Planet *p); static Vec3d getRot(const Planet* p);
const Planet *dest; PlanetP dest;
const QString orig_name; const QString orig_name;
const QString orig_name_i18n; const QString orig_name_i18n;
}; };
ArtificialPlanet::ArtificialPlanet(const Planet &orig) : ArtificialPlanet::ArtificialPlanet(const PlanetP& orig) :
Planet("", 0, 0, 0, Vec3f(0,0,0), 0, "", "", Planet("", 0, 0, 0, Vec3f(0,0,0), 0, "", "",
posFuncType(), 0, false, true, false), dest(0), NULL, NULL, 0, false, true, false), dest(0),
orig_name(orig.getEnglishName()), orig_name_i18n(orig.getNam orig_name(orig->getEnglishName()), orig_name_i18n(orig->getN
eI18n()) ameI18n())
{ {
radius = 0; radius = 0;
// set parent = sun: // set parent = sun:
if (orig.getParent()) if (orig->getParent())
{ {
parent = orig.getParent(); parent = orig->getParent();
while (parent->getParent()) while (parent->getParent())
parent = parent->getParent(); parent = parent->getParent();
} }
else else
{ {
parent = &orig; // sun parent = orig; // sun
} }
re = orig.getRotationElements(); re = orig->getRotationElements();
setRotEquatorialToVsop87(orig.getRotEquatorialToVsop87()); setRotEquatorialToVsop87(orig->getRotEquatorialToVsop87());
setHeliocentricEclipticPos(orig.getHeliocentricEclipticPos()); setHeliocentricEclipticPos(orig->getHeliocentricEclipticPos());
} }
void ArtificialPlanet::setDest(const Planet &dest) void ArtificialPlanet::setDest(const PlanetP& dest)
{ {
ArtificialPlanet::dest = &dest; ArtificialPlanet::dest = dest;
englishName = QString("%1->%2").arg(orig_name).arg(dest.getEnglishNa englishName = QString("%1->%2").arg(orig_name).arg(dest->getEnglishN
me()); ame());
nameI18 = QString("%1->%2").arg(orig_name_i18n).arg(dest.getNameI18n nameI18 = QString("%1->%2").arg(orig_name_i18n).arg(dest->getNameI18
()); n());
// rotation: // rotation:
const RotationElements &r(dest.getRotationElements()); const RotationElements &r(dest->getRotationElements());
lastJD = StelApp::getInstance().getCore()->getNavigator()->getJDay() ; lastJD = StelApp::getInstance().getCore()->getNavigator()->getJDay() ;
re.offset = r.offset + fmod(re.offset - r.offset + 360.0*( (lastJD-r e.epoch)/re.period - (lastJD-r.epoch)/r.period), 360.0); re.offset = r.offset + fmod(re.offset - r.offset + 360.0*( (lastJD-r e.epoch)/re.period - (lastJD-r.epoch)/r.period), 360.0);
re.epoch = r.epoch; re.epoch = r.epoch;
re.period = r.period; re.period = r.period;
if (re.offset - r.offset < -180.f) re.offset += 360.f; else if (re.offset - r.offset < -180.f) re.offset += 360.f; else
if (re.offset - r.offset > 180.f) re.offset -= 360.f; if (re.offset - r.offset > 180.f) re.offset -= 360.f;
} }
skipping to change at line 117 skipping to change at line 117
m.r[ 6] = -sa*cd; m.r[ 6] = -sa*cd;
m.r[10] = sa*sd*sp +ca*cp; m.r[10] = sa*sd*sp +ca*cp;
m.r[14] = 0; m.r[14] = 0;
m.r[ 3] = 0; m.r[ 3] = 0;
m.r[ 7] = 0; m.r[ 7] = 0;
m.r[11] = 0; m.r[11] = 0;
m.r[15] = 1.0; m.r[15] = 1.0;
setRotEquatorialToVsop87(m); setRotEquatorialToVsop87(m);
} }
Vec3d ArtificialPlanet::GetRot(const Planet *p) Vec3d ArtificialPlanet::getRot(const Planet* p)
{ {
const Mat4d m(p->getRotEquatorialToVsop87()); const Mat4d m(p->getRotEquatorialToVsop87());
const double cos_r1 = sqrt(m.r[0]*m.r[0]+m.r[8]*m.r[8]); const double cos_r1 = sqrt(m.r[0]*m.r[0]+m.r[8]*m.r[8]);
Vec3d r; Vec3d r;
r[1] = atan2(m.r[4],cos_r1); r[1] = atan2(m.r[4],cos_r1);
// not well defined if cos(r[1])==0: // not well defined if cos(r[1])==0:
if (cos_r1 <= 0.0) if (cos_r1 <= 0.0)
{ {
// if (m.r[4]>0.0) sin,cos(a-p)=m.r[ 9],m.r[10] // if (m.r[4]>0.0) sin,cos(a-p)=m.r[ 9],m.r[10]
// else sin,cos(a+p)=m.r[ 9],m.r[10] // else sin,cos(a+p)=m.r[ 9],m.r[10]
skipping to change at line 147 skipping to change at line 147
return r; return r;
} }
void ArtificialPlanet::computeAverage(double f1) void ArtificialPlanet::computeAverage(double f1)
{ {
const double f2 = 1.0 - f1; const double f2 = 1.0 - f1;
// position // position
setHeliocentricEclipticPos(getHeliocentricEclipticPos()*f1 + dest->g etHeliocentricEclipticPos()*f2); setHeliocentricEclipticPos(getHeliocentricEclipticPos()*f1 + dest->g etHeliocentricEclipticPos()*f2);
// 3 Euler angles // 3 Euler angles
Vec3d a1(GetRot(this)); Vec3d a1(getRot(this));
const Vec3d a2(GetRot(dest)); const Vec3d a2(getRot(dest.data()));
if (a1[0]-a2[0] > M_PI) if (a1[0]-a2[0] > M_PI)
a1[0] -= 2.0*M_PI; a1[0] -= 2.0*M_PI;
else else
if (a1[0]-a2[0] < -M_PI) if (a1[0]-a2[0] < -M_PI)
a1[0] += 2.0*M_PI; a1[0] += 2.0*M_PI;
if (a1[2]-a2[2] > M_PI) if (a1[2]-a2[2] > M_PI)
a1[2] -= 2.0*M_PI; a1[2] -= 2.0*M_PI;
else else
if (a1[2]-a2[2] < -M_PI) if (a1[2]-a2[2] < -M_PI)
a1[2] += 2.0*M_PI; a1[2] += 2.0*M_PI;
skipping to change at line 180 skipping to change at line 180
{ {
qWarning() << "Can't create StelObserver on planet " + loc.p lanetName + " because it is unknown. Use Earth as default."; qWarning() << "Can't create StelObserver on planet " + loc.p lanetName + " because it is unknown. Use Earth as default.";
planet=ssystem->getEarth(); planet=ssystem->getEarth();
} }
} }
StelObserver::~StelObserver() StelObserver::~StelObserver()
{ {
} }
const QSharedPointer<Planet> StelObserver::getHomePlanet(void) const
{
return planet;
}
Vec3d StelObserver::getCenterVsop87Pos(void) const Vec3d StelObserver::getCenterVsop87Pos(void) const
{ {
return getHomePlanet()->getHeliocentricEclipticPos(); return getHomePlanet()->getHeliocentricEclipticPos();
} }
double StelObserver::getDistanceFromCenter(void) const double StelObserver::getDistanceFromCenter(void) const
{ {
return getHomePlanet()->getRadius() + (currentLocation.altitude/(100 0*AU)); return getHomePlanet()->getRadius() + (currentLocation.altitude/(100 0*AU));
} }
skipping to change at line 211 skipping to change at line 216
Mat4d StelObserver::getRotEquatorialToVsop87(void) const Mat4d StelObserver::getRotEquatorialToVsop87(void) const
{ {
return getHomePlanet()->getRotEquatorialToVsop87(); return getHomePlanet()->getRotEquatorialToVsop87();
} }
SpaceShipObserver::SpaceShipObserver(const StelLocation& startLoc, const St elLocation& target, double atransitSeconds) : StelObserver(startLoc), SpaceShipObserver::SpaceShipObserver(const StelLocation& startLoc, const St elLocation& target, double atransitSeconds) : StelObserver(startLoc),
moveStartLocation(startLoc), moveTargetLocation(target), art ificialPlanet(NULL), transitSeconds(atransitSeconds) moveStartLocation(startLoc), moveTargetLocation(target), art ificialPlanet(NULL), transitSeconds(atransitSeconds)
{ {
SolarSystem* ssystem = GETSTELMODULE(SolarSystem); SolarSystem* ssystem = GETSTELMODULE(SolarSystem);
Planet *targetPlanet = ssystem->searchByEnglishName(moveTargetLocati on.planetName); PlanetP targetPlanet = ssystem->searchByEnglishName(moveTargetLocati on.planetName);
if (moveStartLocation.planetName!=moveTargetLocation.planetName) if (moveStartLocation.planetName!=moveTargetLocation.planetName)
{ {
Planet *startPlanet = ssystem->searchByEnglishName(moveStart PlanetP startPlanet = ssystem->searchByEnglishName(moveStart
Location.planetName); Location.planetName);
if (startPlanet==NULL || targetPlanet==NULL) if (startPlanet.isNull() || targetPlanet.isNull())
{ {
qWarning() << "Can't move from planet " + moveStartL ocation.planetName + " to planet " + moveTargetLocation.planetName + " beca use it is unknown"; qWarning() << "Can't move from planet " + moveStartL ocation.planetName + " to planet " + moveTargetLocation.planetName + " beca use it is unknown";
timeToGo = -1.; // Will abort properly the move timeToGo = -1.; // Will abort properly the move
if (targetPlanet==NULL) if (targetPlanet==NULL)
{ {
// Stay at the same position as a failover // Stay at the same position as a failover
moveTargetLocation = moveStartLocation; moveTargetLocation = moveStartLocation;
} }
return; return;
} }
artificialPlanet = new ArtificialPlanet(*startPlanet); ArtificialPlanet* artPlanet = new ArtificialPlanet(startPlan
artificialPlanet->setDest(*targetPlanet); et);
artPlanet->setDest(targetPlanet);
artificialPlanet = QSharedPointer<Planet>(artPlanet);
} }
planet = targetPlanet; planet = targetPlanet;
timeToGo = transitSeconds; timeToGo = transitSeconds;
} }
SpaceShipObserver::~SpaceShipObserver() SpaceShipObserver::~SpaceShipObserver()
{ {
if (artificialPlanet) artificialPlanet.clear();
delete artificialPlanet; planet.clear();
artificialPlanet=NULL;
planet = NULL;
} }
void SpaceShipObserver::update(double deltaTime) void SpaceShipObserver::update(double deltaTime)
{ {
timeToGo -= deltaTime; timeToGo -= deltaTime;
// If move is over // If move is over
if (timeToGo <= 0.) if (timeToGo <= 0.)
{ {
timeToGo = 0.; timeToGo = 0.;
currentLocation = moveTargetLocation; currentLocation = moveTargetLocation;
} }
else else
{ {
if (artificialPlanet) if (artificialPlanet)
{ {
// Update SpaceShip position // Update SpaceShip position
artificialPlanet->computeAverage(timeToGo/(timeToGo + deltaTime)); static_cast<ArtificialPlanet*>(artificialPlanet.data ())->computeAverage(timeToGo/(timeToGo + deltaTime));
currentLocation.planetName = "SpaceShip"; currentLocation.planetName = "SpaceShip";
currentLocation.name = moveStartLocation.planetName + " -> " + moveTargetLocation.planetName; currentLocation.name = moveStartLocation.planetName + " -> " + moveTargetLocation.planetName;
} }
else else
{ {
currentLocation.name = moveStartLocation.name + " -> " + moveTargetLocation.name; currentLocation.name = moveStartLocation.name + " -> " + moveTargetLocation.name;
currentLocation.planetName = moveTargetLocation.plan etName; currentLocation.planetName = moveTargetLocation.plan etName;
} }
// Move the lon/lat/alt on the planet // Move the lon/lat/alt on the planet
const double moveToMult = 1.-(timeToGo/transitSeconds); const double moveToMult = 1.-(timeToGo/transitSeconds);
currentLocation.latitude = moveStartLocation.latitude - move ToMult*(moveStartLocation.latitude-moveTargetLocation.latitude); currentLocation.latitude = moveStartLocation.latitude - move ToMult*(moveStartLocation.latitude-moveTargetLocation.latitude);
currentLocation.longitude = moveStartLocation.longitude - mo veToMult*(moveStartLocation.longitude-moveTargetLocation.longitude); currentLocation.longitude = moveStartLocation.longitude - mo veToMult*(moveStartLocation.longitude-moveTargetLocation.longitude);
currentLocation.altitude = int(moveStartLocation.altitude - moveToMult*(moveStartLocation.altitude-moveTargetLocation.altitude)); currentLocation.altitude = int(moveStartLocation.altitude - moveToMult*(moveStartLocation.altitude-moveTargetLocation.altitude));
} }
} }
const QSharedPointer<Planet> SpaceShipObserver::getHomePlanet() const
{
return (isObserverLifeOver() || artificialPlanet==NULL) ? planet :
artificialPlanet;
}
 End of changes. 20 change blocks. 
35 lines changed or deleted 40 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/