2004-11-16 03:44:35 +08:00
/* details about distances and rotation on http://www.solarviews.com/eng/solarsys.htm */
2004-10-23 00:39:24 +08:00
# include <iostream>
# include <osg/Notify>
# include <osg/MatrixTransform>
# include <osg/PositionAttitudeTransform>
# include <osg/Geometry>
# include <osg/Geode>
2004-10-24 22:23:42 +08:00
# include <osg/ShapeDrawable>
2004-10-26 02:23:42 +08:00
# include <osg/Texture2D>
2004-10-28 17:38:03 +08:00
# include <osg/Material>
# include <osg/Light>
# include <osg/LightSource>
# include <osg/LightModel>
2004-11-09 23:01:39 +08:00
# include <osg/Billboard>
# include <osg/LineWidth>
2004-10-29 23:42:51 +08:00
# include <osg/TexEnv>
# include <osg/TexEnvCombine>
2004-11-18 23:10:24 +08:00
# include <osg/ClearNode>
2004-10-26 02:23:42 +08:00
2004-10-23 00:39:24 +08:00
# include <osgUtil/Optimizer>
# include <osgDB/Registry>
# include <osgDB/ReadFile>
2004-11-18 23:01:41 +08:00
# include <osgDB/WriteFile>
2004-10-23 00:39:24 +08:00
2004-10-29 03:09:32 +08:00
# include <osgGA/NodeTrackerManipulator>
2004-10-23 00:39:24 +08:00
# include <osgGA/TrackballManipulator>
# include <osgGA/FlightManipulator>
# include <osgGA/DriveManipulator>
2007-01-10 21:52:22 +08:00
# include <osgGA/KeySwitchMatrixManipulator>
2004-10-23 00:39:24 +08:00
2007-01-10 21:52:22 +08:00
# include <osgViewer/Viewer>
2004-10-23 00:39:24 +08:00
2004-10-28 17:38:03 +08:00
static osg : : Vec3 defaultPos ( 0.0f , 0.0f , 0.0f ) ;
static osg : : Vec3 centerScope ( 0.0f , 0.0f , 0.0f ) ;
2004-11-09 23:01:39 +08:00
2004-11-16 03:44:35 +08:00
2004-11-09 23:01:39 +08:00
/** create quad at specified position. */
osg : : Drawable * createSquare ( const osg : : Vec3 & corner , const osg : : Vec3 & width , const osg : : Vec3 & height , osg : : Image * image = NULL )
{
// set up the Geometry.
osg : : Geometry * geom = new osg : : Geometry ;
osg : : Vec3Array * coords = new osg : : Vec3Array ( 4 ) ;
( * coords ) [ 0 ] = corner ;
( * coords ) [ 1 ] = corner + width ;
( * coords ) [ 2 ] = corner + width + height ;
( * coords ) [ 3 ] = corner + height ;
geom - > setVertexArray ( coords ) ;
osg : : Vec3Array * norms = new osg : : Vec3Array ( 1 ) ;
( * norms ) [ 0 ] = width ^ height ;
( * norms ) [ 0 ] . normalize ( ) ;
geom - > setNormalArray ( norms ) ;
geom - > setNormalBinding ( osg : : Geometry : : BIND_OVERALL ) ;
osg : : Vec2Array * tcoords = new osg : : Vec2Array ( 4 ) ;
( * tcoords ) [ 0 ] . set ( 0.0f , 0.0f ) ;
( * tcoords ) [ 1 ] . set ( 1.0f , 0.0f ) ;
( * tcoords ) [ 2 ] . set ( 1.0f , 1.0f ) ;
( * tcoords ) [ 3 ] . set ( 0.0f , 1.0f ) ;
geom - > setTexCoordArray ( 0 , tcoords ) ;
osg : : Vec4Array * colours = new osg : : Vec4Array ( 1 ) ;
( * colours ) [ 0 ] . set ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
geom - > setColorArray ( colours ) ;
geom - > setColorBinding ( osg : : Geometry : : BIND_OVERALL ) ;
geom - > addPrimitiveSet ( new osg : : DrawArrays ( osg : : PrimitiveSet : : QUADS , 0 , 4 ) ) ;
if ( image )
{
osg : : StateSet * stateset = new osg : : StateSet ;
osg : : Texture2D * texture = new osg : : Texture2D ;
texture - > setImage ( image ) ;
stateset - > setTextureAttributeAndModes ( 0 , texture , osg : : StateAttribute : : ON ) ;
stateset - > setMode ( GL_LIGHTING , osg : : StateAttribute : : OFF ) ;
stateset - > setMode ( GL_BLEND , osg : : StateAttribute : : ON ) ;
stateset - > setRenderingHint ( osg : : StateSet : : TRANSPARENT_BIN ) ;
geom - > setStateSet ( stateset ) ;
}
2004-10-28 17:38:03 +08:00
2004-11-09 23:01:39 +08:00
return geom ;
}
2004-10-28 17:38:03 +08:00
2004-11-09 23:01:39 +08:00
osg : : Image * createBillboardImage ( const osg : : Vec4 & centerColour , unsigned int size , float power )
{
osg : : Vec4 backgroundColour = centerColour ;
backgroundColour [ 3 ] = 0.0f ;
osg : : Image * image = new osg : : Image ;
image - > allocateImage ( size , size , 1 ,
GL_RGBA , GL_UNSIGNED_BYTE ) ;
float mid = ( float ( size ) - 1 ) * 0.5f ;
float div = 2.0f / float ( size ) ;
for ( unsigned int r = 0 ; r < size ; + + r )
{
unsigned char * ptr = image - > data ( 0 , r , 0 ) ;
for ( unsigned int c = 0 ; c < size ; + + c )
{
float dx = ( float ( c ) - mid ) * div ;
float dy = ( float ( r ) - mid ) * div ;
float r = powf ( 1.0f - sqrtf ( dx * dx + dy * dy ) , power ) ;
if ( r < 0.0f ) r = 0.0f ;
osg : : Vec4 color = centerColour * r + backgroundColour * ( 1.0f - r ) ;
// color.set(1.0f,1.0f,1.0f,0.5f);
* ptr + + = ( unsigned char ) ( ( color [ 0 ] ) * 255.0f ) ;
* ptr + + = ( unsigned char ) ( ( color [ 1 ] ) * 255.0f ) ;
* ptr + + = ( unsigned char ) ( ( color [ 2 ] ) * 255.0f ) ;
* ptr + + = ( unsigned char ) ( ( color [ 3 ] ) * 255.0f ) ;
}
}
return image ;
2004-10-28 17:38:03 +08:00
2004-11-09 23:01:39 +08:00
//return osgDB::readImageFile("spot.dds");
}
2004-10-28 17:38:03 +08:00
2004-10-24 22:23:42 +08:00
osg : : AnimationPath * createAnimationPath ( const osg : : Vec3 & center , float radius , double looptime )
2004-10-23 00:39:24 +08:00
{
2004-10-24 22:23:42 +08:00
// set up the animation path
osg : : AnimationPath * animationPath = new osg : : AnimationPath ;
animationPath - > setLoopMode ( osg : : AnimationPath : : LOOP ) ;
2004-10-23 02:47:39 +08:00
2004-11-18 23:01:41 +08:00
int numSamples = 1000 ;
2004-10-24 22:23:42 +08:00
float yaw = 0.0f ;
2004-11-22 21:58:57 +08:00
float yaw_delta = - 2.0f * osg : : PI / ( ( float ) numSamples - 1.0f ) ;
2004-10-24 22:23:42 +08:00
float roll = osg : : inDegrees ( 30.0f ) ;
double time = 0.0f ;
double time_delta = looptime / ( double ) numSamples ;
for ( int i = 0 ; i < numSamples ; + + i )
{
osg : : Vec3 position ( center + osg : : Vec3 ( sinf ( yaw ) * radius , cosf ( yaw ) * radius , 0.0f ) ) ;
osg : : Quat rotation ( osg : : Quat ( roll , osg : : Vec3 ( 0.0 , 1.0 , 0.0 ) ) * osg : : Quat ( - ( yaw + osg : : inDegrees ( 90.0f ) ) , osg : : Vec3 ( 0.0 , 0.0 , 1.0 ) ) ) ;
animationPath - > insert ( time , osg : : AnimationPath : : ControlPoint ( position , rotation ) ) ;
yaw + = yaw_delta ;
time + = time_delta ;
}
return animationPath ;
} // end createAnimationPath
class SolarSystem
{
public :
2004-11-16 03:44:35 +08:00
double _radiusSpace ;
2004-10-24 22:23:42 +08:00
double _radiusSun ;
2004-11-16 03:44:35 +08:00
double _radiusMercury ;
double _radiusVenus ;
2004-10-24 22:23:42 +08:00
double _radiusEarth ;
2004-11-16 03:44:35 +08:00
double _radiusMoon ;
double _radiusMars ;
double _radiusJupiter ;
double _RorbitMercury ;
double _RorbitVenus ;
2004-10-24 22:23:42 +08:00
double _RorbitEarth ;
2004-11-16 03:44:35 +08:00
double _RorbitMoon ;
double _RorbitMars ;
double _RorbitJupiter ;
2004-11-22 21:58:57 +08:00
double _rotateSpeedSun ;
2004-11-16 03:44:35 +08:00
double _rotateSpeedMercury ;
double _rotateSpeedVenus ;
2004-10-24 22:23:42 +08:00
double _rotateSpeedEarthAndMoon ;
double _rotateSpeedEarth ;
double _rotateSpeedMoon ;
2004-11-16 03:44:35 +08:00
double _rotateSpeedMars ;
double _rotateSpeedJupiter ;
double _tiltEarth ;
std : : string _mapSpace ;
std : : string _mapSun ;
std : : string _mapVenus ;
std : : string _mapMercury ;
std : : string _mapEarth ;
std : : string _mapEarthNight ;
std : : string _mapMoon ;
std : : string _mapMars ;
std : : string _mapJupiter ;
2004-10-24 22:23:42 +08:00
2004-11-22 21:58:57 +08:00
double _rotateSpeedFactor ;
double _RorbitFactor ;
double _radiusFactor ;
2004-10-26 02:23:42 +08:00
SolarSystem ( )
{
2004-11-22 21:58:57 +08:00
_radiusSpace = 500.0 ;
_radiusSun = 109.0 ;
_radiusMercury = 0.38 ;
_radiusVenus = 0.95 ;
_radiusEarth = 1.0 ;
_radiusMoon = 0.1 ;
_radiusMars = 0.53 ;
_radiusJupiter = 5.0 ;
2004-11-16 03:44:35 +08:00
_RorbitMercury = 11.7 ;
_RorbitVenus = 21.6 ;
_RorbitEarth = 30.0 ;
2004-11-22 21:58:57 +08:00
_RorbitMoon = 1.0 ;
2004-11-16 03:44:35 +08:00
_RorbitMars = 45.0 ;
_RorbitJupiter = 156.0 ;
2004-11-22 21:58:57 +08:00
// orbital period in days
_rotateSpeedSun = 0.0 ; // should be 11.97; // 30.5 average
_rotateSpeedMercury = 4.15 ; // 87.96
_rotateSpeedVenus = 1.62 ; // 224.70
_rotateSpeedEarthAndMoon = 1.0 ; // 365.25
_rotateSpeedEarth = 1.0 ; //
_rotateSpeedMoon = 0.95 ; //
_rotateSpeedMars = 0.53 ; // 686.98
_rotateSpeedJupiter = 0.08 ; // 4332.71
_tiltEarth = 23.45 ; // degrees
2004-11-16 03:44:35 +08:00
_mapSpace = " Images/spacemap2.jpg " ;
2004-11-18 22:43:07 +08:00
_mapSun = " SolarSystem/sun256128.jpg " ;
_mapMercury = " SolarSystem/mercury256128.jpg " ;
_mapVenus = " SolarSystem/venus256128.jpg " ;
2004-11-16 03:44:35 +08:00
_mapEarth = " Images/land_shallow_topo_2048.jpg " ;
_mapEarthNight = " Images/land_ocean_ice_lights_2048.jpg " ;
2004-11-18 22:43:07 +08:00
_mapMoon = " SolarSystem/moon256128.jpg " ;
_mapMars = " SolarSystem/mars256128.jpg " ;
_mapJupiter = " SolarSystem/jupiter256128.jpg " ;
2004-11-22 21:58:57 +08:00
_rotateSpeedFactor = 0.5 ;
_RorbitFactor = 15.0 ;
_radiusFactor = 10.0 ;
2004-10-26 02:23:42 +08:00
}
2004-10-24 22:23:42 +08:00
2004-11-16 03:44:35 +08:00
osg : : MatrixTransform * createTranslationAndTilt ( double translation , double tilt ) ;
2004-10-29 03:09:32 +08:00
osg : : MatrixTransform * createRotation ( double orbit , double speed ) ;
2004-11-16 03:44:35 +08:00
2004-10-29 03:09:32 +08:00
osg : : Geode * createSpace ( const std : : string & name , const std : : string & textureName ) ;
osg : : Geode * createPlanet ( double radius , const std : : string & name , const osg : : Vec4 & color , const std : : string & textureName ) ;
2004-10-29 23:42:51 +08:00
osg : : Geode * createPlanet ( double radius , const std : : string & name , const osg : : Vec4 & color , const std : : string & textureName1 , const std : : string & textureName2 ) ;
2004-10-29 03:09:32 +08:00
osg : : Group * createSunLight ( ) ;
2004-10-24 22:23:42 +08:00
2004-11-22 21:58:57 +08:00
void rotateSpeedCorrection ( )
{
_rotateSpeedSun * = _rotateSpeedFactor ;
_rotateSpeedMercury * = _rotateSpeedFactor ;
_rotateSpeedVenus * = _rotateSpeedFactor ;
_rotateSpeedEarthAndMoon * = _rotateSpeedFactor ;
_rotateSpeedEarth * = _rotateSpeedFactor ;
_rotateSpeedMoon * = _rotateSpeedFactor ;
_rotateSpeedMars * = _rotateSpeedFactor ;
_rotateSpeedJupiter * = _rotateSpeedFactor ;
std : : cout < < " rotateSpeed corrected by factor " < < _rotateSpeedFactor < < std : : endl ;
}
void RorbitCorrection ( )
{
_RorbitMercury * = _RorbitFactor ;
_RorbitVenus * = _RorbitFactor ;
_RorbitEarth * = _RorbitFactor ;
_RorbitMoon * = _RorbitFactor ;
_RorbitMars * = _RorbitFactor ;
_RorbitJupiter * = _RorbitFactor ;
std : : cout < < " Rorbits corrected by factor " < < _RorbitFactor < < std : : endl ;
}
void radiusCorrection ( )
{
_radiusSpace * = _radiusFactor ;
//_radiusSun *= _radiusFactor;
_radiusMercury * = _radiusFactor ;
_radiusVenus * = _radiusFactor ;
_radiusEarth * = _radiusFactor ;
_radiusMoon * = _radiusFactor ;
_radiusMars * = _radiusFactor ;
_radiusJupiter * = _radiusFactor ;
std : : cout < < " Radius corrected by factor " < < _radiusFactor < < std : : endl ;
}
2004-11-16 03:44:35 +08:00
void printParameters ( ) ;
2004-10-28 17:38:03 +08:00
2004-10-24 22:23:42 +08:00
} ; // end SolarSystem
2004-10-29 03:09:32 +08:00
class FindNamedNodeVisitor : public osg : : NodeVisitor
{
public :
FindNamedNodeVisitor ( const std : : string & name ) :
osg : : NodeVisitor ( osg : : NodeVisitor : : TRAVERSE_ALL_CHILDREN ) ,
_name ( name ) { }
virtual void apply ( osg : : Node & node )
{
if ( node . getName ( ) = = _name )
{
_foundNodes . push_back ( & node ) ;
}
traverse ( node ) ;
}
typedef std : : vector < osg : : ref_ptr < osg : : Node > > NodeList ;
std : : string _name ;
NodeList _foundNodes ;
} ;
2004-10-23 00:39:24 +08:00
2004-11-18 23:01:41 +08:00
osg : : MatrixTransform * SolarSystem : : createRotation ( double orbit , double speed )
{
osg : : Vec3 center ( 0.0 , 0.0 , 0.0 ) ;
float animationLength = 10.0f ;
osg : : AnimationPath * animationPath = createAnimationPath ( center , orbit , animationLength ) ;
osg : : MatrixTransform * rotation = new osg : : MatrixTransform ;
rotation - > setUpdateCallback ( new osg : : AnimationPathCallback ( animationPath , 0.0f , speed ) ) ;
return rotation ;
} // end SolarSystem::createEarthRotation
osg : : MatrixTransform * SolarSystem : : createTranslationAndTilt ( double /*translation*/ , double tilt )
{
osg : : MatrixTransform * moonPositioned = new osg : : MatrixTransform ;
moonPositioned - > setMatrix ( osg : : Matrix : : translate ( osg : : Vec3 ( 0.0 , _RorbitMoon , 0.0 ) ) *
osg : : Matrix : : scale ( 1.0 , 1.0 , 1.0 ) *
osg : : Matrix : : rotate ( osg : : inDegrees ( tilt ) , 0.0f , 0.0f , 1.0f ) ) ;
return moonPositioned ;
} // end SolarSystem::createTranslationAndTilt
osg : : Geode * SolarSystem : : createSpace ( const std : : string & name , const std : : string & textureName )
{
osg : : Sphere * spaceSphere = new osg : : Sphere ( osg : : Vec3 ( 0.0 , 0.0 , 0.0 ) , _radiusSpace ) ;
osg : : ShapeDrawable * sSpaceSphere = new osg : : ShapeDrawable ( spaceSphere ) ;
if ( ! textureName . empty ( ) )
{
osg : : Image * image = osgDB : : readImageFile ( textureName ) ;
if ( image )
{
sSpaceSphere - > getOrCreateStateSet ( ) - > setTextureAttributeAndModes ( 0 , new osg : : Texture2D ( image ) , osg : : StateAttribute : : ON ) ;
// reset the object color to white to allow the texture to set the colour.
sSpaceSphere - > setColor ( osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ) ;
}
}
osg : : Geode * geodeSpace = new osg : : Geode ( ) ;
geodeSpace - > setName ( name ) ;
geodeSpace - > addDrawable ( sSpaceSphere ) ;
return ( geodeSpace ) ;
} // end SolarSystem::createSpace
osg : : Geode * SolarSystem : : createPlanet ( double radius , const std : : string & name , const osg : : Vec4 & color , const std : : string & textureName )
{
// create a container that makes the sphere drawable
osg : : Geometry * sPlanetSphere = new osg : : Geometry ( ) ;
{
// set the single colour so bind overall
osg : : Vec4Array * colours = new osg : : Vec4Array ( 1 ) ;
( * colours ) [ 0 ] = color ;
sPlanetSphere - > setColorArray ( colours ) ;
sPlanetSphere - > setColorBinding ( osg : : Geometry : : BIND_OVERALL ) ;
// now set up the coords, normals and texcoords for geometry
unsigned int numX = 100 ;
unsigned int numY = 50 ;
unsigned int numVertices = numX * numY ;
osg : : Vec3Array * coords = new osg : : Vec3Array ( numVertices ) ;
sPlanetSphere - > setVertexArray ( coords ) ;
osg : : Vec3Array * normals = new osg : : Vec3Array ( numVertices ) ;
sPlanetSphere - > setNormalArray ( normals ) ;
sPlanetSphere - > setNormalBinding ( osg : : Geometry : : BIND_PER_VERTEX ) ;
osg : : Vec2Array * texcoords = new osg : : Vec2Array ( numVertices ) ;
sPlanetSphere - > setTexCoordArray ( 0 , texcoords ) ;
sPlanetSphere - > setTexCoordArray ( 1 , texcoords ) ;
double delta_elevation = osg : : PI / ( double ) ( numY - 1 ) ;
double delta_azim = 2.0 * osg : : PI / ( double ) ( numX - 1 ) ;
float delta_tx = 1.0 / ( float ) ( numX - 1 ) ;
float delta_ty = 1.0 / ( float ) ( numY - 1 ) ;
double elevation = - osg : : PI * 0.5 ;
float ty = 0.0 ;
unsigned int vert = 0 ;
unsigned j ;
for ( j = 0 ;
j < numY ;
+ + j , elevation + = delta_elevation , ty + = delta_ty )
{
double azim = 0.0 ;
float tx = 0.0 ;
for ( unsigned int i = 0 ;
i < numX ;
+ + i , + + vert , azim + = delta_azim , tx + = delta_tx )
{
osg : : Vec3 direction ( cos ( azim ) * cos ( elevation ) , sin ( azim ) * cos ( elevation ) , sin ( elevation ) ) ;
( * coords ) [ vert ] . set ( direction * radius ) ;
( * normals ) [ vert ] . set ( direction ) ;
( * texcoords ) [ vert ] . set ( tx , ty ) ;
}
}
for ( j = 0 ;
j < numY - 1 ;
+ + j )
{
unsigned int curr_row = j * numX ;
unsigned int next_row = curr_row + numX ;
osg : : DrawElementsUShort * elements = new osg : : DrawElementsUShort ( GL_QUAD_STRIP ) ;
for ( unsigned int i = 0 ;
i < numX ;
+ + i )
{
elements - > push_back ( next_row + i ) ;
elements - > push_back ( curr_row + i ) ;
}
sPlanetSphere - > addPrimitiveSet ( elements ) ;
}
}
// set the object color
//sPlanetSphere->setColor( color );
// create a geode object to as a container for our drawable sphere object
osg : : Geode * geodePlanet = new osg : : Geode ( ) ;
geodePlanet - > setName ( name ) ;
if ( ! textureName . empty ( ) )
{
osg : : Image * image = osgDB : : readImageFile ( textureName ) ;
if ( image )
{
2005-11-18 04:22:55 +08:00
osg : : Texture2D * tex2d = new osg : : Texture2D ( image ) ;
tex2d - > setWrap ( osg : : Texture : : WRAP_S , osg : : Texture : : REPEAT ) ;
tex2d - > setWrap ( osg : : Texture : : WRAP_T , osg : : Texture : : REPEAT ) ;
2004-11-25 03:10:44 +08:00
geodePlanet - > getOrCreateStateSet ( ) - > setTextureAttributeAndModes ( 0 , tex2d , osg : : StateAttribute : : ON ) ;
2004-11-18 23:01:41 +08:00
// reset the object color to white to allow the texture to set the colour.
//sPlanetSphere->setColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) );
}
}
// add our drawable sphere to the geode container
geodePlanet - > addDrawable ( sPlanetSphere ) ;
return ( geodePlanet ) ;
} // end SolarSystem::createPlanet
osg : : Geode * SolarSystem : : createPlanet ( double radius , const std : : string & name , const osg : : Vec4 & color , const std : : string & textureName1 , const std : : string & textureName2 )
{
osg : : Geode * geodePlanet = createPlanet ( radius , name , color , textureName1 ) ;
if ( ! textureName2 . empty ( ) )
{
osg : : Image * image = osgDB : : readImageFile ( textureName2 ) ;
if ( image )
{
osg : : StateSet * stateset = geodePlanet - > getOrCreateStateSet ( ) ;
osg : : TexEnvCombine * texenv = new osg : : TexEnvCombine ;
texenv - > setCombine_RGB ( osg : : TexEnvCombine : : INTERPOLATE ) ;
texenv - > setSource0_RGB ( osg : : TexEnvCombine : : PREVIOUS ) ;
texenv - > setOperand0_RGB ( osg : : TexEnvCombine : : SRC_COLOR ) ;
texenv - > setSource1_RGB ( osg : : TexEnvCombine : : TEXTURE ) ;
texenv - > setOperand1_RGB ( osg : : TexEnvCombine : : SRC_COLOR ) ;
texenv - > setSource2_RGB ( osg : : TexEnvCombine : : PRIMARY_COLOR ) ;
texenv - > setOperand2_RGB ( osg : : TexEnvCombine : : SRC_COLOR ) ;
stateset - > setTextureAttribute ( 1 , texenv ) ;
2005-11-18 04:22:55 +08:00
osg : : Texture2D * tex2d = new osg : : Texture2D ( image ) ;
tex2d - > setWrap ( osg : : Texture : : WRAP_S , osg : : Texture : : REPEAT ) ;
tex2d - > setWrap ( osg : : Texture : : WRAP_T , osg : : Texture : : REPEAT ) ;
2004-11-25 03:10:44 +08:00
stateset - > setTextureAttributeAndModes ( 1 , tex2d , osg : : StateAttribute : : ON ) ;
2004-11-18 23:01:41 +08:00
}
}
return ( geodePlanet ) ;
} // end SolarSystem::createPlanet
osg : : Group * SolarSystem : : createSunLight ( )
{
osg : : LightSource * sunLightSource = new osg : : LightSource ;
osg : : Light * sunLight = sunLightSource - > getLight ( ) ;
sunLight - > setPosition ( osg : : Vec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
sunLight - > setAmbient ( osg : : Vec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
sunLightSource - > setLight ( sunLight ) ;
sunLightSource - > setLocalStateSetModes ( osg : : StateAttribute : : ON ) ;
sunLightSource - > getOrCreateStateSet ( ) - > setMode ( GL_LIGHTING , osg : : StateAttribute : : ON ) ;
osg : : LightModel * lightModel = new osg : : LightModel ;
lightModel - > setAmbientIntensity ( osg : : Vec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
sunLightSource - > getOrCreateStateSet ( ) - > setAttribute ( lightModel ) ;
return sunLightSource ;
} // end SolarSystem::createSunLight
void SolarSystem : : printParameters ( )
{
std : : cout < < " radiusSpace( " < < _radiusSpace < < " ) " < < std : : endl ;
std : : cout < < " radiusSun( " < < _radiusSun < < " ) " < < std : : endl ;
2004-11-22 21:58:57 +08:00
std : : cout < < " radiusMercury( " < < _radiusMercury < < " ) " < < std : : endl ;
std : : cout < < " radiusVenus( " < < _radiusVenus < < " ) " < < std : : endl ;
2004-11-18 23:01:41 +08:00
std : : cout < < " radiusEarth( " < < _radiusEarth < < " ) " < < std : : endl ;
std : : cout < < " radiusMoon( " < < _radiusMoon < < " ) " < < std : : endl ;
2004-11-22 21:58:57 +08:00
std : : cout < < " radiusMars( " < < _radiusMars < < " ) " < < std : : endl ;
std : : cout < < " radiusJupiter( " < < _radiusJupiter < < " ) " < < std : : endl ;
2004-11-18 23:01:41 +08:00
2004-11-22 21:58:57 +08:00
std : : cout < < " RorbitMercury( " < < _RorbitMercury < < " ) " < < std : : endl ;
std : : cout < < " RorbitVenus( " < < _RorbitVenus < < " ) " < < std : : endl ;
2004-11-18 23:01:41 +08:00
std : : cout < < " RorbitEarth( " < < _RorbitEarth < < " ) " < < std : : endl ;
std : : cout < < " RorbitMoon( " < < _RorbitMoon < < " ) " < < std : : endl ;
2004-11-22 21:58:57 +08:00
std : : cout < < " RorbitMars( " < < _RorbitMars < < " ) " < < std : : endl ;
std : : cout < < " RorbitJupiter( " < < _RorbitJupiter < < " ) " < < std : : endl ;
2004-11-18 23:01:41 +08:00
2004-11-22 21:58:57 +08:00
std : : cout < < " rotateSpeedMercury( " < < _rotateSpeedMercury < < " ) " < < std : : endl ;
std : : cout < < " rotateSpeedVenus( " < < _rotateSpeedVenus < < " ) " < < std : : endl ;
2004-11-18 23:01:41 +08:00
std : : cout < < " rotateSpeedEarthAndMoon( " < < _rotateSpeedEarthAndMoon < < " ) " < < std : : endl ;
std : : cout < < " rotateSpeedEarth( " < < _rotateSpeedEarth < < " ) " < < std : : endl ;
std : : cout < < " rotateSpeedMoon( " < < _rotateSpeedMoon < < " ) " < < std : : endl ;
2004-11-22 21:58:57 +08:00
std : : cout < < " rotateSpeedMars( " < < _rotateSpeedMars < < " ) " < < std : : endl ;
std : : cout < < " rotateSpeedJupiter( " < < _rotateSpeedJupiter < < " ) " < < std : : endl ;
2004-11-18 23:01:41 +08:00
std : : cout < < " tiltEarth( " < < _tiltEarth < < " ) " < < std : : endl ;
2004-11-22 21:58:57 +08:00
std : : cout < < " mapSpace( " < < _mapSpace < < " ) " < < std : : endl ;
std : : cout < < " mapSun( " < < _mapSun < < " ) " < < std : : endl ;
std : : cout < < " mapMercury( " < < _mapMercury < < " ) " < < std : : endl ;
std : : cout < < " mapVenus( " < < _mapVenus < < " ) " < < std : : endl ;
std : : cout < < " mapEarth( " < < _mapEarth < < " ) " < < std : : endl ;
std : : cout < < " mapEarthNight( " < < _mapEarthNight < < " ) " < < std : : endl ;
std : : cout < < " mapMoon( " < < _mapMoon < < " ) " < < std : : endl ;
std : : cout < < " mapMars( " < < _mapMars < < " ) " < < std : : endl ;
std : : cout < < " mapJupiter( " < < _mapJupiter < < " ) " < < std : : endl ;
std : : cout < < " rotateSpeedFactor( " < < _rotateSpeedFactor < < " ) " < < std : : endl ;
std : : cout < < " RorbitFactor( " < < _RorbitFactor < < " ) " < < std : : endl ;
std : : cout < < " radiusFactor( " < < _radiusFactor < < " ) " < < std : : endl ;
2004-11-18 23:01:41 +08:00
}
2004-10-23 00:39:24 +08:00
int main ( int argc , char * * argv )
{
2004-10-23 02:47:39 +08:00
// use an ArgumentParser object to manage the program arguments.
2004-10-23 00:39:24 +08:00
osg : : ArgumentParser arguments ( & argc , argv ) ;
// set up the usage document, in case we need to print out how to use this program.
arguments . getApplicationUsage ( ) - > setDescription ( arguments . getApplicationName ( ) + " is the example which demonstrates use of osg::AnimationPath and UpdateCallbacks for adding animation to your scenes. " ) ;
arguments . getApplicationUsage ( ) - > setCommandLineUsage ( arguments . getApplicationName ( ) + " [options] filename ... " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -h or --help " , " Display this information " ) ;
2004-11-18 23:01:41 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -o <filename> " , " Write created model to file " ) ;
2004-10-23 00:39:24 +08:00
// initialize the viewer.
2007-01-10 21:52:22 +08:00
osgViewer : : Viewer viewer ;
2004-10-23 00:39:24 +08:00
2007-01-10 21:52:22 +08:00
osg : : ref_ptr < osgGA : : KeySwitchMatrixManipulator > keyswitchManipulator = new osgGA : : KeySwitchMatrixManipulator ;
viewer . setCameraManipulator ( keyswitchManipulator . get ( ) ) ;
2004-10-23 00:39:24 +08:00
2004-10-24 22:23:42 +08:00
SolarSystem solarSystem ;
2004-10-23 00:39:24 +08:00
2004-11-16 03:44:35 +08:00
while ( arguments . read ( " --radiusSpace " , solarSystem . _radiusSpace ) ) { }
2004-10-24 22:23:42 +08:00
while ( arguments . read ( " --radiusSun " , solarSystem . _radiusSun ) ) { }
2004-11-22 21:58:57 +08:00
while ( arguments . read ( " --radiusMercury " , solarSystem . _radiusMercury ) ) { }
while ( arguments . read ( " --radiusVenus " , solarSystem . _radiusVenus ) ) { }
2004-10-24 22:23:42 +08:00
while ( arguments . read ( " --radiusEarth " , solarSystem . _radiusEarth ) ) { }
2004-11-16 03:44:35 +08:00
while ( arguments . read ( " --radiusMoon " , solarSystem . _radiusMoon ) ) { }
2004-11-22 21:58:57 +08:00
while ( arguments . read ( " --radiusMars " , solarSystem . _radiusMars ) ) { }
while ( arguments . read ( " --radiusJupiter " , solarSystem . _radiusJupiter ) ) { }
2004-11-16 03:44:35 +08:00
2004-10-24 22:23:42 +08:00
while ( arguments . read ( " --RorbitEarth " , solarSystem . _RorbitEarth ) ) { }
2004-11-16 03:44:35 +08:00
while ( arguments . read ( " --RorbitMoon " , solarSystem . _RorbitMoon ) ) { }
2004-10-24 22:23:42 +08:00
while ( arguments . read ( " --rotateSpeedEarthAndMoon " , solarSystem . _rotateSpeedEarthAndMoon ) ) { }
while ( arguments . read ( " --rotateSpeedEarth " , solarSystem . _rotateSpeedEarth ) ) { }
while ( arguments . read ( " --rotateSpeedMoon " , solarSystem . _rotateSpeedMoon ) ) { }
2004-11-16 03:44:35 +08:00
while ( arguments . read ( " --tiltEarth " , solarSystem . _tiltEarth ) ) { }
while ( arguments . read ( " --mapSpace " , solarSystem . _mapSpace ) ) { }
while ( arguments . read ( " --mapEarth " , solarSystem . _mapEarth ) ) { }
while ( arguments . read ( " --mapEarthNight " , solarSystem . _mapEarthNight ) ) { }
while ( arguments . read ( " --mapMoon " , solarSystem . _mapMoon ) ) { }
2004-11-22 21:58:57 +08:00
while ( arguments . read ( " --rotateSpeedFactor " , solarSystem . _rotateSpeedFactor ) ) { }
while ( arguments . read ( " --RorbitFactor " , solarSystem . _RorbitFactor ) ) { }
while ( arguments . read ( " --radiusFactor " , solarSystem . _radiusFactor ) ) { }
solarSystem . rotateSpeedCorrection ( ) ;
solarSystem . RorbitCorrection ( ) ;
solarSystem . radiusCorrection ( ) ;
2004-11-16 03:44:35 +08:00
2004-11-18 23:01:41 +08:00
std : : string writeFileName ;
while ( arguments . read ( " -o " , writeFileName ) ) { }
2004-10-28 17:38:03 +08:00
2004-10-29 03:09:32 +08:00
osgGA : : NodeTrackerManipulator : : TrackerMode trackerMode = osgGA : : NodeTrackerManipulator : : NODE_CENTER_AND_ROTATION ;
std : : string mode ;
while ( arguments . read ( " --tracker-mode " , mode ) )
{
if ( mode = = " NODE_CENTER_AND_ROTATION " ) trackerMode = osgGA : : NodeTrackerManipulator : : NODE_CENTER_AND_ROTATION ;
else if ( mode = = " NODE_CENTER_AND_AZIM " ) trackerMode = osgGA : : NodeTrackerManipulator : : NODE_CENTER_AND_AZIM ;
else if ( mode = = " NODE_CENTER " ) trackerMode = osgGA : : NodeTrackerManipulator : : NODE_CENTER ;
else
{
std : : cout < < " Unrecognized --tracker-mode option " < < mode < < " , valid options are: " < < std : : endl ;
std : : cout < < " NODE_CENTER_AND_ROTATION " < < std : : endl ;
std : : cout < < " NODE_CENTER_AND_AZIM " < < std : : endl ;
std : : cout < < " NODE_CENTER " < < std : : endl ;
return 1 ;
}
}
osgGA : : NodeTrackerManipulator : : RotationMode rotationMode = osgGA : : NodeTrackerManipulator : : TRACKBALL ;
while ( arguments . read ( " --rotation-mode " , mode ) )
{
if ( mode = = " TRACKBALL " ) rotationMode = osgGA : : NodeTrackerManipulator : : TRACKBALL ;
else if ( mode = = " ELEVATION_AZIM " ) rotationMode = osgGA : : NodeTrackerManipulator : : ELEVATION_AZIM ;
else
{
std : : cout < < " Unrecognized --rotation-mode option " < < mode < < " , valid options are: " < < std : : endl ;
std : : cout < < " TRACKBALL " < < std : : endl ;
std : : cout < < " ELEVATION_AZIM " < < std : : endl ;
return 1 ;
}
}
2004-10-23 00:39:24 +08:00
2004-11-22 21:58:57 +08:00
// solarSystem.printParameters();
2004-10-23 00:39:24 +08:00
// if user request help write it out to cout.
if ( arguments . read ( " -h " ) | | arguments . read ( " --help " ) )
{
2004-10-24 22:23:42 +08:00
std : : cout < < " setup the following arguments: " < < std : : endl ;
2004-11-22 21:58:57 +08:00
std : : cout < < " \t --radiusSpace: double " < < std : : endl ;
std : : cout < < " \t --radiusSun: double " < < std : : endl ;
std : : cout < < " \t --radiusMercury: double " < < std : : endl ;
std : : cout < < " \t --radiusVenus: double " < < std : : endl ;
std : : cout < < " \t --radiusEarth: double " < < std : : endl ;
std : : cout < < " \t --radiusMoon: double " < < std : : endl ;
std : : cout < < " \t --radiusMars: double " < < std : : endl ;
std : : cout < < " \t --radiusJupiter: double " < < std : : endl ;
std : : cout < < " \t --RorbitMercury: double " < < std : : endl ;
std : : cout < < " \t --RorbitVenus: double " < < std : : endl ;
std : : cout < < " \t --RorbitEarth: double " < < std : : endl ;
std : : cout < < " \t --RorbitMoon: double " < < std : : endl ;
std : : cout < < " \t --RorbitMars: double " < < std : : endl ;
std : : cout < < " \t --RorbitJupiter: double " < < std : : endl ;
2004-11-16 03:44:35 +08:00
2004-11-22 21:58:57 +08:00
std : : cout < < " \t --rotateSpeedMercury: double " < < std : : endl ;
std : : cout < < " \t --rotateSpeedVenus: double " < < std : : endl ;
std : : cout < < " \t --rotateSpeedEarthAndMoon: double " < < std : : endl ;
std : : cout < < " \t --rotateSpeedEarth: double " < < std : : endl ;
std : : cout < < " \t --rotateSpeedMoon: double " < < std : : endl ;
std : : cout < < " \t --rotateSpeedMars: double " < < std : : endl ;
std : : cout < < " \t --rotateSpeedJupiter: double " < < std : : endl ;
std : : cout < < " \t --tiltEarth: double " < < std : : endl ;
2004-11-16 03:44:35 +08:00
2004-11-22 21:58:57 +08:00
std : : cout < < " \t --mapSpace: string " < < std : : endl ;
std : : cout < < " \t --mapSun: string " < < std : : endl ;
std : : cout < < " \t --mapMercury: string " < < std : : endl ;
std : : cout < < " \t --mapVenus: string " < < std : : endl ;
std : : cout < < " \t --mapEarth: string " < < std : : endl ;
std : : cout < < " \t --mapEarthNight: string " < < std : : endl ;
std : : cout < < " \t --mapMoon: string " < < std : : endl ;
std : : cout < < " \t --mapMars: string " < < std : : endl ;
std : : cout < < " \t --mapJupiter: string " < < std : : endl ;
2004-10-28 17:38:03 +08:00
2004-11-22 21:58:57 +08:00
std : : cout < < " \t --rotateSpeedFactor: string " < < std : : endl ;
std : : cout < < " \t --RorbitFactor: string " < < std : : endl ;
std : : cout < < " \t --radiusFactor: string " < < std : : endl ;
2004-11-16 03:44:35 +08:00
2004-10-23 00:39:24 +08:00
return 1 ;
}
// any option left unread are converted into errors to write out later.
arguments . reportRemainingOptionsAsUnrecognized ( ) ;
// report any errors if they have occured when parsing the program aguments.
if ( arguments . errors ( ) )
{
arguments . writeErrorMessages ( std : : cout ) ;
return 1 ;
}
2004-10-29 03:09:32 +08:00
osg : : Group * root = new osg : : Group ;
2004-11-18 23:10:24 +08:00
osg : : ClearNode * clearNode = new osg : : ClearNode ;
clearNode - > setClearColor ( osg : : Vec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
root - > addChild ( clearNode ) ;
2004-10-29 03:09:32 +08:00
osg : : Group * sunLight = solarSystem . createSunLight ( ) ;
root - > addChild ( sunLight ) ;
// create the sun
2004-11-18 18:08:29 +08:00
osg : : Node * solarSun = solarSystem . createPlanet ( solarSystem . _radiusSun , " Sun " , osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) , solarSystem . _mapSun ) ;
osg : : StateSet * sunStateSet = solarSun - > getOrCreateStateSet ( ) ;
2004-10-29 03:09:32 +08:00
osg : : Material * material = new osg : : Material ;
material - > setEmission ( osg : : Material : : FRONT_AND_BACK , osg : : Vec4 ( 1.0f , 1.0f , 0.0f , 0.0f ) ) ;
sunStateSet - > setAttributeAndModes ( material , osg : : StateAttribute : : ON ) ;
2004-11-16 03:44:35 +08:00
2004-11-09 23:01:39 +08:00
osg : : Billboard * sunBillboard = new osg : : Billboard ( ) ;
sunBillboard - > setMode ( osg : : Billboard : : POINT_ROT_EYE ) ;
sunBillboard - > addDrawable (
2004-11-22 21:58:57 +08:00
createSquare ( osg : : Vec3 ( - 150.0f , 0.0f , - 150.0f ) , osg : : Vec3 ( 300.0f , 0.0f , 0.0f ) , osg : : Vec3 ( 0.0f , 0.0f , 300.0f ) , createBillboardImage ( osg : : Vec4 ( 1.0 , 1.0 , 0 , 1.0f ) , 64 , 1.0 ) ) ,
2004-11-09 23:01:39 +08:00
osg : : Vec3 ( 0.0f , 0.0f , 0.0f ) ) ;
sunLight - > addChild ( sunBillboard ) ;
2004-11-16 03:44:35 +08:00
2004-11-22 21:58:57 +08:00
2004-10-29 03:09:32 +08:00
// stick sun right under root, no transformations for the sun
2004-11-18 18:08:29 +08:00
sunLight - > addChild ( solarSun ) ;
2004-10-29 03:09:32 +08:00
// create light source in the sun
2004-11-16 03:44:35 +08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * earthMoonGroup and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2004-10-29 03:09:32 +08:00
// create earth and moon
2004-11-16 03:44:35 +08:00
osg : : Node * earth = solarSystem . createPlanet ( solarSystem . _radiusEarth , " Earth " , osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) , solarSystem . _mapEarth , solarSystem . _mapEarthNight ) ;
osg : : Node * moon = solarSystem . createPlanet ( solarSystem . _radiusMoon , " Moon " , osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) , solarSystem . _mapMoon ) ;
2004-10-29 03:09:32 +08:00
// create transformations for the earthMoonGroup
2004-11-16 03:44:35 +08:00
osg : : MatrixTransform * aroundSunRotationEarthMoonGroup = solarSystem . createRotation ( solarSystem . _RorbitEarth , solarSystem . _rotateSpeedEarthAndMoon ) ;
2004-11-22 21:58:57 +08:00
// osg::MatrixTransform* earthMoonGroupPosition = solarSystem.createTranslationAndTilt( solarSystem._RorbitEarth, solarSystem._tiltEarth );
osg : : MatrixTransform * earthMoonGroupPosition = solarSystem . createTranslationAndTilt ( solarSystem . _RorbitEarth , 0.0 ) ;
2004-10-29 03:09:32 +08:00
//Group with earth and moon under it
osg : : Group * earthMoonGroup = new osg : : Group ;
//transformation to rotate the earth around itself
2004-11-16 03:44:35 +08:00
osg : : MatrixTransform * earthAroundItselfRotation = solarSystem . createRotation ( 0.0 , solarSystem . _rotateSpeedEarth ) ;
2004-10-29 03:09:32 +08:00
//transformations for the moon
2004-11-16 03:44:35 +08:00
osg : : MatrixTransform * moonAroundEarthRotation = solarSystem . createRotation ( solarSystem . _RorbitMoon , solarSystem . _rotateSpeedMoon ) ;
2004-11-22 21:58:57 +08:00
osg : : MatrixTransform * moonTranslation = solarSystem . createTranslationAndTilt ( solarSystem . _RorbitMoon , 0.0 ) ;
2004-10-29 03:09:32 +08:00
2004-10-23 00:39:24 +08:00
2004-10-29 03:09:32 +08:00
moonTranslation - > addChild ( moon ) ;
2004-11-16 03:44:35 +08:00
moonAroundEarthRotation - > addChild ( moonTranslation ) ;
earthMoonGroup - > addChild ( moonAroundEarthRotation ) ;
earthAroundItselfRotation - > addChild ( earth ) ;
earthMoonGroup - > addChild ( earthAroundItselfRotation ) ;
2004-11-22 21:58:57 +08:00
2004-11-16 03:44:35 +08:00
earthMoonGroupPosition - > addChild ( earthMoonGroup ) ;
2004-10-29 03:09:32 +08:00
2004-11-16 03:44:35 +08:00
aroundSunRotationEarthMoonGroup - > addChild ( earthMoonGroupPosition ) ;
2004-10-29 03:09:32 +08:00
2004-11-16 03:44:35 +08:00
sunLight - > addChild ( aroundSunRotationEarthMoonGroup ) ;
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * end earthMoonGroup and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * Mercury and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
osg : : Node * mercury = solarSystem . createPlanet ( solarSystem . _radiusMercury , " Mercury " , osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) , solarSystem . _mapMercury , " " ) ;
osg : : MatrixTransform * aroundSunRotationMercury = solarSystem . createRotation ( solarSystem . _RorbitMercury , solarSystem . _rotateSpeedMercury ) ;
osg : : MatrixTransform * mercuryPosition = solarSystem . createTranslationAndTilt ( solarSystem . _RorbitMercury , 0.0f ) ;
mercuryPosition - > addChild ( mercury ) ;
aroundSunRotationMercury - > addChild ( mercuryPosition ) ;
sunLight - > addChild ( aroundSunRotationMercury ) ;
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * end Mercury and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2004-10-29 03:09:32 +08:00
2004-11-16 03:44:35 +08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * Venus and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
osg : : Node * venus = solarSystem . createPlanet ( solarSystem . _radiusVenus , " Venus " , osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) , solarSystem . _mapVenus , " " ) ;
osg : : MatrixTransform * aroundSunRotationVenus = solarSystem . createRotation ( solarSystem . _RorbitVenus , solarSystem . _rotateSpeedVenus ) ;
osg : : MatrixTransform * venusPosition = solarSystem . createTranslationAndTilt ( solarSystem . _RorbitVenus , 0.0f ) ;
venusPosition - > addChild ( venus ) ;
aroundSunRotationVenus - > addChild ( venusPosition ) ;
sunLight - > addChild ( aroundSunRotationVenus ) ;
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * end Venus and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2004-10-29 03:09:32 +08:00
2004-11-16 03:44:35 +08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * Mars and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
osg : : Node * mars = solarSystem . createPlanet ( solarSystem . _radiusMars , " Mars " , osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) , solarSystem . _mapMars , " " ) ;
osg : : MatrixTransform * aroundSunRotationMars = solarSystem . createRotation ( solarSystem . _RorbitMars , solarSystem . _rotateSpeedMars ) ;
osg : : MatrixTransform * marsPosition = solarSystem . createTranslationAndTilt ( solarSystem . _RorbitMars , 0.0f ) ;
marsPosition - > addChild ( mars ) ;
aroundSunRotationMars - > addChild ( marsPosition ) ;
sunLight - > addChild ( aroundSunRotationMars ) ;
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * end Mars and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2004-10-29 03:09:32 +08:00
2004-11-16 03:44:35 +08:00
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * Jupiter and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
osg : : Node * jupiter = solarSystem . createPlanet ( solarSystem . _radiusJupiter , " Jupiter " , osg : : Vec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) , solarSystem . _mapJupiter , " " ) ;
osg : : MatrixTransform * aroundSunRotationJupiter = solarSystem . createRotation ( solarSystem . _RorbitJupiter , solarSystem . _rotateSpeedJupiter ) ;
osg : : MatrixTransform * jupiterPosition = solarSystem . createTranslationAndTilt ( solarSystem . _RorbitJupiter , 0.0f ) ;
jupiterPosition - > addChild ( jupiter ) ;
aroundSunRotationJupiter - > addChild ( jupiterPosition ) ;
sunLight - > addChild ( aroundSunRotationJupiter ) ;
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * end Jupiter and Transformations
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2004-10-29 03:09:32 +08:00
2004-11-16 03:44:35 +08:00
/*
2004-10-29 03:09:32 +08:00
// add space, but don't light it, as its not illuminated by our sun
2004-11-16 03:44:35 +08:00
osg : : Node * space = solarSystem . createSpace ( " Space " , solarSystem . _mapSpace ) ;
2004-10-29 03:09:32 +08:00
space - > getOrCreateStateSet ( ) - > setMode ( GL_LIGHTING , osg : : StateAttribute : : OFF ) ;
root - > addChild ( space ) ;
2004-11-16 03:44:35 +08:00
*/
2004-11-18 23:01:41 +08:00
if ( ! writeFileName . empty ( ) )
{
osgDB : : writeNodeFile ( * root , writeFileName ) ;
std : : cout < < " Written solar system to \" " < < writeFileName < < " \" " < < std : : endl ;
2004-11-18 23:10:24 +08:00
return 0 ;
2004-11-18 23:01:41 +08:00
}
2004-10-23 00:39:24 +08:00
// run optimization over the scene graph
osgUtil : : Optimizer optimzer ;
2004-10-24 22:23:42 +08:00
optimzer . optimize ( root ) ;
2004-10-23 00:39:24 +08:00
// set the scene to render
2004-10-24 22:23:42 +08:00
viewer . setSceneData ( root ) ;
2004-10-23 00:39:24 +08:00
2004-10-29 03:09:32 +08:00
// set up tracker manipulators, once for each astral body
{
2004-11-16 03:44:35 +08:00
FindNamedNodeVisitor fnnv ( " Moon " ) ;
2004-10-29 03:09:32 +08:00
root - > accept ( fnnv ) ;
if ( ! fnnv . _foundNodes . empty ( ) )
{
// set up the node tracker.
osgGA : : NodeTrackerManipulator * tm = new osgGA : : NodeTrackerManipulator ;
tm - > setTrackerMode ( trackerMode ) ;
tm - > setRotationMode ( rotationMode ) ;
tm - > setTrackNode ( fnnv . _foundNodes . front ( ) . get ( ) ) ;
2007-01-10 21:52:22 +08:00
unsigned int num = keyswitchManipulator - > getNumMatrixManipulators ( ) ;
keyswitchManipulator - > addMatrixManipulator ( ' m ' , " moon " , tm ) ;
keyswitchManipulator - > selectMatrixManipulator ( num ) ;
2004-10-29 03:09:32 +08:00
}
}
{
2004-11-16 03:44:35 +08:00
FindNamedNodeVisitor fnnv ( " Earth " ) ;
2004-10-29 03:09:32 +08:00
root - > accept ( fnnv ) ;
if ( ! fnnv . _foundNodes . empty ( ) )
{
// set up the node tracker.
osgGA : : NodeTrackerManipulator * tm = new osgGA : : NodeTrackerManipulator ;
tm - > setTrackerMode ( trackerMode ) ;
tm - > setRotationMode ( rotationMode ) ;
tm - > setTrackNode ( fnnv . _foundNodes . front ( ) . get ( ) ) ;
2007-01-10 21:52:22 +08:00
unsigned int num = keyswitchManipulator - > getNumMatrixManipulators ( ) ;
keyswitchManipulator - > addMatrixManipulator ( ' e ' , " earth " , tm ) ;
keyswitchManipulator - > selectMatrixManipulator ( num ) ;
2004-10-29 03:09:32 +08:00
}
}
2004-11-16 03:44:35 +08:00
2004-10-29 03:09:32 +08:00
{
2004-11-16 03:44:35 +08:00
FindNamedNodeVisitor fnnv ( " Sun " ) ;
2004-10-29 03:09:32 +08:00
root - > accept ( fnnv ) ;
if ( ! fnnv . _foundNodes . empty ( ) )
{
// set up the node tracker.
osgGA : : NodeTrackerManipulator * tm = new osgGA : : NodeTrackerManipulator ;
tm - > setTrackerMode ( trackerMode ) ;
tm - > setRotationMode ( rotationMode ) ;
tm - > setTrackNode ( fnnv . _foundNodes . front ( ) . get ( ) ) ;
2007-01-10 21:52:22 +08:00
unsigned int num = keyswitchManipulator - > getNumMatrixManipulators ( ) ;
keyswitchManipulator - > addMatrixManipulator ( ' s ' , " sun " , tm ) ;
keyswitchManipulator - > selectMatrixManipulator ( num ) ;
2004-10-29 03:09:32 +08:00
}
}
2006-08-03 03:55:03 +08:00
2007-01-10 21:52:22 +08:00
return viewer . run ( ) ;
2004-10-23 00:39:24 +08:00
2004-10-29 03:09:32 +08:00
} // end main