# include <simgear_config.h>
#endif
+#include "sky.hxx"
+#include "cloudfield.hxx"
+#include "newcloud.hxx"
+
#include <simgear/math/sg_random.h>
#include <simgear/scene/util/RenderConstants.hxx>
+#include <simgear/sg_inlines.h>
-#include "sky.hxx"
-#include "cloudfield.hxx"
+#include <osg/StateSet>
+#include <osg/Depth>
// Constructor
SGSky::SGSky( void ) {
ramp_down = 0.15;
in_cloud = -1;
+
+ clouds_3d_enabled = false;
+ clouds_3d_density = 0.8;
pre_root = new osg::Group;
pre_root->setNodeMask(simgear::BACKGROUND_BIT);
+ osg::StateSet* preStateSet = new osg::StateSet;
+ preStateSet->setAttribute(new osg::Depth(osg::Depth::LESS, 0.0, 1.0,
+ false));
+ pre_root->setStateSet(preStateSet);
cloud_root = new osg::Group;
- cloud_root->setNodeMask(simgear::BACKGROUND_BIT | simgear::MODEL_BIT);
+ cloud_root->setNodeMask(simgear::MODEL_BIT);
pre_selector = new osg::Switch;
- pre_transform = new osg::MatrixTransform;
+ pre_transform = new osg::Group;
+
+ _ephTransform = new osg::MatrixTransform;
}
// the provided branch
void SGSky::build( double h_radius_m, double v_radius_m,
double sun_size, double moon_size,
- int nplanets, SGVec3d planet_data[7],
- int nstars, SGVec3d star_data[], SGPropertyNode *property_tree_node )
+ const SGEphemeris& eph, SGPropertyNode *property_tree_node )
{
dome = new SGSkyDome;
pre_transform->addChild( dome->build( h_radius_m, v_radius_m ) );
+ pre_transform->addChild(_ephTransform.get());
planets = new SGStars;
- pre_transform->addChild(planets->build(nplanets, planet_data, h_radius_m));
+ _ephTransform->addChild( planets->build(eph.getNumPlanets(), eph.getPlanets(), h_radius_m) );
stars = new SGStars;
- pre_transform->addChild( stars->build(nstars, star_data, h_radius_m) );
+ _ephTransform->addChild( stars->build(eph.getNumStars(), eph.getStars(), h_radius_m) );
moon = new SGMoon;
- pre_transform->addChild( moon->build(tex_path, moon_size) );
+ _ephTransform->addChild( moon->build(tex_path, moon_size) );
oursun = new SGSun;
- pre_transform->addChild( oursun->build(tex_path, sun_size, property_tree_node ) );
+ _ephTransform->addChild( oursun->build(tex_path, sun_size, property_tree_node ) );
pre_selector->addChild( pre_transform.get() );
- pre_root->addChild( pre_selector.get() );
+ pre_root->addChild( pre_selector.get() );
}
// 0 degrees = high noon
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
-bool SGSky::repaint( const SGSkyColor &sc )
+bool SGSky::repaint( const SGSkyColor &sc, const SGEphemeris& eph )
{
if ( effective_visibility > 1000.0 ) {
enable();
- dome->repaint( sc.sky_color, sc.fog_color, sc.sun_angle,
- effective_visibility );
+ dome->repaint( sc.adj_sky_color, sc.sky_color, sc.fog_color,
+ sc.sun_angle, effective_visibility );
- stars->repaint( sc.sun_angle, sc.nstars, sc.star_data );
- planets->repaint( sc.sun_angle, sc.nplanets, sc.planet_data );
+ stars->repaint( sc.sun_angle, eph.getNumStars(), eph.getStars() );
+ planets->repaint( sc.sun_angle, eph.getNumPlanets(), eph.getPlanets() );
oursun->repaint( sc.sun_angle, effective_visibility );
moon->repaint( sc.moon_angle );
// turn off sky
disable();
}
-
+ SGCloudField::updateFog((double)effective_visibility,
+ osg::Vec4f(toOsg(sc.fog_color), 1.0f));
return true;
}
-
// reposition the sky at the specified origin and orientation
//
// lon specifies a rotation about the Z axis
// spin specifies a rotation about the new Z axis (this allows
// additional orientation for the sunrise/set effects and is used by
// the skydome and perhaps clouds.
-bool SGSky::reposition( SGSkyState &st, double dt )
+bool SGSky::reposition( const SGSkyState &st, const SGEphemeris& eph, double dt )
{
-
double angle = st.gst * 15; // degrees
+ double angleRad = SGMiscd::deg2rad(angle);
- dome->reposition( st.zero_elev, st.alt, st.lon, st.lat, st.spin );
+ SGVec3f zero_elev, view_up;
+ double lon, lat, alt;
- stars->reposition( st.view_pos, angle );
- planets->reposition( st.view_pos, angle );
+ SGGeod geodZeroViewPos = SGGeod::fromGeodM(st.pos_geod, 0);
+ zero_elev = toVec3f( SGVec3d::fromGeod(geodZeroViewPos) );
- oursun->reposition( st.view_pos, angle,
- st.sun_ra, st.sun_dec, st.sun_dist, st.lat, st.alt, st.sun_angle );
+ // calculate the scenery up vector
+ SGQuatd hlOr = SGQuatd::fromLonLat(st.pos_geod);
+ view_up = toVec3f(hlOr.backTransform(-SGVec3d::e3()));
- moon->reposition( st.view_pos, angle,
- st.moon_ra, st.moon_dec, st.moon_dist );
+ // viewer location
+ lon = st.pos_geod.getLongitudeRad();
+ lat = st.pos_geod.getLatitudeRad();
+ alt = st.pos_geod.getElevationM();
+
+ dome->reposition( zero_elev, alt, lon, lat, st.spin );
+
+ osg::Matrix m = osg::Matrix::rotate(angleRad, osg::Vec3(0, 0, -1));
+ m.postMultTranslate(toOsg(st.pos));
+ _ephTransform->setMatrix(m);
+
+ double sun_ra = eph.getSunRightAscension();
+ double sun_dec = eph.getSunDeclination();
+ oursun->reposition( sun_ra, sun_dec, st.sun_dist, lat, alt, st.sun_angle );
+
+ double moon_ra = eph.getMoonRightAscension();
+ double moon_dec = eph.getMoonDeclination();
+ moon->reposition( moon_ra, moon_dec, st.moon_dist );
for ( unsigned i = 0; i < cloud_layers.size(); ++i ) {
- if ( cloud_layers[i]->getCoverage() != SGCloudLayer::SG_CLOUD_CLEAR ) {
- cloud_layers[i]->reposition( st.zero_elev, st.view_up,
- st.lon, st.lat, st.alt, dt );
- } else
+ if ( cloud_layers[i]->getCoverage() != SGCloudLayer::SG_CLOUD_CLEAR ||
+ cloud_layers[i]->get_layer3D()->isDefined3D() ) {
+ cloud_layers[i]->reposition( zero_elev, view_up, lon, lat, alt, dt);
+ } else {
cloud_layers[i]->getNode()->setAllChildrenOff();
}
+ }
return true;
}
{
cloud_layers.push_back(layer);
cloud_root->addChild(layer->getNode());
+
+ layer->set_enable3dClouds(clouds_3d_enabled);
}
const SGCloudLayer *
return cloud_layers.size();
}
+double SGSky::get_3dCloudDensity() const {
+ return SGNewCloud::getDensity();
+}
+
+void SGSky::set_3dCloudDensity(double density)
+{
+ SGNewCloud::setDensity(density);
+}
+
+float SGSky::get_3dCloudVisRange() const {
+ return SGCloudField::getVisRange();
+}
+
+void SGSky::set_3dCloudVisRange(float vis)
+{
+ SGCloudField::setVisRange(vis);
+ for ( int i = 0; i < (int)cloud_layers.size(); ++i ) {
+ cloud_layers[i]->get_layer3D()->applyVisRange();
+ }
+}
+
+bool SGSky::get_3dCloudWrap() const {
+ return SGCloudField::getWrap();
+}
+
+void SGSky::set_3dCloudWrap(bool wrap)
+{
+ SGCloudField::setWrap(wrap);
+}
+
+
+void SGSky::texture_path( const string& path ) {
+ tex_path = SGPath( path );
+}
+
// modify the current visibility based on cloud layers, thickness,
// transition range, and simulated "puffs".
void SGSky::modify_vis( float alt, float time_factor ) {
}
if ( cloud_layers[i]->getCoverage() == SGCloudLayer::SG_CLOUD_CLEAR ||
- cloud_layers[i]->get_layer3D()->is3D() && SGCloudField::enable3D) {
+ cloud_layers[i]->get_layer3D()->isDefined3D()) {
// do nothing, clear layers aren't drawn, don't affect
// visibility andn dont' need to be faded in or out.
} else if ( (cloud_layers[i]->getCoverage() ==
}
#endif
- // never let visibility drop below 25 meters
- if ( effvis <= 25.0 ) {
- effvis = 25.0;
- }
+ // never let visibility drop below the layer's configured visibility
+ effvis = SG_MAX2<float>(cloud_layers[i]->getVisibility_m(), effvis );
} // for
effective_visibility = effvis;
}
+
+