StelCore.cpp   StelCore.cpp 
skipping to change at line 20 skipping to change at line 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* 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 "StelCore.hpp" #include "StelCore.hpp"
#include "Navigator.hpp" #include "StelNavigator.hpp"
#include "Projector.hpp" #include "StelProjector.hpp"
#include "ToneReproducer.hpp" #include "StelProjectorClasses.hpp"
#include "SkyDrawer.hpp" #include "StelToneReproducer.hpp"
#include "StelSkyDrawer.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "GeodesicGrid.hpp" #include "StelGeodesicGrid.hpp"
#include "StarMgr.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "MovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "StelPainter.hpp"
#include <QSettings> #include <QSettings>
#include <QDebug>
#include <QMetaEnum>
/************************************************************************* /*************************************************************************
Constructor Constructor
*************************************************************************/ *************************************************************************/
StelCore::StelCore() StelCore::StelCore() : geodesicGrid(NULL), currentProjectionType(Projection Stereographic)
{ {
toneConverter = new ToneReproducer(); toneConverter = new StelToneReproducer();
projection = new Projector(Vector4<GLint>(0,0,800,600), 60); movementMgr = new StelMovementMgr(this);
projection->init(); movementMgr->init();
skyDrawer = new SkyDrawer(this); StelApp::getInstance().getModuleMgr().registerModule(movementMgr);
QSettings* conf = StelApp::getInstance().getSettings();
// Create and initialize the default projector params
QString tmpstr = conf->value("projection/viewport").toString();
currentProjectorParams.maskType = StelProjector::stringToMaskType(tm
pstr);
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_x = conf->value("projection/viewport_x", 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);
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();
currentProjectorParams.viewportCenter.set(viewportCenterX, viewportC
enterY);
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.flipVert = conf->value("projection/flip_vert"
,false).toBool();
currentProjectorParams.gravityLabels = conf->value("viewing/flag_gra
vity_labels").toBool();
} }
/************************************************************************* /*************************************************************************
Destructor Destructor
*************************************************************************/ *************************************************************************/
StelCore::~StelCore() StelCore::~StelCore()
{ {
delete navigation; navigation=NULL; delete navigation; navigation=NULL;
delete projection; projection=NULL;
delete toneConverter; toneConverter=NULL; delete toneConverter; toneConverter=NULL;
delete geodesicGrid; geodesicGrid=NULL; delete geodesicGrid; geodesicGrid=NULL;
delete skyDrawer; skyDrawer=NULL; delete skyDrawer; skyDrawer=NULL;
} }
// void printLog(GLuint obj)
// {
// int infologLength = 0;
// int maxLength;
//
// if(glIsShader(obj))
// glGetShaderiv(obj,GL_INFO_LOG_LENGTH,&maxLength);
// else
// glGetProgramiv(obj,GL_INFO_LOG_LENGTH,&maxLength);
//
// char infoLog[maxLength];
//
// if (glIsShader(obj))
// glGetShaderInfoLog(obj, maxLength, &infologLength, infoLog);
// else
// glGetProgramInfoLog(obj, maxLength, &infologLength, infoLog)
;
//
// if (infologLength > 0)
// printf("%s\n",infoLog);
// }
/************************************************************************* /*************************************************************************
Load core data and initialize with default values Load core data and initialize with default values
*************************************************************************/ *************************************************************************/
void StelCore::init() void StelCore::init()
{ {
// Navigator StelPainter::initSystemGLInfo();
navigation = new Navigator();
QSettings* conf = StelApp::getInstance().getSettings();
// StelNavigator
navigation = new StelNavigator();
navigation->init(); navigation->init();
movementMgr = new MovementMgr(this); QString tmpstr = conf->value("projection/type", "stereographic").toS
movementMgr->init(); tring();
StelApp::getInstance().getModuleMgr().registerModule(movementMgr); setCurrentProjectionTypeKey(tmpstr);
StarMgr* hip_stars = (StarMgr*)StelApp::getInstance().getModuleMgr() // double overwrite_max_fov = conf->value("projection/equal_area_max_fo
.getModule("StarMgr"); v",0.0).toDouble();
int grid_level = hip_stars->getMaxGridLevel(); // if (overwrite_max_fov > 360.0)
geodesicGrid = new GeodesicGrid(grid_level); // overwrite_max_fov = 360.0;
hip_stars->setGrid(geodesicGrid); // 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->init(); skyDrawer->init();
// Debug // Debug
// Invert colors fragment shader // 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);}"); // 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 fs; // Fragment Shader
// GLuint sp; // Shader Program // GLuint sp; // Shader Program
// fs = glCreateShader(GL_FRAGMENT_SHADER); // fs = glCreateShader(GL_FRAGMENT_SHADER);
// const char* str = a.constData(); // const char* str = a.constData();
// glShaderSource(fs, 1, &str, NULL); // glShaderSource(fs, 1, &str, NULL);
// glCompileShader(fs); // glCompileShader(fs);
// printLog(fs); // printLog(fs);
// //
// sp = glCreateProgram(); // sp = glCreateProgram();
// glAttachShader(sp, fs); // glAttachShader(sp, fs);
// glLinkProgram(sp); // glLinkProgram(sp);
// printLog(sp); // printLog(sp);
// glUseProgram(sp); // glUseProgram(sp);
} }
// Get the shared instance of StelGeodesicGrid.
// The returned instance is garanteed to allow for at least maxLevel levels
const StelGeodesicGrid* StelCore::getGeodesicGrid(int maxLevel) const
{
if (geodesicGrid==NULL)
{
geodesicGrid = new StelGeodesicGrid(maxLevel);
}
else if (maxLevel>geodesicGrid->getMaxLevel())
{
delete geodesicGrid;
geodesicGrid = new StelGeodesicGrid(maxLevel);
}
return geodesicGrid;
}
const StelProjectorP StelCore::getProjection2d() const
{
StelProjectorP prj(new StelProjector2d());
prj->init(currentProjectorParams);
return prj;
}
// Get an instance of projector using the current display parameters from N
avigation, StelMovementMgr
// and using the given modelview matrix
const StelProjectorP StelCore::getProjection(const Mat4d& modelViewMat, Pro
jectionType projType) const
{
if (projType==1000)
projType = currentProjectionType;
StelProjectorP prj;
switch (projType)
{
case ProjectionPerspective:
prj = StelProjectorP(new StelProjectorPerspective(mo
delViewMat));
break;
case ProjectionEqualArea:
prj = StelProjectorP(new StelProjectorEqualArea(mode
lViewMat));
break;
case ProjectionStereographic:
prj = StelProjectorP(new StelProjectorStereographic(
modelViewMat));
break;
case ProjectionFisheye:
prj = StelProjectorP(new StelProjectorFisheye(modelV
iewMat));
break;
case ProjectionCylinder:
prj = StelProjectorP(new StelProjectorCylinder(model
ViewMat));
break;
case ProjectionMercator:
prj = StelProjectorP(new StelProjectorMercator(model
ViewMat));
break;
case ProjectionOrthographic:
prj = StelProjectorP(new StelProjectorOrthographic(m
odelViewMat));
break;
default:
qWarning() << "Unknown projection type: " << projTyp
e << "using ProjectionStereographic instead";
prj = StelProjectorP(new StelProjectorStereographic(
modelViewMat));
Q_ASSERT(0);
}
prj->init(currentProjectorParams);
return prj;
}
// Get an instance of projector using the current display parameters from N
avigation, StelMovementMgr
const StelProjectorP StelCore::getProjection(FrameType frameType, Projectio
nType projType) const
{
switch (frameType)
{
case FrameAltAz:
return getProjection(navigation->getAltAzModelViewMa
t(), projType);
case FrameHeliocentricEcliptic:
return getProjection(navigation->getHeliocentricEcli
pticModelViewMat(), projType);
case FrameObservercentricEcliptic:
return getProjection(navigation->getObservercentricE
clipticModelViewMat(), projType);
case FrameEquinoxEqu:
return getProjection(navigation->getEquinoxEquModelV
iewMat(), projType);
case FrameJ2000:
return getProjection(navigation->getJ2000ModelViewMa
t(), projType);
default:
qDebug() << "Unknown reference frame type: " << (int
)frameType << ".";
}
Q_ASSERT(0);
return getProjection2d();
}
// Handle the resizing of the window
void StelCore::windowHasBeenResized(int width,int height)
{
// Maximize display when resized since it invalidates previous optio
ns anyway
currentProjectorParams.viewportXywh.set(0, 0, width, height);
currentProjectorParams.viewportCenter.set(0.5*width, 0.5*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 etc...
navigation->updateTime(deltaTime); navigation->updateTime(deltaTime);
// Position of sun and all the satellites (ie planets) // Position of sun and all the satellites (ie planets)
SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getMod uleMgr().getModule("SolarSystem"); SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getMod uleMgr().getModule("SolarSystem");
solsystem->computePositions(navigation->getJDay(), navigation->getHo mePlanet()->getHeliocentricEclipticPos()); 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);
// Give the updated standard projection matrices to the projector. currentProjectorParams.fov = movementMgr->getCurrentFov();
// atmosphere->computeColor needs the projection matrices, so we mus
t
// set them before calling atmosphere->computeColor, otherwise
// the first image will be rendered with invalid (nan)
// inverse projection matrices.
// On the other hand it must be called after ssystem->update
// and panView in order to have the new observers position
// and not interfere with vision vector movement.
projection->setModelviewMatrices( navigation->getEarthEquToEye
Mat(),
navigation->getHelioToEyeMat(),
navigation->getLocalToEyeMat(),
navigation->getJ2000ToEyeMat());
skyDrawer->update(deltaTime); skyDrawer->update(deltaTime);
} }
/************************************************************************* /*************************************************************************
Execute all the pre-drawing functions Execute all the pre-drawing functions
*************************************************************************/ *************************************************************************/
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
projection->setClippingPlanes(0.000001 ,50); currentProjectorParams.zNear = 0.000001;
currentProjectorParams.zFar = 50.;
// Init GL viewport to current projector values
glViewport(projection->getViewportPosX(), projection->getViewportPos
Y(), projection->getViewportWidth(), projection->getViewportHeight());
projection->setCurrentFrame(Projector::FrameJ2000); 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)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
skyDrawer->preDraw();
} }
/************************************************************************* /*************************************************************************
Update core state after drawing modules Update core state after drawing modules
*************************************************************************/ *************************************************************************/
void StelCore::postDraw() void StelCore::postDraw()
{ {
projection->drawViewportShape(); StelPainter sPainter(getProjection(StelCore::FrameJ2000));
sPainter.drawViewportShape();
// // Inverted mode // // Inverted mode
// glPixelTransferi(GL_RED_BIAS, 1); // glPixelTransferi(GL_RED_BIAS, 1);
// glPixelTransferi(GL_GREEN_BIAS, 1); // glPixelTransferi(GL_GREEN_BIAS, 1);
// glPixelTransferi(GL_BLUE_BIAS, 1); // glPixelTransferi(GL_BLUE_BIAS, 1);
// glPixelTransferi(GL_RED_SCALE, -1); // glPixelTransferi(GL_RED_SCALE, -1);
// glPixelTransferi(GL_GREEN_SCALE, -1); // glPixelTransferi(GL_GREEN_SCALE, -1);
// glPixelTransferi(GL_BLUE_SCALE, -1); // glPixelTransferi(GL_BLUE_SCALE, -1);
// // Night red mode // // Night red mode
skipping to change at line 203 skipping to change at line 315
// glDisable(GL_LIGHTING); // glDisable(GL_LIGHTING);
// glDisable(GL_MULTISAMPLE); // glDisable(GL_MULTISAMPLE);
// glDisable(GL_DITHER); // glDisable(GL_DITHER);
// glDisable(GL_ALPHA_TEST); // glDisable(GL_ALPHA_TEST);
// glRasterPos2i(0,0); // glRasterPos2i(0,0);
// //
// glReadBuffer(GL_BACK); // glReadBuffer(GL_BACK);
// glDrawBuffer(GL_BACK); // glDrawBuffer(GL_BACK);
// glCopyPixels(1, 1, 200, 200, GL_COLOR); // glCopyPixels(1, 1, 200, 200, GL_COLOR);
} }
//! Set the current projection type to use
void StelCore::setCurrentProjectionTypeKey(QString key)
{
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf
Enumerator("ProjectionType"));
currentProjectionType = (ProjectionType)en.keyToValue(key.toAscii().
data());
if (currentProjectionType<0)
{
qWarning() << "Unknown projection type: " << key << "setting
\"ProjectionStereographic\" instead";
currentProjectionType = ProjectionStereographic;
}
const double savedFov = currentProjectorParams.fov;
currentProjectorParams.fov = 0.0001; // Avoid crash
double newMaxFov = getProjection(Mat4d())->getMaxFov();
movementMgr->setMaxFov(newMaxFov);
currentProjectorParams.fov = qMin(newMaxFov, savedFov);
}
//! Get the current Mapping used by the Projection
QString StelCore::getCurrentProjectionTypeKey(void) const
{
return metaObject()->enumerator(metaObject()->indexOfEnumerator("Pro
jectionType")).key(currentProjectionType);
}
//! Get the list of all the available projections
QStringList StelCore::getAllProjectionTypeKeys() const
{
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf
Enumerator("ProjectionType"));
QStringList l;
for (int i=0;i<en.keyCount();++i)
l << en.key(i);
return l;
}
//! Get the translated projection name from its TypeKey for the current loc
ale
QString StelCore::projectionTypeKeyToNameI18n(const QString& key) const
{
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf
Enumerator("ProjectionType"));
QString s(getProjection(Mat4d(), (ProjectionType)en.keysToValue(key.
toAscii()))->getNameI18());
return s;
}
//! Get the projection TypeKey from its translated name for the current loc
ale
QString StelCore::projectionNameI18nToTypeKey(const QString& nameI18n) cons
t
{
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf
Enumerator("ProjectionType"));
for (int i=0;i<en.keyCount();++i)
{
if (getProjection(Mat4d(), (ProjectionType)i)->getNameI18()=
=nameI18n)
return en.valueToKey(i);
}
// Unknown translated name
Q_ASSERT(0);
return en.valueToKey(ProjectionStereographic);
}
 End of changes. 21 change blocks. 
69 lines changed or deleted 219 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/