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 | |
---|
10 | using namespace osg; |
---|
11 | |
---|
12 | |
---|
13 | //Viewer(arguments) |
---|
14 | CustomViewer::CustomViewer(osg::ArgumentParser& arguments) : osgProducer::Viewer() |
---|
15 | { |
---|
16 | } |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | void CustomViewer::setUpViewer(unsigned int options) |
---|
21 | { |
---|
22 | // set up the keyboard and mouse handling. |
---|
23 | Producer::InputArea *ia = getCameraConfig()->getInputArea(); |
---|
24 | |
---|
25 | if (!_kbm) |
---|
26 | { |
---|
27 | _kbm = ia ? |
---|
28 | (new Producer::KeyboardMouse(ia)) : |
---|
29 | (new Producer::KeyboardMouse(getCamera(0)->getRenderSurface())); |
---|
30 | } |
---|
31 | |
---|
32 | // set the keyboard mouse callback to catch the events from the windows. |
---|
33 | if (!_kbmcb) |
---|
34 | _kbmcb = new osgProducer::KeyboardMouseCallback( _kbm.get(), _done, (options & ESCAPE_SETS_DONE)!=0 ); |
---|
35 | |
---|
36 | _kbmcb->setStartTick(_start_tick); |
---|
37 | |
---|
38 | // register the callback with the keyboard mouse manager. |
---|
39 | _kbm->setCallback( _kbmcb.get() ); |
---|
40 | //kbm->allowContinuousMouseMotionUpdate(true); |
---|
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 | //_trackball = new CustomTrackballManipulator; |
---|
66 | //_eventHandlerList.push_back( _trackball ); |
---|
67 | |
---|
68 | _terrainmanipulator = new CustomTerrainManipulator; |
---|
69 | if( options&TERRAIN_MANIPULATOR ) addCameraManipulator( _terrainmanipulator ); |
---|
70 | |
---|
71 | |
---|
72 | if( options&STATE_MANIPULATOR ) |
---|
73 | { |
---|
74 | osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new osgGA::StateSetManipulator; |
---|
75 | statesetManipulator->setStateSet( getGlobalStateSet() ); |
---|
76 | _eventHandlerList.push_back( statesetManipulator.get() ); |
---|
77 | } |
---|
78 | |
---|
79 | if( options&VIEWER_MANIPULATOR ) |
---|
80 | { |
---|
81 | osg::ref_ptr<CustomViewerEventHandler> viewereventhandler = new CustomViewerEventHandler(this); |
---|
82 | getEventHandlerList().push_back( viewereventhandler.get() ); |
---|
83 | } |
---|
84 | |
---|
85 | } |
---|