| 81 | | |
| 82 | | osg::MatrixTransform* createEarthTranslationAndTilt( double RorbitEarth, double tiltEarth ) |
| 83 | | { |
| 84 | | osg::MatrixTransform* earthPositioned = new osg::MatrixTransform; |
| 85 | | //earthPositioned->setDataVariance(osg::Object::STATIC); |
| 86 | | earthPositioned->setMatrix(osg::Matrix::translate(osg::Vec3( 0.0, RorbitEarth, 0.0 ) )* |
| 87 | | osg::Matrix::scale(1.0, 1.0, 1.0)* |
| 88 | | osg::Matrix::rotate(osg::inDegrees( tiltEarth ),0.0f,0.0f,1.0f)); |
| 89 | | |
| 90 | | return earthPositioned; |
| 91 | | }// end createEarthTranslationAndTilt |
| 92 | | |
| 93 | | |
| 94 | | osg::MatrixTransform* createRotation( double orbit, double speed ) |
| 95 | | { |
| 96 | | osg::Vec3 center( 0.0, 0.0, 0.0 ); |
| 97 | | float animationLength = 10.0f; |
| 98 | | osg::AnimationPath* animationPath = createAnimationPath( center, orbit, animationLength ); |
| 99 | | |
| 100 | | osg::MatrixTransform* rotation = new osg::MatrixTransform; |
| 101 | | rotation->setUpdateCallback( new osg::AnimationPathCallback( animationPath, 0.0f, speed ) ); |
| 102 | | |
| 103 | | return rotation; |
| 104 | | }// end createEarthRotation |
| 105 | | |
| 106 | | |
| 107 | | osg::MatrixTransform* createMoonTranslation( double RorbitMoon ) |
| 108 | | { |
| 109 | | osg::MatrixTransform* moonPositioned = new osg::MatrixTransform; |
| 110 | | //earthPositioned->setDataVariance(osg::Object::STATIC); |
| 111 | | //earthPositioned->setMatrix(osg::Matrix::translate(osg::Vec3( RorbitEarth, 0.0, 0.0 ) )* |
| 112 | | moonPositioned->setMatrix(osg::Matrix::translate(osg::Vec3( 0.0, RorbitMoon, 0.0 ) )* |
| 113 | | //earthPositioned->setMatrix(osg::Matrix::translate(osg::Vec3( 0.0, 0.0, RorbitEarth ) )* |
| 114 | | osg::Matrix::scale(1.0, 1.0, 1.0)* |
| 115 | | osg::Matrix::rotate(osg::inDegrees(0.0f),0.0f,0.0f,1.0f)); |
| 116 | | |
| 117 | | return moonPositioned; |
| 118 | | }// end createMoonTranslation |
| 119 | | |
| 120 | | |
| 121 | | osg::Geode* createSpace( double radius, const std::string& name, const std::string& textureName ) |
| 122 | | { |
| 123 | | osg::Sphere *spaceSphere = new osg::Sphere( osg::Vec3( 0.0, 0.0, 0.0 ), radius ); |
| 124 | | |
| 125 | | osg::ShapeDrawable *sSpaceSphere = new osg::ShapeDrawable( spaceSphere ); |
| 126 | | |
| 127 | | if( !textureName.empty() ) |
| 128 | | { |
| 129 | | osg::Image* image = osgDB::readImageFile( textureName ); |
| 130 | | if ( image ) |
| 131 | | { |
| 132 | | sSpaceSphere->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D( image ), osg::StateAttribute::ON ); |
| 133 | | |
| 134 | | // reset the object color to white to allow the texture to set the colour. |
| 135 | | sSpaceSphere->setColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); |
| 136 | | } |
| 137 | | } |
| 138 | | |
| 139 | | osg::Geode* geodeSpace = new osg::Geode(); |
| 140 | | geodeSpace->setName( name ); |
| 141 | | |
| 142 | | geodeSpace->addDrawable( sSpaceSphere ); |
| 143 | | |
| 144 | | return( geodeSpace ); |
| 145 | | |
| 146 | | }// end createSpace |
| 147 | | |
| 148 | | |
| 149 | | osg::Geode* createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName ) |
| 150 | | { |
| 151 | | // create a cube shape |
| 152 | | osg::Sphere *planetSphere = new osg::Sphere( osg::Vec3( 0.0, 0.0, 0.0 ), radius ); |
| 153 | | |
| 154 | | // create a container that makes the sphere drawable |
| 155 | | osg::ShapeDrawable *sPlanetSphere = new osg::ShapeDrawable( planetSphere ); |
| 156 | | |
| 157 | | // set the object color |
| 158 | | sPlanetSphere->setColor( color ); |
| 159 | | |
| 160 | | if( !textureName.empty() ) |
| 161 | | { |
| 162 | | osg::Image* image = osgDB::readImageFile( textureName ); |
| 163 | | if ( image ) |
| 164 | | { |
| 165 | | sPlanetSphere->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D( image ), osg::StateAttribute::ON ); |
| 166 | | |
| 167 | | // reset the object color to white to allow the texture to set the colour. |
| 168 | | sPlanetSphere->setColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); |
| 169 | | } |
| 170 | | } |
| 171 | | |
| 172 | | |
| 173 | | // create a geode object to as a container for our drawable sphere object |
| 174 | | osg::Geode* geodePlanet = new osg::Geode(); |
| 175 | | geodePlanet->setName( name ); |
| 176 | | |
| 177 | | // add our drawable sphere to the geode container |
| 178 | | geodePlanet->addDrawable( sPlanetSphere ); |
| 179 | | |
| 180 | | return( geodePlanet ); |
| 181 | | |
| 182 | | }// end createPlanet |
| 214 | | osg::Group* built() |
| 215 | | { |
| 216 | | osg::Group* thisSystem = new osg::Group; |
| 217 | | |
| 218 | | osg::StateSet* sunStateSet = new osg::StateSet; |
| 219 | | osg::Material* material = new osg::Material; |
| 220 | | material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0f, 1.0f, 0.0f, 0.0f ) ); |
| 221 | | sunStateSet->setAttributeAndModes( material, osg::StateAttribute::ON ); |
| 222 | | |
| 223 | | |
| 224 | | |
| 225 | | // create the sun |
| 226 | | osg::Node* sun = createPlanet( _radiusSun, "Sun", osg::Vec4( 0, 0, 0, 1.0f), "" ); |
| 227 | | sun->setStateSet( sunStateSet ); |
| 228 | | |
| 229 | | // stick sun right under root, no transformations for the sun |
| 230 | | thisSystem->addChild( sun ); |
| 231 | | |
| 232 | | |
| 233 | | // create light source in the sun |
| 234 | | osg::Group* sunLight = createSunLight(); |
| 235 | | |
| 236 | | //creating right side of the graph with earth and moon and the rotations above it |
| 237 | | |
| 238 | | // create earth and moon |
| 239 | | osg::Node* earth = createPlanet( _radiusEarth, "Earth", osg::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), "Images/land_shallow_topo_2048.jpg" ); |
| 240 | | osg::Node* moon = createPlanet( _radiusMoon, "Moon", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), "Images/moon256128.TGA" ); |
| 241 | | |
| 242 | | // create transformations for the earthMoonGroup |
| 243 | | osg::MatrixTransform* aroundSunRotation = createRotation( _RorbitEarth, _rotateSpeedEarthAndMoon ); |
| 244 | | osg::MatrixTransform* earthPosition = createEarthTranslationAndTilt( _RorbitEarth, _tiltEarth ); |
| 245 | | |
| 246 | | //Group with earth and moon under it |
| 247 | | osg::Group* earthMoonGroup = new osg::Group; |
| 248 | | |
| 249 | | //transformation to rotate the earth around itself |
| 250 | | osg::MatrixTransform* earthRotationAroundItself = createRotation ( 0.0, _rotateSpeedEarth ); |
| 251 | | |
| 252 | | //transformations for the moon |
| 253 | | osg::MatrixTransform* moonAroundEarthXform = createRotation( _RorbitMoon, _rotateSpeedMoon ); |
| 254 | | osg::MatrixTransform* moonTranslation = createMoonTranslation( _RorbitMoon ); |
| 255 | | |
| 256 | | |
| 257 | | moonTranslation->addChild( moon ); |
| 258 | | moonAroundEarthXform->addChild( moonTranslation ); |
| 259 | | earthMoonGroup->addChild( moonAroundEarthXform ); |
| 260 | | |
| 261 | | earthRotationAroundItself->addChild( earth ); |
| 262 | | earthMoonGroup->addChild( earthRotationAroundItself ); |
| 263 | | |
| 264 | | |
| 265 | | earthPosition->addChild( earthMoonGroup ); |
| 266 | | aroundSunRotation->addChild( earthPosition ); |
| 267 | | |
| 268 | | sunLight->addChild( aroundSunRotation ); |
| 269 | | |
| 270 | | thisSystem->addChild( sunLight ); |
| 271 | | |
| 272 | | #if 0 |
| 273 | | // add space, but don't light it, as its not illuminated by our sun |
| 274 | | osg::Node* space = createSpace( _radiusSpace, "Space", "Images/spacemap1.jpg" ); |
| 275 | | space->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); |
| 276 | | thisSystem->addChild( space ); |
| 277 | | #endif |
| 278 | | |
| 279 | | return( thisSystem ); |
| 280 | | } |
| | 94 | osg::MatrixTransform* createEarthTranslationAndTilt(); |
| | 95 | osg::MatrixTransform* createRotation( double orbit, double speed ); |
| | 96 | osg::MatrixTransform* createMoonTranslation(); |
| | 97 | osg::Geode* createSpace( const std::string& name, const std::string& textureName ); |
| | 98 | osg::Geode* createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName ); |
| | 99 | osg::Group* createSunLight(); |
| | 100 | osg::Group* built(); |
| 365 | | osg::Group* root = solarSystem.built(); |
| 366 | | |
| 367 | | /* |
| 368 | | // tilt the scene so the default eye position is looking down on the model. |
| 369 | | osg::MatrixTransform* rootnode = new osg::MatrixTransform; |
| 370 | | rootnode->setMatrix(osg::Matrix::rotate(osg::inDegrees(30.0f),1.0f,0.0f,0.0f)); |
| 371 | | rootnode->addChild(model); |
| 372 | | */ |
| 373 | | |
| | 239 | osg::Group* root = new osg::Group; |
| | 240 | |
| | 241 | osg::Group* sunLight = solarSystem.createSunLight(); |
| | 242 | root->addChild(sunLight); |
| | 243 | |
| | 244 | // create the sun |
| | 245 | osg::Node* sun = solarSystem.createPlanet( solarSystem._radiusSun, "Sun", osg::Vec4( 1.0, 1.0, 0, 1.0f), "" ); |
| | 246 | osg::StateSet* sunStateSet = sun->getOrCreateStateSet(); |
| | 247 | osg::Material* material = new osg::Material; |
| | 248 | material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0f, 1.0f, 0.0f, 0.0f ) ); |
| | 249 | sunStateSet->setAttributeAndModes( material, osg::StateAttribute::ON ); |
| | 250 | |
| | 251 | // stick sun right under root, no transformations for the sun |
| | 252 | sunLight->addChild( sun ); |
| | 253 | |
| | 254 | // create light source in the sun |
| | 255 | |
| | 256 | // create earth and moon |
| | 257 | osg::Node* earth = solarSystem.createPlanet( solarSystem._radiusEarth, "Earth", osg::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), "Images/land_shallow_topo_2048.jpg" ); |
| | 258 | osg::Node* moon = solarSystem.createPlanet( solarSystem._radiusMoon, "Moon", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), "Images/moon256128.TGA" ); |
| | 259 | |
| | 260 | // create transformations for the earthMoonGroup |
| | 261 | osg::MatrixTransform* aroundSunRotation = solarSystem.createRotation( solarSystem._RorbitEarth, solarSystem._rotateSpeedEarthAndMoon ); |
| | 262 | osg::MatrixTransform* earthPosition = solarSystem.createEarthTranslationAndTilt(); |
| | 263 | |
| | 264 | |
| | 265 | //Group with earth and moon under it |
| | 266 | osg::Group* earthMoonGroup = new osg::Group; |
| | 267 | |
| | 268 | |
| | 269 | //transformation to rotate the earth around itself |
| | 270 | osg::MatrixTransform* earthRotationAroundItself = solarSystem.createRotation ( 0.0, solarSystem._rotateSpeedEarth ); |
| | 271 | |
| | 272 | //transformations for the moon |
| | 273 | osg::MatrixTransform* moonAroundEarthXform = solarSystem.createRotation( solarSystem._RorbitMoon, solarSystem._rotateSpeedMoon ); |
| | 274 | osg::MatrixTransform* moonTranslation = solarSystem.createMoonTranslation(); |
| | 275 | |
| | 276 | |
| | 277 | moonTranslation->addChild( moon ); |
| | 278 | moonAroundEarthXform->addChild( moonTranslation ); |
| | 279 | earthMoonGroup->addChild( moonAroundEarthXform ); |
| | 280 | |
| | 281 | earthRotationAroundItself->addChild( earth ); |
| | 282 | |
| | 283 | earthMoonGroup->addChild( earthRotationAroundItself ); |
| | 284 | |
| | 285 | earthPosition->addChild( earthMoonGroup ); |
| | 286 | |
| | 287 | aroundSunRotation->addChild( earthPosition ); |
| | 288 | |
| | 289 | sunLight->addChild( aroundSunRotation ); |
| | 290 | |
| | 291 | #if 0 |
| | 292 | // add space, but don't light it, as its not illuminated by our sun |
| | 293 | osg::Node* space = solarSystem.createSpace( "Space", "Images/spacemap.jpg" ); |
| | 294 | space->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); |
| | 295 | root->addChild( space ); |
| | 296 | #endif |
| | 297 | |
| | 306 | |
| | 307 | // set up tracker manipulators, once for each astral body |
| | 308 | { |
| | 309 | FindNamedNodeVisitor fnnv("Sun"); |
| | 310 | root->accept(fnnv); |
| | 311 | |
| | 312 | if (!fnnv._foundNodes.empty()) |
| | 313 | { |
| | 314 | // set up the node tracker. |
| | 315 | osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; |
| | 316 | tm->setTrackerMode( trackerMode ); |
| | 317 | tm->setRotationMode( rotationMode ); |
| | 318 | tm->setTrackNode( fnnv._foundNodes.front().get() ); |
| | 319 | |
| | 320 | unsigned int num = viewer.addCameraManipulator( tm ); |
| | 321 | viewer.selectCameraManipulator( num ); |
| | 322 | } |
| | 323 | } |
| | 324 | |
| | 325 | { |
| | 326 | FindNamedNodeVisitor fnnv("Moon"); |
| | 327 | root->accept(fnnv); |
| | 328 | |
| | 329 | if (!fnnv._foundNodes.empty()) |
| | 330 | { |
| | 331 | // set up the node tracker. |
| | 332 | osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; |
| | 333 | tm->setTrackerMode( trackerMode ); |
| | 334 | tm->setRotationMode( rotationMode ); |
| | 335 | tm->setTrackNode( fnnv._foundNodes.front().get() ); |
| | 336 | |
| | 337 | unsigned int num = viewer.addCameraManipulator( tm ); |
| | 338 | viewer.selectCameraManipulator( num ); |
| | 339 | } |
| | 340 | } |
| | 341 | |
| | 342 | { |
| | 343 | FindNamedNodeVisitor fnnv("Earth"); |
| | 344 | root->accept(fnnv); |
| | 345 | |
| | 346 | if (!fnnv._foundNodes.empty()) |
| | 347 | { |
| | 348 | // set up the node tracker. |
| | 349 | osgGA::NodeTrackerManipulator* tm = new osgGA::NodeTrackerManipulator; |
| | 350 | tm->setTrackerMode( trackerMode ); |
| | 351 | tm->setRotationMode( rotationMode ); |
| | 352 | tm->setTrackNode( fnnv._foundNodes.front().get() ); |
| | 353 | |
| | 354 | unsigned int num = viewer.addCameraManipulator( tm ); |
| | 355 | viewer.selectCameraManipulator( num ); |
| | 356 | } |
| | 357 | } |
| | 358 | |
| 409 | | } |
| | 382 | }// end main |
| | 383 | |
| | 384 | |
| | 385 | osg::MatrixTransform* SolarSystem::createEarthTranslationAndTilt() |
| | 386 | { |
| | 387 | osg::MatrixTransform* earthPositioned = new osg::MatrixTransform; |
| | 388 | earthPositioned->setMatrix(osg::Matrix::translate(osg::Vec3( 0.0, _RorbitEarth, 0.0 ) )* |
| | 389 | osg::Matrix::scale(1.0, 1.0, 1.0)* |
| | 390 | osg::Matrix::rotate(osg::inDegrees( _tiltEarth ),0.0f,0.0f,1.0f)); |
| | 391 | |
| | 392 | return earthPositioned; |
| | 393 | }// end SolarSystem::createEarthTranslationAndTilt |
| | 394 | |
| | 395 | |
| | 396 | osg::MatrixTransform* SolarSystem::createRotation( double orbit, double speed ) |
| | 397 | { |
| | 398 | osg::Vec3 center( 0.0, 0.0, 0.0 ); |
| | 399 | float animationLength = 10.0f; |
| | 400 | osg::AnimationPath* animationPath = createAnimationPath( center, orbit, animationLength ); |
| | 401 | |
| | 402 | osg::MatrixTransform* rotation = new osg::MatrixTransform; |
| | 403 | rotation->setUpdateCallback( new osg::AnimationPathCallback( animationPath, 0.0f, speed ) ); |
| | 404 | |
| | 405 | return rotation; |
| | 406 | }// end SolarSystem::createEarthRotation |
| | 407 | |
| | 408 | |
| | 409 | osg::MatrixTransform* SolarSystem::createMoonTranslation() |
| | 410 | { |
| | 411 | osg::MatrixTransform* moonPositioned = new osg::MatrixTransform; |
| | 412 | moonPositioned->setMatrix(osg::Matrix::translate(osg::Vec3( 0.0, _RorbitMoon, 0.0 ) )* |
| | 413 | osg::Matrix::scale(1.0, 1.0, 1.0)* |
| | 414 | osg::Matrix::rotate(osg::inDegrees(0.0f),0.0f,0.0f,1.0f)); |
| | 415 | |
| | 416 | return moonPositioned; |
| | 417 | }// end SolarSystem::createMoonTranslation |
| | 418 | |
| | 419 | |
| | 420 | osg::Geode* SolarSystem::createSpace( const std::string& name, const std::string& textureName ) |
| | 421 | { |
| | 422 | osg::Sphere *spaceSphere = new osg::Sphere( osg::Vec3( 0.0, 0.0, 0.0 ), _radiusSpace ); |
| | 423 | |
| | 424 | osg::ShapeDrawable *sSpaceSphere = new osg::ShapeDrawable( spaceSphere ); |
| | 425 | |
| | 426 | if( !textureName.empty() ) |
| | 427 | { |
| | 428 | osg::Image* image = osgDB::readImageFile( textureName ); |
| | 429 | if ( image ) |
| | 430 | { |
| | 431 | sSpaceSphere->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D( image ), osg::StateAttribute::ON ); |
| | 432 | |
| | 433 | // reset the object color to white to allow the texture to set the colour. |
| | 434 | sSpaceSphere->setColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); |
| | 435 | } |
| | 436 | } |
| | 437 | |
| | 438 | osg::Geode* geodeSpace = new osg::Geode(); |
| | 439 | geodeSpace->setName( name ); |
| | 440 | |
| | 441 | geodeSpace->addDrawable( sSpaceSphere ); |
| | 442 | |
| | 443 | return( geodeSpace ); |
| | 444 | |
| | 445 | }// end SolarSystem::createSpace |
| | 446 | |
| | 447 | |
| | 448 | osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName ) |
| | 449 | { |
| | 450 | // create a cube shape |
| | 451 | osg::Sphere *planetSphere = new osg::Sphere( osg::Vec3( 0.0, 0.0, 0.0 ), radius ); |
| | 452 | |
| | 453 | // create a container that makes the sphere drawable |
| | 454 | osg::ShapeDrawable *sPlanetSphere = new osg::ShapeDrawable( planetSphere ); |
| | 455 | |
| | 456 | // set the object color |
| | 457 | sPlanetSphere->setColor( color ); |
| | 458 | |
| | 459 | if( !textureName.empty() ) |
| | 460 | { |
| | 461 | osg::Image* image = osgDB::readImageFile( textureName ); |
| | 462 | if ( image ) |
| | 463 | { |
| | 464 | sPlanetSphere->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D( image ), osg::StateAttribute::ON ); |
| | 465 | |
| | 466 | // reset the object color to white to allow the texture to set the colour. |
| | 467 | sPlanetSphere->setColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); |
| | 468 | } |
| | 469 | } |
| | 470 | |
| | 471 | |
| | 472 | // create a geode object to as a container for our drawable sphere object |
| | 473 | osg::Geode* geodePlanet = new osg::Geode(); |
| | 474 | geodePlanet->setName( name ); |
| | 475 | |
| | 476 | // add our drawable sphere to the geode container |
| | 477 | geodePlanet->addDrawable( sPlanetSphere ); |
| | 478 | |
| | 479 | return( geodePlanet ); |
| | 480 | |
| | 481 | }// end SolarSystem::createPlanet |
| | 482 | |
| | 483 | osg::Group* SolarSystem::createSunLight() |
| | 484 | { |
| | 485 | |
| | 486 | osg::LightSource* sunLightSource = new osg::LightSource; |
| | 487 | |
| | 488 | osg::Light* sunLight = sunLightSource->getLight(); |
| | 489 | sunLight->setPosition( osg::Vec4( 0.0f, 0.0f, 0.0f, 1.0f ) ); |
| | 490 | sunLight->setAmbient( osg::Vec4( 0.0f, 0.0f, 0.0f, 1.0f ) ); |
| | 491 | |
| | 492 | sunLightSource->setLight( sunLight ); |
| | 493 | sunLightSource->setLocalStateSetModes( osg::StateAttribute::ON ); |
| | 494 | sunLightSource->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON); |
| | 495 | |
| | 496 | osg::LightModel* lightModel = new osg::LightModel; |
| | 497 | lightModel->setAmbientIntensity(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); |
| | 498 | sunLightSource->getOrCreateStateSet()->setAttribute(lightModel); |
| | 499 | |
| | 500 | |
| | 501 | return sunLightSource; |
| | 502 | }// end SolarSystem::createSunLight |
| | 503 | |
| | 504 | |
| | 505 | /* |
| | 506 | osg::Group* SolarSystem::built() |
| | 507 | { |
| | 508 | osg::Group* thisSystem = new osg::Group; |
| | 509 | |
| | 510 | // create light source in the sun |
| | 511 | osg::Group* sunLight = createSunLight(); |
| | 512 | thisSystem->addChild( sunLight ); |
| | 513 | |
| | 514 | |
| | 515 | // create the sun |
| | 516 | osg::Node* sun = createPlanet( _radiusSun, "Sun", osg::Vec4( 0, 0, 0, 1.0f), "" ); |
| | 517 | osg::StateSet* sunStateSet = sun->getOrCreateStateSet(); |
| | 518 | osg::Material* material = new osg::Material; |
| | 519 | material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( 1.0f, 1.0f, 0.0f, 0.0f ) ); |
| | 520 | sunStateSet->setAttributeAndModes( material, osg::StateAttribute::ON ); |
| | 521 | |
| | 522 | if( !sun ) |
| | 523 | { |
| | 524 | std::cout << "Sonne konnte nicht erstellt werden!" << std::endl; |
| | 525 | exit(0); |
| | 526 | } |
| | 527 | sun->setStateSet( sunStateSet ); |
| | 528 | |
| | 529 | // stick sun right under root, no transformations for the sun |
| | 530 | sunLight->addChild(sun); |
| | 531 | |
| | 532 | |
| | 533 | //creating right side of the graph with earth and moon and the rotations above it |
| | 534 | |
| | 535 | // create earth and moon |
| | 536 | osg::Node* earth = createPlanet( _radiusEarth, "Earth", osg::Vec4( 0.0f, 0.0f, 1.0f, 1.0f), "Images/land_shallow_topo_2048.jpg" ); |
| | 537 | osg::Node* moon = createPlanet( _radiusMoon, "Moon", osg::Vec4( 1.0f, 1.0f, 1.0f, 1.0f), "Images/moon256128.TGA" ); |
| | 538 | |
| | 539 | // create transformations for the earthMoonGroup |
| | 540 | osg::MatrixTransform* aroundSunRotation = createRotation( _RorbitEarth, _rotateSpeedEarthAndMoon ); |
| | 541 | osg::MatrixTransform* earthPosition = createEarthTranslationAndTilt( _RorbitEarth, _tiltEarth ); |
| | 542 | |
| | 543 | //Group with earth and moon under it |
| | 544 | osg::Group* earthMoonGroup = new osg::Group; |
| | 545 | |
| | 546 | //transformation to rotate the earth around itself |
| | 547 | osg::MatrixTransform* earthRotationAroundItself = createRotation ( 0.0, _rotateSpeedEarth ); |
| | 548 | |
| | 549 | //transformations for the moon |
| | 550 | osg::MatrixTransform* moonAroundEarthXform = createRotation( _RorbitMoon, _rotateSpeedMoon ); |
| | 551 | osg::MatrixTransform* moonTranslation = createMoonTranslation( _RorbitMoon ); |
| | 552 | |
| | 553 | |
| | 554 | moonTranslation->addChild( moon ); |
| | 555 | moonAroundEarthXform->addChild( moonTranslation ); |
| | 556 | earthMoonGroup->addChild( moonAroundEarthXform ); |
| | 557 | |
| | 558 | earthRotationAroundItself->addChild( earth ); |
| | 559 | |
| | 560 | earthMoonGroup->addChild( earthRotationAroundItself ); |
| | 561 | |
| | 562 | earthPosition->addChild( earthMoonGroup ); |
| | 563 | |
| | 564 | |
| | 565 | aroundSunRotation->addChild( earthPosition ); |
| | 566 | |
| | 567 | sunLight->addChild( aroundSunRotation ); |
| | 568 | |
| | 569 | // add space, but don't light it, as its not illuminated by our sun |
| | 570 | osg::Node* space = createSpace( _radiusSpace, "Space", "Images/spacemap.jpg" ); |
| | 571 | space->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); |
| | 572 | thisSystem->addChild( space ); |
| | 573 | |
| | 574 | return( thisSystem ); |
| | 575 | }// end SolarSystem::built() |
| | 576 | */ |