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

« back to all changes in this revision

Viewing changes to src/meteor_mgr.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
 
 * Stellarium
3
 
 * This file Copyright (C) 2004 Robert Spearman
4
 
 * 
5
 
 * This program is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU General Public License
7
 
 * as published by the Free Software Foundation; either version 2
8
 
 * of the License, or (at your option) any later version.
9
 
 * 
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 * 
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
 
 */
19
 
 
20
 
#include "meteor_mgr.h"
21
 
 
22
 
MeteorMgr::MeteorMgr(int zhr, int maxv )
23
 
{
24
 
        ZHR = zhr;
25
 
        max_velocity = maxv;
26
 
 
27
 
        // calculate factor for meteor creation rate per second since visible area ZHR is for
28
 
        // estimated visible radius of 458km
29
 
        // (calculated for average meteor magnitude of +2.5 and limiting magnitude of 5)
30
 
 
31
 
        //  zhr_to_wsr = 1.0f/3600.f;
32
 
        zhr_to_wsr = 1.6667f/3600.f;
33
 
        // this is a correction factor to adjust for the model as programmed to match observed rates
34
 
}
35
 
 
36
 
MeteorMgr::~MeteorMgr()
37
 
{}
38
 
 
39
 
void MeteorMgr::set_ZHR(int zhr)
40
 
{
41
 
        ZHR = zhr;
42
 
}
43
 
 
44
 
int MeteorMgr::get_ZHR()
45
 
{
46
 
        return ZHR;
47
 
}
48
 
 
49
 
void MeteorMgr::set_max_velocity(int maxv)
50
 
{
51
 
        max_velocity = maxv;
52
 
}
53
 
 
54
 
void MeteorMgr::update(Projector *proj, Navigator* nav, ToneReproductor* eye, int delta_time)
55
 
{
56
 
 
57
 
        // step through and update all active meteors
58
 
        int n =0;
59
 
        for(vector<Meteor*>::iterator iter = active.begin(); iter != active.end(); ++iter)
60
 
        {
61
 
                n++;
62
 
                //printf("Meteor %d update\n", ++n);
63
 
                if( !( (*iter)->update(delta_time) ) )
64
 
                {
65
 
                        // remove dead meteor
66
 
                        //      printf("Meteor \tdied\n");
67
 
 
68
 
                        delete *iter;
69
 
                        active.erase(iter);
70
 
                        iter--;  // important!
71
 
                }
72
 
        }
73
 
 
74
 
        // only makes sense given lifetimes of meteors to draw when time_speed is realtime
75
 
        // otherwise high overhead of large numbers of meteors
76
 
        double tspeed = nav->get_time_speed() *86400;  // sky seconds per actual second
77
 
        if(tspeed <= 0 || fabs(tspeed) > 1 )
78
 
        {
79
 
                // don't start any more meteors
80
 
                return;
81
 
        }
82
 
 
83
 
        /*
84
 
        // debug - one at a time
85
 
        if(active.begin() == active.end() ) {
86
 
          Meteor *m = new Meteor(projection, navigation, max_velocity);
87
 
          active.push_back(m);
88
 
            }
89
 
        */
90
 
 
91
 
 
92
 
        // if stellarium has been suspended, don't create huge number of meteors to
93
 
        // make up for lost time!
94
 
        if( delta_time > 500 )
95
 
        {
96
 
                delta_time = 500;
97
 
        }
98
 
 
99
 
        // determine average meteors per frame needing to be created
100
 
        int mpf = (int)((double)ZHR*zhr_to_wsr*(double)delta_time/1000.0f + 0.5);
101
 
        if( mpf < 1 ) mpf = 1;
102
 
 
103
 
        int mlaunch = 0;
104
 
        for(int i=0; i<mpf; i++)
105
 
        {
106
 
 
107
 
                // start new meteor based on ZHR time probability
108
 
                double prob = (double)rand()/((double)RAND_MAX+1);
109
 
                if( ZHR > 0 && prob < ((double)ZHR*zhr_to_wsr*(double)delta_time/1000.0f/(double)mpf) )
110
 
                {
111
 
                        Meteor *m = new Meteor(proj, nav, eye, max_velocity);
112
 
                        active.push_back(m);
113
 
                        mlaunch++;
114
 
                }
115
 
        }
116
 
 
117
 
        //  printf("mpf: %d\tm launched: %d\t(mps: %f)\t%d\n", mpf, mlaunch, ZHR*zhr_to_wsr, delta_time);
118
 
 
119
 
 
120
 
}
121
 
 
122
 
 
123
 
void MeteorMgr::draw(Projector *proj, Navigator* nav)
124
 
{
125
 
 
126
 
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
127
 
        glEnable(GL_BLEND);
128
 
        glDisable(GL_TEXTURE_2D);  // much dimmer without this
129
 
 
130
 
        // step through and draw all active meteors
131
 
        for(vector<Meteor*>::iterator iter = active.begin(); iter != active.end(); ++iter)
132
 
        {
133
 
                (*iter)->draw(proj, nav);
134
 
        }
135
 
 
136
 
        glEnable(GL_TEXTURE_2D);
137
 
 
138
 
}