// declination, offset by our current position (p) so that it appears
// fixed at a great distance from the viewer. Also add in an optional
// rotation (i.e. for the current time of day.)
-bool SGMoon::reposition( const SGVec3f& p, double angle,
- double rightAscension, double declination,
+bool SGMoon::reposition( double rightAscension, double declination,
double moon_dist )
{
- osg::Matrix T1, T2, GST, RA, DEC;
+ osg::Matrix T2, RA, DEC;
- T1.makeTranslate(p.osg());
-
- GST.makeRotate(SGD_DEGREES_TO_RADIANS*angle, osg::Vec3(0, 0, -1));
-
- // xglRotatef( ((SGD_RADIANS_TO_DEGREES * rightAscension)- 90.0),
- // 0.0, 0.0, 1.0);
RA.makeRotate(rightAscension - 90.0 * SGD_DEGREES_TO_RADIANS,
osg::Vec3(0, 0, 1));
- // xglRotatef((SGD_RADIANS_TO_DEGREES * declination), 1.0, 0.0, 0.0);
DEC.makeRotate(declination, osg::Vec3(1, 0, 0));
- // xglTranslatef(0,moon_dist);
T2.makeTranslate(osg::Vec3(0, moon_dist, 0));
- moon_transform->setMatrix(T2*DEC*RA*GST*T1);
+ moon_transform->setMatrix(T2*DEC*RA);
return true;
}
// declination, offset by our current position (p) so that it
// appears fixed at a great distance from the viewer. Also add in
// an optional rotation (i.e. for the current time of day.)
- bool reposition( const SGVec3f& p, double angle,
- double rightAscension, double declination,
+ bool reposition( double rightAscension, double declination,
double moon_dist );
};
// 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( const SGVec3f& p, double angle,
- 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
- osg::Matrix T1, T2, GST, RA, DEC;
-
- T1.makeTranslate(p.osg());
- GST.makeRotate(SGD_DEGREES_TO_RADIANS*angle, osg::Vec3(0, 0, -1));
+ osg::Matrix T2, RA, DEC;
// xglRotatef( ((SGD_RADIANS_TO_DEGREES * rightAscension)- 90.0),
// 0.0, 0.0, 1.0);
// xglTranslatef(0,sun_dist);
T2.makeTranslate(osg::Vec3(0, sun_dist, 0));
- sun_transform->setMatrix(T2*DEC*RA*GST*T1);
+ sun_transform->setMatrix(T2*DEC*RA);
// Suncolor related things:
if ( prev_sun_angle != sun_angle ) {
// declination, offset by our current position (p) so that it
// appears fixed at a great distance from the viewer. Also add in
// an optional rotation (i.e. for the current time of day.)
- bool reposition( const SGVec3f& p, double angle,
- double rightAscension, double declination,
+ bool reposition( double rightAscension, double declination,
double sun_dist, double lat, double alt_asl, double sun_angle );
// retrun the current color of the sun
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() );
// 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 );
- 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 );
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 );
- stars->reposition( st.view_pos, angle );
- planets->reposition( st.view_pos, angle );
+ osg::Matrix m = osg::Matrix::rotate(angleRad, osg::Vec3(0, 0, -1));
+ m.postMultTranslate(st.view_pos.osg());
+ _ephTransform->setMatrix(m);
- oursun->reposition( st.view_pos, angle,
- st.sun_ra, st.sun_dec, st.sun_dist, st.lat, st.alt, st.sun_angle );
+ double sun_ra = eph.getSunRightAscension();
+ double sun_dec = eph.getSunDeclination();
+ oursun->reposition( sun_ra, sun_dec, st.sun_dist, st.lat, st.alt, st.sun_angle );
- moon->reposition( st.view_pos, angle,
- st.moon_ra, st.moon_dec, st.moon_dist );
+ 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 ) {
#include <osg/Node>
#include <osg/Switch>
+#include <simgear/ephemeris/ephemeris.hxx>
+
#include <simgear/scene/sky/cloud.hxx>
#include <simgear/scene/sky/dome.hxx>
#include <simgear/scene/sky/moon.hxx>
SGVec3f view_pos, zero_elev, view_up;
double lon, lat, alt, spin;
double gst;
- double sun_ra, sun_dec, sun_dist;
- double moon_ra, moon_dec, moon_dist;
+ double sun_dist;
+ double moon_dist;
double sun_angle;
} SGSkyState;
SGVec3f sky_color, fog_color;
SGVec3f cloud_color;
double sun_angle, moon_angle;
- int nplanets, nstars;
- SGVec3d *planet_data;
- SGVec3d *star_data;
} SGSkyColor;
/**
osg::ref_ptr<osg::Group> pre_root, cloud_root;
osg::ref_ptr<osg::Switch> pre_selector;
- osg::ref_ptr<osg::MatrixTransform> pre_transform;
+ osg::ref_ptr<osg::Group> pre_transform;
+
+ osg::ref_ptr<osg::MatrixTransform> _ephTransform;
SGPath tex_path;
*/
void 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 );
/**
* Repaint the sky components based on current value of sun_angle,
* @param star_data an array of star right ascensions, declinations,
* and magnitudes
*/
- bool repaint( const SGSkyColor &sc );
+ bool repaint( const SGSkyColor &sc, const SGEphemeris& eph );
/**
* Reposition the sky at the specified origin and orientation
* @param moon_dec the moon's current declination
* @param moon_dist the moon's distance from the current view point.
*/
- bool reposition( SGSkyState &st, double dt = 0.0 );
+ bool reposition( const SGSkyState &st, const SGEphemeris& eph, double dt = 0.0 );
/**
* Modify the given visibility based on cloud layers, thickness,
#include <osg/Material>
#include <osg/Point>
#include <osg/ShadeModel>
+#include <osg/Node>
#include "stars.hxx"
// initialize the stars object and connect it into our scene graph root
osg::Node*
SGStars::build( int num, const SGVec3d star_data[], double star_dist ) {
- // build the ssg scene graph sub tree for the sky and connected
- // into the provide scene graph branch
- stars_transform = new osg::MatrixTransform;
-
osg::Geode* geode = new osg::Geode;
osg::StateSet* stateSet = geode->getOrCreateStateSet();
stateSet->setRenderBinDetails(-9, "RenderBin");
// set up the star state
-
- // Ok, the old implementation did have a color material set.
- // But with lighting off, I don't see how this should change the result
- 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));
-// material->setSpecular(osg::Material::FRONT_AND_BACK,
-// osg::Vec4(0, 0, 0, 1));
- stateSet->setAttribute(material);
-
osg::BlendFunc* blendFunc = new osg::BlendFunc;
blendFunc->setFunction(osg::BlendFunc::SRC_ALPHA,
osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_POINTS, 0, vl->size()));
geode->addDrawable(geometry);
- stars_transform->addChild(geode);
-
- SG_LOG( SG_EVENT, SG_INFO, "stars = " << stars_transform.get());
-
- return stars_transform.get();
+ return geode;
}
mag = star_data[i][2];
if ( mag < cutoff ) {
nmag = ( 4.5 - mag ) / 5.5; // translate to 0 ... 1.0 scale
- // alpha = nmag * 0.7 + 0.3; // translate to a 0.3 ... 1.0 scale
alpha = nmag * 0.85 + 0.15; // translate to a 0.15 ... 1.0 scale
alpha *= factor; // dim when the sun is brighter
} else {
return true;
}
-
-
-// reposition the stars for the specified time (GST rotation),
-// offset by our current position (p) so that it appears fixed at a
-// great distance from the viewer.
-bool
-SGStars::reposition( const SGVec3f& p, double angle )
-{
- osg::Matrix T1, GST;
- T1.makeTranslate(p.osg());
-
- GST.makeRotate(angle*SGD_DEGREES_TO_RADIANS, osg::Vec3(0, 0, -1));
-
- stars_transform->setMatrix(GST*T1);
-
- return true;
-}
#include <osg/Array>
-#include <osg/Node>
-#include <osg/MatrixTransform>
#include <simgear/math/SGMath.hxx>
#include <simgear/structure/SGReferenced.hxx>
class SGStars : public SGReferenced {
- osg::ref_ptr<osg::MatrixTransform> stars_transform;
osg::ref_ptr<osg::Vec4Array> cl;
int old_phase; // data for optimization
// 90 degrees = sun rise/set
// 180 degrees = darkest midnight
bool repaint( double sun_angle, int num, const SGVec3d star_data[] );
-
- // reposition the stars for the specified time (GST rotation),
- // offset by our current position (p) so that it appears fixed at
- // a great distance from the viewer.
- bool reposition( const SGVec3f& p, double angle );
};