2
* Copyright (C) 2003 Fabien Chereau
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
#include "StelCore.hpp"
20
#include "Navigator.hpp"
21
#include "Observer.hpp"
22
#include "Projector.hpp"
23
#include "ToneReproducer.hpp"
24
#include "StelApp.hpp"
25
#include "StelUtils.hpp"
26
#include "GeodesicGrid.hpp"
27
#include "StarMgr.hpp"
28
#include "SolarSystem.hpp"
29
#include "MovementMgr.hpp"
30
#include "StelModuleMgr.hpp"
33
/*************************************************************************
35
*************************************************************************/
36
StelCore::StelCore() : projection(NULL)
38
tone_converter = new ToneReproducer();
42
/*************************************************************************
44
*************************************************************************/
47
delete navigation; navigation=NULL;
48
delete projection; projection=NULL;
49
delete observatory; observatory=NULL;
50
delete tone_converter; tone_converter=NULL;
60
/*************************************************************************
61
Init projection temp TODO remove
62
*************************************************************************/
63
void StelCore::initProj(const InitParser& conf)
66
projection = new Projector(Vector4<GLint>(0,0,800,600), 60);
67
projection->init(conf);
71
/*************************************************************************
72
Load core data and initialize with default values
73
*************************************************************************/
74
void StelCore::init(const InitParser& conf)
77
SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("SolarSystem");
78
observatory = new Observer(*solsystem);
79
observatory->load(conf, "init_location");
82
navigation = new Navigator(observatory);
83
navigation->init(conf);
85
movementMgr = new MovementMgr(this);
86
movementMgr->init(conf);
87
StelApp::getInstance().getModuleMgr().registerModule(movementMgr);
89
StarMgr* hip_stars = (StarMgr*)StelApp::getInstance().getModuleMgr().getModule("StarMgr");
90
int grid_level = hip_stars->getMaxGridLevel();
91
geodesic_grid = new GeodesicGrid(grid_level);
92
hip_stars->setGrid(geodesic_grid);
96
/*************************************************************************
97
Update all the objects in function of the time
98
*************************************************************************/
99
void StelCore::update(int delta_time)
101
// Update the position of observation and time etc...
102
observatory->update(delta_time);
103
navigation->updateTime(delta_time);
105
// Position of sun and all the satellites (ie planets)
106
SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("SolarSystem");
107
solsystem->computePositions(navigation->getJDay(), navigation->getHomePlanet()->get_heliocentric_ecliptic_pos());
108
//cerr << "get_heliocentric_ecliptic_pos()[0]=" << navigation->getHomePlanet()->get_heliocentric_ecliptic_pos()[0] << endl;
110
// Transform matrices between coordinates systems
111
navigation->updateTransformMatrices();
113
// Update direction of vision/Zoom level
114
movementMgr->updateMotion((double)delta_time/1000);
116
// Give the updated standard projection matrices to the projector.
117
// atmosphere->compute_color needs the projection matrices, so we must
118
// set them before calling atmosphere->compute_color, otherwise
119
// the first image will be rendered with invalid (nan)
120
// inverse projection matrices.
121
// On the other hand it must be called after ssystem->update
122
// and panView in order to have the new observers position
123
// and not interfere with vision vector movement.
124
projection->set_modelview_matrices( navigation->get_earth_equ_to_eye_mat(),
125
navigation->get_helio_to_eye_mat(),
126
navigation->get_local_to_eye_mat(),
127
navigation->get_j2000_to_eye_mat());
131
/*************************************************************************
132
Execute all the pre-drawing functions
133
*************************************************************************/
134
void StelCore::preDraw()
136
// Init openGL viewing with fov, screen size and clip planes
137
projection->set_clipping_planes(0.000001 ,50);
139
// Init viewport to current projector values
140
projection->applyViewport();
142
projection->setCurrentFrame(Projector::FRAME_J2000);
146
/*************************************************************************
147
Update core state after drawing modules
148
*************************************************************************/
149
void StelCore::postDraw()
151
projection->draw_viewport_shape();