Planet.cpp   Planet.cpp 
skipping to change at line 33 skipping to change at line 33
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QVarLengthArray> #include <QVarLengthArray>
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelTexture.hpp" #include "StelTexture.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelNavigator.hpp"
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "sideral_time.h" #include "sideral_time.h"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StarMgr.hpp" #include "StarMgr.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
Vec3f Planet::labelColor = Vec3f(0.4,0.4,0.8); Vec3f Planet::labelColor = Vec3f(0.4,0.4,0.8);
skipping to change at line 57 skipping to change at line 57
Planet::Planet(const QString& englishName, Planet::Planet(const QString& englishName,
int flagLighting, int flagLighting,
double radius, double radius,
double oblateness, double oblateness,
Vec3f color, Vec3f color,
float albedo, float albedo,
const QString& atexMapName, const QString& atexMapName,
posFuncType coordFunc, posFuncType coordFunc,
void* auserDataPtr, void* auserDataPtr,
OsulatingFunctType *osculatingFunc, OsculatingFunctType *osculatingFunc,
bool acloseOrbit, bool acloseOrbit,
bool hidden, bool hidden,
bool hasAtmosphere) bool hasAtmosphere)
: englishName(englishName), : englishName(englishName),
flagLighting(flagLighting), flagLighting(flagLighting),
radius(radius), oneMinusOblateness(1.0-oblateness), radius(radius), oneMinusOblateness(1.0-oblateness),
color(color), albedo(albedo), axisRotation(0.), rings(NULL), color(color), albedo(albedo), axisRotation(0.), rings(NULL),
sphereScale(1.f), sphereScale(1.f),
lastJD(J2000), lastJD(J2000),
coordFunc(coordFunc), coordFunc(coordFunc),
userDataPtr(auserDataPtr), userDataPtr(auserDataPtr),
osculatingFunc(osculatingFunc), osculatingFunc(osculatingFunc),
parent(NULL), parent(NULL),
hidden(hidden), hidden(hidden),
atmosphere(hasAtmosphere) atmosphere(hasAtmosphere)
{ {
texMapName = atexMapName; texMapName = atexMapName;
lastOrbitJD =0; lastOrbitJD =0;
deltaJD = JD_SECOND; deltaJD = StelCore::JD_SECOND;
orbitCached = 0; orbitCached = 0;
closeOrbit = acloseOrbit; closeOrbit = acloseOrbit;
eclipticPos=Vec3d(0.,0.,0.); eclipticPos=Vec3d(0.,0.,0.);
rotLocalToParent = Mat4d::identity(); rotLocalToParent = Mat4d::identity();
texMap = StelApp::getInstance().getTextureManager().createTextureThr ead("textures/"+texMapName, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT)); texMap = StelApp::getInstance().getTextureManager().createTextureThr ead("textures/"+texMapName, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT));
nameI18 = englishName; nameI18 = englishName;
if (englishName!="Pluto") if (englishName!="Pluto")
{ {
deltaJD = 0.001*JD_SECOND; deltaJD = 0.001*StelCore::JD_SECOND;
} }
flagLabels = true; flagLabels = true;
} }
Planet::~Planet() Planet::~Planet()
{ {
if (rings) if (rings)
delete rings; delete rings;
} }
void Planet::translateName(StelTranslator& trans) {nameI18 = trans.qtransla void Planet::translateName(StelTranslator& trans)
te(englishName);} {
nameI18 = trans.qtranslate(englishName);
}
// Return the information string "ready to print" :) // Return the information string "ready to print" :)
QString Planet::getInfoString(const StelCore* core, const InfoStringGroup& flags) const QString Planet::getInfoString(const StelCore* core, const InfoStringGroup& flags) const
{ {
const StelNavigator* nav = core->getNavigator();
QString str; QString str;
QTextStream oss(&str); QTextStream oss(&str);
if (flags&Name) if (flags&Name)
{ {
oss << "<h2>" << q_(englishName); // UI translation can dif fer from sky translation oss << "<h2>" << q_(englishName); // UI translation can dif fer from sky translation
oss.setRealNumberNotation(QTextStream::FixedNotation); oss.setRealNumberNotation(QTextStream::FixedNotation);
oss.setRealNumberPrecision(1); oss.setRealNumberPrecision(1);
if (sphereScale != 1.f) if (sphereScale != 1.f)
oss << QString::fromUtf8(" (\xC3\x97") << sphereScal e << ")"; oss << QString::fromUtf8(" (\xC3\x97") << sphereScal e << ")";
oss << "</h2>"; oss << "</h2>";
} }
if (flags&Magnitude) if (flags&Magnitude)
oss << q_("Magnitude: <b>%1</b>").arg(getVMagnitude(nav), 0, 'f', 2) << "<br>"; oss << q_("Magnitude: <b>%1</b>").arg(getVMagnitude(core), 0 , 'f', 2) << "<br>";
if (flags&AbsoluteMagnitude) if (flags&AbsoluteMagnitude)
oss << q_("Absolute Magnitude: %1").arg(getVMagnitude(nav)-5 .*(std::log10(getJ2000EquatorialPos(nav).length()*AU/PARSEC)-1.), 0, 'f', 2 ) << "<br>"; oss << q_("Absolute Magnitude: %1").arg(getVMagnitude(core)- 5.*(std::log10(getJ2000EquatorialPos(core).length()*AU/PARSEC)-1.), 0, 'f', 2) << "<br>";
oss << getPositionInfoString(core, flags); oss << getPositionInfoString(core, flags);
if ((flags&Extra2) && (core->getCurrentLocation().planetName=="Earth
"))
{
//static SolarSystem *ssystem=GETSTELMODULE(SolarSystem);
//double ecl= -(ssystem->getEarth()->getRotObliquity()); //
BUG DETECTED! Earth's obliquity is apparently reported constant.
double ra_equ, dec_equ, lambda, beta;
double ecl= get_mean_ecliptical_obliquity(core->getJDay()) *
M_PI/180.0;
StelUtils::rectToSphe(&ra_equ,&dec_equ,getEquinoxEquatorialP
os(core));
StelUtils::ctRadec2Ecl(ra_equ, dec_equ, ecl, &lambda, &beta)
;
if (lambda<0) lambda+=2.0*M_PI;
oss << q_("Ecliptic Geocentric (of date): %1/%2").arg(StelUt
ils::radToDmsStr(lambda, true), StelUtils::radToDmsStr(beta, true)) << "<br
>";
oss << q_("Obliquity (of date): %1").arg(StelUtils::radToDms
Str(ecl, true)) << "<br>";
}
if (flags&Distance) if (flags&Distance)
{ {
// xgettext:no-c-format // xgettext:no-c-format
oss << q_("Distance: %1AU").arg(getJ2000EquatorialPos(nav).l ength(), 0, 'f', 8) << "<br>"; oss << q_("Distance: %1AU").arg(getJ2000EquatorialPos(core). length(), 0, 'f', 8) << "<br>";
} }
if (flags&Size) if (flags&Size)
oss << q_("Apparent diameter: %1").arg(StelUtils::radToDmsSt r(2.*getAngularSize(core)*M_PI/180., true)); oss << q_("Apparent diameter: %1").arg(StelUtils::radToDmsSt r(2.*getAngularSize(core)*M_PI/180., true));
postProcessInfoString(str, flags); postProcessInfoString(str, flags);
return str; return str;
} }
//! Get sky label (sky translation) //! Get sky label (sky translation)
QString Planet::getSkyLabel(const StelNavigator*) const QString Planet::getSkyLabel(const StelCore*) const
{ {
QString str; QString str;
QTextStream oss(&str); QTextStream oss(&str);
oss.setRealNumberPrecision(2); oss.setRealNumberPrecision(2);
oss << nameI18; oss << nameI18;
if (sphereScale != 1.f) if (sphereScale != 1.f)
{ {
oss << QString::fromUtf8(" (\xC3\x97") << sphereScale << ")" ; oss << QString::fromUtf8(" (\xC3\x97") << sphereScale << ")" ;
} }
return str; return str;
} }
float Planet::getSelectPriority(const StelNavigator *nav) const float Planet::getSelectPriority(const StelCore* core) const
{ {
if( ((SolarSystem*)StelApp::getInstance().getModuleMgr().getModule(" SolarSystem"))->getFlagHints() ) if( ((SolarSystem*)StelApp::getInstance().getModuleMgr().getModule(" SolarSystem"))->getFlagHints() )
{ {
// easy to select, especially pluto // easy to select, especially pluto
return getVMagnitude(nav)-15.f; return getVMagnitude(core)-15.f;
} }
else else
{ {
return getVMagnitude(nav) - 8.f; return getVMagnitude(core) - 8.f;
} }
} }
Vec3f Planet::getInfoColor(void) const Vec3f Planet::getInfoColor(void) const
{ {
return StelApp::getInstance().getVisionModeNight() ? Vec3f(0.8, 0.2, 0.4) : ((SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("Sol arSystem"))->getLabelsColor(); return StelApp::getInstance().getVisionModeNight() ? Vec3f(0.8, 0.2, 0.4) : ((SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("Sol arSystem"))->getLabelsColor();
} }
double Planet::getCloseViewFov(const StelNavigator* nav) const double Planet::getCloseViewFov(const StelCore* core) const
{ {
return std::atan(radius*sphereScale*2.f/getEquinoxEquatorialPos(nav) .length())*180./M_PI * 4; return std::atan(radius*sphereScale*2.f/getEquinoxEquatorialPos(core ).length())*180./M_PI * 4;
} }
double Planet::getSatellitesFov(const StelNavigator * nav) const double Planet::getSatellitesFov(const StelCore* core) const
{ {
// TODO: calculate from satellite orbits rather than hard code // TODO: calculate from satellite orbits rather than hard code
if (englishName=="Jupiter") return std::atan(0.005f/getEquinoxEquato if (englishName=="Jupiter") return std::atan(0.005f/getEquinoxEquato
rialPos(nav).length())*180./M_PI * 4; rialPos(core).length())*180./M_PI * 4;
if (englishName=="Saturn") return std::atan(0.005f/getEquinoxEquator if (englishName=="Saturn") return std::atan(0.005f/getEquinoxEquator
ialPos(nav).length())*180./M_PI * 4; ialPos(core).length())*180./M_PI * 4;
if (englishName=="Mars") return std::atan(0.0001f/getEquinoxEquatori if (englishName=="Mars") return std::atan(0.0001f/getEquinoxEquatori
alPos(nav).length())*180./M_PI * 4; alPos(core).length())*180./M_PI * 4;
if (englishName=="Uranus") return std::atan(0.002f/getEquinoxEquator if (englishName=="Uranus") return std::atan(0.002f/getEquinoxEquator
ialPos(nav).length())*180./M_PI * 4; ialPos(core).length())*180./M_PI * 4;
return -1.; return -1.;
} }
double Planet::getParentSatellitesFov(const StelNavigator *nav) const double Planet::getParentSatellitesFov(const StelCore* core) const
{ {
if (parent && parent->parent) return parent->getSatellitesFov(nav); if (parent && parent->parent) return parent->getSatellitesFov(core);
return -1.0; return -1.0;
} }
// Set the orbital elements // Set the orbital elements
void Planet::setRotationElements(float _period, float _offset, double _epoc h, float _obliquity, float _ascendingNode, float _precessionRate, double _s iderealPeriod ) void Planet::setRotationElements(float _period, float _offset, double _epoc h, float _obliquity, float _ascendingNode, float _precessionRate, double _s iderealPeriod )
{ {
re.period = _period; re.period = _period;
re.offset = _offset; re.offset = _offset;
re.epoch = _epoch; re.epoch = _epoch;
re.obliquity = _obliquity; re.obliquity = _obliquity;
re.ascendingNode = _ascendingNode; re.ascendingNode = _ascendingNode;
re.precessionRate = _precessionRate; re.precessionRate = _precessionRate;
re.siderealPeriod = _siderealPeriod; // used for drawing orbit line s re.siderealPeriod = _siderealPeriod; // used for drawing orbit line s
deltaOrbitJD = re.siderealPeriod/ORBIT_SEGMENTS; deltaOrbitJD = re.siderealPeriod/ORBIT_SEGMENTS;
} }
Vec3d Planet::getJ2000EquatorialPos(const StelNavigator *nav) const Vec3d Planet::getJ2000EquatorialPos(const StelCore *core) const
{ {
return StelNavigator::matVsop87ToJ2000.multiplyWithoutTranslation(ge tHeliocentricEclipticPos() - nav->getObserverHeliocentricEclipticPos()); return StelCore::matVsop87ToJ2000.multiplyWithoutTranslation(getHeli ocentricEclipticPos() - core->getObserverHeliocentricEclipticPos());
} }
// Compute the position in the parent Planet coordinate system // Compute the position in the parent Planet coordinate system
// Actually call the provided function to compute the ecliptical position // Actually call the provided function to compute the ecliptical position
void Planet::computePositionWithoutOrbits(const double date) void Planet::computePositionWithoutOrbits(const double date)
{ {
if (fabs(lastJD-date)>deltaJD) if (fabs(lastJD-date)>deltaJD)
{ {
coordFunc(date, eclipticPos, userDataPtr); coordFunc(date, eclipticPos, userDataPtr);
lastJD = date; lastJD = date;
skipping to change at line 450 skipping to change at line 464
double Planet::getPhase(const Vec3d& obsPos) const double Planet::getPhase(const Vec3d& obsPos) const
{ {
const double observerRq = obsPos.lengthSquared(); const double observerRq = obsPos.lengthSquared();
const Vec3d& planetHelioPos = getHeliocentricEclipticPos(); const Vec3d& planetHelioPos = getHeliocentricEclipticPos();
const double planetRq = planetHelioPos.lengthSquared(); const double planetRq = planetHelioPos.lengthSquared();
const double observerPlanetRq = (obsPos - planetHelioPos).lengthSqua red(); const double observerPlanetRq = (obsPos - planetHelioPos).lengthSqua red();
return std::acos(observerPlanetRq + planetRq - observerRq)/(2.0*sqrt (observerPlanetRq*planetRq)); return std::acos(observerPlanetRq + planetRq - observerRq)/(2.0*sqrt (observerPlanetRq*planetRq));
} }
// Computation of the visual magnitude (V band) of the planet. // Computation of the visual magnitude (V band) of the planet.
float Planet::getVMagnitude(const StelNavigator * nav) const float Planet::getVMagnitude(const StelCore* core) const
{ {
if (parent == 0) if (parent == 0)
{ {
// sun, compute the apparent magnitude for the absolute mag (4.83) and observer's distance // sun, compute the apparent magnitude for the absolute mag (4.83) and observer's distance
const double distParsec = std::sqrt(nav->getObserverHeliocen tricEclipticPos().lengthSquared())*AU/PARSEC; const double distParsec = std::sqrt(core->getObserverHelioce ntricEclipticPos().lengthSquared())*AU/PARSEC;
return 4.83 + 5.*(std::log10(distParsec)-1.); return 4.83 + 5.*(std::log10(distParsec)-1.);
} }
// Compute the angular phase // Compute the angular phase
const Vec3d& observerHelioPos = nav->getObserverHeliocentricEcliptic Pos(); const Vec3d& observerHelioPos = core->getObserverHeliocentricEclipti cPos();
const double observerRq = observerHelioPos.lengthSquared(); const double observerRq = observerHelioPos.lengthSquared();
const Vec3d& planetHelioPos = getHeliocentricEclipticPos(); const Vec3d& planetHelioPos = getHeliocentricEclipticPos();
const double planetRq = planetHelioPos.lengthSquared(); const double planetRq = planetHelioPos.lengthSquared();
const double observerPlanetRq = (observerHelioPos - planetHelioPos). lengthSquared(); const double observerPlanetRq = (observerHelioPos - planetHelioPos). lengthSquared();
const double cos_chi = (observerPlanetRq + planetRq - observerRq)/(2 .0*sqrt(observerPlanetRq*planetRq)); const double cos_chi = (observerPlanetRq + planetRq - observerRq)/(2 .0*sqrt(observerPlanetRq*planetRq));
double phase = std::acos(cos_chi); double phase = std::acos(cos_chi);
double shadowFactor = 1.; double shadowFactor = 1.;
// Check if the satellite is inside the inner shadow of the parent p lanet: // Check if the satellite is inside the inner shadow of the parent p lanet:
if (parent->parent != 0) if (parent->parent != 0)
skipping to change at line 502 skipping to change at line 516
// The satellite is partly inside the inner shadow, // The satellite is partly inside the inner shadow,
// compute a fantasy value for the magnitude : // compute a fantasy value for the magnitude :
d /= radius; d /= radius;
shadowFactor = (0.5 - (std::asin(d)+d*std::s qrt(1.0-d*d))/M_PI); shadowFactor = (0.5 - (std::asin(d)+d*std::s qrt(1.0-d*d))/M_PI);
} }
} }
} }
// Use empirical formulae for main planets when seen from earth // Use empirical formulae for main planets when seen from earth
// Algorithm provided by Pere Planesas (Observatorio Astronomico Nac ional) // Algorithm provided by Pere Planesas (Observatorio Astronomico Nac ional)
if (nav->getCurrentLocation().planetName=="Earth") if (core->getCurrentLocation().planetName=="Earth")
{ {
phase*=180./M_PI; phase*=180./M_PI;
const double d = 5. * log10(sqrt(observerPlanetRq*planetRq)) ; const double d = 5. * log10(sqrt(observerPlanetRq*planetRq)) ;
double f1 = phase/100.; double f1 = phase/100.;
if (englishName=="Mercury") if (englishName=="Mercury")
{ {
if ( phase > 150. ) f1 = 1.5; if ( phase > 150. ) f1 = 1.5;
return -0.36 + d + 3.8*f1 - 2.73*f1*f1 + 2*f1*f1*f1; return -0.36 + d + 3.8*f1 - 2.73*f1*f1 + 2*f1*f1*f1;
} }
skipping to change at line 547 skipping to change at line 561
const double p = (1.0 - phase/M_PI) * cos_chi + std::sqrt(1.0 - cos_ chi*cos_chi) / M_PI; const double p = (1.0 - phase/M_PI) * cos_chi + std::sqrt(1.0 - cos_ chi*cos_chi) / M_PI;
double F = 2.0 * albedo * radius * radius * p / (3.0*observerPlanetR q*planetRq) * shadowFactor; double F = 2.0 * albedo * radius * radius * p / (3.0*observerPlanetR q*planetRq) * shadowFactor;
return -26.73 - 2.5 * std::log10(F); return -26.73 - 2.5 * std::log10(F);
} }
double Planet::getAngularSize(const StelCore* core) const double Planet::getAngularSize(const StelCore* core) const
{ {
double rad = radius; double rad = radius;
if (rings) if (rings)
rad = rings->getSize(); rad = rings->getSize();
return std::atan2(rad*sphereScale,getJ2000EquatorialPos(core->getNav igator()).length()) * 180./M_PI; return std::atan2(rad*sphereScale,getJ2000EquatorialPos(core).length ()) * 180./M_PI;
} }
double Planet::getSpheroidAngularSize(const StelCore* core) const double Planet::getSpheroidAngularSize(const StelCore* core) const
{ {
return std::atan2(radius*sphereScale,getJ2000EquatorialPos(core->get Navigator()).length()) * 180./M_PI; return std::atan2(radius*sphereScale,getJ2000EquatorialPos(core).len gth()) * 180./M_PI;
} }
// Draw the Planet and all the related infos : name, circle etc.. // Draw the Planet and all the related infos : name, circle etc..
void Planet::draw(StelCore* core, float maxMagLabels, const QFont& planetNa meFont) void Planet::draw(StelCore* core, float maxMagLabels, const QFont& planetNa meFont)
{ {
if (hidden) if (hidden)
return; return;
StelNavigator* nav = core->getNavigator();
Mat4d mat = Mat4d::translation(eclipticPos) * rotLocalToParent; Mat4d mat = Mat4d::translation(eclipticPos) * rotLocalToParent;
PlanetP p = parent; PlanetP p = parent;
while (p && p->parent) while (p && p->parent)
{ {
mat = Mat4d::translation(p->eclipticPos) * mat * p->rotLocal ToParent; mat = Mat4d::translation(p->eclipticPos) * mat * p->rotLocal ToParent;
p = p->parent; p = p->parent;
} }
// This removed totally the Planet shaking bug!!! // This removed totally the Planet shaking bug!!!
mat = nav->getHeliocentricEclipticModelViewMat() * mat; StelProjector::ModelViewTranformP transfo = core->getHeliocentricEcl
ipticModelViewTransform();
if (getEnglishName() == nav->getCurrentLocation().planetName) transfo->combine(mat);
if (getEnglishName() == core->getCurrentLocation().planetName)
{ {
// Draw the rings if we are located on a planet with rings, but not the planet itself. // Draw the rings if we are located on a planet with rings, but not the planet itself.
if (rings) if (rings)
{ {
StelPainter sPainter(core->getProjection(mat)); StelPainter sPainter(core->getProjection(transfo));
rings->draw(&sPainter,mat,1000.0); rings->draw(&sPainter,transfo,1000.0);
} }
return; return;
} }
// Compute the 2D position and check if in the screen // Compute the 2D position and check if in the screen
const StelProjectorP prj = core->getProjection(mat); const StelProjectorP prj = core->getProjection(transfo);
float screenSz = getAngularSize(core)*M_PI/180.*prj->getPixelPerRadA tCenter(); float screenSz = getAngularSize(core)*M_PI/180.*prj->getPixelPerRadA tCenter();
float viewport_left = prj->getViewportPosX(); float viewport_left = prj->getViewportPosX();
float viewport_bottom = prj->getViewportPosY(); float viewport_bottom = prj->getViewportPosY();
if (prj->project(Vec3d(0), screenPos) && if (prj->project(Vec3d(0), screenPos)
screenPos[1]>viewport_bottom - screenSz && screenPos && screenPos[1]>viewport_bottom - screenSz && screenPos[1] < vie
[1]<viewport_bottom + prj->getViewportHeight()+screenSz && wport_bottom + prj->getViewportHeight()+screenSz
screenPos[0]>viewport_left - screenSz && screenPos[0 && screenPos[0]>viewport_left - screenSz && screenPos[0] < viewp
]<viewport_left + prj->getViewportWidth() + screenSz) ort_left + prj->getViewportWidth() + screenSz)
{ {
// Draw the name, and the circle if it's not too close from the body it's turning around // Draw the name, and the circle if it's not too close from the body it's turning around
// this prevents name overlaping (ie for jupiter satellites) // this prevents name overlaping (ie for jupiter satellites)
float ang_dist = 300.f*atan(getEclipticPos().length()/getEqu inoxEquatorialPos(nav).length())/core->getMovementMgr()->getCurrentFov(); float ang_dist = 300.f*atan(getEclipticPos().length()/getEqu inoxEquatorialPos(core).length())/core->getMovementMgr()->getCurrentFov();
if (ang_dist==0.f) if (ang_dist==0.f)
ang_dist = 1.f; // if ang_dist == 0, the Planet is s un.. ang_dist = 1.f; // if ang_dist == 0, the Planet is s un..
// by putting here, only draw orbit if Planet is visible for clarity // by putting here, only draw orbit if Planet is visible for clarity
drawOrbit(core); // TODO - fade in here also... drawOrbit(core); // TODO - fade in here also...
if (flagLabels && ang_dist>0.25 && maxMagLabels>getVMagnitud e(nav)) if (flagLabels && ang_dist>0.25 && maxMagLabels>getVMagnitud e(core))
{ {
labelsFader=true; labelsFader=true;
} }
else else
{ {
labelsFader=false; labelsFader=false;
} }
drawHints(core, planetNameFont); drawHints(core, planetNameFont);
draw3dModel(core,mat,screenSz); draw3dModel(core,transfo,screenSz);
} }
return; return;
} }
void Planet::draw3dModel(StelCore* core, const Mat4d& mat, float screenSz) void Planet::draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz)
{ {
// This is the main method drawing a planet 3d model // This is the main method drawing a planet 3d model
// Some work has to be done on this method to make the rendering nic er // Some work has to be done on this method to make the rendering nic er
StelNavigator* nav = core->getNavigator();
if (screenSz>1.) if (screenSz>1.)
{ {
StelPainter* sPainter = new StelPainter(core->getProjection( StelProjector::ModelViewTranformP transfo2 = transfo->clone(
mat * Mat4d::zrotation(M_PI/180*(axisRotation + 90.)))); );
transfo2->combine(Mat4d::zrotation(M_PI/180*(axisRotation +
90.)));
StelPainter* sPainter = new StelPainter(core->getProjection(
transfo2));
if (flagLighting) if (flagLighting)
{ {
sPainter->getLight().enable(); sPainter->getLight().enable();
// Set the main source of light to be the sun // Set the main source of light to be the sun
const Vec3d& sunPos = core->getNavigator()->getHelio Vec3d sunPos(0);
centricEclipticModelViewMat()*Vec3d(0,0,0); core->getHeliocentricEclipticModelViewTransform()->f
orward(sunPos);
sPainter->getLight().setPosition(Vec4f(sunPos[0],sun Pos[1],sunPos[2],1.f)); sPainter->getLight().setPosition(Vec4f(sunPos[0],sun Pos[1],sunPos[2],1.f));
// Set the light parameters taking sun as the light source // Set the light parameters taking sun as the light source
static const Vec4f diffuse = Vec4f(2.f,2.f,2.f,1.f); static const Vec4f diffuse = Vec4f(2.f,2.f,2.f,1.f);
static const Vec4f zero = Vec4f(0.f,0.f,0.f,0.f); static const Vec4f zero = Vec4f(0.f,0.f,0.f,0.f);
static const Vec4f ambient = Vec4f(0.02f,0.02f,0.02f ,0.02f); static const Vec4f ambient = Vec4f(0.02f,0.02f,0.02f ,0.02f);
sPainter->getLight().setAmbient(ambient); sPainter->getLight().setAmbient(ambient);
sPainter->getLight().setDiffuse(diffuse); sPainter->getLight().setDiffuse(diffuse);
sPainter->getLight().setSpecular(zero); sPainter->getLight().setSpecular(zero);
skipping to change at line 658 skipping to change at line 671
sPainter->getMaterial().setSpecular(zero); sPainter->getMaterial().setSpecular(zero);
} }
else else
{ {
sPainter->getLight().disable(); sPainter->getLight().disable();
sPainter->setColor(1.f,1.f,1.f); sPainter->setColor(1.f,1.f,1.f);
} }
if (rings) if (rings)
{ {
const double dist = getEquinoxEquatorialPos(nav).len gth(); const double dist = getEquinoxEquatorialPos(core).le ngth();
double z_near = 0.9*(dist - rings->getSize()); double z_near = 0.9*(dist - rings->getSize());
double z_far = 1.1*(dist + rings->getSize()); double z_far = 1.1*(dist + rings->getSize());
if (z_near < 0.0) z_near = 0.0; if (z_near < 0.0) z_near = 0.0;
double n,f; double n,f;
core->getClippingPlanes(&n,&f); // Save clipping pla nes core->getClippingPlanes(&n,&f); // Save clipping pla nes
core->setClippingPlanes(z_near,z_far); core->setClippingPlanes(z_near,z_far);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
drawSphere(sPainter, screenSz); drawSphere(sPainter, screenSz);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
sPainter->getLight().disable(); sPainter->getLight().disable();
rings->draw(sPainter,mat,screenSz); rings->draw(sPainter,transfo,screenSz);
sPainter->getLight().enable(); sPainter->getLight().enable();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
core->setClippingPlanes(n,f); // Restore old clippi ng planes core->setClippingPlanes(n,f); // Restore old clippi ng planes
} }
else else
{ {
SolarSystem* ssm = GETSTELMODULE(SolarSystem); SolarSystem* ssm = GETSTELMODULE(SolarSystem);
if (this==ssm->getMoon() && nav->getCurrentLocation( ).planetName=="Earth" && ssm->nearLunarEclipse()) if (this==ssm->getMoon() && core->getCurrentLocation ().planetName=="Earth" && ssm->nearLunarEclipse())
{ {
// Draw earth shadow over moon using stencil buffer if appropriate // Draw earth shadow over moon using stencil buffer if appropriate
// This effect curently only looks right fro m earth viewpoint // This effect curently only looks right fro m earth viewpoint
// TODO: moon magnitude label during eclipse isn't accurate... // TODO: moon magnitude label during eclipse isn't accurate...
glClearStencil(0x0); glClearStencil(0x0);
glClear(GL_STENCIL_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 0x1, 0x1); glStencilFunc(GL_ALWAYS, 0x1, 0x1);
glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE) ; glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE) ;
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
drawSphere(sPainter, screenSz); drawSphere(sPainter, screenSz);
skipping to change at line 713 skipping to change at line 726
sPainter=NULL; sPainter=NULL;
} }
// Draw the halo // Draw the halo
// Prepare openGL lighting parameters according to luminance // Prepare openGL lighting parameters according to luminance
float surfArcMin2 = getSpheroidAngularSize(core)*60; float surfArcMin2 = getSpheroidAngularSize(core)*60;
surfArcMin2 = surfArcMin2*surfArcMin2*M_PI; // the total illuminated area in arcmin^2 surfArcMin2 = surfArcMin2*surfArcMin2*M_PI; // the total illuminated area in arcmin^2
StelPainter sPainter(core->getProjection(StelCore::FrameJ2000)); StelPainter sPainter(core->getProjection(StelCore::FrameJ2000));
Vec3d tmp = getJ2000EquatorialPos(nav); Vec3d tmp = getJ2000EquatorialPos(core);
core->getSkyDrawer()->postDrawSky3dModel(&sPainter, Vec3f(tmp[0], tm core->getSkyDrawer()->postDrawSky3dModel(&sPainter, Vec3f(tmp[0], tm
p[1], tmp[2]), surfArcMin2, getVMagnitude(core->getNavigator()), color); p[1], tmp[2]), surfArcMin2, getVMagnitude(core), color);
} }
void Planet::drawSphere(StelPainter* painter, float screenSz) void Planet::drawSphere(StelPainter* painter, float screenSz)
{ {
if (texMap) if (texMap)
{ {
// For lazy loading, return if texture not yet loaded // For lazy loading, return if texture not yet loaded
if (!texMap->bind()) if (!texMap->bind())
return; return;
} }
skipping to change at line 844 skipping to change at line 857
glClearStencil(0x0); glClearStencil(0x0);
glClear(GL_STENCIL_BUFFER_BIT); // Clean again to let a clean buffer for later Qt display glClear(GL_STENCIL_BUFFER_BIT); // Clean again to let a clean buffer for later Qt display
sPainter->setProjector(saveProj); sPainter->setProjector(saveProj);
} }
void Planet::drawHints(const StelCore* core, const QFont& planetNameFont) void Planet::drawHints(const StelCore* core, const QFont& planetNameFont)
{ {
if (labelsFader.getInterstate()<=0.f) if (labelsFader.getInterstate()<=0.f)
return; return;
const StelNavigator* nav = core->getNavigator();
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ; const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000) ;
StelPainter sPainter(prj); StelPainter sPainter(prj);
sPainter.setFont(planetNameFont); sPainter.setFont(planetNameFont);
// Draw nameI18 + scaling if it's not == 1. // Draw nameI18 + scaling if it's not == 1.
float tmp = (hintFader.getInterstate()<=0 ? 7.f : 10.f) + getAngular Size(core)*M_PI/180.f*prj->getPixelPerRadAtCenter()/1.44f; // Shift for nam eI18 printing float tmp = (hintFader.getInterstate()<=0 ? 7.f : 10.f) + getAngular Size(core)*M_PI/180.f*prj->getPixelPerRadAtCenter()/1.44f; // Shift for nam eI18 printing
sPainter.setColor(labelColor[0], labelColor[1], labelColor[2],labels Fader.getInterstate()); sPainter.setColor(labelColor[0], labelColor[1], labelColor[2],labels Fader.getInterstate());
sPainter.drawText(screenPos[0],screenPos[1], getSkyLabel(nav), 0, tm p, tmp, false); sPainter.drawText(screenPos[0],screenPos[1], getSkyLabel(core), 0, t mp, tmp, false);
// hint disapears smoothly on close view // hint disapears smoothly on close view
if (hintFader.getInterstate()<=0) if (hintFader.getInterstate()<=0)
return; return;
tmp -= 10.f; tmp -= 10.f;
if (tmp<1) tmp=1; if (tmp<1) tmp=1;
sPainter.setColor(labelColor[0], labelColor[1], labelColor[2],labels Fader.getInterstate()*hintFader.getInterstate()/tmp*0.7f); sPainter.setColor(labelColor[0], labelColor[1], labelColor[2],labels Fader.getInterstate()*hintFader.getInterstate()/tmp*0.7f);
// Draw the 2D small circle // Draw the 2D small circle
glEnable(GL_BLEND); glEnable(GL_BLEND);
skipping to change at line 878 skipping to change at line 890
Ring::Ring(double radiusMin,double radiusMax,const QString &texname) Ring::Ring(double radiusMin,double radiusMax,const QString &texname)
:radiusMin(radiusMin),radiusMax(radiusMax) :radiusMin(radiusMin),radiusMax(radiusMax)
{ {
tex = StelApp::getInstance().getTextureManager().createTexture("text ures/"+texname); tex = StelApp::getInstance().getTextureManager().createTexture("text ures/"+texname);
} }
Ring::~Ring(void) Ring::~Ring(void)
{ {
} }
void Ring::draw(StelPainter* sPainter,const Mat4d& mat,double screenSz) void Ring::draw(StelPainter* sPainter,StelProjector::ModelViewTranformP tra nsfo,double screenSz)
{ {
screenSz -= 50; screenSz -= 50;
screenSz /= 250.0; screenSz /= 250.0;
if (screenSz < 0.0) screenSz = 0.0; if (screenSz < 0.0) screenSz = 0.0;
else if (screenSz > 1.0) screenSz = 1.0; else if (screenSz > 1.0) screenSz = 1.0;
const int slices = 128+(int)((256-128)*screenSz); const int slices = 128+(int)((256-128)*screenSz);
const int stacks = 8+(int)((32-8)*screenSz); const int stacks = 8+(int)((32-8)*screenSz);
// Normal transparency mode // Normal transparency mode
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
sPainter->setColor(1.f, 1.f, 1.f); sPainter->setColor(1.f, 1.f, 1.f);
sPainter->enableTexture2d(true); sPainter->enableTexture2d(true);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glEnable(GL_BLEND); glEnable(GL_BLEND);
if (tex) tex->bind(); if (tex) tex->bind();
Mat4d mat = transfo->getApproximateLinearTransfo();
// solve the ring wraparound by culling: // solve the ring wraparound by culling:
// decide if we are above or below the ring plane // decide if we are above or below the ring plane
const double h = mat.r[ 8]*mat.r[12] const double h = mat.r[ 8]*mat.r[12]
+ mat.r[ 9]*mat.r[13] + mat.r[ 9]*mat.r[13]
+ mat.r[10]*mat.r[14]; + mat.r[10]*mat.r[14];
sPainter->sRing(radiusMin,radiusMax,(h<0.0)?slices:-slices,stacks, 0 ); sPainter->sRing(radiusMin,radiusMax,(h<0.0)?slices:-slices,stacks, 0 );
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
} }
// draw orbital path of Planet // draw orbital path of Planet
 End of changes. 48 change blocks. 
68 lines changed or deleted 91 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/