source: Swollen/swollen/customviewer.cpp @ 9

Last change on this file since 9 was 6, checked in by darran, 20 years ago

new import

File size: 2.5 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    _trackball = new CustomTrackballManipulator;
63
64    // FIXME: trying to eliminate need for keyswitchmanipulator
65    //_eventHandlerList.push_back( _trackball );
66    if (options&TRACKBALL_MANIPULATOR) addCameraManipulator(_trackball);
67   
68    if (options&STATE_MANIPULATOR)
69    {
70        osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new osgGA::StateSetManipulator;
71        statesetManipulator->setStateSet(getGlobalStateSet());
72        _eventHandlerList.push_back(statesetManipulator.get());
73    }
74       
75    if (options&VIEWER_MANIPULATOR)
76    {
77        getEventHandlerList().push_back(new osgProducer::ViewerEventHandler(this));
78    }
79   
80}
Note: See TracBrowser for help on using the repository browser.