1 | |
---|
2 | #include <osg/LightSource> |
---|
3 | #include <osg/AlphaFunc> |
---|
4 | #include <osgUtil/UpdateVisitor> |
---|
5 | #include <osgGA/StateSetManipulator> |
---|
6 | #include <osgProducer/ViewerEventHandler> |
---|
7 | #include "customviewer.h" |
---|
8 | |
---|
9 | using namespace osg; |
---|
10 | |
---|
11 | |
---|
12 | CustomViewer::CustomViewer(osg::ArgumentParser& arguments) : Viewer(arguments) |
---|
13 | { |
---|
14 | } |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | void 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 | |
---|
69 | |
---|
70 | if( options&STATE_MANIPULATOR ) |
---|
71 | { |
---|
72 | osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new osgGA::StateSetManipulator; |
---|
73 | statesetManipulator->setStateSet( getGlobalStateSet() ); |
---|
74 | _eventHandlerList.push_back( statesetManipulator.get() ); |
---|
75 | } |
---|
76 | |
---|
77 | if( options&VIEWER_MANIPULATOR ) |
---|
78 | { |
---|
79 | osg::ref_ptr<osgProducer::ViewerEventHandler> viewereventhandler = new osgProducer::ViewerEventHandler(this); |
---|
80 | getEventHandlerList().push_back( viewereventhandler.get() ); |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|