// oursun.hxx -- model earth's sun
//
-// Written by Durk Talsma. Originally started October 1997, for distribution
-// with the FlightGear project. Version 2 was written in August and
-// September 1998. This code is based upon algorithms and data kindly
-// provided by Mr. Paul Schlyter. (pausch@saaf.se).
+// Written by Durk Talsma. Originally started October 1997, for distribution
+// with the FlightGear project. Version 2 was written in August and
+// September 1998. This code is based upon algorithms and data kindly
+// provided by Mr. Paul Schlyter. (pausch@saaf.se).
//
// Separated out rendering pieces and converted to ssg by Curt Olson,
// March 2000
#include <osgDB/ReadFile>
#include <simgear/math/SGMath.hxx>
-#include <simgear/scene/util/PathOptions.hxx>
+#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/screen/colors.hxx>
#include <simgear/scene/model/model.hxx>
#include "oursun.hxx"
env_node = property_tree_Node;
- osg::ref_ptr<osgDB::ReaderWriter::Options> options
- = makeOptionsFromPath(path);
+ osg::ref_ptr<SGReaderWriterOptions> options;
+ options = SGReaderWriterOptions::fromPath(path.str());
// build the ssg scene graph sub tree for the sky and connected
// into the provide scene graph branch
sun_transform = new osg::MatrixTransform;
osg::TexEnv* texEnv = new osg::TexEnv;
texEnv->setMode(osg::TexEnv::MODULATE);
stateSet->setTextureAttribute(0, texEnv, osg::StateAttribute::ON);
-
+
osg::Material* material = new osg::Material;
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0,0,0,1));
osg::Geometry* geometry = new osg::Geometry;
geometry->setUseDisplayList(false);
geometry->setVertexArray(sun_vl);
- geometry->setColorArray(sun_cl.get());
- geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
+ geometry->setColorArray(sun_cl.get(), osg::Array::BIND_OVERALL);
geometry->setNormalBinding(osg::Geometry::BIND_OFF);
- geometry->setTexCoordArray(0, sun_tl);
+ geometry->setTexCoordArray(0, sun_tl, osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4));
geode->addDrawable(geometry);
geode = new osg::Geode;
stateSet = geode->getOrCreateStateSet();
stateSet->setRenderBinDetails(-7, "RenderBin");
-
+
texture = SGLoadTexture2D("inner_halo.png", options.get());
stateSet->setTextureAttributeAndModes(0, texture);
geometry = new osg::Geometry;
geometry->setUseDisplayList(false);
geometry->setVertexArray(ihalo_vl);
- geometry->setColorArray(ihalo_cl.get());
- geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
+ geometry->setColorArray(ihalo_cl.get(), osg::Array::BIND_OVERALL);
geometry->setNormalBinding(osg::Geometry::BIND_OFF);
- geometry->setTexCoordArray(0, ihalo_tl);
+ geometry->setTexCoordArray(0, ihalo_tl, osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4));
geode->addDrawable(geometry);
sun_transform->addChild( geode );
-
+
// set up the outer halo state
-
+
geode = new osg::Geode;
stateSet = geode->getOrCreateStateSet();
stateSet->setRenderBinDetails(-8, "RenderBin");
geometry = new osg::Geometry;
geometry->setUseDisplayList(false);
geometry->setVertexArray(ohalo_vl);
- geometry->setColorArray(ohalo_cl.get());
- geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
+ geometry->setColorArray(ohalo_cl.get(), osg::Array::BIND_OVERALL);
geometry->setNormalBinding(osg::Geometry::BIND_OFF);
- geometry->setTexCoordArray(0, ohalo_tl);
+ geometry->setTexCoordArray(0, ohalo_tl, osg::Array::BIND_PER_VERTEX);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4));
geode->addDrawable(geometry);
density_avg = 0.7;
}
else {
- rel_humidity = env_node->getFloatValue( "relative-humidity" );
+ rel_humidity = env_node->getFloatValue( "relative-humidity" );
density_avg = env_node->getFloatValue( "atmosphere/density-tropo-avg" );
}
// ok, now let's go and generate the sun and scene color
osg::Vec4 i_halo_color, o_halo_color, scene_color, sun_color;
- // Some comments:
+ // Some comments:
// * When the sunangle changes, light has to travel a longer
// distance through the atmosphere. So it's scattered more due
// to raleigh scattering, which affects blue more than green
// * Visability also affects suncolor inasmuch as more particles
// are in the air that cause more scattering.
// * We base our calculation on the halo's color, which is most
- // scattered.
+ // scattered.
double red_scat_f, red_scat_corr_f, green_scat_f, blue_scat_f;
-
- // Red - is almost not scattered
+
+ // Red - is almost not scattered
// Lambda is 700 nm
-
+
red_scat_f = (aerosol_factor * path_distance * density_avg)/5E+07;
red_scat_corr_f = sun_exp2_punch_through / (1 - red_scat_f);
sun_color[0] = 1;
green_scat_f = (aerosol_factor * path_distance * density_avg)/8.8938E+06;
sun_color[1] = 1 - green_scat_f * red_scat_corr_f;
scene_color[1] = 1 - green_scat_f;
-
+
// Blue - 435.8 nm
blue_scat_f = (aerosol_factor * path_distance * density_avg)/3.607E+06;
sun_color[2] = 1 - blue_scat_f * red_scat_corr_f;
sun_color[3] = 1;
scene_color[3] = 1;
- // Now that we have the color calculated
+ // Now that we have the color calculated
// let's consider the saturation which is produced by mie scattering
double saturation = 1 - ( rel_humidity / 200 );
scene_color[1] += (( 1 - saturation ) * ( 1 - scene_color[1] ));
gamma_correct_rgb( i_halo_color._v );
gamma_correct_rgb( o_halo_color._v );
- gamma_correct_rgb( scene_color._v );
+ gamma_correct_rgb( scene_color._v );
gamma_correct_rgb( sun_color._v );
(*sun_cl)[0] = sun_color;
// fixed at a great distance from the viewer. Also add in an optional
// rotation (i.e. for the current time of day.)
// Then calculate stuff needed for the sun-coloring
-bool SGSun::reposition( double rightAscension, double declination,
+bool SGSun::reposition( double rightAscension, double declination,
double sun_dist, double lat, double alt_asl, double sun_angle)
{
- // GST - GMT sidereal time
+ // GST - GMT sidereal time
osg::Matrix T2, RA, DEC;
// xglRotatef( ((SGD_RADIANS_TO_DEGREES * rightAscension)- 90.0),
double r_tropo = r_tropo_pole / sqrt ( 1 - ( epsilon_tropo2 * pow ( cos( lat ), 2 )));
double r_earth = r_earth_pole / sqrt ( 1 - ( epsilon_earth2 * pow ( cos( lat ), 2 )));
-
+
double position_radius = r_earth + alt_asl;
double gamma = SG_PI - sun_angle;