Planet.cpp   Planet.cpp 
skipping to change at line 45 skipping to change at line 45
#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);
Vec3f Planet::orbitColor = Vec3f(1,0.6,1); Vec3f Planet::orbitColor = Vec3f(1,0.6,1);
Vec3f Planet::trailColor = Vec3f(1,0.7,0.7);
StelTextureSP Planet::hintCircleTex; StelTextureSP Planet::hintCircleTex;
StelTextureSP Planet::texEarthShadow; StelTextureSP Planet::texEarthShadow;
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,
const QString& texHaloName,
posFuncType coordFunc, posFuncType coordFunc,
void* auserDataPtr, void* auserDataPtr,
OsulatingFunctType *osculatingFunc, OsulatingFunctType *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),
skipping to change at line 84 skipping to change at line 82
atmosphere(hasAtmosphere) atmosphere(hasAtmosphere)
{ {
texMapName = atexMapName; texMapName = atexMapName;
lastOrbitJD =0; lastOrbitJD =0;
deltaJD = JD_SECOND; deltaJD = 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().createTexture(te texMap = StelApp::getInstance().getTextureManager().createTextureThr
xMapName, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT)); ead("textures/"+texMapName, StelTexture::StelTextureParams(true, GL_LINEAR,
GL_REPEAT));
// 60 day trails
DeltaTrail = 1;
// small increment like 0.125 would allow observation of latitude re
lated wobble of moon
// if decide to show moon trail
MaxTrail = 60;
lastTrailJD = 0; // for now
trailOn = 0;
firstPoint = 1;
nameI18 = englishName; nameI18 = englishName;
if (englishName!="Pluto") if (englishName!="Pluto")
{ {
deltaJD = 0.001*JD_SECOND; deltaJD = 0.001*JD_SECOND;
} }
flagLabels = true; flagLabels = true;
} }
Planet::~Planet() Planet::~Planet()
skipping to change at line 152 skipping to change at line 141
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 * nav) const QString Planet::getSkyLabel(const StelNavigator*) 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 << ")" ;
} }
skipping to change at line 601 skipping to change at line 590
rings->draw(&sPainter,mat,1000.0); rings->draw(&sPainter,mat,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(mat);
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(Vec3f(0,0,0), screenPos) && if (prj->project(Vec3d(0), screenPos) &&
screenPos[1]>viewport_bottom - screenSz && screenPos [1]<viewport_bottom + prj->getViewportHeight()+screenSz && screenPos[1]>viewport_bottom - screenSz && screenPos [1]<viewport_bottom + prj->getViewportHeight()+screenSz &&
screenPos[0]>viewport_left - screenSz && screenPos[0 ]<viewport_left + prj->getViewportWidth() + screenSz) screenPos[0]>viewport_left - screenSz && screenPos[0 ]<viewport_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(nav).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...
drawTrail(core);
if (flagLabels && ang_dist>0.25 && maxMagLabels>getVMagnitud e(nav)) if (flagLabels && ang_dist>0.25 && maxMagLabels>getVMagnitud e(nav))
{ {
labelsFader=true; labelsFader=true;
} }
else else
{ {
labelsFader=false; labelsFader=false;
} }
drawHints(core, planetNameFont); drawHints(core, planetNameFont);
skipping to change at line 650 skipping to change at line 638
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 centricEclipticModelViewMat()*Vec3d(0,0,0); const Vec3d& sunPos = core->getNavigator()->getHelio centricEclipticModelViewMat()*Vec3d(0,0,0);
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.,2.,2.,1); static const Vec4f diffuse = Vec4f(2.f,2.f,2.f,1.f);
static const Vec4f zero = Vec4f(0,0,0,0); static const Vec4f zero = Vec4f(0.f,0.f,0.f,0.f);
static const Vec4f ambient = Vec4f(0.02,0.02,0.02,0. static const Vec4f ambient = Vec4f(0.02f,0.02f,0.02f
02); ,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);
sPainter->getMaterial().setAmbient(ambient); sPainter->getMaterial().setAmbient(ambient);
sPainter->getMaterial().setEmission(zero); sPainter->getMaterial().setEmission(zero);
sPainter->getMaterial().setShininess(0); sPainter->getMaterial().setShininess(0.f);
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)
{ {
skipping to change at line 725 skipping to change at line 713
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));
core->getSkyDrawer()->postDrawSky3dModel(&sPainter, getJ2000Equatori Vec3d tmp = getJ2000EquatorialPos(nav);
alPos(nav), surfArcMin2, getVMagnitude(core->getNavigator()), color); core->getSkyDrawer()->postDrawSky3dModel(&sPainter, Vec3f(tmp[0], tm
p[1], tmp[2]), surfArcMin2, getVMagnitude(core->getNavigator()), color);
} }
void Planet::drawSphere(StelPainter* painter, float screenSz) void Planet::drawSphere(StelPainter* painter, float screenSz)
{ {
if (texMap)
{
// For lazy loading, return if texture not yet loaded
if (!texMap->bind())
return;
}
painter->enableTexture2d(true); painter->enableTexture2d(true);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
if (texMap)
texMap->bind();
// Draw the spheroid itself // Draw the spheroid itself
// Adapt the number of facets according with the size of the sphere for optimization // Adapt the number of facets according with the size of the sphere for optimization
int nb_facet = (int)(screenSz * 40/50); // 40 facets for 1024 pixels diameter on screen int nb_facet = (int)(screenSz * 40/50); // 40 facets for 1024 pixels diameter on screen
if (nb_facet<10) nb_facet = 10; if (nb_facet<10) nb_facet = 10;
if (nb_facet>40) nb_facet = 40; if (nb_facet>40) nb_facet = 40;
painter->setShadeModel(StelPainter::ShadeModelSmooth); painter->setShadeModel(StelPainter::ShadeModelSmooth);
// Rotate and add an extra quarter rotation so that the planet textu re map // Rotate and add an extra quarter rotation so that the planet textu re map
// fits to the observers position. No idea why this is necessary, // fits to the observers position. No idea why this is necessary,
// perhaps some openGl strangeness, or confusing sin/cos. // perhaps some openGl strangeness, or confusing sin/cos.
painter->sSphere(radius*sphereScale, oneMinusOblateness, nb_facet, n b_facet); painter->sSphere(radius*sphereScale, oneMinusOblateness, nb_facet, n b_facet);
skipping to change at line 805 skipping to change at line 798
glStencilFunc(GL_EQUAL, 0x1, 0x1); glStencilFunc(GL_EQUAL, 0x1, 0x1);
// Don't change stencil buffer value // Don't change stencil buffer value
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// shadow radial texture // shadow radial texture
texEarthShadow->bind(); texEarthShadow->bind();
Vec3d r; Vec3d r;
// Draw umbra first // Draw umbra first
QVarLengthArray<Vec2f, 210> texCoordArray(210); QVector<Vec2f> texCoordArray;
QVarLengthArray<Vec3d, 210> vertexArray(210); QVector<Vec3d> vertexArray;
texCoordArray[0].set(0.f, 0.5); texCoordArray.reserve(210);
vertexArray.reserve(210);
texCoordArray << Vec2f(0.f, 0.5f);
// johannes: work-around for nasty ATI rendering bug: use y-texture coordinate of 0.5 instead of 0.0 // johannes: work-around for nasty ATI rendering bug: use y-texture coordinate of 0.5 instead of 0.0
vertexArray[0]=shadow; vertexArray << shadow;
const Mat4d& rotMat = Mat4d::rotation(shadow, 2.*M_PI/100.); const Mat4d& rotMat = Mat4d::rotation(shadow, 2.*M_PI/100.);
r = upt; r = upt;
for (int i=1; i<=101; ++i) for (int i=1; i<=101; ++i)
{ {
// position in texture of umbra edge // position in texture of umbra edge
texCoordArray[i].set(0.6, 0.5); texCoordArray << Vec2f(0.6f, 0.5f);
r.transfo4d(rotMat); r.transfo4d(rotMat);
vertexArray[i] = shadow + r; vertexArray << shadow + r;
} }
sPainter->setArrays(vertexArray.constData(), texCoordArray.constData ()); sPainter->setArrays(vertexArray.constData(), texCoordArray.constData ());
sPainter->drawFromArray(StelPainter::TriangleFan, 102); sPainter->drawFromArray(StelPainter::TriangleFan, 102);
// now penumbra // now penumbra
vertexArray.resize(0);
texCoordArray.resize(0);
Vec3d u; Vec3d u;
r = rpt; r = rpt;
u = upt; u = upt;
for (int i=0; i<=200; i+=2) for (int i=0; i<=200; i+=2)
{ {
r.transfo4d(rotMat); r.transfo4d(rotMat);
u.transfo4d(rotMat); u.transfo4d(rotMat);
texCoordArray[i].set(0.6, 0.5); texCoordArray << Vec2f(0.6f, 0.5f) << Vec2f(1.f, 0.5f); // p
texCoordArray[i+1].set(1., 0.5); // position in texture of u osition in texture of umbra edge
mbra edge vertexArray << shadow + u << shadow + r;
vertexArray[i] = shadow + u;
vertexArray[i+1] = shadow + r;
} }
sPainter->setArrays(vertexArray.constData(), texCoordArray.constData ()); sPainter->setArrays(vertexArray.constData(), texCoordArray.constData ());
sPainter->drawFromArray(StelPainter::TriangleStrip, 202); sPainter->drawFromArray(StelPainter::TriangleStrip, 202);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
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 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 = 10.f + getAngularSize(core)*M_PI/180.*prj->getPixelPerRa dAtCenter()/1.44; // Shift for nameI18 printing float tmp = 10.f + getAngularSize(core)*M_PI/180.f*prj->getPixelPerR adAtCenter()/1.44f; // Shift for nameI18 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(nav), 0, tm p, 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.7); 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);
sPainter.enableTexture2d(true); sPainter.enableTexture2d(true);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Planet::hintCircleTex->bind(); Planet::hintCircleTex->bind();
sPainter.drawSprite2dMode(screenPos[0], screenPos[1], 11); sPainter.drawSprite2dMode(screenPos[0], screenPos[1], 11);
} }
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(texna me); 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,const Mat4d& mat,double screenSz)
{ {
screenSz -= 50; screenSz -= 50;
screenSz /= 250.0; screenSz /= 250.0;
skipping to change at line 960 skipping to change at line 955
} }
orbit[ORBIT_SEGMENTS/2]=savePos; orbit[ORBIT_SEGMENTS/2]=savePos;
if (!vertexArray.isEmpty()) if (!vertexArray.isEmpty())
{ {
sPainter.setVertexPointer(2, GL_FLOAT, vertexArray.constData ()); sPainter.setVertexPointer(2, GL_FLOAT, vertexArray.constData ());
sPainter.drawFromArray(StelPainter::LineStrip, vertexArray.s ize()/2, 0, false); sPainter.drawFromArray(StelPainter::LineStrip, vertexArray.s ize()/2, 0, false);
} }
sPainter.enableClientStates(false); sPainter.enableClientStates(false);
} }
// draw trail of Planet as seen from earth
void Planet::drawTrail(const StelCore* core)
{
if (!trailFader.getInterstate())
return;
const StelNavigator* nav = core->getNavigator();
const StelProjectorP prj = core->getProjection(StelCore::FrameJ2000)
;
Vec3d onscreen1;
Vec3d onscreen2;
StelPainter sPainter(prj);
glEnable(GL_BLEND);
sPainter.setColor(trailColor[0]*trailFader.getInterstate(), trailCol
or[1]*trailFader.getInterstate(), trailColor[2]*trailFader.getInterstate(),
1.);
std::list<TrailPoint>::iterator iter;
std::list<TrailPoint>::iterator nextiter;
std::list<TrailPoint>::iterator begin = trail.begin();
// begin++;
if (trail.begin() != trail.end())
{
nextiter = trail.end();
nextiter--;
for (iter=nextiter; iter != begin; --iter)
{
nextiter--;
if (prj->projectLineCheck( (*iter).point, onscreen1,
(*(nextiter)).point, onscreen2))
sPainter.drawLine2d(onscreen1[0], onscreen1[
1], onscreen2[0], onscreen2[1]);
}
}
// draw final segment to finish at current Planet position
if (!firstPoint && prj->projectLineCheck( (*trail.begin()).point, on
screen1, getEquinoxEquatorialPos(nav), onscreen2))
sPainter.drawLine2d(onscreen1[0], onscreen1[1], onscreen2[0]
, onscreen2[1]);
}
// update trail points as needed
void Planet::updateTrail(const StelNavigator* nav)
{
if (!trailOn)
return;
double date = nav->getJDay();
int dt=0;
if(firstPoint || (dt=abs(int((date-lastTrailJD)/DeltaTrail))) > MaxT
rail)
{
dt=1;
// clear old trail
trail.clear();
firstPoint = 0;
}
// Note that when jump by a week or day at a time, loose detail on t
rails
// particularly for moon (if decide to show moon trail)
// add only one point at a time, using current position only
if(dt)
{
lastTrailJD = date;
TrailPoint tp;
tp.point = getJ2000EquatorialPos(nav);
tp.date = date;
trail.push_front( tp );
// if( trail.size() > (unsigned int)MaxTrail ) {
if( trail.size() > (unsigned int)MaxTrail )
{
trail.pop_back();
}
}
// because sampling depends on speed and frame rate, need to clear o
ut
// points if trail gets longer than desired
std::list<TrailPoint>::iterator iter;
std::list<TrailPoint>::iterator end = trail.end();
for( iter=trail.begin(); iter != end; iter++)
{
if( fabs((*iter).date - date)/DeltaTrail > MaxTrail )
{
trail.erase(iter, end);
break;
}
}
}
// Start/stop accumulating new trail data (clear old data)
void Planet::startTrail(bool b)
{
if (b)
{
firstPoint = 1;
// qDebug("trail for %s: %f\n", name.c_str(), re.siderealPe
riod);
// only interested in trails for planets
if(re.siderealPeriod > 0) trailOn = 1;
}
else
{
trailOn = 0;
}
}
void Planet::update(int deltaTime) void Planet::update(int deltaTime)
{ {
hintFader.update(deltaTime); hintFader.update(deltaTime);
labelsFader.update(deltaTime); labelsFader.update(deltaTime);
orbitFader.update(deltaTime); orbitFader.update(deltaTime);
trailFader.update(deltaTime);
} }
 End of changes. 22 change blocks. 
161 lines changed or deleted 36 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/