StelCore.cpp   StelCore.cpp 
skipping to change at line 28 skipping to change at line 28
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelNavigator.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 "SolarSystem.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "Planet.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include <QtOpenGL>
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QMetaEnum> #include <QMetaEnum>
/************************************************************************* /*************************************************************************
Constructor Constructor
*************************************************************************/ *************************************************************************/
StelCore::StelCore() : geodesicGrid(NULL), currentProjectionType(Projection Stereographic) StelCore::StelCore() : navigation(NULL), movementMgr(NULL), geodesicGrid(NU LL), currentProjectionType(ProjectionStereographic)
{ {
toneConverter = new StelToneReproducer(); toneConverter = new StelToneReproducer();
movementMgr = new StelMovementMgr(this);
movementMgr->init();
StelApp::getInstance().getModuleMgr().registerModule(movementMgr);
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 ();
const int viewport_y = conf->value("projection/viewport_y", 0).toInt (); const int viewport_y = conf->value("projection/viewport_y", 0).toInt ();
currentProjectorParams.viewportXywh.set(viewport_x,viewport_y,viewpo rt_width,viewport_height); currentProjectorParams.viewportXywh.set(viewport_x,viewport_y,viewpo rt_width,viewport_height);
const double viewportCenterX = conf->value("projection/viewport_cent er_x",0.5*viewport_width).toDouble(); const double viewportCenterX = conf->value("projection/viewport_cent er_x",0.5*viewport_width).toDouble();
const double viewportCenterY = conf->value("projection/viewport_cent er_y",0.5*viewport_height).toDouble(); const double viewportCenterY = conf->value("projection/viewport_cent er_y",0.5*viewport_height).toDouble();
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)).toDouble(); currentProjectorParams.viewportFovDiameter = conf->value("projection /viewport_fov_diameter", qMin(viewport_width,viewport_height)).toDouble();
currentProjectorParams.fov = movementMgr->getInitFov();
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 Destructor
*************************************************************************/ *************************************************************************/
StelCore::~StelCore() StelCore::~StelCore()
skipping to change at line 86 skipping to change at line 80
delete toneConverter; toneConverter=NULL; delete toneConverter; toneConverter=NULL;
delete geodesicGrid; geodesicGrid=NULL; delete geodesicGrid; geodesicGrid=NULL;
delete skyDrawer; skyDrawer=NULL; delete skyDrawer; skyDrawer=NULL;
} }
/************************************************************************* /*************************************************************************
Load core data and initialize with default values Load core data and initialize with default values
*************************************************************************/ *************************************************************************/
void StelCore::init() void StelCore::init()
{ {
StelPainter::initSystemGLInfo();
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
// StelNavigator // StelNavigator
navigation = new StelNavigator(); navigation = new StelNavigator();
navigation->init(); navigation->init();
movementMgr = new StelMovementMgr(this);
movementMgr->init();
currentProjectorParams.fov = movementMgr->getInitFov();
StelApp::getInstance().getModuleMgr().registerModule(movementMgr);
QString tmpstr = conf->value("projection/type", "stereographic").toS tring(); QString tmpstr = conf->value("projection/type", "stereographic").toS tring();
setCurrentProjectionTypeKey(tmpstr); setCurrentProjectionTypeKey(tmpstr);
// double overwrite_max_fov = conf->value("projection/equal_area_max_fo
v",0.0).toDouble();
// if (overwrite_max_fov > 360.0)
// overwrite_max_fov = 360.0;
// if (overwrite_max_fov > 0.0)
// MappingEqualArea::getMapping()->maxFov = overwrite_max_fov;
// overwrite_max_fov = conf->value("projection/stereographic_max_fov",0
.0).toDouble();
// if (overwrite_max_fov > 359.999999)
// overwrite_max_fov = 359.999999;
// if (overwrite_max_fov > 0.0)
// MappingStereographic::getMapping()->maxFov = overwrite_max_f
ov;
// overwrite_max_fov = conf->value("projection/fisheye_max_fov",0.0).to
Double();
// if (overwrite_max_fov > 360.0)
// overwrite_max_fov = 360.0;
// if (overwrite_max_fov > 0.0)
// MappingFisheye::getMapping()->maxFov = overwrite_max_fov;
// overwrite_max_fov = conf->value("projection/cylinder_max_fov",0.0).t
oDouble();
// if (overwrite_max_fov > 540.0)
// overwrite_max_fov = 540.0;
// if (overwrite_max_fov > 0.0)
// MappingCylinder::getMapping()->maxFov = overwrite_max_fov;
// overwrite_max_fov = conf->value("projection/perspective_max_fov",0.0
).toDouble();
// if (overwrite_max_fov > 179.999999)
// overwrite_max_fov = 179.999999;
// if (overwrite_max_fov > 0.0)
// MappingPerspective::getMapping()->maxFov = overwrite_max_fov
;
// overwrite_max_fov = conf->value("projection/orthographic_max_fov",0.
0).toDouble();
// if (overwrite_max_fov > 180.0)
// overwrite_max_fov = 180.0;
// if (overwrite_max_fov > 0.0)
// MappingOrthographic::getMapping()->maxFov = overwrite_max_fo
v;
skyDrawer = new StelSkyDrawer(this); skyDrawer = new StelSkyDrawer(this);
skyDrawer->init(); skyDrawer->init();
// Debug
// Invert colors fragment shader
// const QByteArray a("void main(void) {float gray = dot(gl_Color.rgb,
vec3(0.299, 0.587, 0.114)); gl_FragColor = vec4(gray * vec3(1.2, 1.0, 0.8),
1.0);}");
// GLuint fs; // Fragment Shader
// GLuint sp; // Shader Program
// fs = glCreateShader(GL_FRAGMENT_SHADER);
// const char* str = a.constData();
// glShaderSource(fs, 1, &str, NULL);
// glCompileShader(fs);
// printLog(fs);
//
// sp = glCreateProgram();
// glAttachShader(sp, fs);
// glLinkProgram(sp);
// printLog(sp);
// glUseProgram(sp);
} }
// 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);
} }
else if (maxLevel>geodesicGrid->getMaxLevel()) else if (maxLevel>geodesicGrid->getMaxLevel())
{ {
delete geodesicGrid; delete geodesicGrid;
geodesicGrid = new StelGeodesicGrid(maxLevel); geodesicGrid = new StelGeodesicGrid(maxLevel);
} }
return geodesicGrid; return geodesicGrid;
} }
const 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 avigation, StelMovementMgr // Get an instance of projector using the current display parameters from N avigation, StelMovementMgr
// and using the given modelview matrix // and using the given modelview matrix
const StelProjectorP StelCore::getProjection(const Mat4d& modelViewMat, Pro jectionType projType) const 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 delViewMat));
break; break;
skipping to change at line 206 skipping to change at line 156
case ProjectionCylinder: case ProjectionCylinder:
prj = StelProjectorP(new StelProjectorCylinder(model ViewMat)); prj = StelProjectorP(new StelProjectorCylinder(model ViewMat));
break; break;
case ProjectionMercator: case ProjectionMercator:
prj = StelProjectorP(new StelProjectorMercator(model ViewMat)); prj = StelProjectorP(new StelProjectorMercator(model ViewMat));
break; break;
case ProjectionOrthographic: case ProjectionOrthographic:
prj = StelProjectorP(new StelProjectorOrthographic(m odelViewMat)); prj = StelProjectorP(new StelProjectorOrthographic(m odelViewMat));
break; break;
default: default:
qWarning() << "Unknown projection type: " << projTyp e << "using ProjectionStereographic instead"; qWarning() << "Unknown projection type: " << (int)(p rojType) << "using ProjectionStereographic instead";
prj = StelProjectorP(new StelProjectorStereographic( modelViewMat)); prj = StelProjectorP(new StelProjectorStereographic( modelViewMat));
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
const StelProjectorP StelCore::getProjection(FrameType frameType, Projectio nType projType) const StelProjectorP StelCore::getProjection(FrameType frameType, ProjectionType projType) const
{ {
switch (frameType) switch (frameType)
{ {
case FrameAltAz: case FrameAltAz:
return getProjection(navigation->getAltAzModelViewMa t(), projType); return getProjection(navigation->getAltAzModelViewMa t(), projType);
case FrameHeliocentricEcliptic: case FrameHeliocentricEcliptic:
return getProjection(navigation->getHeliocentricEcli pticModelViewMat(), projType); return getProjection(navigation->getHeliocentricEcli pticModelViewMat(), projType);
case FrameObservercentricEcliptic: case FrameObservercentricEcliptic:
return getProjection(navigation->getObservercentricE clipticModelViewMat(), projType); return getProjection(navigation->getObservercentricE clipticModelViewMat(), projType);
case FrameEquinoxEqu: case FrameEquinoxEqu:
return getProjection(navigation->getEquinoxEquModelV iewMat(), projType); return getProjection(navigation->getEquinoxEquModelV iewMat(), projType);
case FrameJ2000: case FrameJ2000:
return getProjection(navigation->getJ2000ModelViewMa t(), projType); return getProjection(navigation->getJ2000ModelViewMa t(), projType);
case FrameGalactic:
return getProjection(navigation->getGalacticModelVi
ewMat(), projType);
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(int width,int height) void StelCore::windowHasBeenResized(float x, float y, float width, float he ight)
{ {
// Maximize display when resized since it invalidates previous optio ns anyway // Maximize display when resized since it invalidates previous optio ns anyway
currentProjectorParams.viewportXywh.set(0, 0, width, height); currentProjectorParams.viewportXywh.set(x, y, width, height);
currentProjectorParams.viewportCenter.set(0.5*width, 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 etc... // Update the position of observation and time and recompute planet positions etc...
navigation->updateTime(deltaTime); navigation->updateTime(deltaTime);
// Position of sun and all the satellites (ie planets)
SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getMod
uleMgr().getModule("SolarSystem");
solsystem->computePositions(navigation->getJDay(), navigation->getHo
mePlanet()->getHeliocentricEclipticPos());
// Transform matrices between coordinates systems // Transform matrices between coordinates systems
navigation->updateTransformMatrices(); navigation->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 281 skipping to change at line 228
*************************************************************************/ *************************************************************************/
void StelCore::preDraw() void StelCore::preDraw()
{ {
// Init openGL viewing with fov, screen size and clip planes // Init openGL viewing with fov, screen size and clip planes
currentProjectorParams.zNear = 0.000001; currentProjectorParams.zNear = 0.000001;
currentProjectorParams.zFar = 50.; currentProjectorParams.zFar = 50.;
skyDrawer->preDraw(); skyDrawer->preDraw();
// Clear areas not redrawn by main viewport (i.e. fisheye square vie wport) // Clear areas not redrawn by main viewport (i.e. fisheye square vie wport)
StelPainter sPainter(getProjection2d());
glClearColor(0,0,0,0); glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
/************************************************************************* /*************************************************************************
Update core state after drawing modules Update core state after drawing modules
*************************************************************************/ *************************************************************************/
void StelCore::postDraw() void StelCore::postDraw()
{ {
StelPainter sPainter(getProjection(StelCore::FrameJ2000)); StelPainter sPainter(getProjection(StelCore::FrameJ2000));
sPainter.drawViewportShape(); sPainter.drawViewportShape();
// // Inverted mode
// glPixelTransferi(GL_RED_BIAS, 1);
// glPixelTransferi(GL_GREEN_BIAS, 1);
// glPixelTransferi(GL_BLUE_BIAS, 1);
// glPixelTransferi(GL_RED_SCALE, -1);
// glPixelTransferi(GL_GREEN_SCALE, -1);
// glPixelTransferi(GL_BLUE_SCALE, -1);
// // Night red mode
// glPixelTransferf(GL_GREEN_SCALE, 0.1f);
// glPixelTransferf(GL_BLUE_SCALE, 0.1f);
//
// glDisable(GL_TEXTURE_2D);
// glShadeModel(GL_FLAT);
// glDisable(GL_DEPTH_TEST);
// glDisable(GL_CULL_FACE);
// glDisable(GL_LIGHTING);
// glDisable(GL_MULTISAMPLE);
// glDisable(GL_DITHER);
// glDisable(GL_ALPHA_TEST);
// glRasterPos2i(0,0);
//
// glReadBuffer(GL_BACK);
// glDrawBuffer(GL_BACK);
// glCopyPixels(1, 1, 200, 200, GL_COLOR);
} }
//! 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"));
currentProjectionType = (ProjectionType)en.keyToValue(key.toAscii(). data()); currentProjectionType = (ProjectionType)en.keyToValue(key.toAscii(). data());
if (currentProjectionType<0) if (currentProjectionType<0)
{ {
qWarning() << "Unknown projection type: " << key << "setting \"ProjectionStereographic\" instead"; qWarning() << "Unknown projection type: " << key << "setting \"ProjectionStereographic\" instead";
 End of changes. 22 change blocks. 
109 lines changed or deleted 20 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/