~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/StelCore.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003 Fabien Chereau
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
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"
 
31
#include "Planet.hpp"
 
32
 
 
33
/*************************************************************************
 
34
 Constructor
 
35
*************************************************************************/
 
36
StelCore::StelCore() : projection(NULL)
 
37
{
 
38
        tone_converter = new ToneReproducer();
 
39
}
 
40
 
 
41
 
 
42
/*************************************************************************
 
43
 Destructor
 
44
*************************************************************************/
 
45
StelCore::~StelCore()
 
46
{
 
47
        delete navigation; navigation=NULL;
 
48
        delete projection; projection=NULL;
 
49
        delete observatory; observatory=NULL;
 
50
        delete tone_converter; tone_converter=NULL;
 
51
        
 
52
        if (geodesic_grid)
 
53
        {
 
54
                delete geodesic_grid;
 
55
                geodesic_grid = NULL;
 
56
        }
 
57
}
 
58
 
 
59
 
 
60
/*************************************************************************
 
61
 Init projection temp TODO remove
 
62
*************************************************************************/
 
63
void StelCore::initProj(const InitParser& conf)
 
64
{
 
65
        // Projector
 
66
        projection = new Projector(Vector4<GLint>(0,0,800,600), 60);
 
67
        projection->init(conf);
 
68
}
 
69
 
 
70
 
 
71
/*************************************************************************
 
72
 Load core data and initialize with default values
 
73
*************************************************************************/
 
74
void StelCore::init(const InitParser& conf)
 
75
{       
 
76
        // Observer
 
77
        SolarSystem* solsystem = (SolarSystem*)StelApp::getInstance().getModuleMgr().getModule("SolarSystem");
 
78
        observatory = new Observer(*solsystem);
 
79
        observatory->load(conf, "init_location");
 
80
 
 
81
        // Navigator
 
82
        navigation = new Navigator(observatory);
 
83
        navigation->init(conf);
 
84
        
 
85
        movementMgr = new MovementMgr(this);
 
86
        movementMgr->init(conf);
 
87
        StelApp::getInstance().getModuleMgr().registerModule(movementMgr);      
 
88
        
 
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);
 
93
}
 
94
 
 
95
 
 
96
/*************************************************************************
 
97
 Update all the objects in function of the time
 
98
*************************************************************************/
 
99
void StelCore::update(int delta_time)
 
100
{
 
101
        // Update the position of observation and time etc...
 
102
        observatory->update(delta_time);
 
103
        navigation->updateTime(delta_time);
 
104
 
 
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;
 
109
 
 
110
        // Transform matrices between coordinates systems
 
111
        navigation->updateTransformMatrices();
 
112
        
 
113
        // Update direction of vision/Zoom level
 
114
        movementMgr->updateMotion((double)delta_time/1000);     
 
115
        
 
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());
 
128
}
 
129
 
 
130
 
 
131
/*************************************************************************
 
132
 Execute all the pre-drawing functions
 
133
*************************************************************************/
 
134
void StelCore::preDraw()
 
135
{
 
136
        // Init openGL viewing with fov, screen size and clip planes
 
137
        projection->set_clipping_planes(0.000001 ,50);
 
138
 
 
139
        // Init viewport to current projector values
 
140
        projection->applyViewport();
 
141
 
 
142
        projection->setCurrentFrame(Projector::FRAME_J2000);
 
143
}
 
144
 
 
145
 
 
146
/*************************************************************************
 
147
 Update core state after drawing modules
 
148
*************************************************************************/
 
149
void StelCore::postDraw()
 
150
{
 
151
        projection->draw_viewport_shape();
 
152
}