source: Swollen/swollen/customviewer.cpp @ 71

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