Meteor.cpp   Meteor.cpp 
skipping to change at line 33 skipping to change at line 33
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelTexture.hpp" #include "StelTexture.hpp"
StelTextureSP Meteor::bolideTexture; StelTextureSP Meteor::bolideTexture;
Meteor::Meteor(const StelCore* core, float v) Meteor::Meteor(const StelCore* core, float v)
: m_distMultiplier(0.) : m_distMultiplier(0.)
, m_segments(10) , m_segments(10)
{ {
qsrand (QDateTime::currentMSecsSinceEpoch());
// determine meteor velocity // determine meteor velocity
// abs range 11-72 km/s by default (see line 427 in StelApp.cpp) // abs range 11-72 km/s by default (see line 427 in StelApp.cpp)
m_speed = 11+(float)rand()/((float)RAND_MAX+1)*(v-11); m_speed = 11+(float)qrand()/((float)RAND_MAX+1)*(v-11);
// view matrix of sporadic meteors model // view matrix of sporadic meteors model
float alpha = (double)rand()/((double)RAND_MAX+1)*2*M_PI; float alpha = (double)qrand()/((double)RAND_MAX+1)*2*M_PI;
float delta = M_PI_2 - (double)rand()/((double)RAND_MAX+1)*M_PI; float delta = M_PI_2 - (double)qrand()/((double)RAND_MAX+1)*M_PI;
m_viewMatrix = Mat4d::zrotation(alpha) * Mat4d::yrotation(delta); m_viewMatrix = Mat4d::zrotation(alpha) * Mat4d::yrotation(delta);
// building meteor model // building meteor model
m_alive = initMeteorModel(core, m_segments, m_viewMatrix, meteor); m_alive = initMeteorModel(core, m_segments, m_viewMatrix, meteor);
if (!m_alive) if (!m_alive)
{ {
return; return;
} }
// building lineColorArray and trainColorArray // building lineColorArray and trainColorArray
skipping to change at line 68 skipping to change at line 69
bool Meteor::initMeteorModel(const StelCore* core, const int segments, cons t Mat4d viewMatrix, MeteorModel &mm) bool Meteor::initMeteorModel(const StelCore* core, const int segments, cons t Mat4d viewMatrix, MeteorModel &mm)
{ {
float high_range = EARTH_RADIUS + HIGH_ALTITUDE; float high_range = EARTH_RADIUS + HIGH_ALTITUDE;
float low_range = EARTH_RADIUS + LOW_ALTITUDE; float low_range = EARTH_RADIUS + LOW_ALTITUDE;
// find observer position in meteor coordinate system // find observer position in meteor coordinate system
mm.obs = core->altAzToJ2000(Vec3d(0,0,EARTH_RADIUS)); mm.obs = core->altAzToJ2000(Vec3d(0,0,EARTH_RADIUS));
mm.obs.transfo4d(viewMatrix.transpose()); mm.obs.transfo4d(viewMatrix.transpose());
// select random trajectory using polar coordinates in XY plane, cen tered on observer // select random trajectory using polar coordinates in XY plane, cen tered on observer
mm.xydistance = (double)rand() / ((double)RAND_MAX+1)*(VISIBLE_RADIU mm.xydistance = (double)qrand() / ((double)RAND_MAX+1)*(VISIBLE_RADI
S); US);
float angle = (double)rand() / ((double)RAND_MAX+1)*2*M_PI; float angle = (double)qrand() / ((double)RAND_MAX+1)*2*M_PI;
// set meteor start x,y // set meteor start x,y
mm.position[0] = mm.posTrain[0] = mm.xydistance*cos(angle) + mm.obs[ 0]; mm.position[0] = mm.posTrain[0] = mm.xydistance*cos(angle) + mm.obs[ 0];
mm.position[1] = mm.posTrain[1] = mm.xydistance*sin(angle) + mm.obs[ 1]; mm.position[1] = mm.posTrain[1] = mm.xydistance*sin(angle) + mm.obs[ 1];
// D is distance from center of earth // D is distance from center of earth
float D = sqrt(mm.position[0]*mm.position[0] + mm.position[1]*mm.pos ition[1]); float D = std::sqrt(mm.position[0]*mm.position[0] + mm.position[1]*m m.position[1]);
if (D > high_range) // won't be visible, meteor still dead if (D > high_range) // won't be visible, meteor still dead
{ {
return false; return false;
} }
mm.posTrain[2] = mm.position[2] = mm.startH = sqrt(high_range*high_r ange - D*D); mm.posTrain[2] = mm.position[2] = mm.startH = std::sqrt(high_range*h igh_range - D*D);
// determine end of burn point, and nearest point to observer for di stance mag calculation // determine end of burn point, and nearest point to observer for di stance mag calculation
// mag should be max at nearest point still burning // mag should be max at nearest point still burning
if (D > low_range) if (D > low_range)
{ {
mm.endH = -mm.startH; // earth grazing mm.endH = -mm.startH; // earth grazing
mm.minDist = mm.xydistance; mm.minDist = mm.xydistance;
} }
else else
{ {
mm.endH = sqrt(low_range*low_range - D*D); mm.endH = std::sqrt(low_range*low_range - D*D);
mm.minDist = sqrt(mm.xydistance*mm.xydistance + pow(mm.endH mm.minDist = std::sqrt(mm.xydistance*mm.xydistance + pow(mm.
- mm.obs[2], 2)); endH - mm.obs[2], 2));
} }
if (mm.minDist > VISIBLE_RADIUS) if (mm.minDist > VISIBLE_RADIUS)
{ {
// on average, not visible (although if were zoomed ...) // on average, not visible (although if were zoomed ...)
return false; //meteor still dead return false; //meteor still dead
} }
// determine intensity [-3; 4.5] // determine intensity [-3; 4.5]
float Mag1 = (double)rand()/((double)RAND_MAX+1)*7.5f - 3; float Mag1 = (double)qrand()/((double)RAND_MAX+1)*7.5f - 3;
float Mag2 = (double)rand()/((double)RAND_MAX+1)*7.5f - 3; float Mag2 = (double)qrand()/((double)RAND_MAX+1)*7.5f - 3;
float Mag = (Mag1 + Mag2)/2.0f; float Mag = (Mag1 + Mag2)/2.0f;
// compute RMag and CMag // compute RMag and CMag
RCMag rcMag; RCMag rcMag;
core->getSkyDrawer()->computeRCMag(Mag, &rcMag); core->getSkyDrawer()->computeRCMag(Mag, &rcMag);
mm.mag = rcMag.luminance; mm.mag = rcMag.luminance;
// most visible meteors are under about 180km distant // most visible meteors are under about 180km distant
// scale max mag down if outside this range // scale max mag down if outside this range
float scale = 1; float scale = 1;
if (mm.minDist) if (mm.minDist)
{ {
scale = 180*180 / (mm.minDist*mm.minDist); scale = 180*180 / (mm.minDist*mm.minDist);
} }
if (scale < 1) if (scale < 1)
{ {
mm.mag *= scale; mm.mag *= scale;
} }
mm.firstBrightSegment = (double)rand()/((double)RAND_MAX+1)*segments ; mm.firstBrightSegment = (double)qrand()/((double)RAND_MAX+1)*segment s;
// If everything is ok until here, // If everything is ok until here,
return true; //the meteor is alive return true; //the meteor is alive
} }
Vec4f Meteor::getColorFromName(QString colorName) { Vec4f Meteor::getColorFromName(QString colorName) {
int R, G, B; // 0-255 int R, G, B; // 0-255
if (colorName == "violet") { // Calcium if (colorName == "violet") { // Calcium
R = 176; R = 176;
G = 67; G = 67;
skipping to change at line 165 skipping to change at line 166
R = 255; R = 255;
G = 255; G = 255;
B = 255; B = 255;
} }
return Vec4f(R/255.f, G/255.f, B/255.f, 1); return Vec4f(R/255.f, G/255.f, B/255.f, 1);
} }
QList<Meteor::colorPair> Meteor::getRandColor() { QList<Meteor::colorPair> Meteor::getRandColor() {
QList<colorPair> colors; QList<colorPair> colors;
float prob = (double)rand()/((double)RAND_MAX+1); float prob = (double)qrand()/((double)RAND_MAX+1);
if (prob > 0.9) { if (prob > 0.9) {
colors.push_back(Meteor::colorPair("white", 70)); colors.push_back(Meteor::colorPair("white", 70));
colors.push_back(Meteor::colorPair("orangeYellow", 10)); colors.push_back(Meteor::colorPair("orangeYellow", 10));
colors.push_back(Meteor::colorPair("yellow", 10)); colors.push_back(Meteor::colorPair("yellow", 10));
colors.push_back(Meteor::colorPair("blueGreen", 10)); colors.push_back(Meteor::colorPair("blueGreen", 10));
} else if (prob > 0.85) { } else if (prob > 0.85) {
colors.push_back(Meteor::colorPair("white", 80)); colors.push_back(Meteor::colorPair("white", 80));
colors.push_back(Meteor::colorPair("violet", 20)); colors.push_back(Meteor::colorPair("violet", 20));
} else if (prob > 0.80) { } else if (prob > 0.80) {
colors.push_back(Meteor::colorPair("white", 80)); colors.push_back(Meteor::colorPair("white", 80));
skipping to change at line 191 skipping to change at line 192
return colors; return colors;
} }
void Meteor::buildColorArrays(const int segments, void Meteor::buildColorArrays(const int segments,
const QList<colorPair> colors, const QList<colorPair> colors,
QList<Vec4f> &lineColorArray, QList<Vec4f> &lineColorArray,
QList<Vec4f> &trainColorArray) QList<Vec4f> &trainColorArray)
{ {
// building color arrays (line and prism) // building color arrays (line and prism)
int totalOfSegments = 0; int totalOfSegments = 0;
int currentSegment = 1+(double)rand()/((double)RAND_MAX+1)*(segments -1); int currentSegment = 1+(double)qrand()/((double)RAND_MAX+1)*(segment s-1);
for (int colorIndex=0; colorIndex<colors.size(); colorIndex++) { for (int colorIndex=0; colorIndex<colors.size(); colorIndex++) {
colorPair currentColor = colors[colorIndex]; colorPair currentColor = colors[colorIndex];
// segments which we'll paint with the current color // segments which we'll paint with the current color
int numOfSegments = segments*(currentColor.second / 100.f) + 0.4f; // +0.4 affect approximation int numOfSegments = segments*(currentColor.second / 100.f) + 0.4f; // +0.4 affect approximation
if (colorIndex == colors.size()-1) { if (colorIndex == colors.size()-1) {
numOfSegments = segments - totalOfSegments; numOfSegments = segments - totalOfSegments;
} }
totalOfSegments += numOfSegments; totalOfSegments += numOfSegments;
skipping to change at line 229 skipping to change at line 230
// burning has stopped so magnitude fades out // burning has stopped so magnitude fades out
// assume linear fade out // assume linear fade out
mm.mag -= deltaTime/500.0f; mm.mag -= deltaTime/500.0f;
if(mm.mag < 0) if(mm.mag < 0)
{ {
return false; // no longer visible return false; // no longer visible
} }
} }
// *** would need time direction multiplier to allow reverse time re play // *** would need time direction multiplier to allow reverse time re play
float dt = 820+(double)rand()/((double)RAND_MAX+1)*185; // range 820 -1005 float dt = 820+(double)qrand()/((double)RAND_MAX+1)*185; // range 82 0-1005
mm.position[2] -= speed*deltaTime/dt; mm.position[2] -= speed*deltaTime/dt;
// train doesn't extend beyond start of burn // train doesn't extend beyond start of burn
if (mm.position[2] + speed*0.5f > mm.startH) if (mm.position[2] + speed*0.5f > mm.startH)
{ {
mm.posTrain[2] = mm.startH; mm.posTrain[2] = mm.startH;
} }
else else
{ {
mm.posTrain[2] -= speed*deltaTime/dt; mm.posTrain[2] -= speed*deltaTime/dt;
skipping to change at line 256 skipping to change at line 257
bool Meteor::update(double deltaTime) bool Meteor::update(double deltaTime)
{ {
if (!m_alive) if (!m_alive)
{ {
return false; return false;
} }
m_alive = updateMeteorModel(deltaTime, m_speed, meteor); m_alive = updateMeteorModel(deltaTime, m_speed, meteor);
// determine visual magnitude based on distance to observer // determine visual magnitude based on distance to observer
double dist = sqrt(meteor.xydistance*meteor.xydistance + pow(meteor. position[2]-meteor.obs[2], 2)); double dist = std::sqrt(meteor.xydistance*meteor.xydistance + pow(me teor.position[2]-meteor.obs[2], 2));
if (dist == 0) if (dist == 0)
{ {
dist = .01; // just to be cautious (meteor hits observer! ) dist = .01; // just to be cautious (meteor hits observer! )
} }
m_distMultiplier = meteor.minDist*meteor.minDist / (dist*dist); m_distMultiplier = meteor.minDist*meteor.minDist / (dist*dist);
return m_alive; return m_alive;
} }
void Meteor::insertVertex(const StelCore* core, const Mat4d& viewMatrix, QV ector<Vec3d> &vertexArray, Vec3d vertex) void Meteor::insertVertex(const StelCore* core, const Mat4d& viewMatrix, QV ector<Vec3d> &vertexArray, Vec3d vertex)
skipping to change at line 364 skipping to change at line 365
posTrainB[0] += thickness*0.7; posTrainB[0] += thickness*0.7;
posTrainB[1] += thickness*0.7; posTrainB[1] += thickness*0.7;
Vec3d posTrainL = mm.posTrain; Vec3d posTrainL = mm.posTrain;
posTrainL[1] -= thickness; posTrainL[1] -= thickness;
Vec3d posTrainR = mm.posTrain; Vec3d posTrainR = mm.posTrain;
posTrainR[0] -= thickness; posTrainR[0] -= thickness;
for (int i=0; i<segments; i++) { for (int i=0; i<segments; i++) {
float mag = mm.mag * i/(3* (segments-1)); float mag = mm.mag * i/(3* (segments-1));
if (i > mm.firstBrightSegment) { if (i > mm.firstBrightSegment) {
mag *= 12/5; mag *= 12./5.;
} }
double height = mm.posTrain[2] + i*(mm.position[2] - mm.posT rain[2])/(segments-1); double height = mm.posTrain[2] + i*(mm.position[2] - mm.posT rain[2])/(segments-1);
Vec3d posi; Vec3d posi;
posi = mm.posTrain; posi = mm.posTrain;
posi[2] = height; posi[2] = height;
insertVertex(core, viewMatrix, vertexArrayLine, posi); insertVertex(core, viewMatrix, vertexArrayLine, posi);
posi = posTrainB; posi = posTrainB;
 End of changes. 14 change blocks. 
19 lines changed or deleted 20 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/