Cleanup. Use already structured data instead of copying stuff.
This commit is contained in:
@@ -165,28 +165,19 @@ bool SGMoon::repaint( double moon_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 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;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ public:
|
||||
// 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 );
|
||||
};
|
||||
|
||||
|
||||
@@ -363,15 +363,11 @@ bool SGSun::repaint( double sun_angle, double new_visibility ) {
|
||||
// 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);
|
||||
@@ -383,7 +379,7 @@ bool SGSun::reposition( const SGVec3f& p, double angle,
|
||||
// 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 ) {
|
||||
|
||||
@@ -75,8 +75,7 @@ public:
|
||||
// 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
|
||||
|
||||
@@ -62,7 +62,9 @@ SGSky::SGSky( void ) {
|
||||
|
||||
pre_selector = new osg::Switch;
|
||||
|
||||
pre_transform = new osg::MatrixTransform;
|
||||
pre_transform = new osg::Group;
|
||||
|
||||
_ephTransform = new osg::MatrixTransform;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,23 +78,23 @@ SGSky::~SGSky( void )
|
||||
// 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() );
|
||||
|
||||
@@ -107,15 +109,15 @@ void SGSky::build( double h_radius_m, double v_radius_m,
|
||||
// 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 );
|
||||
|
||||
@@ -133,7 +135,6 @@ bool SGSky::repaint( const SGSkyColor &sc )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// reposition the sky at the specified origin and orientation
|
||||
//
|
||||
// lon specifies a rotation about the Z axis
|
||||
@@ -141,21 +142,24 @@ bool SGSky::repaint( const SGSkyColor &sc )
|
||||
// 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 ) {
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
#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>
|
||||
@@ -57,8 +59,8 @@ typedef struct {
|
||||
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;
|
||||
|
||||
@@ -66,9 +68,6 @@ typedef struct {
|
||||
SGVec3f sky_color, fog_color;
|
||||
SGVec3f cloud_color;
|
||||
double sun_angle, moon_angle;
|
||||
int nplanets, nstars;
|
||||
SGVec3d *planet_data;
|
||||
SGVec3d *star_data;
|
||||
} SGSkyColor;
|
||||
|
||||
/**
|
||||
@@ -219,7 +218,9 @@ private:
|
||||
|
||||
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;
|
||||
|
||||
@@ -268,8 +269,7 @@ public:
|
||||
*/
|
||||
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,
|
||||
@@ -295,7 +295,7 @@ public:
|
||||
* @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
|
||||
@@ -325,7 +325,7 @@ public:
|
||||
* @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,
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <osg/Material>
|
||||
#include <osg/Point>
|
||||
#include <osg/ShadeModel>
|
||||
#include <osg/Node>
|
||||
|
||||
#include "stars.hxx"
|
||||
|
||||
@@ -64,26 +65,11 @@ SGStars::~SGStars( void ) {
|
||||
// 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);
|
||||
@@ -126,11 +112,7 @@ SGStars::build( int num, const SGVec3d star_data[], double star_dist ) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -202,7 +184,6 @@ bool SGStars::repaint( double sun_angle, int num, const SGVec3d star_data[] ) {
|
||||
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 {
|
||||
@@ -225,20 +206,3 @@ bool SGStars::repaint( double sun_angle, int num, const SGVec3d star_data[] ) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
|
||||
#include <osg/Array>
|
||||
#include <osg/Node>
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include <simgear/structure/SGReferenced.hxx>
|
||||
@@ -39,7 +37,6 @@
|
||||
|
||||
class SGStars : public SGReferenced {
|
||||
|
||||
osg::ref_ptr<osg::MatrixTransform> stars_transform;
|
||||
osg::ref_ptr<osg::Vec4Array> cl;
|
||||
|
||||
int old_phase; // data for optimization
|
||||
@@ -62,11 +59,6 @@ public:
|
||||
// 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 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user