Atmosphere.cpp   Atmosphere.cpp 
skipping to change at line 25 skipping to change at line 25
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include <QDebug> #include <QDebug>
#include "GLee.h" #include "GLee.h"
#include "Atmosphere.hpp" #include "Atmosphere.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "Projector.hpp" #include "StelApp.hpp"
#include "ToneReproducer.hpp" #include "StelProjector.hpp"
#include "StelToneReproducer.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelPainter.hpp"
// Uncomment to try out vertex buffers // Uncomment to try out vertex buffers
//#define USE_VERTEX_BUFFERS 1 //#define USE_VERTEX_BUFFERS 1
inline bool myisnan(double value)
{
return value != value;
}
Atmosphere::Atmosphere(void) :viewport(0,0,0,0),skyResolutionY(44), posGrid (NULL), colorGrid(NULL), indices(NULL), Atmosphere::Atmosphere(void) :viewport(0,0,0,0),skyResolutionY(44), posGrid (NULL), colorGrid(NULL), indices(NULL),
averageLuminance(0.f), eclipseFactor(1.), lightPollutionLuminan ce(0) averageLuminance(0.f), eclipseFactor(1.), lightPollutionLuminan ce(0)
{ {
setFadeDuration(3.f); setFadeDuration(3.f);
} }
Atmosphere::~Atmosphere(void) Atmosphere::~Atmosphere(void)
{ {
if (posGrid) if (posGrid)
{ {
skipping to change at line 58 skipping to change at line 65
colorGrid = NULL; colorGrid = NULL;
} }
if (indices) if (indices)
{ {
delete[] indices; delete[] indices;
indices = NULL; indices = NULL;
} }
} }
void Atmosphere::computeColor(double JD, Vec3d _sunPos, Vec3d moonPos, floa t moonPhase, void Atmosphere::computeColor(double JD, Vec3d _sunPos, Vec3d moonPos, floa t moonPhase,
ToneReproducer * eye, Projector* prj, StelCore* core, float latitude, float altitu
float latitude, float altitude, float temper de, float temperature, float relativeHumidity)
ature, float relativeHumidity)
{ {
const StelProjectorP prj = core->getProjection(StelCore::FrameAltAz) ;
if (viewport != prj->getViewport()) if (viewport != prj->getViewport())
{ {
// The viewport changed: update the number of point of the g rid // The viewport changed: update the number of point of the g rid
viewport = prj->getViewport(); viewport = prj->getViewport();
if (posGrid) if (posGrid)
delete[] posGrid; delete[] posGrid;
if (colorGrid) if (colorGrid)
delete[] colorGrid; delete[] colorGrid;
if (indices) if (indices)
delete[] indices; delete[] indices;
skipping to change at line 128 skipping to change at line 135
glBufferDataARB(GL_ARRAY_BUFFER_ARB, (1+skyResolutionX)*(1+s kyResolutionY)*2*sizeof(float), posGrid, GL_STATIC_DRAW_ARB); glBufferDataARB(GL_ARRAY_BUFFER_ARB, (1+skyResolutionX)*(1+s kyResolutionY)*2*sizeof(float), posGrid, GL_STATIC_DRAW_ARB);
glGenBuffersARB(1, &indicesBufferId); glGenBuffersARB(1, &indicesBufferId);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesBufferId ); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesBufferId );
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, skyResolutionX* skyResolutionY*4*sizeof(GLushort), indices, GL_STATIC_DRAW_ARB); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, skyResolutionX* skyResolutionY*4*sizeof(GLushort), indices, GL_STATIC_DRAW_ARB);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
#endif #endif
} }
if (myisnan(_sunPos.length()))
_sunPos.set(0.,0.,-1.*AU);
if (myisnan(moonPos.length()))
moonPos.set(0.,0.,-1.*AU);
// Update the eclipse intensity factor to apply on atmosphere model // Update the eclipse intensity factor to apply on atmosphere model
// these are for radii // these are for radii
const double sun_angular_size = atan(696000./AU/_sunPos.length()); const double sun_angular_size = atan(696000./AU/_sunPos.length());
const double moon_angular_size = atan(1738./AU/moonPos.length()); const double moon_angular_size = atan(1738./AU/moonPos.length());
const double touch_angle = sun_angular_size + moon_angular_size; const double touch_angle = sun_angular_size + moon_angular_size;
// determine luminance falloff during solar eclipses // determine luminance falloff during solar eclipses
_sunPos.normalize(); _sunPos.normalize();
moonPos.normalize(); moonPos.normalize();
double separation_angle = std::acos(_sunPos.dot(moonPos)); // angle between them double separation_angle = std::acos(_sunPos.dot(moonPos)); // angle between them
skipping to change at line 201 skipping to change at line 213
skyb.setDate(year, month, moonPhase); skyb.setDate(year, month, moonPhase);
// Variables used to compute the average sky luminance // Variables used to compute the average sky luminance
double sum_lum = 0.; double sum_lum = 0.;
unsigned int nb_lum = 0; unsigned int nb_lum = 0;
Vec3d point(1., 0., 0.); Vec3d point(1., 0., 0.);
skylightStruct2 b2; skylightStruct2 b2;
float lumi; float lumi;
prj->setCurrentFrame(Projector::FrameLocal);
// Compute the sky color for every point above the ground // Compute the sky color for every point above the ground
for (int i=0; i<(1+skyResolutionX)*(1+skyResolutionY); ++i) for (int i=0; i<(1+skyResolutionX)*(1+skyResolutionY); ++i)
{ {
Vec2f &v(posGrid[i]); Vec2f &v(posGrid[i]);
prj->unProject(v[0],v[1],point); prj->unProject(v[0],v[1],point);
assert(fabs(point.lengthSquared()-1.0) < 1e-10); Q_ASSERT(fabs(point.lengthSquared()-1.0) < 1e-10);
if (point[2]<=0) if (point[2]<=0)
{ {
point[2] = -point[2]; point[2] = -point[2];
// The sky below the ground is the symetric of the o ne above : // The sky below the ground is the symetric of the o ne above :
// it looks nice and gives proper values for brightn ess estimation // it looks nice and gives proper values for brightn ess estimation
} }
// Use the Skybright.cpp 's models for brightness which give s better results. // Use the Skybright.cpp 's models for brightness which give s better results.
lumi = skyb.getLuminance(moon_pos[0]*point[0]+moon_pos[1]*po int[1]+ lumi = skyb.getLuminance(moon_pos[0]*point[0]+moon_pos[1]*po int[1]+
skipping to change at line 247 skipping to change at line 257
{ {
b2.pos[0] = point[0]; b2.pos[0] = point[0];
b2.pos[1] = point[1]; b2.pos[1] = point[1];
b2.pos[2] = point[2]; b2.pos[2] = point[2];
// Use the Skylight model for the color // Use the Skylight model for the color
sky.getxyYValuev(b2); sky.getxyYValuev(b2);
} }
else else
{ {
// Too dark to see atmosphere color, don't bother co mputing it // Too dark to see atmosphere color, don't bother co mputing it
b2.color[0]=0.; b2.color[0]=0.25;
b2.color[1]=0.; b2.color[1]=0.25;
} }
b2.color[2] = lumi;
colorGrid[i].set(b2.color[0], b2.color[1], b2.color[2]); colorGrid[i].set(b2.color[0], b2.color[1], lumi);
} }
// Update average luminance // Update average luminance
averageLuminance = sum_lum/nb_lum; averageLuminance = sum_lum/nb_lum;
} }
// Draw the atmosphere using the precalc values stored in tab_sky // Draw the atmosphere using the precalc values stored in tab_sky
void Atmosphere::draw(StelCore* core) void Atmosphere::draw(StelCore* core)
{ {
ToneReproducer* eye = core->getToneReproducer(); if (StelApp::getInstance().getVisionModeNight())
return;
StelToneReproducer* eye = core->getToneReproducer();
if (fader.getInterstate()) if (fader.getInterstate())
{ {
const float atm_intensity = fader.getInterstate(); const float atm_intensity = fader.getInterstate();
glBlendFunc(GL_ONE, GL_ONE);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH);
// Adapt luminance at this point to avoid a mismatch with th e adaption value // Adapt luminance at this point to avoid a mismatch with th e adaption value
for (int i=0;i<(1+skyResolutionX)*(1+skyResolutionY);++i) for (int i=0;i<(1+skyResolutionX)*(1+skyResolutionY);++i)
{ {
Vec3f& c = colorGrid[i]; Vec3f& c = colorGrid[i];
eye->xyYToRGB(c); eye->xyYToRGB(c);
c*=atm_intensity; c*=atm_intensity;
} }
StelPainter sPainter(core->getProjection2d());
glBlendFunc(GL_ONE, GL_ONE);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
// Load the color components // Load the color components
glColorPointer(3, GL_FLOAT, 0, colorGrid); glColorPointer(3, GL_FLOAT, 0, colorGrid);
#ifdef USE_VERTEX_BUFFERS #ifdef USE_VERTEX_BUFFERS
// Bind the vertex and indices buffer // Bind the vertex and indices buffer
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferId); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferId);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesBufferId ); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indicesBufferId );
 End of changes. 14 change blocks. 
18 lines changed or deleted 31 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/