Show
Ignore:
Timestamp:
07/03/09 21:16:53 (13 months ago)
Author:
robert
Message:

Added Dragger::s/getActivationModKeyMask(..) and Dragger::s/getActivationKeyEvent(...) methods to make it possible to have draggers that only respond when you press a specified modified key or standard key.

Changed the optional dragger in osgvolume to require the shift key to be pressed for the dragger to become active.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/applications/osgviewer/osgviewer.cpp

    r10244 r10454  
    11/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield  
    2  * 
    3  * This application is open source and may be redistributed and/or modified    
    4  * freely and without restriction, both in commericial and non commericial applications, 
    5  * as long as this copyright notice is maintained. 
    6  *  
    7  * This application is distributed in the hope that it will be useful, 
    8  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
     2* 
     3* This application is open source and may be redistributed and/or modified    
     4* freely and without restriction, both in commericial and non commericial applications, 
     5* as long as this copyright notice is maintained. 
     6*  
     7* This application is distributed in the hope that it will be useful, 
     8* but WITHOUT ANY WARRANTY; without even the implied warranty of 
     9* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    1010*/ 
    1111 
     
    1616#include <osg/Switch> 
    1717#include <osgText/Text> 
     18#include <osg/Group> 
    1819 
    1920#include <osgViewer/Viewer> 
     
    2728#include <osgGA/AnimationPathManipulator> 
    2829#include <osgGA/TerrainManipulator> 
    29 #include <osgGA/SphericalManipulator> 
    3030 
    3131#include <iostream> 
    3232 
     33#ifdef _WINDOWS 
     34#include <Windows.h> 
     35#include <GL/glext.h> 
     36#include <GL/wglext.h> 
     37#include "vsynctoggle_custom.h" 
     38#endif 
     39 
    3340int main(int argc, char** argv) 
    3441{ 
    35     // use an ArgumentParser object to manage the program arguments. 
    36     osg::ArgumentParser arguments(&argc,argv); 
     42  // use an ArgumentParser object to manage the program arguments. 
     43  osg::ArgumentParser arguments(&argc,argv); 
    3744 
    38     arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 
    39     arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); 
    40     arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
    41     arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); 
    42     arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); 
    43     arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access."); 
     45  arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 
     46  arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); 
     47  arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 
     48  arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); 
     49  arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); 
     50  arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access."); 
    4451 
    45     osgViewer::Viewer viewer(arguments); 
     52  osgViewer::Viewer viewer(arguments); 
    4653 
    47     unsigned int helpType = 0; 
    48     if ((helpType = arguments.readHelpType())) 
     54  unsigned int helpType = 0; 
     55  if ((helpType = arguments.readHelpType())) 
     56  { 
     57    arguments.getApplicationUsage()->write(std::cout, helpType); 
     58    return 1; 
     59  } 
     60 
     61  // report any errors if they have occurred when parsing the program arguments. 
     62  if (arguments.errors()) 
     63  { 
     64    arguments.writeErrorMessages(std::cout); 
     65    return 1; 
     66  } 
     67 
     68  if (arguments.argc()<=1) 
     69  { 
     70    arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
     71    return 1; 
     72  } 
     73 
     74  std::string url, username, password; 
     75  while(arguments.read("--login",url, username, password)) 
     76  { 
     77    if (!osgDB::Registry::instance()->getAuthenticationMap()) 
    4978    { 
    50         arguments.getApplicationUsage()->write(std::cout, helpType); 
    51         return 1; 
     79      osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); 
     80      osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( 
     81        url, 
     82        new osgDB::AuthenticationDetails(username, password) 
     83        ); 
    5284    } 
    53      
    54     // report any errors if they have occurred when parsing the program arguments. 
    55     if (arguments.errors()) 
     85  } 
     86 
     87  // set up the camera manipulators. 
     88  { 
     89    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; 
     90 
     91    keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); 
     92    keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); 
     93    keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); 
     94    keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); 
     95 
     96    std::string pathfile; 
     97    char keyForAnimationPath = '5'; 
     98    while (arguments.read("-p",pathfile)) 
    5699    { 
    57         arguments.writeErrorMessages(std::cout); 
    58         return 1; 
    59     } 
    60      
    61     if (arguments.argc()<=1) 
    62     { 
    63         arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    64         return 1; 
     100      osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); 
     101      if (apm || !apm->valid())  
     102      { 
     103        unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); 
     104        keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); 
     105        keyswitchManipulator->selectMatrixManipulator(num); 
     106        ++keyForAnimationPath; 
     107      } 
    65108    } 
    66109 
    67     std::string url, username, password; 
    68     while(arguments.read("--login",url, username, password)) 
    69     { 
    70         if (!osgDB::Registry::instance()->getAuthenticationMap()) 
    71         { 
    72             osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); 
    73             osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( 
    74                 url, 
    75                 new osgDB::AuthenticationDetails(username, password) 
    76             ); 
    77         } 
    78     } 
     110    viewer.setCameraManipulator( keyswitchManipulator.get() ); 
     111  } 
    79112 
    80     // set up the camera manipulators. 
    81     { 
    82         osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; 
     113  // add the state manipulator 
     114  viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); 
    83115 
    84         keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); 
    85         keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); 
    86         keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); 
    87         keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); 
    88         keyswitchManipulator->addMatrixManipulator( '5', "Spherical", new osgGA::SphericalManipulator() ); 
     116  // add the thread model handler 
     117  viewer.addEventHandler(new osgViewer::ThreadingHandler); 
    89118 
    90         std::string pathfile; 
    91         char keyForAnimationPath = '6'; 
    92         while (arguments.read("-p",pathfile)) 
    93         { 
    94             osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); 
    95             if (apm || !apm->valid())  
    96             { 
    97                 unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); 
    98                 keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); 
    99                 keyswitchManipulator->selectMatrixManipulator(num); 
    100                 ++keyForAnimationPath; 
    101             } 
    102         } 
     119  // add the window size toggle handler 
     120  viewer.addEventHandler(new osgViewer::WindowSizeHandler); 
    103121 
    104         viewer.setCameraManipulator( keyswitchManipulator.get() ); 
    105     } 
     122  // add the stats handler 
     123  viewer.addEventHandler(new osgViewer::StatsHandler); 
    106124 
    107     // add the state manipulator 
    108     viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); 
    109      
    110     // add the thread model handler 
    111     viewer.addEventHandler(new osgViewer::ThreadingHandler); 
     125  // add the help handler 
     126  viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); 
    112127 
    113     // add the window size toggle handler 
    114     viewer.addEventHandler(new osgViewer::WindowSizeHandler); 
    115          
    116     // add the stats handler 
    117     viewer.addEventHandler(new osgViewer::StatsHandler); 
     128  // add the record camera path handler 
     129  viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); 
    118130 
    119     // add the help handler 
    120     viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); 
     131  // add the LOD Scale handler 
     132  viewer.addEventHandler(new osgViewer::LODScaleHandler); 
    121133 
    122     // add the record camera path handler 
    123     viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); 
     134  // add the screen capture handler 
     135  viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); 
    124136 
    125     // add the LOD Scale handler 
    126     viewer.addEventHandler(new osgViewer::LODScaleHandler); 
     137  // load the data 
     138  osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
     139  if (!loadedModel)  
     140  { 
     141    std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 
     142    return 1; 
     143  } 
    127144 
    128     // add the screen capture handler 
    129     viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); 
     145  // any option left unread are converted into errors to write out later. 
     146  arguments.reportRemainingOptionsAsUnrecognized(); 
    130147 
    131     // load the data 
    132     osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
    133     if (!loadedModel)  
    134     { 
    135         std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 
    136         return 1; 
    137     } 
    138  
    139     // any option left unread are converted into errors to write out later. 
    140     arguments.reportRemainingOptionsAsUnrecognized(); 
    141  
    142     // report any errors if they have occurred when parsing the program arguments. 
    143     if (arguments.errors()) 
    144     { 
    145         arguments.writeErrorMessages(std::cout); 
    146         return 1; 
    147     } 
     148  // report any errors if they have occurred when parsing the program arguments. 
     149  if (arguments.errors()) 
     150  { 
     151    arguments.writeErrorMessages(std::cout); 
     152    return 1; 
     153  } 
    148154 
    149155 
    150     // optimize the scene graph, remove redundant nodes and state etc. 
    151     osgUtil::Optimizer optimizer; 
    152     optimizer.optimize(loadedModel.get()); 
     156  // optimize the scene graph, remove redundant nodes and state etc. 
     157  osgUtil::Optimizer optimizer; 
     158  optimizer.optimize(loadedModel.get()); 
    153159 
    154     viewer.setSceneData( loadedModel.get() ); 
     160  osg::ref_ptr<osg::Group> group = new osg::Group(); 
     161  group->addChild(loadedModel.get()); 
    155162 
    156     viewer.realize(); 
     163  viewer.setSceneData( group.get() ); 
    157164 
    158     return viewer.run(); 
     165  { 
     166    char tmp[256]; 
     167    tmp[sizeof(tmp) - 1] = 0; 
     168    getcwd(tmp, sizeof(tmp) - 1); 
     169 
     170    std::string path(tmp); 
     171    path += "\\system\\cache\\planet"; 
     172 
     173    tmp[sizeof(tmp) - 1] = 0; 
     174    snprintf(tmp, sizeof(tmp) - 1, "%s", path.c_str()); 
     175    //_putenv(tmp); 
     176    // osgDB::Registry::instance()->setFileCache(new osgDB::FileCache( tmp ) ); 
     177    viewer.getDatabasePager()->setTargetMaximumNumberOfPageLOD(500); 
     178 
     179#ifdef _WINDOWS 
     180    osg::ref_ptr<baronvsync::CVsyncDrawable> vsync = new baronvsync::CVsyncDrawable(); 
     181    osg::ref_ptr<osg::Geode> vsyncGeode = new osg::Geode(); 
     182    vsyncGeode->addDrawable(vsync.get()); 
     183    vsync->SetVSync(false); 
     184    group->addChild(vsyncGeode.get()); 
     185#endif 
     186 
     187  } 
     188 
     189  viewer.realize(); 
     190 
     191  return viewer.run(); 
    159192 
    160193}