EarthManipulator

changeset 5:f7128c932c6d

add PolygonOffset keys to test it
author "Cedric Pinson <cedric.pinson@alcove.fr> <mornifle@plopbyte.net>"
date Thu Nov 15 13:42:30 2007 +0100 (2007-11-15)
parents da2e5a5ca2b6
children 19af43a91041
files example/viewer.cpp src/EarthManipulator.cpp src/EarthManipulator.hpp
line diff
     1.1 --- a/example/viewer.cpp	Thu Nov 15 11:49:40 2007 +0100
     1.2 +++ b/example/viewer.cpp	Thu Nov 15 13:42:30 2007 +0100
     1.3 @@ -13,7 +13,57 @@
     1.4  #include <osgUtil/Optimizer>
     1.5  #include <osgProducer/Viewer>
     1.6  #include <osg/CoordinateSystemNode>
     1.7 +#include <osg/PolygonOffset>
     1.8  #include <EarthManipulator.hpp>
     1.9 +#include <osgGA/GUIEventHandler>
    1.10 +#include <osgGA/GUIEventAdapter>
    1.11 +
    1.12 +
    1.13 +class KeyboardEventHandler : public osgGA::GUIEventHandler
    1.14 +{
    1.15 +public:
    1.16 +  osg::ref_ptr<osg::Node> _node;
    1.17 +  osg::ref_ptr<osg::PolygonOffset> _polygonOffset;
    1.18 +
    1.19 +  KeyboardEventHandler(osg::Node* node)
    1.20 +  {
    1.21 +    _node = node;
    1.22 +    _polygonOffset = new osg::PolygonOffset;
    1.23 +    _node->getOrCreateStateSet()->setAttributeAndModes(_polygonOffset.get());
    1.24 +  }
    1.25 +    
    1.26 +  virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
    1.27 +  {
    1.28 +    switch(ea.getEventType())
    1.29 +      {
    1.30 +      case(osgGA::GUIEventAdapter::KEYUP):
    1.31 +        {
    1.32 +          if (ea.getKey() == 'i') {
    1.33 +            _polygonOffset->setFactor(_polygonOffset->getFactor() - 0.1);
    1.34 +            std::cout << "PolygonOffset factor " << _polygonOffset->getFactor() << " units " << _polygonOffset->getUnits() << std::endl;
    1.35 +            return true;
    1.36 +          } else if (ea.getKey() == 'o') {
    1.37 +            _polygonOffset->setFactor(_polygonOffset->getFactor() + 0.1);
    1.38 +            std::cout << "PolygonOffset factor " << _polygonOffset->getFactor() << " units " << _polygonOffset->getUnits() << std::endl;
    1.39 +            return true;
    1.40 +          } else if (ea.getKey() == 'k') {
    1.41 +            _polygonOffset->setUnits(_polygonOffset->getUnits() - 0.1);
    1.42 +            std::cout << "PolygonOffset factor " << _polygonOffset->getFactor() << " units " << _polygonOffset->getUnits() << std::endl;
    1.43 +            return true;
    1.44 +          } else if (ea.getKey() == 'l') {
    1.45 +            _polygonOffset->setUnits(_polygonOffset->getUnits() + 0.1);
    1.46 +            std::cout << "PolygonOffset factor " << _polygonOffset->getFactor() << " units " << _polygonOffset->getUnits() << std::endl;
    1.47 +            return true;
    1.48 +          }
    1.49 +        }
    1.50 +
    1.51 +      default:
    1.52 +        return false;
    1.53 +      }
    1.54 +  }
    1.55 +
    1.56 +};
    1.57 +
    1.58  
    1.59  
    1.60  int main( int argc, char **argv )
    1.61 @@ -43,6 +93,7 @@
    1.62      osgSW::EarthManipulator* em = new osgSW::EarthManipulator;
    1.63      viewer.addCameraManipulator(em);
    1.64  
    1.65 +
    1.66      // get details on keyboard and mouse bindings used by the viewer.
    1.67      viewer.getUsage(*arguments.getApplicationUsage());
    1.68  
    1.69 @@ -82,6 +133,9 @@
    1.70          return 1;
    1.71      }
    1.72  
    1.73 +    KeyboardEventHandler* keh = new KeyboardEventHandler(loadedModel.get());
    1.74 +    viewer.getEventHandlerList().push_front(keh);
    1.75 +
    1.76      // any option left unread are converted into errors to write out later.
    1.77      arguments.reportRemainingOptionsAsUnrecognized();
    1.78  
    1.79 @@ -105,7 +159,7 @@
    1.80  
    1.81      // create the windows and run the threads.
    1.82      viewer.realize();
    1.83 -
    1.84 +    
    1.85      while( !viewer.done() )
    1.86      {
    1.87          // wait for all cull and draw threads to complete.
     2.1 --- a/src/EarthManipulator.cpp	Thu Nov 15 11:49:40 2007 +0100
     2.2 +++ b/src/EarthManipulator.cpp	Thu Nov 15 13:42:30 2007 +0100
     2.3 @@ -21,6 +21,8 @@
     2.4    along with this program; if not, write to the Free Software
     2.5    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.6  */
     2.7 +/// (C) Cedric Pinson - 2007 mornifle@plopbyte.net
     2.8 +/// 15.11.2007
     2.9  
    2.10  
    2.11  #include "EarthManipulator.hpp"
     3.1 --- a/src/EarthManipulator.hpp	Thu Nov 15 11:49:40 2007 +0100
     3.2 +++ b/src/EarthManipulator.hpp	Thu Nov 15 13:42:30 2007 +0100
     3.3 @@ -24,6 +24,8 @@
     3.4    along with this program; if not, write to the Free Software
     3.5    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     3.6  */
     3.7 +/// (C) Cedric Pinson - 2007 mornifle@plopbyte.net
     3.8 +/// 15.11.2007
     3.9  
    3.10  
    3.11  #include <osgGA/MatrixManipulator>