Show
Ignore:
Timestamp:
11/05/03 11:24:51 (10 years ago)
Author:
robert
Message:

Added code to load the bluemarble.ive database instead of the texture mapped
sphere for the earth model in the logo.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osglogo/osglogo.cpp

    r1927 r2419  
    188188} 
    189189 
    190 osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio) 
    191 { 
    192     osg::Geode* geode = new osg::Geode(); 
    193  
    194     osg::StateSet* stateset = geode->getOrCreateStateSet(); 
    195  
    196     osg::Image* image = osgDB::readImageFile("Images/land_shallow_topo_2048.jpg"); 
    197     if (image) 
    198     { 
    199         osg::Texture2D* texture = new osg::Texture2D; 
    200         texture->setImage(image); 
    201         texture->setMaxAnisotropy(8); 
    202         stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); 
    203     } 
    204      
    205     osg::Material* material = new osg::Material; 
    206     stateset->setAttribute(material);     
    207      
    208      
    209     // the globe 
    210     geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(bb.center(),bb.radius()*ratio))); 
    211      
    212      
     190osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::string& filename) 
     191{ 
    213192    osg::MatrixTransform* xform = new osg::MatrixTransform; 
    214     xform->setUpdateCallback(new osgUtil::TransformCallback(bb.center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(30.0f))); 
    215     xform->addChild(geode); 
    216          
     193    xform->setUpdateCallback(new osgUtil::TransformCallback(bb.center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(10.0f))); 
     194 
     195    osg::Node* bluemarble = osgDB::readNodeFile(filename.c_str()); 
     196    if (bluemarble) 
     197    { 
     198        const osg::BoundingSphere& bs = bluemarble->getBound(); 
     199        float s = 1.2*bb.radius()/bs.radius(); 
     200        osg::MatrixTransform* positioner = new osg::MatrixTransform; 
     201        positioner->setMatrix(osg::Matrix::translate(-bs.center())*osg::Matrix::scale(s,s,s)*osg::Matrix::translate(bb.center())); 
     202        positioner->addChild(bluemarble); 
     203     
     204        xform->addChild(positioner); 
     205    } 
     206    else 
     207    { 
     208 
     209        osg::Geode* geode = new osg::Geode(); 
     210 
     211        osg::StateSet* stateset = geode->getOrCreateStateSet(); 
     212 
     213        osg::Image* image = osgDB::readImageFile("Images/land_shallow_topo_2048.jpg"); 
     214        if (image) 
     215        { 
     216            osg::Texture2D* texture = new osg::Texture2D; 
     217            texture->setImage(image); 
     218            texture->setMaxAnisotropy(8); 
     219            stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); 
     220        } 
     221 
     222        osg::Material* material = new osg::Material; 
     223        stateset->setAttribute(material);     
     224 
     225        // the globe 
     226        geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(bb.center(),bb.radius()*ratio))); 
     227 
     228        xform->addChild(geode); 
     229    } 
     230             
    217231    return xform; 
    218232} 
     
    332346} 
    333347 
    334 osg::Node* createLogo() 
     348osg::Node* createLogo(const std::string& filename) 
    335349{ 
    336350    osg::BoundingBox bb(osg::Vec3(0.0f,0.0f,0.0f),osg::Vec3(100.0f,100.0f,100.0f)); 
     
    367381    logo_group->addChild(xform); 
    368382 
    369     logo_group->addChild(createGlobe(bb,sphereRatio)); 
     383    logo_group->addChild(createGlobe(bb,sphereRatio,filename)); 
    370384 
    371385    // add the text to the group. 
     
    409423    // set up the usage document, in case we need to print out how to use this program. 
    410424    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo.."); 
    411     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
     425    
     426arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+"[options] [filename] ..."); 
    412427    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    413428    arguments.getApplicationUsage()->addCommandLineOption("ps","Render the Professional Services logo"); 
     
    441456    } 
    442457     
    443     osg::Node* node = createLogo(); 
     458    osg::Node* node = 0; 
     459     
     460    if (arguments.argc()>1) createLogo(arguments[1]); 
     461    else node = createLogo("bluemarble.ive"); 
    444462 
    445463    // add model to viewer.