source: swollen_viewer/swollen/customviewer.cpp @ 2612

Last change on this file since 2612 was 1993, checked in by darran, 19 years ago
  • viewer again accepts --stereo option
File size: 2.6 KB
Line 
1
2#include <osg/LightSource>
3#include <osg/AlphaFunc>
4#include <osgUtil/UpdateVisitor>
5#include <osgGA/StateSetManipulator>
6#include <osgProducer/OsgCameraGroup>
7#include "customviewer.h"
8#include "customviewereventhandler.h"
9
10using namespace osg;
11
12
13//Viewer(arguments)
14CustomViewer::CustomViewer(osg::ArgumentParser& arguments) : osgProducer::Viewer()
15{
16   osg::DisplaySettings::instance()->readCommandLine(arguments);
17}
18
19
20
21void CustomViewer::setUpViewer(unsigned int options)
22{
23    // set up the keyboard and mouse handling.
24    Producer::InputArea *ia = getCameraConfig()->getInputArea();
25   
26    if (!_kbm)
27    {
28        _kbm = ia ?
29                   (new Producer::KeyboardMouse(ia)) : 
30                   (new Producer::KeyboardMouse(getCamera(0)->getRenderSurface()));                   
31    }
32   
33    // set the keyboard mouse callback to catch the events from the windows.
34    if (!_kbmcb)
35        _kbmcb = new osgProducer::KeyboardMouseCallback( _kbm.get(), _done, (options & ESCAPE_SETS_DONE)!=0 );
36       
37    _kbmcb->setStartTick(_start_tick);
38   
39    // register the callback with the keyboard mouse manager.
40    _kbm->setCallback( _kbmcb.get() );
41
42    // set the global state   
43    osg::ref_ptr<osg::StateSet> globalStateSet = new osg::StateSet;
44    setGlobalStateSet(globalStateSet.get());
45    {
46        globalStateSet->setGlobalDefaults();
47
48        // enable depth testing by default.
49        globalStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
50
51        // enable lighting by default
52        globalStateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
53
54        // set up an alphafunc by default to speed up blending operations.
55        osg::AlphaFunc* alphafunc = new osg::AlphaFunc;
56        alphafunc->setFunction(osg::AlphaFunc::GREATER,0.0f);
57        globalStateSet->setAttributeAndModes(alphafunc, osg::StateAttribute::ON);
58    }
59   
60   
61    if (!_updateVisitor) _updateVisitor = new osgUtil::UpdateVisitor;
62    _updateVisitor->setFrameStamp(_frameStamp.get());
63
64
65    _terrainmanipulator = new CustomTerrainManipulator;
66    if( options&TERRAIN_MANIPULATOR ) addCameraManipulator( _terrainmanipulator );
67
68   
69    if( options&STATE_MANIPULATOR )
70    {
71        osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new osgGA::StateSetManipulator;
72        statesetManipulator->setStateSet( getGlobalStateSet() );
73        _eventHandlerList.push_back( statesetManipulator.get() );
74    }
75       
76    if( options&VIEWER_MANIPULATOR )
77    {
78       osg::ref_ptr<CustomViewerEventHandler> viewereventhandler = new CustomViewerEventHandler(this);
79       getEventHandlerList().push_back( viewereventhandler.get() );
80    }
81   
82}
Note: See TracBrowser for help on using the repository browser.