source: Swollen/swollen/customviewer.cpp @ 1353

Last change on this file since 1353 was 116, checked in by darran, 20 years ago
  • distro20050627
  • functioning record/playback/save. Can't yet replay from movie.swm
  • image capture not yet implemented.
File size: 2.7 KB
RevLine 
[6]1
2#include <osg/LightSource>
[88]3#include <osg/AlphaFunc>
[6]4#include <osgUtil/UpdateVisitor>
5#include <osgGA/StateSetManipulator>
[116]6#include <osgProducer/OsgCameraGroup>
[6]7#include "customviewer.h"
[116]8#include "customviewereventhandler.h"
[6]9
10using namespace osg;
11
12
[116]13//Viewer(arguments)
14CustomViewer::CustomViewer(osg::ArgumentParser& arguments) : osgProducer::Viewer()
[6]15{
16}
17
18
19
20void 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   
[65]61    if (!_updateVisitor) _updateVisitor = new osgUtil::UpdateVisitor;
[6]62    _updateVisitor->setFrameStamp(_frameStamp.get());
63
[66]64
[74]65    //_trackball = new CustomTrackballManipulator;
66    //_eventHandlerList.push_back( _trackball );
[6]67
[66]68    _terrainmanipulator = new CustomTerrainManipulator;
[74]69    if( options&TERRAIN_MANIPULATOR ) addCameraManipulator( _terrainmanipulator );
[66]70
[6]71   
[74]72    if( options&STATE_MANIPULATOR )
[6]73    {
74        osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new osgGA::StateSetManipulator;
[66]75        statesetManipulator->setStateSet( getGlobalStateSet() );
76        _eventHandlerList.push_back( statesetManipulator.get() );
[6]77    }
78       
[74]79    if( options&VIEWER_MANIPULATOR )
[6]80    {
[116]81       osg::ref_ptr<CustomViewerEventHandler> viewereventhandler = new CustomViewerEventHandler(this);
[70]82       getEventHandlerList().push_back( viewereventhandler.get() );
[6]83    }
84   
85}
Note: See TracBrowser for help on using the repository browser.