Changeset 3551 for OpenSceneGraph/trunk/examples/osgplanets/osgplanets.cpp
- Timestamp:
- 10/28/04 11:38:03 (9 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgplanets/osgplanets.cpp
r3532 r3551 8 8 #include <osg/ShapeDrawable> 9 9 #include <osg/Texture2D> 10 #include <osg/Material> 11 #include <osg/Light> 12 #include <osg/LightSource> 13 #include <osg/LightModel> 10 14 11 15 … … 20 24 21 25 #include <osgProducer/Viewer> 26 27 28 static osg::Vec3 defaultPos( 0.0f, 0.0f, 0.0f ); 29 static osg::Vec3 centerScope(0.0f, 0.0f, 0.0f); 30 31 32 osg::Group* createSunLight() 33 { 34 osg::Group* lightNode = new osg::Group; 35 36 osg::Light* sunLight = new osg::Light; 37 sunLight->setPosition( osg::Vec4( 0.0f, 0.0f, 0.0f, 1.0f ) ); 38 sunLight->setAmbient( osg::Vec4( 0.0f, 0.0f, 0.0f, 1.0f ) ); 39 40 osg::LightSource* sunLightSource = new osg::LightSource; 41 sunLightSource->setLight( sunLight ); 42 43 lightNode->addChild( sunLightSource ); 44 45 osg::LightModel* lightModel = new osg::LightModel; 46 lightModel->setAmbientIntensity(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); 47 lightNode->getOrCreateStateSet()->setAttribute(lightModel); 48 49 50 return lightNode; 51 }// end createSunLight 22 52 23 53 … … 89 119 90 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 91 149 osg::Geode* createPlanet( double radius, const std::string& name, const osg::Vec4& color , const std::string& textureName ) 92 150 { … … 121 179 122 180 return( geodePlanet ); 181 123 182 }// end createPlanet 124 //--radiusSun 5.0 --radiusEarth 2.0 --RorbitEarth 10.0 --RorbitMoon 2.0 --radiusMoon 0.5 --tiltEarth 18.0 --rotateSpeedEarth 1.0 125 //--rotateSpeedMoon 1.0 --rotateSpeedEarthAndMoon 1.0 183 126 184 127 185 class SolarSystem … … 138 196 double _RorbitMoon; 139 197 double _rotateSpeedMoon; 198 double _radiusSpace; 140 199 141 200 SolarSystem() … … 150 209 _RorbitMoon = 2.0; 151 210 _rotateSpeedMoon = 1.0; 211 _radiusSpace = 300.0; 152 212 } 153 213 … … 156 216 osg::Group* thisSystem = new osg::Group; 157 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 158 224 159 225 // create the sun 160 osg::Node* sun = createPlanet( _radiusSun, "Sun", osg::Vec4( 1.0f, 1.0f, 0.5f, 1.0f), "" ); 226 osg::Node* sun = createPlanet( _radiusSun, "Sun", osg::Vec4( 0, 0, 0, 1.0f), "" ); 227 sun->setStateSet( sunStateSet ); 161 228 162 229 // stick sun right under root, no transformations for the sun … … 164 231 165 232 233 // create light source in the sun 234 osg::Group* sunLight = createSunLight(); 166 235 167 236 //creating right side of the graph with earth and moon and the rotations above it … … 197 266 aroundSunRotation->addChild( earthPosition ); 198 267 199 200 thisSystem->addChild( aroundSunRotation ); 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 201 278 202 279 return( thisSystem ); … … 214 291 std::cout << "RorbitMoon\t= " << _RorbitMoon << std::endl; 215 292 std::cout << "rotateSpeedMoon\t= " << _rotateSpeedMoon << std::endl; 293 std::cout << "radiusSpace\t= " << _radiusSpace << std::endl; 294 216 295 } 217 296 … … 249 328 while (arguments.read("--RorbitMoon",solarSystem._RorbitMoon)) { } 250 329 while (arguments.read("--rotateSpeedMoon",solarSystem._rotateSpeedMoon)) { } 330 while (arguments.read("--radiusSpace",solarSystem._radiusSpace)) { } 331 251 332 252 333 solarSystem.printParameters(); … … 265 346 std::cout << "--RorbitMoon: double" << std::endl; 266 347 std::cout << "--rotateSpeedMoon: double" << std::endl; 348 std::cout << "--radiusSpace: double" << std::endl; 349 267 350 268 351 return 1; … … 298 381 // create the windows and run the threads. 299 382 viewer.realize(); 383 384 osg::Matrix lookAt; 385 lookAt.makeLookAt( osg::Vec3(0.0f, -80.0f, 0.0f), centerScope, osg::Vec3(0.0f, 0.0f, 1.0f ) ); 386 387 viewer.setView( lookAt ); 388 389 viewer.setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f)); 300 390 301 391 while( !viewer.done() )
