Meteor.cpp   Meteor.cpp 
skipping to change at line 33 skipping to change at line 33
/* /*
NOTE: Here the radiant is always along the ecliptic at the apex of the Eart h's way. NOTE: Here the radiant is always along the ecliptic at the apex of the Eart h's way.
In reality, individual meteor streams have varying velocity vectors and the refore radiants In reality, individual meteor streams have varying velocity vectors and the refore radiants
which are generally not at the apex of the Earth's way, such as the Perseid s shower. which are generally not at the apex of the Earth's way, such as the Perseid s shower.
*/ */
// Improved realism and efficiency 2004-12 // Improved realism and efficiency 2004-12
#include <cstdlib> #include <cstdlib>
#include "Meteor.hpp" #include "Meteor.hpp"
#include "StelCore.hpp"
#include "StelNavigator.hpp"
#include "StelToneReproducer.hpp"
#include "StelMovementMgr.hpp"
#include "StelPainter.hpp"
Meteor::Meteor(Projector *proj, Navigator* nav, ToneReproducer* eye, double v) Meteor::Meteor(const StelCore* core, double v)
{ {
const StelNavigator* nav = core->getNavigator();
const StelToneReproducer* eye = core->getToneReproducer();
// velocity = 11+(double)rand()/((double)RAND_MAX+1)*v; // abs range 11 -72 km/s // velocity = 11+(double)rand()/((double)RAND_MAX+1)*v; // abs range 11 -72 km/s
velocity=v; velocity=v;
maxMag = 1; maxMag = 1;
// determine meteor model view matrix (want z in dir of travel of earth, z=0 at center of earth) // determine meteor model view matrix (want z in dir of travel of earth, z=0 at center of earth)
// meteor life is so short, no need to recalculate // meteor life is so short, no need to recalculate
double equ_rotation; // rotation needed to align with path of earth double equ_rotation; // rotation needed to align with path of earth
Vec3d sun_dir = nav->helioToEarthEqu( Vec3d(0,0,0) ); Vec3d sun_dir = nav->heliocentricEclipticToEquinoxEqu( Vec3d(0,0,0) );
Mat4d tmat = Mat4d::xrotation(-23.45f*M_PI/180.f); // ecliptical tilt Mat4d tmat = Mat4d::xrotation(-23.45f*M_PI/180.f); // ecliptical tilt
sun_dir.transfo4d(tmat); // convert to ecliptical coordinates sun_dir.transfo4d(tmat); // convert to ecliptical coordinates
sun_dir.normalize(); sun_dir.normalize();
equ_rotation = acos( sun_dir.dot( Vec3d(1,0,0) ) ); equ_rotation = acos( sun_dir.dot( Vec3d(1,0,0) ) );
if( sun_dir[1] < 0 ) equ_rotation = 2*M_PI - equ_rotation; if( sun_dir[1] < 0 ) equ_rotation = 2*M_PI - equ_rotation;
equ_rotation -= M_PI_2; equ_rotation -= M_PI_2;
mmat = Mat4d::xrotation(23.45f*M_PI/180.f) * Mat4d::zrotation(equ_rotatio n) * Mat4d::yrotation(M_PI_2); mmat = Mat4d::xrotation(23.45f*M_PI/180.f) * Mat4d::zrotation(equ_rotatio n) * Mat4d::yrotation(M_PI_2);
// select random trajectory using polar coordinates in XY plane, centered on observer // select random trajectory using polar coordinates in XY plane, centered on observer
xydistance = (double)rand()/((double)RAND_MAX+1)*(VISIBLE_RADIUS); xydistance = (double)rand()/((double)RAND_MAX+1)*(VISIBLE_RADIUS);
double angle = (double)rand()/((double)RAND_MAX+1)*2*M_PI; double angle = (double)rand()/((double)RAND_MAX+1)*2*M_PI;
// find observer position in meteor coordinate system // find observer position in meteor coordinate system
obs = nav->localToEarthEqu(Vec3d(0,0,EARTH_RADIUS)); obs = nav->altAzToEquinoxEqu(Vec3d(0,0,EARTH_RADIUS));
obs.transfo4d(mmat.transpose()); obs.transfo4d(mmat.transpose());
// set meteor start x,y // set meteor start x,y
posInternal[0] = posTrain[0] = position[0] = xydistance*cos(angle) +obs[0 ]; posInternal[0] = posTrain[0] = position[0] = xydistance*cos(angle) +obs[0 ];
posInternal[1] = posTrain[1] = position[1] = xydistance*sin(angle) +obs[1 ]; posInternal[1] = posTrain[1] = position[1] = xydistance*sin(angle) +obs[1 ];
// determine life of meteor (start and end z value based on atmosphere bu rn altitudes) // determine life of meteor (start and end z value based on atmosphere bu rn altitudes)
// D is distance from center of earth // D is distance from center of earth
double D = sqrt( position[0]*position[0] + position[1]*position[1] ); double D = sqrt( position[0]*position[0] + position[1]*position[1] );
skipping to change at line 133 skipping to change at line 141
if (mag>250) mag = mag - 256; if (mag>250) mag = mag - 256;
float term1 = std::exp(-0.92103f*(mag + 12.12331f)) * 108064.73f; float term1 = std::exp(-0.92103f*(mag + 12.12331f)) * 108064.73f;
float cmag=1.f; float cmag=1.f;
float rmag; float rmag;
// Compute the equivalent star luminance for a 5 arc min circle and conve rt it // Compute the equivalent star luminance for a 5 arc min circle and conve rt it
// in function of the eye adaptation // in function of the eye adaptation
rmag = eye->adaptLuminanceScaled(term1); rmag = eye->adaptLuminanceScaled(term1);
rmag = rmag/powf(proj->getFov(),0.85f)*500.f; rmag = rmag/powf(core->getMovementMgr()->getCurrentFov(),0.85f)*500.f;
// if size of star is too small (blink) we put its size to 1.2 --> no mor e blink // if size of star is too small (blink) we put its size to 1.2 --> no mor e blink
// And we compensate the difference of brighteness with cmag // And we compensate the difference of brighteness with cmag
if (rmag<1.2f) { if (rmag<1.2f) {
cmag=rmag*rmag/1.44f; cmag=rmag*rmag/1.44f;
} }
mag = cmag; // assumes white mag = cmag; // assumes white
// most visible meteors are under about 180km distant // most visible meteors are under about 180km distant
skipping to change at line 193 skipping to change at line 201
if( dist == 0 ) dist = .01; // just to be cautious (meteor hits observer !) if( dist == 0 ) dist = .01; // just to be cautious (meteor hits observer !)
distMultiplier = minDist*minDist / (dist*dist); distMultiplier = minDist*minDist / (dist*dist);
return(alive); return(alive);
} }
// returns true if visible // returns true if visible
// Assumes that we are in local frame // Assumes that we are in local frame
bool Meteor::draw(Projector *proj, const Navigator* nav) bool Meteor::draw(const StelCore* core, const StelPainter& sPainter)
{ {
if(!alive) return(0); if (!alive)
return(0);
Vec3d start, end; const StelNavigator* nav = core->getNavigator();
const StelProjectorP proj = sPainter.getProjector();
Vec3d spos = position; Vec3d spos = position;
Vec3d epos = posTrain; Vec3d epos = posTrain;
// convert to equ // convert to equ
spos.transfo4d(mmat); spos.transfo4d(mmat);
epos.transfo4d(mmat); epos.transfo4d(mmat);
// convert to local and correct for earth radius [since equ and loca l coordinates in stellarium use same 0 point!] // convert to local and correct for earth radius [since equ and loca l coordinates in stellarium use same 0 point!]
spos = nav->earthEquToLocal( spos ); spos = nav->equinoxEquToAltAz( spos );
epos = nav->earthEquToLocal( epos ); epos = nav->equinoxEquToAltAz( epos );
spos[2] -= EARTH_RADIUS; spos[2] -= EARTH_RADIUS;
epos[2] -= EARTH_RADIUS; epos[2] -= EARTH_RADIUS;
Vec3d start, end;
int t1 = proj->projectCheck(spos/1216, start); // 1216 is to scale down under 1 for desktop version int t1 = proj->projectCheck(spos/1216, start); // 1216 is to scale down under 1 for desktop version
int t2 = proj->projectCheck(epos/1216, end); int t2 = proj->projectCheck(epos/1216, end);
// don't draw if not visible (but may come into view) // don't draw if not visible (but may come into view)
if( t1 + t2 == 0 ) return 1; if( t1 + t2 == 0 ) return 1;
// qDebug("[%f %f %f] (%d, %d) (%d, %d)\n", position[0], position[1 ], position[2], (int)start[0], (int)start[1], (int)end[0], (int)end[1]); // qDebug("[%f %f %f] (%d, %d) (%d, %d)\n", position[0], position[1 ], position[2], (int)start[0], (int)start[1], (int)end[0], (int)end[1]);
if( train ) { if( train ) {
// connect this point with last drawn point // connect this point with last drawn point
double tmag = mag*distMultiplier; double tmag = mag*distMultiplier;
// compute an intermediate point so can curve slightly along projection distortions // compute an intermediate point so can curve slightly along projection distortions
Vec3d intpos;
Vec3d posi = posInternal; Vec3d posi = posInternal;
posi[2] = position[2] + (posTrain[2] - position[2])/2; posi[2] = position[2] + (posTrain[2] - position[2])/2;
posi.transfo4d(mmat); posi.transfo4d(mmat);
posi = nav->earthEquToLocal( posi ); posi = nav->equinoxEquToAltAz( posi );
posi[2] -= EARTH_RADIUS; posi[2] -= EARTH_RADIUS;
Vec3d intpos;
proj->project(posi/1216, intpos); proj->project(posi/1216, intpos);
// draw dark to light // draw dark to light
glBegin(GL_LINE_STRIP); glBegin(GL_LINE_STRIP);
glColor4f(0,0,0,0); glColor4f(0,0,0,0);
glVertex3f(end[0],end[1],0); glVertex3f(end[0],end[1],0);
glColor4f(1,1,1,tmag/2); glColor4f(1,1,1,tmag/2);
glVertex3f(intpos[0],intpos[1],0); glVertex3f(intpos[0],intpos[1],0);
glColor4f(1,1,1,tmag); glColor4f(1,1,1,tmag);
glVertex3f(start[0],start[1],0); glVertex3f(start[0],start[1],0);
glEnd(); glEnd();
} else { } else {
glPointSize(1); glPointSize(1);
proj->drawPoint2d(start[0],start[1]); sPainter.drawPoint2d(start[0],start[1]);
} }
/* /*
// TEMP - show radiant // TEMP - show radiant
Vec3d radiant = Vec3d(0,0,0.5f); Vec3d radiant = Vec3d(0,0,0.5f);
radiant.transfo4d(mmat); radiant.transfo4d(mmat);
if( projection->project_earth_equ(radiant, start) ) { if( projection->project_earth_equ(radiant, start) ) {
glColor3f(1,0,1); glColor3f(1,0,1);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex3f(start[0]-10,start[1],0); glVertex3f(start[0]-10,start[1],0);
 End of changes. 15 change blocks. 
12 lines changed or deleted 23 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/