Changeset 20217

Show
Ignore:
Timestamp:
05/14/07 16:03:12 (1 year ago)
Author:
patrick
Message:

Merges from the trunk to get vrj::OpenSGApp and the OpenSG sample applications
working with both OpenSG 1.x and 2.x. The revisions merged are as follows:

r19804: OpenSG2 uses Thread::getCurrentAspect() instead of getAspect() so

recognize when we are compiling against OpenSG2 and act accordingly.
This may not be needed in the future when OpenSG2 is used and built
with OSG_1_COMPAT, but this change will be more reliable for all
OpenSG2 builds.

r20202: Changes needed for OpenSG 2. OpenSG2 uses a RenderTraversalAction?

instead of a RenderAction?.

r20214: Finished making vrj::OpenSGApp work with OpenSG 1.x and 2.x without

having to enable the deprecated APIs in OpenSG 2. The sample
applications have been updated and tested, too.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/branches/2.0/modules/vrjuggler/ChangeLog

    r19916 r20217  
    11DATE        AUTHOR      CHANGE 
    22----------- ----------- ------------------------------------------------------- 
     3May-14-2007 patrick     Merged changes from the trunk to get vrj::OpenSGApp and 
     4                        the OpenSG sample applications working with both OpenSG 
     5                        1.x and 2.x. 
    36Apr-09-2007 patrick     Made the number of sample buffers and samples per 
    47                        buffer configurable when using multisampling. 
  • juggler/branches/2.0/modules/vrjuggler/VERSION

    r19916 r20217  
     12.0.3-3 @05/14/2007 21:05:00 UTC@ 
    122.0.3-2 @04/09/2007 14:15:00 UTC@ 
    232.0.3-1 @02/14/2007 19:40:00 UTC@ 
  • juggler/branches/2.0/modules/vrjuggler/samples/OpenSG/advanced/OpenSGNavGrab/Makefile.in

    r17024 r20217  
    4949OPENSG_LIBS=    $(shell osg-config --libs) -lOSGBase -lOSGSystem 
    5050OPENSG_CFLAGS=  $(shell osg-config --cflags) 
     51#OPENSG_LIBS=   $(shell osg2-config OSGFileIO OSGWindow OSGRenderTraversal --libs) 
     52#OPENSG_CFLAGS= $(shell osg2-config OSGFileIO OSGWindow OSGRenderTraversal --cflags) 
    5153 
    5254EXTRA_CXXFLAGS+=        $(OPENSG_CFLAGS) 
  • juggler/branches/2.0/modules/vrjuggler/samples/OpenSG/advanced/OpenSGNavGrab/OpenSGNavGrab.cpp

    r17467 r20217  
    4242#include <gmtl/Vec.h> 
    4343 
     44#if OSG_MAJOR_VERSION >= 2 
     45#  include <OpenSG/OSGTypedGeoIntegralProperty.h> 
     46#endif 
     47 
    4448#include <OpenSGNavGrab.h> 
    4549 
     
    5054   : vrj::OpenSGApp(kern) 
    5155   , mVelocity(0.0f) 
    52    , mIntersectedObj(NULL) 
    53    , mGrabbedObj(NULL) 
    5456   , mIntersectColor(1.0f, 1.0f, 0.0f) 
    5557   , mGrabColor(1.0f, 0.0f, 1.0f) 
     
    6062OpenSGNavGrab::~OpenSGNavGrab() 
    6163{ 
    62    for ( std::vector<GrabObject*>::iterator i = mObjects.begin(); 
    63          i != mObjects.end(); 
    64          ++i ) 
    65    { 
    66       delete *i; 
    67    } 
     64   /* Do nothing. */ ; 
    6865} 
    6966 
     
    107104   mModelGroup = OSG::Group::create(); 
    108105 
    109    OSG::beginEditCP(mModelRoot); 
    110       mModelRoot->setCore(mModelGroup); 
    111    OSG::endEditCP(mModelRoot); 
     106#if OSG_MAJOR_VERSION < 2 
     107   CPEdit(mModelRoot, OSG::Node::CoreFieldMask); 
     108#endif 
     109 
     110   mModelRoot->setCore(mModelGroup); 
    112111 
    113112   // Load the model to use. 
     
    120119      // Box geometry: 2.5x2.5x2.5 (units are in feet) 
    121120      // Center point: (0,0,0) 
    122       OSG::NodePtr geom_node = OSG::makeBox(2.5f, 2.5f, 2.5f, 1, 1, 1); 
    123       OSG::addRefCP(geom_node); 
     121      OSG::NodeRefPtr geom_node(OSG::makeBox(2.5f, 2.5f, 2.5f, 1, 1, 1)); 
    124122 
    125123      // Move it so that it would butt up against a wall five feet in front 
     
    137135      OSG::Pnt3f::RealReturnType max_dist(0.0f); 
    138136 
    139       std::vector<OSG::NodePtr> nodes; 
     137      std::vector<OSG::NodeRefPtr> nodes; 
    140138 
    141139      // Load all the models that the user told us to load. 
    142       for ( std::vector<std::string>::iterator i = mFilesToLoad.begin(); 
    143             i != mFilesToLoad.end(); 
    144             ++i ) 
     140      typedef std::vector<std::string>::iterator iter_type; 
     141      for ( iter_type i = mFilesToLoad.begin(); i != mFilesToLoad.end(); ++i ) 
    145142      { 
    146143         vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) 
    147144            << "[OpenSGNavGrab::initScene()] Loading '" << *i << "' ..." 
    148145            << std::endl << vprDEBUG_FLUSH; 
    149          OSG::NodePtr geom_node = 
    150             OSG::SceneFileHandler::the().read((OSG::Char8*) (*i).c_str()); 
    151          OSG::addRefCP(geom_node); 
     146         const OSG::Char8* file = (*i).c_str(); 
     147         OSG::NodeRefPtr geom_node( 
     148#if OSG_MAJOR_VERSION < 2 
     149            OSG::SceneFileHandler::the().read(file) 
     150#else 
     151            OSG::SceneFileHandler::the()->read(file) 
     152#endif 
     153         ); 
    152154 
    153155         nodes.push_back(geom_node); 
     
    181183      if ( ! nodes.empty() ) 
    182184      { 
    183          const std::vector<OSG::NodePtr>::size_type num_objs(nodes.size()); 
     185         const std::vector<OSG::NodeRefPtr>::size_type num_objs(nodes.size()); 
    184186         const OSG::Real32 interval_dist(distance_vec[0]); 
    185187 
     
    193195            -(interval_dist * OSG::Real32(num_objs) - interval_dist) / 2.0f; 
    194196 
    195          for ( std::vector<OSG::NodePtr>::iterator i = nodes.begin(); 
     197         typedef std::vector<OSG::NodeRefPtr>::iterator iter_type; 
     198         for ( iter_type i = nodes.begin(); 
    196199               i != nodes.end(); 
    197200               ++i, x_offset += interval_dist ) 
     
    226229   light_pos.setTransform(OSG::Vec3f(2.0f, 5.0f, 4.0f)); 
    227230 
    228    OSG::beginEditCP(light_beacon_core, OSG::Transform::MatrixFieldMask); 
    229       light_beacon_core->setMatrix(light_pos); 
    230    OSG::endEditCP(light_beacon_core, OSG::Transform::MatrixFieldMask); 
    231  
    232    OSG::beginEditCP(mLightBeacon); 
    233       mLightBeacon->setCore(light_beacon_core); 
    234    OSG::endEditCP(mLightBeacon); 
     231#if OSG_MAJOR_VERSION < 2 
     232   CPEdit(light_beacon_core, OSG::Transform::MatrixFieldMask); 
     233   CPEdit(mLightBeacon, OSG::Node::CoreFieldMask); 
     234   CPEdit(mLightNode, OSG::Node::CoreFieldMask | OSG::Node::ChildrenFieldMask); 
     235   CPEditAll(light_core); 
     236#endif 
     237 
     238   light_beacon_core->setMatrix(light_pos); 
     239 
     240   mLightBeacon->setCore(light_beacon_core); 
    235241 
    236242   // Set up light node 
    237    OSG::addRefCP(mLightNode); 
    238    OSG::beginEditCP(mLightNode); 
    239       mLightNode->setCore(light_core); 
    240       mLightNode->addChild(mLightBeacon); 
    241    OSG::endEditCP(mLightNode); 
    242  
    243    OSG::beginEditCP(light_core); 
    244       light_core->setAmbient(0.9, 0.8, 0.8, 1); 
    245       light_core->setDiffuse(0.6, 0.6, 0.6, 1); 
    246       light_core->setSpecular(1, 1, 1, 1); 
    247       light_core->setDirection(0, 0, 1); 
    248       light_core->setBeacon(mLightNode); 
    249    OSG::endEditCP(light_core); 
     243   mLightNode->setCore(light_core); 
     244   mLightNode->addChild(mLightBeacon); 
     245 
     246   light_core->setAmbient(0.9, 0.8, 0.8, 1); 
     247   light_core->setDiffuse(0.6, 0.6, 0.6, 1); 
     248   light_core->setSpecular(1, 1, 1, 1); 
     249   light_core->setDirection(0, 0, 1); 
     250   light_core->setBeacon(mLightNode); 
    250251 
    251252   // --- Set up scene -- // 
    252253   // add the loaded scene to the light node, so that it is lit by the light 
    253  
    254    OSG::beginEditCP(mLightNode); 
    255       mLightNode->addChild(mModelRoot); 
    256    OSG::endEditCP(mLightNode); 
     254   mLightNode->addChild(mModelRoot); 
    257255 
    258256   // create the root part of the scene 
     
    260258   mSceneTransform = OSG::Transform::create(); 
    261259 
     260#if OSG_MAJOR_VERSION < 2 
     261   CPEdit(mSceneRoot, OSG::Node::CoreFieldMask | OSG::Node::ChildrenFieldMask); 
     262#endif 
     263 
    262264   // Set up the root node 
    263    OSG::beginEditCP(mSceneRoot); 
    264       mSceneRoot->setCore(mSceneTransform); 
    265       mSceneRoot->addChild(mLightNode); 
    266    OSG::endEditCP(mSceneRoot); 
     265   mSceneRoot->setCore(mSceneTransform); 
     266   mSceneRoot->addChild(mLightNode); 
    267267} 
    268268 
     
    314314   updateGrabbing(wand_mat); 
    315315   updateNavigation(wand_mat); 
     316 
     317   vrj::OpenSGApp::preFrame(); 
    316318} 
    317319 
     
    320322   mVelocity = 0.0f; 
    321323 
    322    OSG::beginEditCP(mSceneTransform, OSG::Transform::MatrixFieldMask); 
    323       mSceneTransform->getMatrix().setIdentity(); 
    324    OSG::endEditCP(mSceneTransform, OSG::Transform::MatrixFieldMask); 
    325  
    326    for ( std::vector<GrabObject*>::iterator i = mObjects.begin(); 
    327          i != mObjects.end(); 
    328          ++i ) 
    329    { 
    330       OSG::beginEditCP((*i)->xformCore, OSG::Transform::MatrixFieldMask); 
    331          (*i)->xformCore->getMatrix().setValue((*i)->homePos); 
    332       OSG::endEditCP((*i)->xformCore, OSG::Transform::MatrixFieldMask); 
    333    } 
     324#if OSG_MAJOR_VERSION < 2 
     325   CPEdit(mSceneTransform, OSG::Transform::MatrixFieldMask); 
     326 
     327   mSceneTransform->getMatrix().setIdentity(); 
     328#else 
     329   mSceneTransform->editMatrix().setIdentity(); 
     330#endif 
     331 
     332   typedef std::vector<GrabObjectPtr>::iterator iter_type; 
     333   for ( iter_type i = mObjects.begin(); i != mObjects.end(); ++i ) 
     334   { 
     335#if OSG_MAJOR_VERSION < 2 
     336      OSG::TransformPtr core = (*i)->getXformNode(); 
     337      CPEdit(core, OSG::Transform::MatrixFieldMask); 
     338      core->getMatrix().setValue((*i)->getHomePos()); 
     339#else 
     340      (*i)->getXformNode()->editMatrix().setValue((*i)->getHomePos()); 
     341#endif 
     342   } 
     343
     344 
     345void OpenSGNavGrab::exit() 
     346
     347   mObjects.clear(); 
     348 
     349   mIntersectedObj = GrabObjectPtr(); 
     350   mGrabbedObj     = GrabObjectPtr(); 
     351 
     352   mSceneRoot         = OSG::NullFC; 
     353   mSceneTransform    = OSG::NullFC; 
     354   mModelRoot         = OSG::NullFC; 
     355   mModelGroup        = OSG::NullFC; 
     356   mLightNode         = OSG::NullFC; 
     357   mLightBeacon       = OSG::NullFC; 
     358   mHighlight         = OSG::NullFC; 
     359   mHighlightNode     = OSG::NullFC; 
     360   mHighlightPoints   = OSG::NullFC; 
     361   mHighlightMaterial = OSG::NullFC; 
     362 
     363   vrj::OpenSGApp::exit(); 
    334364} 
    335365 
     
    371401} 
    372402 
    373 OpenSGNavGrab::GrabObject* OpenSGNavGrab::makeGrabbable(OSG::NodePtr model, 
    374                                                         const OSG::Matrix& modelPos) 
    375 
    376    OSG::TransformPtr model_xform_core = OSG::Transform::create(); 
    377    OSG::beginEditCP(model_xform_core, OSG::Transform::MatrixFieldMask); 
    378       model_xform_core->setMatrix(modelPos); 
    379    OSG::endEditCP(model_xform_core, OSG::Transform::MatrixFieldMask); 
    380  
    381    OSG::NodePtr model_xform_node = OSG::Node::create(); 
    382    OSG::beginEditCP(model_xform_node); 
    383       model_xform_node->setCore(model_xform_core); 
    384       model_xform_node->addChild(model); 
    385    OSG::endEditCP(model_xform_node); 
    386  
    387    OSG::beginEditCP(mModelRoot, OSG::Node::ChildrenFieldMask); 
    388       mModelRoot->addChild(model_xform_node); 
    389    OSG::endEditCP(mModelRoot, OSG::Node::ChildrenFieldMask); 
    390  
    391    return new GrabObject(model_xform_node, model_xform_core, modelPos); 
     403OpenSGNavGrab::GrabObjectPtr 
     404OpenSGNavGrab::makeGrabbable(OSG::NodeRefPtr model, 
     405                             const OSG::Matrix& modelPos) 
     406
     407   OSG::TransformNodePtr model_xform_node = OSG::TransformNodePtr::create(); 
     408 
     409#if OSG_MAJOR_VERSION < 2 
     410   OSG::TransformPtr core = model_xform_node; 
     411   CPEdit(core, OSG::Transform::MatrixFieldMask); 
     412   OSG::CPEditor e(model_xform_node.node(), 
     413                   OSG::Node::CoreFieldMask | OSG::Node::ChildrenFieldMask); 
     414   CPEdit(mModelRoot, OSG::Node::ChildrenFieldMask); 
     415#endif 
     416 
     417   model_xform_node->setMatrix(modelPos); 
     418   model_xform_node.node()->addChild(model); 
     419 
     420   mModelRoot->addChild(model_xform_node.node()); 
     421 
     422   return GrabObject::create(model_xform_node, modelPos); 
    392423} 
    393424 
     
    416447   // Only perform the intersection testing when we are not already grabbing 
    417448   // an object. 
    418    if ( mGrabbedObj == NULL ) 
    419    { 
    420       GrabObject* intersect_obj(NULL)
     449   if ( mGrabbedObj.get() == NULL ) 
     450   { 
     451      GrabObjectPtr intersect_obj
    421452 
    422453      // Find the first object--if any--in mObjects with which the wand 
    423454      // intersects. 
    424       for ( std::vector<GrabObject*>::iterator o = mObjects.begin(); 
    425             o != mObjects.end(); 
    426             ++o ) 
     455      typedef std::vector<GrabObjectPtr>::iterator iter_type; 
     456      for ( iter_type o = mObjects.begin(); o != mObjects.end(); ++o ) 
    427457      { 
    428          const OSG::DynamicVolume& bbox = (*o)->xformNode->getVolume(); 
     458         const OSG::DynamicVolume& bbox = 
     459            (*o)->getXformNode().node()->getVolume(); 
    429460 
    430461         if ( bbox.intersect(wand_point) ) 
     
    441472         // If mIntersectedObj was not NULL, then we need to remove the 
    442473         // bounding box rendering that is now out of date. 
    443          if ( mIntersectedObj != NULL ) 
     474         if ( mIntersectedObj.get() != NULL ) 
    444475         { 
    445             OSG::beginEditCP(mIntersectedObj->xformNode, 
    446                              OSG::Node::ChildrenFieldMask); 
    447                mIntersectedObj->xformNode->subChild(mHighlightNode); 
    448             OSG::endEditCP(mIntersectedObj->xformNode, 
    449                            OSG::Node::ChildrenFieldMask); 
     476#if OSG_MAJOR_VERSION < 2 
     477            OSG::CPEditor e(mIntersectedObj->getXformNode().node(), 
     478                            OSG::Node::ChildrenFieldMask); 
     479#endif 
     480            mIntersectedObj->getXformNode().node()->subChild(mHighlightNode); 
    450481         } 
    451482 
     
    454485         // If mIntersectedObj is non-NULL, we have selected a new object. 
    455486         // Create a new bounding box around that object. 
    456          if ( mIntersectedObj != NULL ) 
     487         if ( mIntersectedObj.get() != NULL ) 
    457488         { 
    458             mHighlight = mIntersectedObj->xformNode->getChild(0); 
     489            mHighlight = mIntersectedObj->getXformNode().node()->getChild(0); 
     490 
     491#if OSG_MAJOR_VERSION < 2 
     492            CPEdit(mHighlightMaterial, OSG::SimpleMaterial::DiffuseFieldMask); 
     493            OSG::CPEditor e(mIntersectedObj->getXformNode().node(), 
     494                            OSG::Node::ChildrenFieldMask); 
     495#endif 
    459496 
    460497            // Set the highlight color to mIntersectColor. 
    461             OSG::beginEditCP(mHighlightMaterial, 
    462                              OSG::SimpleMaterial::DiffuseFieldMask); 
    463                mHighlightMaterial->setDiffuse(mIntersectColor); 
    464             OSG::endEditCP(mHighlightMaterial, 
    465                            OSG::SimpleMaterial::DiffuseFieldMask); 
    466  
    467             OSG::beginEditCP(mIntersectedObj->xformNode, 
    468                              OSG::Node::ChildrenFieldMask); 
    469                mIntersectedObj->xformNode->addChild(mHighlightNode); 
    470             OSG::endEditCP(mIntersectedObj->xformNode, 
    471                            OSG::Node::ChildrenFieldMask); 
     498            mHighlightMaterial->setDiffuse(mIntersectColor); 
     499 
     500            mIntersectedObj->getXformNode().node()->addChild(mHighlightNode); 
     501 
    472502            updateHighlight(); 
    473503         } 
     
    477507   // Enable grabbing only when no other object is currently grabbed, when 
    478508   // the wand button is intersecting an object, and when button 0 is pressed. 
    479    if ( mIntersectedObj != NULL && mGrabbedObj == NULL && 
     509   if ( mIntersectedObj.get() != NULL && mGrabbedObj.get() == NULL && 
    480510        mButton0->getData() == gadget::Digital::ON ) 
    481511   { 
    482512      mGrabbedObj = mIntersectedObj; 
    483513 
     514#if OSG_MAJOR_VERSION < 2 
     515      CPEdit(mHighlightMaterial, OSG::SimpleMaterial::DiffuseFieldMask); 
     516#endif 
     517 
    484518      // Set the highlight color to mGrabColor. 
    485       OSG::beginEditCP(mHighlightMaterial, 
    486                        OSG::SimpleMaterial::DiffuseFieldMask); 
    487          mHighlightMaterial->setDiffuse(mGrabColor); 
    488       OSG::endEditCP(mHighlightMaterial, 
    489                      OSG::SimpleMaterial::DiffuseFieldMask); 
     519      mHighlightMaterial->setDiffuse(mGrabColor); 
    490520   } 
    491521   // We cannot be grabbing anything unless button 0 is pressed. 
     
    494524      // If we are dropping a grabbed object, then set the highlight color 
    495525      // back to mIntersectColor. 
    496       if ( mGrabbedObj != NULL ) 
     526      if ( mGrabbedObj.get() != NULL ) 
    497527      { 
    498          OSG::beginEditCP(mHighlightMaterial, 
    499                           OSG::SimpleMaterial::DiffuseFieldMask); 
    500             mHighlightMaterial->setDiffuse(mIntersectColor); 
    501          OSG::endEditCP(mHighlightMaterial, 
    502                         OSG::SimpleMaterial::DiffuseFieldMask); 
     528#if OSG_MAJOR_VERSION < 2 
     529      CPEdit(mHighlightMaterial, OSG::SimpleMaterial::DiffuseFieldMask); 
     530#endif 
     531 
     532         mHighlightMaterial->setDiffuse(mIntersectColor); 
    503533      } 
    504534 
    505       mGrabbedObj = NULL
     535      mGrabbedObj = GrabObjectPtr()
    506536   } 
    507537 
    508538   // If mGrabbedObj is non-NULL, then we are grabbing the object pointed at 
    509539   // by mGrabbedObj. 
    510    if ( mGrabbedObj != NULL ) 
    511    { 
    512       OSG::beginEditCP(mGrabbedObj->xformCore, OSG::Transform::MatrixFieldMask); 
    513          mGrabbedObj->xformCore->getMatrix().setTranslate(wand_point); 
    514       OSG::endEditCP(mGrabbedObj->xformCore, OSG::Transform::MatrixFieldMask); 
     540   if ( mGrabbedObj.get() != NULL ) 
     541   { 
     542#if OSG_MAJOR_VERSION < 2 
     543      OSG::TransformPtr core = mGrabbedObj->getXformNode(); 
     544      CPEdit(core, OSG::Transform::MatrixFieldMask); 
     545      mGrabbedObj->getXformNode()->getMatrix().setTranslate(wand_point); 
     546#else 
     547      mGrabbedObj->getXformNode()->editMatrix().setTranslate(wand_point); 
     548#endif 
    515549   } 
    516550} 
     
    527561   trans_mat.setTranslate(trans[0], trans[1], trans[2]); 
    528562 
    529    OSG::beginEditCP(mSceneTransform, OSG::Transform::MatrixFieldMask); 
    530       mSceneTransform->getMatrix().multLeft(trans_mat); 
    531    OSG::endEditCP(mSceneTransform, OSG::Transform::MatrixFieldMask); 
     563#if OSG_MAJOR_VERSION < 2 
     564   CPEdit(mSceneTransform, OSG::Transform::MatrixFieldMask); 
     565   mSceneTransform->getMatrix().multLeft(trans_mat); 
     566#else 
     567   mSceneTransform->editMatrix().multLeft(trans_mat); 
     568#endif 
    532569} 
    533570 
     
    540577      mHighlightMaterial = OSG::SimpleMaterial::create(); 
    541578 
    542       OSG::beginEditCP(mHighlightMaterial); 
    543          mHighlightMaterial->setLit(false); 
    544       OSG::endEditCP(mHighlightMaterial); 
     579#if OSG_MAJOR_VERSION < 2 
     580      CPEdit(mHighlightMaterial, OSG::SimpleMaterial::LitFieldMask); 
     581#endif 
     582 
     583      mHighlightMaterial->setLit(false); 
    545584   } 
    546585 
    547586   if ( mHighlightNode == OSG::NullFC ) 
    548587   { 
    549       OSG::GeoPTypesPtr type = OSG::GeoPTypesUI8::create(); 
    550       OSG::beginEditCP(type); 
    551          type->push_back(GL_LINE_STRIP); 
    552          type->push_back(GL_LINES); 
    553       OSG::endEditCP(type); 
    554  
    555       OSG::GeoPLengthsPtr lens = OSG::GeoPLengthsUI32::create(); 
    556       OSG::beginEditCP(lens); 
    557          lens->push_back(10); 
    558          lens->push_back(6); 
    559       OSG::endEditCP(lens); 
    560  
     588#if OSG_MAJOR_VERSION < 2 
     589      OSG::GeoPTypesPtr type       = OSG::GeoPTypesUI8::create(); 
     590      OSG::GeoPLengthsPtr lens     = OSG::GeoPLengthsUI32::create(); 
     591#else 
     592      OSG::GeoPTypesUI8Ptr type    = OSG::GeoPTypesUI8::create(); 
     593      OSG::GeoPLengthsUI32Ptr lens = OSG::GeoPLengthsUI32::create(); 
     594#endif 
    561595      OSG::GeoIndicesUI32Ptr index = OSG::GeoIndicesUI32::create(); 
    562       OSG::beginEditCP(index); 
    563          index->getFieldPtr()->push_back(0); 
    564          index->getFieldPtr()->push_back(1); 
    565          index->getFieldPtr()->push_back(3); 
    566          index->getFieldPtr()->push_back(2); 
    567          index->getFieldPtr()->push_back(0); 
    568          index->getFieldPtr()->push_back(4); 
    569          index->getFieldPtr()->push_back(5); 
    570          index->getFieldPtr()->push_back(7); 
    571          index->getFieldPtr()->push_back(6); 
    572          index->getFieldPtr()->push_back(4); 
    573  
    574          index->getFieldPtr()->push_back(1); 
    575          index->getFieldPtr()->push_back(5); 
    576          index->getFieldPtr()->push_back(2); 
    577          index->getFieldPtr()->push_back(6); 
    578          index->getFieldPtr()->push_back(3); 
    579          index->getFieldPtr()->push_back(7); 
    580       OSG::endEditCP(index); 
    581  
    582       mHighlightPoints = OSG::GeoPositions3f::create(); 
    583       OSG::beginEditCP(mHighlightPoints); 
    584          mHighlightPoints->push_back(OSG::Pnt3f(-1, -1, -1)); 
    585          mHighlightPoints->push_back(OSG::Pnt3f( 1, -1, -1)); 
    586          mHighlightPoints->push_back(OSG::Pnt3f(-1,  1, -1)); 
    587          mHighlightPoints->push_back(OSG::Pnt3f( 1,  1, -1)); 
    588          mHighlightPoints->push_back(OSG::Pnt3f(-1, -1,  1)); 
    589          mHighlightPoints->push_back(OSG::Pnt3f( 1, -1,  1)); 
    590          mHighlightPoints->push_back(OSG::Pnt3f(-1,  1,  1)); 
    591          mHighlightPoints->push_back(OSG::Pnt3f( 1,  1,  1)); 
    592       OSG::endEditCP(mHighlightPoints); 
    593  
    594       OSG::GeometryPtr geo = OSG::Geometry::create(); 
    595       OSG::beginEditCP(geo); 
    596          geo->setTypes(type); 
    597          geo->setLengths(lens); 
    598          geo->setIndices(index); 
    599          geo->setPositions(mHighlightPoints); 
    600          geo->setMaterial(mHighlightMaterial); 
    601       OSG::endEditCP(geo); 
    602       OSG::addRefCP(geo); 
    603  
    604       mHighlightNode = OSG::Node::create(); 
    605       OSG::beginEditCP(mHighlightNode); 
    606          mHighlightNode->setCore(geo); 
    607       OSG::endEditCP(mHighlightNode); 
    608       OSG::addRefCP(mHighlightNode); 
     596      mHighlightPoints             = OSG::GeoPositions3f::create(); 
     597      OSG::GeometryPtr geo         = OSG::Geometry::create(); 
     598      mHighlightNode               = OSG::Node::create(); 
     599 
     600#if OSG_MAJOR_VERSION < 2 
     601      CPEditAll(type); 
     602      CPEditAll(lens); 
     603      CPEditAll(index); 
     604      CPEditAll(mHighlightPoints); 
     605      CPEditAll(geo); 
     606      CPEdit(mHighlightNode, OSG::Node::CoreFieldMask); 
     607#endif 
     608 
     609      type->push_back(GL_LINE_STRIP); 
     610      type->push_back(GL_LINES); 
     611 
     612      lens->push_back(10); 
     613      lens->push_back(6); 
     614 
     615#if OSG_MAJOR_VERSION < 2 
     616      OSG::GeoIndicesUI32::StoredFieldType* index_field = 
     617         index->getFieldPtr(); 
     618#else 
     619      OSG::GeoIndicesUI32::StoredFieldType* index_field = 
     620         index->editFieldPtr(); 
     621#endif 
     622 
     623      index_field->push_back(0); 
     624      index_field->push_back(1); 
     625      index_field->push_back(3); 
     626      index_field->push_back(2); 
     627      index_field->push_back(0); 
     628      index_field->push_back(4); 
     629      index_field->push_back(5); 
     630      index_field->push_back(7); 
     631      index_field->push_back(6); 
     632      index_field->push_back(4); 
     633 
     634      index_field->push_back(1); 
     635      index_field->push_back(5); 
     636      index_field->push_back(2); 
     637      index_field->push_back(6); 
     638      index_field->push_back(3); 
     639      index_field->push_back(7); 
     640 
     641      mHighlightPoints->push_back(OSG::Pnt3f(-1, -1, -1)); 
     642      mHighlightPoints->push_back(OSG::Pnt3f( 1, -1, -1)); 
     643      mHighlightPoints->push_back(OSG::Pnt3f(-1,  1, -1)); 
     644      mHighlightPoints->push_back(OSG::Pnt3f( 1,  1, -1)); 
     645      mHighlightPoints->push_back(OSG::Pnt3f(-1, -1,  1)); 
     646      mHighlightPoints->push_back(OSG::Pnt3f( 1, -1,  1)); 
     647      mHighlightPoints->push_back(OSG::Pnt3f(-1,  1,  1)); 
     648      mHighlightPoints->push_back(OSG::Pnt3f( 1,  1,  1)); 
     649 
     650      geo->setTypes(type); 
     651      geo->setLengths(lens); 
     652      geo->setIndices(index); 
     653      geo->setPositions(mHighlightPoints); 
     654      geo->setMaterial(mHighlightMaterial); 
     655 
     656      mHighlightNode->setCore(geo); 
    609657   } 
    610658} 
     
    624672   vol.getBounds(min, max); 
    625673 
    626    OSG::beginEditCP(mHighlightPoints); 
    627       mHighlightPoints->setValue(OSG::Pnt3f(min[0], min[1], min[2]), 0); 
    628       mHighlightPoints->setValue(OSG::Pnt3f(max[0], min[1], min[2]), 1); 
    629       mHighlightPoints->setValue(OSG::Pnt3f(min[0], max[1], min[2]), 2); 
    630       mHighlightPoints->setValue(OSG::Pnt3f(max[0], max[1], min[2]), 3); 
    631       mHighlightPoints->setValue(OSG::Pnt3f(min[0], min[1], max[2]), 4); 
    632       mHighlightPoints->setValue(OSG::Pnt3f(max[0], min[1], max[2]), 5); 
    633       mHighlightPoints->setValue(OSG::Pnt3f(min[0], max[1], max[2]), 6); 
    634       mHighlightPoints->setValue(OSG::Pnt3f(max[0], max[1], max[2]), 7); 
    635    OSG::endEditCP(mHighlightPoints); 
    636  
    637    OSG::beginEditCP(mHighlightNode->getCore(), 
    638                     OSG::Geometry::PositionsFieldMask); 
    639    OSG::endEditCP(mHighlightNode->getCore(), 
    640                   OSG::Geometry::PositionsFieldMask); 
    641 
     674#if OSG_MAJOR_VERSION < 2 
     675   CPEditAll(mHighlightPoints); 
     676   OSG::CPEditor e(mHighlightNode->getCore(), 
     677                   OSG::Geometry::PositionsFieldMask); 
     678#endif 
     679 
     680   mHighlightPoints->setValue(OSG::Pnt3f(min[0], min[1], min[2]), 0); 
     681   mHighlightPoints->setValue(OSG::Pnt3f(max[0], min[1], min[2]), 1); 
     682   mHighlightPoints->setValue(OSG::Pnt3f(min[0], max[1], min[2]), 2); 
     683   mHighlightPoints->setValue(OSG::Pnt3f(max[0], max[1], min[2]), 3); 
     684   mHighlightPoints->setValue(OSG::Pnt3f(min[0], min[1], max[2]), 4); 
     685   mHighlightPoints->setValue(OSG::Pnt3f(max[0], min[1], max[2]), 5); 
     686   mHighlightPoints->setValue(OSG::Pnt3f(min[0], max[1], max[2]), 6); 
     687   mHighlightPoints->setValue(OSG::Pnt3f(max[0], max[1], max[2]), 7); 
     688 
     689#if OSG_MAJOR_VERSION >= 2 
     690   OSG::commitChanges(); 
     691#endif 
     692
  • juggler/branches/2.0/modules/vrjuggler/samples/OpenSG/advanced/OpenSGNavGrab/OpenSGNavGrab.h

    r18676 r20217  
    3636#include <string> 
    3737#include <vector> 
    38  
    39 #include <OpenSG/OSGGeoPropPtrs.h> 
     38#include <boost/shared_ptr.hpp> 
     39 
    4040#include <OpenSG/OSGNode.h> 
    4141#include <OpenSG/OSGSimpleMaterial.h> 
    4242#include <OpenSG/OSGTransform.h> 
    4343#include <OpenSG/OSGGL.h> 
     44#if OSG_MAJOR_VERSION < 2 
     45#  include <OpenSG/OSGGeoPropPtrs.h> 
     46#else 
     47#  include <OpenSG/OSGTypedGeoVectorProperty.h> 
     48#endif 
    4449 
    4550#include <gmtl/Matrix.h> 
     
    103108   virtual void reset(); 
    104109 
     110   virtual void exit(); 
     111 
    105112private: 
    106    struct GrabObject 
    107    { 
    108       GrabObject(OSG::NodePtr node, OSG::TransformPtr xform, 
    109                  const OSG::Matrix& pos) 
    110          : xformNode(node) 
    111          , xformCore(xform) 
    112          , homePos(pos) 
     113   class GrabObject; 
     114   typedef boost::shared_ptr<GrabObject> GrabObjectPtr; 
     115 
     116   class GrabObject 
     117   { 
     118   public: 
     119      static GrabObjectPtr create(OSG::TransformNodePtr node, 
     120                                  const OSG::Matrix& pos) 
     121      { 
     122         return GrabObjectPtr(new GrabObject(node, pos)); 
     123      } 
     124 
     125      OSG::TransformNodePtr getXformNode() const 
     126      { 
     127         return mXformNode; 
     128      } 
     129 
     130      const OSG::Matrix& getHomePos() const 
     131      { 
     132         return mHomePos; 
     133      } 
     134 
     135   private: 
     136      GrabObject(OSG::TransformNodePtr node, const OSG::Matrix& pos) 
     137         : mXformNode(node) 
     138         , mHomePos(pos) 
    113139      { 
    114140         ; 
     
    116142 
    117143      /** The transform node (parent) for the grabbable object. */ 
    118       OSG::NodePtr xformNode; 
    119  
    120       /** The transform core for the grabbable object. */ 
    121       OSG::TransformPtr xformCore; 
     144      OSG::TransformNodePtr mXformNode; 
    122145 
    123146      /** 
     
    125148       * for resetting the scene. 
    126149       */ 
    127       const OSG::Matrix homePos; 
     150      const OSG::Matrix mHomePos; 
    128151   }; 
    129152 
     
    142165    *         caller to release the memory. 
    143166    */ 
    144    GrabObject* makeGrabbable(OSG::NodePtr model, const OSG::Matrix& modelPos); 
     167   GrabObjectPtr makeGrabbable(OSG::NodeRefPtr model, 
     168                               const OSG::Matrix& modelPos); 
    145169 
    146170   void updateGrabbing(const gmtl::Matrix44f& wandMatrix); 
     
    161185   //         | 
    162186   //   mModelRoot:[mModelGroup] 
    163    OSG::NodePtr        mSceneRoot;       /**< The root of the scene */ 
    164    OSG::TransformPtr  mSceneTransform;  /**< Transform core */ 
    165    OSG::NodePtr        mModelRoot;       /**< Root of the loaded model */ 
    166    OSG::GroupPtr       mModelGroup; 
    167  
    168    OSG::NodePtr mLightNode;       /**< Light node to use */ 
    169    OSG::NodePtr mLightBeacon;     /**< A beacon for the light */ 
     187   OSG::NodeRefPtr      mSceneRoot;       /**< The root of the scene */ 
     188   OSG::TransformRefPtr mSceneTransform;  /**< Transform core */ 
     189   OSG::NodeRefPtr      mModelRoot;       /**< Root of the loaded model */ 
     190   OSG::GroupRefPtr     mModelGroup; 
     191 
     192   OSG::NodeRefPtr mLightNode;       /**< Light node to use */ 
     193   OSG::NodeRefPtr mLightBeacon;     /**< A beacon for the light */ 
    170194 
    171195   gadget::PositionInterface  mWandPos;     /**< The position of the wand */ 
     
    178202   /** @name Grabbed object management */ 
    179203   //@{ 
    180    std::vector<GrabObject*> mObjects; 
    181    GrabObject*              mIntersectedObj; 
    182    GrabObject*              mGrabbedObj; 
     204   std::vector<GrabObjectPtr> mObjects; 
     205   GrabObjectPtr              mIntersectedObj; 
     206   GrabObjectPtr              mGrabbedObj; 
    183207   //@} 
    184208 
    185209   /** @name Highlight node management */ 
    186210   //@{ 
    187    OSG::Color3f           mIntersectColor; 
    188    OSG::Color3f           mGrabColor; 
    189  
    190    OSG::NodePtr           mHighlight;        /**< The node to highlight */ 
    191    OSG::NodePtr           mHighlightNode;    /**< The highlight node */ 
    192    OSG::GeoPositions3fPtr mHighlightPoints; /**< Points for mHighlightNode */ 
    193  
    194    OSG::SimpleMaterialPtr mHighlightMaterial; 
     211   OSG::Color3f              mIntersectColor; 
     212   OSG::Color3f              mGrabColor; 
     213 
     214   OSG::NodeRefPtr           mHighlight;       /**< The node to highlight */ 
     215   OSG::NodeRefPtr           mHighlightNode;   /**< The highlight node */ 
     216   OSG::GeoPositions3fPtr    mHighlightPoints; /**< Points for mHighlightNode */ 
     217 
     218   OSG::SimpleMaterialRefPtr mHighlightMaterial; 
    195219   //@} 
    196220}; 
  • juggler/branches/2.0/modules/vrjuggler/samples/OpenSG/simple/OpenSGNav/Makefile.in

    r16525 r20217  
    4949OPENSG_LIBS=    $(shell osg-config --libs) -lOSGBase -lOSGSystem 
    5050OPENSG_CFLAGS=  $(shell osg-config --cflags) 
     51#OPENSG_LIBS=   $(shell osg2-config OSGFileIO OSGWindow OSGRenderTraversal --libs) 
     52#OPENSG_CFLAGS= $(shell osg2-config OSGFileIO OSGWindow OSGRenderTraversal --cflags) 
    5153 
    5254EXTRA_CXXFLAGS+=        $(OPENSG_CFLAGS) 
  • juggler/branches/2.0/modules/vrjuggler/samples/OpenSG/simple/OpenSGNav/OpenSGNav.cpp

    r18676 r20217  
    117117   trans_mat.setTranslate(trans[0], trans[1], trans[2]); 
    118118 
    119    OSG::beginEditCP(mSceneTransform); 
    120       mSceneTransform->getMatrix().multLeft(trans_mat); 
    121    OSG::endEditCP(mSceneTransform); 
     119#if OSG_MAJOR_VERSION < 2 
     120   CPEdit(mSceneTransform, OSG::Transform::MatrixFieldMask); 
     121   mSceneTransform->getMatrix().multLeft(trans_mat); 
     122#else 
     123   mSceneTransform->editMatrix().multLeft(trans_mat); 
     124#endif 
     125 
     126   vrj::OpenSGApp::preFrame(); 
     127
     128 
     129void OpenSGNav::exit() 
     130
     131   // Ensure that we release all the OSG::RefPtr<T> objects that we hold so 
     132   // that OpenSG can shut down cleanly. 
     133   mSceneRoot      = OSG::NullFC; 
     134   mSceneTransform = OSG::NullFC; 
     135   mModelRoot      = OSG::NullFC; 
     136   mLightNode      = OSG::NullFC; 
     137   mLightBeacon    = OSG::NullFC; 
     138 
     139   vrj::OpenSGApp::exit(); 
    122140} 
    123141 
     
    188206         << "[OpenSGNav::initScene()] Loading '" << mFileToLoad << "' ..." 
    189207         << std::endl << vprDEBUG_FLUSH; 
    190       mModelRoot = 
    191          OSG::SceneFileHandler::the().read((OSG::Char8*) (mFileToLoad.c_str())); 
     208      const OSG::Char8* file = mFileToLoad.c_str(); 
     209#if OSG_MAJOR_VERSION < 2 
     210      mModelRoot = OSG::SceneFileHandler::the().read(file); 
     211#else 
     212      mModelRoot = OSG::SceneFileHandler::the()->read(file); 
     213#endif 
    192214   } 
    193215 
     
    204226   light_pos.setTransform(OSG::Vec3f(2.0f, 5.0f, 4.0f)); 
    205227 
    206    OSG::beginEditCP(light_beacon_core, OSG::Transform::MatrixFieldMask); 
    207       light_beacon_core->setMatrix(light_pos); 
    208    OSG::endEditCP(light_beacon_core, OSG::Transform::MatrixFieldMask); 
    209  
    210    OSG::beginEditCP(mLightBeacon); 
    211       mLightBeacon->setCore(light_beacon_core); 
    212    OSG::endEditCP(mLightBeacon); 
     228#if OSG_MAJOR_VERSION < 2 
     229   CPEdit(light_beacon_core, OSG::Transform::MatrixFieldMask); 
     230   CPEdit(mLightBeacon, OSG::Node::CoreFieldMask); 
     231   CPEdit(mLightNode, OSG::Node::CoreFieldMask | OSG::Node::ChildrenFieldMask); 
     232   CPEditAll(light_core); 
     233   CPEdit(mSceneRoot, OSG::Node::CoreFieldMask | OSG::Node::ChildrenFieldMask); 
     234#endif 
     235 
     236   light_beacon_core->setMatrix(light_pos); 
     237 
     238   mLightBeacon->setCore(light_beacon_core); 
    213239 
    214240   // Setup light node 
    215    OSG::addRefCP(mLightNode); 
    216    OSG::beginEditCP(mLightNode); 
    217       mLightNode->setCore(light_core); 
    218       mLightNode->addChild(mLightBeacon); 
    219    OSG::endEditCP(mLightNode); 
    220  
    221    OSG::beginEditCP(light_core); 
    222       light_core->setAmbient   (0.9, 0.8, 0.8, 1); 
    223       light_core->setDiffuse   (0.6, 0.6, 0.6, 1); 
    224       light_core->setSpecular  (1, 1, 1, 1); 
    225       light_core->setDirection (0, 0, 1); 
    226       light_core->setBeacon    (mLightNode); 
    227    OSG::endEditCP(light_core); 
     241   mLightNode->setCore(light_core); 
     242   mLightNode->addChild(mLightBeacon); 
     243 
     244   light_core->setAmbient  (0.9, 0.8, 0.8, 1); 
     245   light_core->setDiffuse  (0.6, 0.6, 0.6, 1); 
     246   light_core->setSpecular (1, 1, 1, 1); 
     247   light_core->setDirection(0, 0, 1); 
     248   light_core->setBeacon   (mLightNode); 
    228249 
    229250   // --- Setup Scene -- // 
    230251   // add the loaded scene to the light node, so that it is lit by the light 
    231    OSG::addRefCP(mModelRoot); 
    232    OSG::beginEditCP(mLightNode); 
    233       mLightNode->addChild(mModelRoot); 
    234    OSG::endEditCP(mLightNode); 
     252   mLightNode->addChild(mModelRoot); 
    235253 
    236254   // create the root part of the scene 
     
    239257 
    240258   // Set up the root node 
    241    OSG::beginEditCP(mSceneRoot); 
    242       mSceneRoot->setCore(mSceneTransform); 
    243       mSceneRoot->addChild(mLightNode); 
    244    OSG::endEditCP(mSceneRoot); 
    245 
     259   mSceneRoot->setCore(mSceneTransform); 
     260   mSceneRoot->addChild(mLightNode); 
     261
  • juggler/branches/2.0/modules/vrjuggler/samples/OpenSG/simple/OpenSGNav/OpenSGNav.h

    r18676 r20217  
    101101   } 
    102102 
     103   virtual void exit(); 
     104 
    103105   void setModelFileName(std::string filename) 
    104106   { 
     
    121123   //         | 
    122124   //     mModelRoot 
    123    OSG::NodePtr        mSceneRoot;       /**< The root of the scene */ 
    124    OSG::TransformPtr   mSceneTransform;  /**< Transform core */ 
    125    OSG::NodePtr        mModelRoot;       /**< Root of the loaded model */ 
     125   OSG::NodeRefPtr        mSceneRoot;       /**< The root of the scene */ 
     126   OSG::TransformRefPtr   mSceneTransform;  /**< Transform core */ 
     127   OSG::NodeRefPtr        mModelRoot;       /**< Root of the loaded model */ 
    126128 
    127    OSG::NodePtr  mLightNode;       /**< Light node to use */ 
    128    OSG::NodePtr  mLightBeacon;     /**< A beacon for the light */ 
     129   OSG::NodeRefPtr  mLightNode;       /**< Light node to use */ 
     130   OSG::NodeRefPtr  mLightBeacon;     /**< A beacon for the light */ 
    129131 
    130132public: