Show
Ignore:
Timestamp:
07/11/08 21:52:25 (6 years ago)
Author:
robert
Message:

From Adrain Egli, "i added a default scene with 7 different draggers attached. it's more easy to test the draggers."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgmanipulator/osgmanipulator.cpp

    r6941 r8567  
    3232#include <osgManipulator/TranslateAxisDragger> 
    3333 
     34#include <osg/ShapeDrawable> 
     35#include <osg/MatrixTransform> 
     36#include <osg/Geometry> 
     37#include <osg/Material> 
     38 
    3439#include <iostream> 
    3540 
     
    7984        dragger = d; 
    8085    } 
     86 
     87     
    8188  
    8289    return dragger; 
    8390} 
     91 
    8492 
    8593osg::Node* createHUD() 
     
    141149    return root; 
    142150} 
     151 
     152osg::Node* createDemoScene(osgManipulator::CommandManager* cmdMgr) { 
     153  
     154    osg::Group* root = new osg::Group; 
     155 
     156    osg::ref_ptr<osg::Geode> geode_1 = new osg::Geode; 
     157    osg::ref_ptr<osg::MatrixTransform> transform_1 = new osg::MatrixTransform; 
     158 
     159    osg::ref_ptr<osg::Geode> geode_2 = new osg::Geode; 
     160    osg::ref_ptr<osg::MatrixTransform> transform_2 = new osg::MatrixTransform; 
     161 
     162    osg::ref_ptr<osg::Geode> geode_3 = new osg::Geode; 
     163    osg::ref_ptr<osg::MatrixTransform> transform_3 = new osg::MatrixTransform; 
     164 
     165    osg::ref_ptr<osg::Geode> geode_4 = new osg::Geode; 
     166    osg::ref_ptr<osg::MatrixTransform> transform_4 = new osg::MatrixTransform; 
     167 
     168    osg::ref_ptr<osg::Geode> geode_5 = new osg::Geode; 
     169    osg::ref_ptr<osg::MatrixTransform> transform_5 = new osg::MatrixTransform; 
     170 
     171    osg::ref_ptr<osg::Geode> geode_6 = new osg::Geode; 
     172    osg::ref_ptr<osg::MatrixTransform> transform_6 = new osg::MatrixTransform; 
     173 
     174    osg::ref_ptr<osg::Geode> geode_7 = new osg::Geode; 
     175    osg::ref_ptr<osg::MatrixTransform> transform_7 = new osg::MatrixTransform; 
     176 
     177  
     178 
     179 
     180 
     181    const float radius = 0.8f; 
     182    const float height = 1.0f; 
     183    osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints; 
     184    hints->setDetailRatio(2.0f); 
     185    osg::ref_ptr<osg::ShapeDrawable> shape; 
     186 
     187    shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, -2.0f), 10, 10.0f, 0.1f), hints.get()); 
     188    shape->setColor(osg::Vec4(0.5f, 0.5f, 0.7f, 1.0f)); 
     189    geode_1->addDrawable(shape.get()); 
     190 
     191    shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 0.0f), radius * 2,radius), hints.get()); 
     192    shape->setColor(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f)); 
     193    geode_2->addDrawable(shape.get()); 
     194 
     195    shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(-3.0f, 0.0f, 0.0f), radius,radius), hints.get()); 
     196    shape->setColor(osg::Vec4(0.6f, 0.8f, 0.8f, 1.0f)); 
     197    geode_3->addDrawable(shape.get()); 
     198 
     199    shape = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(3.0f, 0.0f, 0.0f), 2 * radius,radius), hints.get()); 
     200    shape->setColor(osg::Vec4(0.4f, 0.9f, 0.3f, 1.0f)); 
     201    geode_4->addDrawable(shape.get()); 
     202 
     203    shape = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(0.0f, -3.0f, 0.0f), radius, height), hints.get()); 
     204    shape->setColor(osg::Vec4(0.2f, 0.5f, 0.7f, 1.0f)); 
     205    geode_5->addDrawable(shape.get()); 
     206 
     207    shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 3.0f, 0.0f), radius, height), hints.get()); 
     208    shape->setColor(osg::Vec4(1.0f, 0.3f, 0.3f, 1.0f)); 
     209    geode_6->addDrawable(shape.get()); 
     210 
     211    shape = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(0.0f, 0.0f, 3.0f), 2.0f, 2.0f), hints.get()); 
     212    shape->setColor(osg::Vec4(0.8f, 0.8f, 0.4f, 1.0f)); 
     213    geode_7->addDrawable(shape.get()); 
     214 
     215 
     216 
     217 
     218 
     219 
     220    // material 
     221    osg::ref_ptr<osg::Material> matirial = new osg::Material; 
     222    matirial->setColorMode(osg::Material::DIFFUSE); 
     223    matirial->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1)); 
     224    matirial->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1)); 
     225    matirial->setShininess(osg::Material::FRONT_AND_BACK, 64.0f); 
     226    root->getOrCreateStateSet()->setAttributeAndModes(matirial.get(), osg::StateAttribute::ON); 
     227 
     228      transform_1.get()->addChild(addDraggerToScene(geode_1.get(),cmdMgr,"TabBoxDragger")); 
     229    transform_2.get()->addChild(addDraggerToScene(geode_2.get(),cmdMgr,"TabPlaneDragger")); 
     230    transform_3.get()->addChild(addDraggerToScene(geode_3.get(),cmdMgr,"TabPlaneTrackballDragger")); 
     231    transform_4.get()->addChild(addDraggerToScene(geode_4.get(),cmdMgr,"TrackballDragger")); 
     232    transform_5.get()->addChild(addDraggerToScene(geode_5.get(),cmdMgr,"Translate1DDragger")); 
     233    transform_6.get()->addChild(addDraggerToScene(geode_6.get(),cmdMgr,"Translate2DDragger")); 
     234    transform_7.get()->addChild(addDraggerToScene(geode_7.get(),cmdMgr,"TranslateAxisDragger")); 
     235 
     236    root->addChild(transform_1.get()); 
     237    root->addChild(transform_2.get()); 
     238    root->addChild(transform_3.get()); 
     239    root->addChild(transform_4.get()); 
     240    root->addChild(transform_5.get()); 
     241    root->addChild(transform_6.get()); 
     242    root->addChild(transform_7.get()); 
     243 
     244  
     245  
     246    return root; 
     247} 
     248 
    143249 
    144250class PickModeHandler : public osgGA::GUIEventHandler 
     
    255361    arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings."); 
    256362 
    257     arguments.getApplicationUsage()->addCommandLineOption("--dragger <draggername>","Use the specified dragger for manipulation"); 
     363    arguments.getApplicationUsage()->addCommandLineOption("--dragger <draggername>","Use the specified dragger for manipulation [TabPlaneDragger,TabPlaneTrackballDragger,TrackballDragger,Translate1DDragger,Translate2DDragger,TranslateAxisDragger,TabBoxDragger]"); 
    258364     
    259365 
     
    281387        return 1; 
    282388    } 
    283      
    284     if (arguments.argc()<=1) 
    285     { 
    286         arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    287         return 1; 
    288     } 
    289389 
    290390    std::string dragger_name = "TabBoxDragger"; 
     
    296396    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
    297397 
     398    // create a command manager 
     399    osg::ref_ptr<osgManipulator::CommandManager> cmdMgr = new osgManipulator::CommandManager; 
     400 
    298401    // if no model has been successfully loaded report failure. 
     402    bool tragger2Scene(true); 
    299403    if (!loadedModel)  
    300404    { 
    301         std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 
    302         return 1; 
     405        //std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 
     406        //return 1; 
     407        loadedModel = createDemoScene(cmdMgr.get()); 
     408        tragger2Scene=false; 
    303409    } 
    304410 
     
    321427    optimizer.optimize(loadedModel.get()); 
    322428 
    323     osg::ref_ptr<osgManipulator::CommandManager> cmdMgr = new osgManipulator::CommandManager; 
    324429     
    325430    // pass the loaded scene graph to the viewer. 
    326     viewer.setSceneData(addDraggerToScene(loadedModel.get(), cmdMgr.get(), dragger_name)); 
    327  
     431    if ( tragger2Scene ) { 
     432        viewer.setSceneData(addDraggerToScene(loadedModel.get(), cmdMgr.get(), dragger_name)); 
     433    } else {  
     434        viewer.setSceneData(loadedModel.get()); 
     435    } 
    328436    viewer.addEventHandler(new PickModeHandler()); 
    329437