LandscapeMgr.cpp   LandscapeMgr.cpp 
skipping to change at line 24 skipping to change at line 24
* *
* 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 <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#ifdef USE_OPENGL_ES2
#include "GLES2/gl2.h"
#else
#include <QtOpenGL>
#endif
#include "LandscapeMgr.hpp" #include "LandscapeMgr.hpp"
#include "Landscape.hpp" #include "Landscape.hpp"
#include "Atmosphere.hpp" #include "Atmosphere.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelFontMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "StelFont.hpp"
#include "StelSkyDrawer.hpp" #include "StelSkyDrawer.hpp"
#include "StelStyle.hpp" #include "StelStyle.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
// Class which manages the cardinal points displaying // Class which manages the cardinal points displaying
class Cardinals class Cardinals
{ {
public: public:
Cardinals(float _radius = 1.); Cardinals(float _radius = 1.);
virtual ~Cardinals(); virtual ~Cardinals();
void draw(const StelCore* core, double latitude, bool gravityON = fa lse) const; void draw(const StelCore* core, double latitude, bool gravityON = fa lse) const;
void setColor(const Vec3f& c) {color = c;} void setColor(const Vec3f& c) {color = c;}
Vec3f get_color() {return color;} Vec3f get_color() {return color;}
void updateI18n(); void updateI18n();
void update(double deltaTime) {fader.update((int)(deltaTime*1000));} void update(double deltaTime) {fader.update((int)(deltaTime*1000));}
void set_fade_duration(float duration) {fader.setDuration((int)(dura tion*1000.f));} void set_fade_duration(float duration) {fader.setDuration((int)(dura tion*1000.f));}
void setFlagShow(bool b){fader = b;} void setFlagShow(bool b){fader = b;}
bool getFlagShow(void) const {return fader;} bool getFlagShow(void) const {return fader;}
private: private:
float radius; float radius;
double fontSize; QFont font;
StelFont& font;
Vec3f color; Vec3f color;
QString sNorth, sSouth, sEast, sWest; QString sNorth, sSouth, sEast, sWest;
LinearFader fader; LinearFader fader;
}; };
Cardinals::Cardinals(float _radius) : radius(_radius), fontSize(30), Cardinals::Cardinals(float _radius) : radius(_radius), color(0.6,0.2,0.2)
font(StelApp::getInstance().getFontManager().getStandardFont(StelApp::getIn
stance().getLocaleMgr().getAppLanguage(), fontSize)), color(0.6,0.2,0.2)
{ {
font.setPixelSize(30);
// Default labels - if sky locale specified, loaded later // Default labels - if sky locale specified, loaded later
// Improvement for gettext translation // Improvement for gettext translation
sNorth = "N"; sNorth = "N";
sSouth = "S"; sSouth = "S";
sEast = "E"; sEast = "E";
sWest = "W"; sWest = "W";
} }
Cardinals::~Cardinals() Cardinals::~Cardinals()
{ {
} }
// Draw the cardinals points : N S E W // Draw the cardinals points : N S E W
// handles special cases at poles // handles special cases at poles
void Cardinals::draw(const StelCore* core, double latitude, bool gravityON) const void Cardinals::draw(const StelCore* core, double latitude, bool gravityON) const
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ; const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ;
StelPainter sPainter(prj); StelPainter sPainter(prj);
sPainter.setFont(font);
if (!fader.getInterstate()) return; if (!fader.getInterstate()) return;
// direction text // direction text
QString d[4]; QString d[4];
d[0] = sNorth; d[0] = sNorth;
d[1] = sSouth; d[1] = sSouth;
d[2] = sEast; d[2] = sEast;
d[3] = sWest; d[3] = sWest;
// fun polar special cases // fun polar special cases
if(latitude == 90.0 ) d[0] = d[1] = d[2] = d[3] = sSouth; if (latitude == 90.0 ) d[0] = d[1] = d[2] = d[3] = sSouth;
if(latitude == -90.0 ) d[0] = d[1] = d[2] = d[3] = sNorth; if (latitude == -90.0 ) d[0] = d[1] = d[2] = d[3] = sNorth;
glColor4f(color[0],color[1],color[2],fader.getInterstate()); sPainter.setColor(color[0],color[1],color[2],fader.getInterstate());
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D); sPainter.enableTexture2d(true);
// Normal transparency mode // Normal transparency mode
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Vec3f pos; Vec3f pos;
Vec3d xy; Vec3d xy;
float shift = font.getStrLen(sNorth)/2; float shift = sPainter.getFontMetrics().width(sNorth)/2;
// N for North // N for North
pos.set(-1.f, 0.f, 0.f); pos.set(-1.f, 0.f, 0.f);
if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[0 ], 0., -shift, -shift); if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[0], 0., -shift, -shift);
// S for South // S for South
pos.set(1.f, 0.f, 0.f); pos.set(1.f, 0.f, 0.f);
if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[1 ], 0., -shift, -shift); if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[1], 0., -shift, -shift);
// E for East // E for East
pos.set(0.f, 1.f, 0.f); pos.set(0.f, 1.f, 0.f);
if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[2 ], 0., -shift, -shift); if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[2], 0., -shift, -shift);
// W for West // W for West
pos.set(0.f, -1.f, 0.f); pos.set(0.f, -1.f, 0.f);
if (prj->project(pos,xy)) sPainter.drawText(&font, xy[0], xy[1], d[3 ], 0., -shift, -shift); if (prj->project(pos,xy)) sPainter.drawText(xy[0], xy[1], d[3], 0., -shift, -shift);
} }
// Translate cardinal labels with gettext to current sky language and updat e font for the language // Translate cardinal labels with gettext to current sky language and updat e font for the language
void Cardinals::updateI18n() void Cardinals::updateI18n()
{ {
StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSky Translator(); StelTranslator& trans = StelApp::getInstance().getLocaleMgr().getSky Translator();
sNorth = trans.qtranslate("N"); sNorth = trans.qtranslate("N");
sSouth = trans.qtranslate("S"); sSouth = trans.qtranslate("S");
sEast = trans.qtranslate("E"); sEast = trans.qtranslate("E");
sWest = trans.qtranslate("W"); sWest = trans.qtranslate("W");
font = StelApp::getInstance().getFontManager().getStandardFont(trans .getTrueLocaleName(), fontSize);
} }
LandscapeMgr::LandscapeMgr() : atmosphere(NULL), cardinalsPoints(NULL), lan dscape(NULL), flagLandscapeSetsLocation(false) LandscapeMgr::LandscapeMgr() : atmosphere(NULL), cardinalsPoints(NULL), lan dscape(NULL), flagLandscapeSetsLocation(false)
{ {
setObjectName("LandscapeMgr"); setObjectName("LandscapeMgr");
} }
LandscapeMgr::~LandscapeMgr() LandscapeMgr::~LandscapeMgr()
{ {
delete atmosphere; delete atmosphere;
skipping to change at line 159 skipping to change at line 162
delete landscape; delete landscape;
landscape = NULL; landscape = NULL;
} }
/************************************************************************* /*************************************************************************
Reimplementation of the getCallOrder method Reimplementation of the getCallOrder method
*************************************************************************/ *************************************************************************/
double LandscapeMgr::getCallOrder(StelModuleActionName actionName) const double LandscapeMgr::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Tele scopeMgr")->getCallOrder(actionName)+10; return StelApp::getInstance().getModuleMgr().getModule("Mete orMgr")->getCallOrder(actionName)+20;
if (actionName==StelModule::ActionUpdate) if (actionName==StelModule::ActionUpdate)
return StelApp::getInstance().getModuleMgr().getModule("Sola rSystem")->getCallOrder(actionName)+10; return StelApp::getInstance().getModuleMgr().getModule("Sola rSystem")->getCallOrder(actionName)+10;
return 0; return 0;
} }
void LandscapeMgr::update(double deltaTime) void LandscapeMgr::update(double deltaTime)
{ {
atmosphere->update(deltaTime); atmosphere->update(deltaTime);
landscape->update(deltaTime); landscape->update(deltaTime);
cardinalsPoints->update(deltaTime); cardinalsPoints->update(deltaTime);
skipping to change at line 216 skipping to change at line 219
// } // }
// groundLuminance*=atmosphere->getFadeIntensity(); // groundLuminance*=atmosphere->getFadeIntensity();
// groundLuminance=atmosphere->getAverageLuminance()/50; // groundLuminance=atmosphere->getAverageLuminance()/50;
// qDebug() << "Atmosphere lum=" << atmosphere->getAverageLuminance() < < " ground lum=" << groundLuminance; // qDebug() << "Atmosphere lum=" << atmosphere->getAverageLuminance() < < " ground lum=" << groundLuminance;
// qDebug() << "Adapted Atmosphere lum=" << eye->adaptLuminance(atmosph ere->getAverageLuminance()) << " Adapted ground lum=" << eye->adaptLuminanc e(groundLuminance); // qDebug() << "Adapted Atmosphere lum=" << eye->adaptLuminance(atmosph ere->getAverageLuminance()) << " Adapted ground lum=" << eye->adaptLuminanc e(groundLuminance);
// compute global ground brightness in a simplistic way, directly in RGB // compute global ground brightness in a simplistic way, directly in RGB
float landscapeBrightness = 0; float landscapeBrightness = 0;
sunPos.normalize(); sunPos.normalize();
moonPos.normalize(); moonPos.normalize();
if(sunPos[2] < -0.1/1.5 )
// We define the brigthness zero when the sun is 8 degrees below the
horizon.
float sinSunAngleRad = sin(qMin(M_PI_2, asin(sunPos[2])+8.*M_PI/180.
));
if(sinSunAngleRad < -0.1/1.5 )
landscapeBrightness = 0.01; landscapeBrightness = 0.01;
else else
landscapeBrightness = (0.01 + 1.5*(sunPos[2]+0.1/1.5)); landscapeBrightness = (0.01 + 1.5*(sinSunAngleRad+0.1/1.5));
if (moonPos[2] > -0.1/1.5) if (moonPos[2] > -0.1/1.5)
landscapeBrightness += qMax(0.2/-12.*ssystem->getMoon()->get VMagnitude(nav),0.)*moonPos[2]; landscapeBrightness += qMax(0.2/-12.*ssystem->getMoon()->get VMagnitude(nav),0.)*moonPos[2];
//
// TODO make this more generic for non-atmosphere planets // TODO make this more generic for non-atmosphere planets
if(atmosphere->getFadeIntensity() == 1) if(atmosphere->getFadeIntensity() == 1)
{ {
// If the atmosphere is on, a solar eclipse might darken the sky // If the atmosphere is on, a solar eclipse might darken the sky
// otherwise we just use the sun position calculation above // otherwise we just use the sun position calculation above
landscapeBrightness *= (atmosphere->getRealDisplayIntensityF actor()+0.1); landscapeBrightness *= (atmosphere->getRealDisplayIntensityF actor()+0.1);
} }
// TODO: should calculate dimming with solar eclipse even without at mosphere on // TODO: should calculate dimming with solar eclipse even without at mosphere on
landscape->setBrightness(landscapeBrightness+0.05); landscape->setBrightness(landscapeBrightness+0.05);
skipping to change at line 503 skipping to change at line 510
return atmosphere->getLightPollutionLuminance(); return atmosphere->getLightPollutionLuminance();
} }
//! Set the light pollution following the Bortle Scale //! Set the light pollution following the Bortle Scale
void LandscapeMgr::setAtmosphereBortleLightPollution(int bIndex) void LandscapeMgr::setAtmosphereBortleLightPollution(int bIndex)
{ {
// This is an empirical formula // This is an empirical formula
setAtmosphereLightPollutionLuminance(qMax(0.,0.0020*std::pow(bIndex- 1, 2.1))); setAtmosphereLightPollutionLuminance(qMax(0.,0.0020*std::pow(bIndex- 1, 2.1)));
} }
//! Get the light pollution following the Bortle Scale
int LandscapeMgr::getAtmosphereBortleLightPollution(void)
{
return (int)std::pow(getAtmosphereLightPollutionLuminance()/0.0020,
1./2.1) + 1;
}
void LandscapeMgr::setZRotation(double d) void LandscapeMgr::setZRotation(double d)
{ {
if (landscape) if (landscape)
landscape->setZRotation(d); landscape->setZRotation(d);
} }
float LandscapeMgr::getLuminance(void) float LandscapeMgr::getLuminance(void)
{ {
return atmosphere->getRealDisplayIntensityFactor(); return atmosphere->getRealDisplayIntensityFactor();
} }
skipping to change at line 593 skipping to change at line 606
} }
} }
/************************************************************************** ** /************************************************************************** **
get a map of landscape name (from landscape.ini name field) to ID (dir nam e) get a map of landscape name (from landscape.ini name field) to ID (dir nam e)
************************************************************************** **/ ************************************************************************** **/
QMap<QString,QString> LandscapeMgr::getNameToDirMap(void) const QMap<QString,QString> LandscapeMgr::getNameToDirMap(void) const
{ {
QSet<QString> landscapeDirs; QSet<QString> landscapeDirs;
QMap<QString,QString> result; QMap<QString,QString> result;
StelFileMgr& fileMan(StelApp::getInstance().getFileMgr());
try try
{ {
landscapeDirs = fileMan.listContents("landscapes",StelFileMg r::Directory); landscapeDirs = StelFileMgr::listContents("landscapes",StelF ileMgr::Directory);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qDebug() << "ERROR while trying list landscapes:" << e.what( ); qDebug() << "ERROR while trying list landscapes:" << e.what( );
} }
foreach (QString dir, landscapeDirs) foreach (const QString& dir, landscapeDirs)
{ {
try try
{ {
QSettings landscapeIni(fileMan.findFile("landscapes/ " + dir + "/landscape.ini"), StelIniFormat); QSettings landscapeIni(StelFileMgr::findFile("landsc apes/" + dir + "/landscape.ini"), StelIniFormat);
QString k = landscapeIni.value("landscape/name").toS tring(); QString k = landscapeIni.value("landscape/name").toS tring();
result[k] = dir; result[k] = dir;
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
//qDebug << "WARNING: unable to successfully read la ndscape.ini file from landscape " << dir; //qDebug << "WARNING: unable to successfully read la ndscape.ini file from landscape " << dir;
} }
} }
return result; return result;
} }
bool LandscapeMgr::doSetCurrentLandscapeID(const QString& id) bool LandscapeMgr::doSetCurrentLandscapeID(const QString& id)
{ {
if (id.isEmpty()) if (id.isEmpty())
{ {
emit(requestCompleteSetCurrentLandscapeID(false)); emit(requestCompleteSetCurrentLandscapeID(false));
return false; return false;
} }
// we want to lookup the landscape ID (dir) from the name. // We want to lookup the landscape ID (dir) from the name.
StelFileMgr& fileMan = StelApp::getInstance().getFileMgr();
Landscape* newLandscape = NULL; Landscape* newLandscape = NULL;
try try
{ {
newLandscape = createFromFile(fileMan.findFile("landscapes/" + id + "/landscape.ini"), id); newLandscape = createFromFile(StelFileMgr::findFile("landsca pes/" + id + "/landscape.ini"), id);
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
{ {
qWarning() << "ERROR while loading landscape " << "landscape s/" + id + "/landscape.ini" << ", (" << e.what() << ")" << endl; qWarning() << "ERROR while loading landscape " << "landscape s/" + id + "/landscape.ini" << ", (" << e.what() << ")" << endl;
} }
if (!newLandscape) if (!newLandscape)
{ {
emit(requestCompleteSetCurrentLandscapeID(false)); emit(requestCompleteSetCurrentLandscapeID(false));
return false; return false;
 End of changes. 28 change blocks. 
29 lines changed or deleted 41 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/