From 595a04831976c171a3d4fff1965a61ec6541b3ea Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 9 Apr 2015 18:38:53 +0000 Subject: [PATCH] Added WindowSizeHandler to osgmanipulator example git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14827 16af8721-9629-0410-8352-f15c8da7e697 --- examples/osgmanipulator/osgmanipulator.cpp | 60 ++++++++++++---------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/examples/osgmanipulator/osgmanipulator.cpp b/examples/osgmanipulator/osgmanipulator.cpp index beab4b295..6dafc170e 100644 --- a/examples/osgmanipulator/osgmanipulator.cpp +++ b/examples/osgmanipulator/osgmanipulator.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -47,11 +48,11 @@ class PlaneConstraint : public osgManipulator::Constraint { public: PlaneConstraint() {} - + virtual bool constrain(osgManipulator::TranslateInLineCommand& command) const { OSG_NOTICE<<"PlaneConstraint TranslateInLineCommand "<setupDefaultGeometry(); - d->setAxisLineWidth(5.0f); - d->setPickCylinderHeight(0.1f); + //d->setAxisLineWidth(5.0f); + //d->setPickCylinderHeight(0.1f); dragger = d; } else if ("Translate1DDragger" == name) @@ -168,8 +169,8 @@ osgManipulator::Dragger* createDragger(const std::string& name) dragger = d; } - - + + return dragger; } @@ -178,29 +179,29 @@ class DraggerContainer : public osg::Group { public: DraggerContainer() : _draggerSize(240.0f), _active(true) {} - + DraggerContainer( const DraggerContainer& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY ) : osg::Group(copy, copyop), _dragger(copy._dragger), _draggerSize(copy._draggerSize), _active(copy._active) {} - + META_Node( osgManipulator, DraggerContainer ); - + void setDragger( osgManipulator::Dragger* dragger ) { _dragger = dragger; if ( !containsNode(dragger) ) addChild( dragger ); } - + osgManipulator::Dragger* getDragger() { return _dragger.get(); } const osgManipulator::Dragger* getDragger() const { return _dragger.get(); } - + void setDraggerSize( float size ) { _draggerSize = size; } float getDraggerSize() const { return _draggerSize; } - + void setActive( bool b ) { _active = b; } bool getActive() const { return _active; } - + void traverse( osg::NodeVisitor& nv ) { if ( _dragger.valid() ) @@ -208,13 +209,13 @@ public: if ( _active && nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR ) { osgUtil::CullVisitor* cv = static_cast(&nv); - + float pixelSize = cv->pixelSize(_dragger->getBound().center(), 0.48f); if ( pixelSize!=_draggerSize ) { float pixelScale = pixelSize>0.0f ? _draggerSize/pixelSize : 1.0f; osg::Vec3d scaleFactor(pixelScale, pixelScale, pixelScale); - + osg::Vec3 trans = _dragger->getMatrix().getTrans(); _dragger->setMatrix( osg::Matrix::scale(scaleFactor) * osg::Matrix::translate(trans) ); } @@ -222,7 +223,7 @@ public: } osg::Group::traverse(nv); } - + protected: osg::ref_ptr _dragger; float _draggerSize; @@ -278,7 +279,7 @@ osg::Node* addDraggerToScene(osg::Node* scene, const std::string& name, bool fix } osg::Node* createDemoScene(bool fixedSizeInScreen) { - + osg::Group* root = new osg::Group; osg::ref_ptr geode_1 = new osg::Geode; @@ -302,7 +303,7 @@ osg::Node* createDemoScene(bool fixedSizeInScreen) { osg::ref_ptr geode_7 = new osg::Geode; osg::ref_ptr transform_7 = new osg::MatrixTransform; - + @@ -369,17 +370,17 @@ osg::Node* createDemoScene(bool fixedSizeInScreen) { root->addChild(transform_6.get()); root->addChild(transform_7.get()); - - + + return root; } -// +// int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); @@ -392,13 +393,16 @@ int main( int argc, char **argv ) arguments.getApplicationUsage()->addCommandLineOption("--dragger ","Use the specified dragger for manipulation [TabPlaneDragger, TabPlaneTrackballDragger, TrackballDragger, Translate1DDragger, Translate2DDragger, TranslateAxisDragger, TabBoxDragger, TranslatePlaneDragger, Scale1DDragger, Scale2DDragger, RotateCylinderDragger, RotateSphereDragger]"); arguments.getApplicationUsage()->addCommandLineOption("--fixedDraggerSize","Fix the size of the dragger geometry in the screen space"); - + bool fixedSizeInScreen = false; while (arguments.read("--fixedDraggerSize")) { fixedSizeInScreen = true; } // construct the viewer. osgViewer::Viewer viewer; + // add the window size toggle handler + viewer.addEventHandler(new osgViewer::WindowSizeHandler); + // get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(*arguments.getApplicationUsage()); @@ -430,7 +434,7 @@ int main( int argc, char **argv ) // if no model has been successfully loaded report failure. bool tragger2Scene(true); - if (!loadedModel) + if (!loadedModel) { //std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; //return 1; @@ -456,11 +460,11 @@ int main( int argc, char **argv ) osgUtil::Optimizer optimizer; optimizer.optimize(loadedModel.get()); - + // pass the loaded scene graph to the viewer. if ( tragger2Scene ) { viewer.setSceneData(addDraggerToScene(loadedModel.get(), dragger_name, fixedSizeInScreen)); - } else { + } else { viewer.setSceneData(loadedModel.get()); }