Changeset 370 for experimental


Ignore:
Timestamp:
Jun 1, 2012, 6:11:26 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r367 r370  
    5151        sh->setName("shaderIntensityMapVis");
    5252        ds->setShaderIntensityMapVis( sh );
     53
     54        //LF Get Screen Resolution for Cursor Position Scaling
     55        osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
     56        if (!wsi) { osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; }
     57        wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), _screenPixWidth, _screenPixHeight);
     58
     59
    5360}
    5461
     
    7178bool DistortionManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv)
    7279{
     80
     81
    7382        switch(ea.getEventType())
    7483    {
     
    8796                                OSG_ALWAYS<<"ea.getYin()="<<ea.getYmin()<<std::endl;
    8897                                OSG_ALWAYS<<"ea.getYmax()="<<ea.getYmax()<<std::endl;
    89 
    90 
     98                               
     99                                //LF get X,Y normalized to lowerleftcorner (0,0) / upperrightcorner (1,1)
     100                                OSG_ALWAYS<<"getXnormalizedLF()="<<(ea.getXnormalized()+1.0)/2.0<<std::endl;
     101                                OSG_ALWAYS<<"getYnormalizedLF()="<<(ea.getYnormalized()+1.0)/2.0<<std::endl;
     102
     103                                //LF get X,Y in pixels (lowerleftcorner (0,0) / upperrightcorner (screenwidth,screenheigth)
     104                                OSG_ALWAYS<<std::endl<<"Screen Resolution: "<<_screenPixWidth<<" x "<<_screenPixHeight<<std::endl;
     105                                OSG_ALWAYS<<"getXPixelspaceLF()="<<(int)((float)_screenPixWidth*(ea.getXnormalized()+1.0)/2.0)<<std::endl;
     106                                OSG_ALWAYS<<"getYPixelspaceLF()="<<(int)((float)_screenPixHeight*(ea.getYnormalized()+1.0)/2.0)<<std::endl;
    91107
    92108                                if(activeDistortionMode == MESH)
     
    120136                                        if ( intersector->containsIntersections() )
    121137                                        {
    122                                                 osgUtil::LineSegmentIntersector::Intersection& result = *(intersector->getIntersections().begin());
    123                                                 computeSelectedVertex( result );
     138                                                //osgUtil::LineSegmentIntersector::Intersection& result = *(intersector->getIntersections().begin());
     139                                                osgUtil::LineSegmentIntersector::Intersection *result;
     140                                                result=&intersector->getFirstIntersection();
     141                                                computeSelectedVertex( *result );
     142                                                //computeSelectedVertex( result );
    124143                                        }
    125144                                }
     
    222241                                OSG_ALWAYS<<"KEY_KP_8 : todo: Save DistortionContainer"<<std::endl;
    223242
    224 
    225 
    226         // Configure Compression and instantiate read/write-options
    227         bool asAscii_ = true;
    228         bool compressionEnabled = false;
    229 
    230         std::string readOptionString = "";
    231         std::string writeOptionString = "";
    232         if(asAscii_)
    233         {
    234                 readOptionString = "Ascii";
    235                 writeOptionString = "Ascii";
    236         }
    237         if (compressionEnabled)
    238                 writeOptionString+=" Compressor=zlib";
    239        
    240         osg::ref_ptr<osgDB::Options> readOptions = new osgDB::Options( readOptionString.c_str() );
    241         osg::ref_ptr<osgDB::Options> writeOptions = new osgDB::Options( writeOptionString.c_str() );
    242 
    243         //// Get ReaderWriter
    244         //osg::ref_ptr<osgDB::ReaderWriter> rw = osgDB::Registry::instance()->getReaderWriterForExtension("osgb");     
    245 
    246         //// Writing node to stream
    247         //std::stringstream myOstream;
    248         //if ( rw )
    249         //{
    250         //      osgDB::ReaderWriter::WriteResult wr = rw->writeObject( *_distortionSet, myOstream, writeOptions );
    251         //      if (wr.success() )                     
    252         //      {
    253         //              OSG_ALWAYS<<"write node success"<<std::endl;
    254         //      }
    255         //      else
    256         //      {
    257         //              OSG_ALWAYS<<"write node failed"<<std::endl;
    258         //      }
    259         //}
    260 
    261         if( osgDB::writeObjectFile(*_distortionSet, "test.osgt", writeOptions) )
    262         {
    263                 OSG_ALWAYS<<"write node success"<<std::endl;
    264         }
    265         else
    266         {
    267                 OSG_ALWAYS<<"write node failed"<<std::endl;
    268         }
    269 
    270 
    271 
    272 
    273 
    274 
    275 
    276 
    277 
    278 
    279 
    280 
    281 
     243                                osgDB::writeObjectFile( *_distortionSet, "distortionset.dist" );
    282244                                return(true);
    283245                        }
     
    411373        stateSet->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    412374
     375        // Modify StateSet to protect it against state changes by the stateset Manipulator
     376        osg::PolygonMode* polyModeObj = new osg::PolygonMode;
     377    stateSet->setAttribute(polyModeObj, osg::StateAttribute::PROTECTED|osg::StateAttribute::ON);
     378
    413379        // Add Text:
    414380        osg::Vec3 position(20.0f,120.0f,0.0f);
     
    462428       
    463429        updateHUD();
    464         _distortionSet->getDistortionInternals()->addChild(geode, false);       //  = child #2  :definition: child #0 = mesh, #1 = highlighter, #2 HUD
     430        _distortionSet->getDistortionInternals()->addChild(geode, false);       //  = child #2. The definition is: child #0 = mesh, #1 = highlighter, #2 HUD
    465431}
    466432
  • experimental/distortionNG/DistortionManipulator.h

    r356 r370  
    9090        osg::Geometry* _distortionMesh;
    9191        const osg::Vec4 _highlightColor;
     92       
     93        //LF Screen Resolution
     94        unsigned int _screenPixWidth, _screenPixHeight;
     95       
    9296
    9397        // HUD
  • experimental/distortionNG/extViewer.cpp

    r362 r370  
    276276        stateset->setTextureAttributeAndModes(_distortionSet->getTexUnitScene(), sceneTexture,osg::StateAttribute::ON);
    277277        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    278                 // Modify StateSet to protectit agaiunst state changes by the stateset Manipulator
     278                // Modify StateSet to protectit against state changes by the stateset Manipulator
    279279                osg::PolygonMode* polyModeObj = new osg::PolygonMode;
    280280        stateset->setAttribute(polyModeObj, osg::StateAttribute::PROTECTED|osg::StateAttribute::ON);
  • experimental/distortionNG/main.cpp

    r369 r370  
    5858// ---- test plugin read / write
    5959
    60         //osgDB::writeObjectFile( *_distortionSet, "testcont.dist" );
     60        //osgDB::writeObjectFile( *_distortionSet, "distortionset.dist" );
    6161        _distortionSet = NULL;
    62         _distortionSet = dynamic_cast<osgViewer::DistortionSet*>( osgDB::readObjectFile( "testcont.dist" ) );
     62        _distortionSet = dynamic_cast<osgViewer::DistortionSet*>( osgDB::readObjectFile( "distortionset.dist" ) );
    6363               
    6464
     
    164164 *                                                                                                                                                                      Ensures the Coordinates are normalized before saving the container.
    165165 *                                                                              Load:
    166  *                                                                              * use serializer to load container
     166 *                                                      [done]          * use ReaderWriterOSG2 to load container
    167167 *                                                                              * invoke osgViewer::setUpViewForManualDistortion(distSet, screenNum, projectorMatrix) to set up distortion
    168168 *                                                                              Save:
    169169 *                                                                              * check if container is normalized. if not, copy and normalize container
    170  *                                                                              * use serializer to save container
     170 *                                                      [done]          * use ReaderWriterOSG2 to save container
    171171 * 
    172172 *
Note: See TracChangeset for help on using the changeset viewer.