#include #include #include #include #include "customviewer.h" using namespace osg; CustomViewer::CustomViewer(osg::ArgumentParser& arguments) : Viewer(arguments) { } void CustomViewer::setUpViewer(unsigned int options) { // set up the keyboard and mouse handling. Producer::InputArea *ia = getCameraConfig()->getInputArea(); if (!_kbm) { _kbm = ia ? (new Producer::KeyboardMouse(ia)) : (new Producer::KeyboardMouse(getCamera(0)->getRenderSurface())); } // set the keyboard mouse callback to catch the events from the windows. if (!_kbmcb) _kbmcb = new osgProducer::KeyboardMouseCallback( _kbm.get(), _done, (options & ESCAPE_SETS_DONE)!=0 ); _kbmcb->setStartTick(_start_tick); // register the callback with the keyboard mouse manager. _kbm->setCallback( _kbmcb.get() ); //kbm->allowContinuousMouseMotionUpdate(true); // set the global state osg::ref_ptr globalStateSet = new osg::StateSet; setGlobalStateSet(globalStateSet.get()); { globalStateSet->setGlobalDefaults(); // enable depth testing by default. globalStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); // enable lighting by default globalStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); // set up an alphafunc by default to speed up blending operations. osg::AlphaFunc* alphafunc = new osg::AlphaFunc; alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f); globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::ON); } if (!_updateVisitor) _updateVisitor = new osgUtil::UpdateVisitor; _updateVisitor->setFrameStamp(_frameStamp.get()); _trackball = new CustomTrackballManipulator; // FIXME: trying to eliminate need for keyswitchmanipulator //_eventHandlerList.push_back( _trackball ); if (options&TRACKBALL_MANIPULATOR) addCameraManipulator(_trackball); if (options&STATE_MANIPULATOR) { osg::ref_ptr statesetManipulator = new osgGA::StateSetManipulator; statesetManipulator->setStateSet(getGlobalStateSet()); _eventHandlerList.push_back(statesetManipulator.get()); } if (options&VIEWER_MANIPULATOR) { getEventHandlerList().push_back(new osgProducer::ViewerEventHandler(this)); } }