Show
Ignore:
Timestamp:
12/07/08 18:02:30 (6 years ago)
Author:
robert
Message:

Intoduce new osgWidget::PdfReader? and osgWidget::VncClient? front ends to osgWidget,
with new pdf plugin and updated vnc plugin that now support these front ends.

Updated osgpdf and osgvnc examples to new these new interfaces.

Files:
1 modified

Legend:

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

    r9221 r9319  
    1212 
    1313#include <osgDB/ReadFile> 
    14  
    15  
    16 osg::Node* createInteractiveQuad(const osg::Vec3& origin, osg::Vec3& widthAxis, osg::Vec3& heightAxis,  
    17                                  osg::Image* image) 
    18 { 
    19     bool flip = image->getOrigin()==osg::Image::TOP_LEFT; 
    20  
    21     osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(origin, widthAxis, heightAxis, 
    22                                        0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f); 
    23  
    24     osg::Texture2D* texture = new osg::Texture2D(image); 
    25     texture->setResizeNonPowerOfTwoHint(false); 
    26     texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); 
    27     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); 
    28     texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); 
    29      
    30     pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, 
    31                 texture, 
    32                 osg::StateAttribute::ON); 
    33                  
    34      
    35                  
    36     osg::ref_ptr<osgViewer::InteractiveImageHandler> callback = new osgViewer::InteractiveImageHandler(image); 
    37  
    38     pictureQuad->setEventCallback(callback.get()); 
    39     pictureQuad->setCullCallback(callback.get()); 
    40  
    41     osg::Geode* geode = new osg::Geode; 
    42     geode->addDrawable(pictureQuad); 
    43      
    44     return geode; 
    45 } 
    4614 
    4715class EscapeHandler : public osgGA::GUIEventHandler 
     
    7745int main(int argc,char** argv) 
    7846{ 
     47    osg::ArgumentParser arguments(&argc, argv); 
     48    osgViewer::Viewer viewer(arguments); 
    7949 
    80     osg::ArgumentParser arguments(&argc, argv); 
    81     osgViewer::Viewer viewer; 
    82      
    83     typedef std::list< osg::ref_ptr<osg::Image> > Images; 
    84     Images images; 
     50    osgWidget::GeometryHints hints(osg::Vec3(1.0f,0.0f,0.0f), 
     51                                   osg::Vec3(1.0f,0.0f,0.0f), 
     52                                   osg::Vec3(0.0f,0.0f,1.0f), 
     53                                   osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO); 
    8554 
    86     std::string hostname; 
    87     while (arguments.read("--host",hostname)) 
     55    osg::ref_ptr<osg::Group> group = new osg::Group; 
     56 
     57    for(int i=1; i<arguments.argc(); ++i) 
    8858    { 
    89         osg::ref_ptr<osg::Image> image = osgDB::readImageFile(hostname+std::string(".vnc")); 
    90         if (image.valid()) images.push_back(image.get()); 
    91     } 
    92      
    93     if (images.empty()) 
    94     { 
    95         return 1; 
     59        if (!arguments.isOption(i)) 
     60        { 
     61            osg::ref_ptr<osgWidget::VncClient> vncClient = new osgWidget::VncClient; 
     62            if (vncClient->connect(arguments[i], hints)) 
     63            {             
     64                group->addChild(vncClient.get()); 
     65                 
     66                hints.position.x() += 1.1f; 
     67            } 
     68        } 
    9669    } 
    9770 
    98     bool xyPlane = false; 
    99  
    100     osg::Group* group = new osg::Group; 
    101  
    102     osg::Vec3 origin = osg::Vec3(0.0f,0.0f,0.0f); 
    103     for(Images::iterator itr = images.begin(); 
    104         itr != images.end(); 
    105         ++itr) 
    106     { 
    107         osg::Image* image = itr->get(); 
    108         float width = 1.0; 
    109         float height = float(image->t())/float(image->s()); 
    110         osg::Vec3 widthAxis = osg::Vec3(width,0.0f,0.0f); 
    111         osg::Vec3 heightAxis = xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height); 
    112         group->addChild(createInteractiveQuad(origin, widthAxis, heightAxis, image)); 
    113          
    114         origin += widthAxis*1.1f; 
    115     } 
    116      
    117     viewer.setSceneData(group); 
     71    viewer.setSceneData(group.get()); 
    11872 
    11973    viewer.addEventHandler(new osgViewer::StatsHandler); 
    120      
     74 
    12175    // add a custom escape handler, but disable the standard viewer one to enable the vnc images to handle 
    12276    // the escape without it getting caught by the viewer.