3
* This file Copyright (C) 2004 Robert Spearman
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.
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.
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.
20
#include "meteor_mgr.h"
22
MeteorMgr::MeteorMgr(int zhr, int maxv )
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)
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
36
MeteorMgr::~MeteorMgr()
39
void MeteorMgr::set_ZHR(int zhr)
44
int MeteorMgr::get_ZHR()
49
void MeteorMgr::set_max_velocity(int maxv)
54
void MeteorMgr::update(Projector *proj, Navigator* nav, ToneReproductor* eye, int delta_time)
57
// step through and update all active meteors
59
for(vector<Meteor*>::iterator iter = active.begin(); iter != active.end(); ++iter)
62
//printf("Meteor %d update\n", ++n);
63
if( !( (*iter)->update(delta_time) ) )
66
// printf("Meteor \tdied\n");
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 )
79
// don't start any more meteors
84
// debug - one at a time
85
if(active.begin() == active.end() ) {
86
Meteor *m = new Meteor(projection, navigation, max_velocity);
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 )
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;
104
for(int i=0; i<mpf; i++)
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) )
111
Meteor *m = new Meteor(proj, nav, eye, max_velocity);
117
// printf("mpf: %d\tm launched: %d\t(mps: %f)\t%d\n", mpf, mlaunch, ZHR*zhr_to_wsr, delta_time);
123
void MeteorMgr::draw(Projector *proj, Navigator* nav)
126
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
128
glDisable(GL_TEXTURE_2D); // much dimmer without this
130
// step through and draw all active meteors
131
for(vector<Meteor*>::iterator iter = active.begin(); iter != active.end(); ++iter)
133
(*iter)->draw(proj, nav);
136
glEnable(GL_TEXTURE_2D);