Changeset 329


Ignore:
Timestamp:
Mar 3, 2012, 1:22:05 AM (13 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/distortionNG.cpp

    r313 r329  
    2727        _highlighter->setUseDisplayList( false );
    2828        _highlighter->setUseVertexBufferObjects( true );
    29         _highlighter->setVertexArray( new osg::Vec3Array(1) );
     29        _highlighter->setVertexArray( new osg::Vec3Array(1) );  // The highlighter vertex is updated by computeSelectedVertex(..)
    3030        _highlighter->setColorArray( colors.get() );
    3131        _highlighter->setColorBinding( osg::Geometry::BIND_OVERALL );
     
    5454                        osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY());
    5555                        osgUtil::IntersectionVisitor iv( intersector.get() );
    56                         viewer->getCamera()->accept( iv );
     56                        //viewer->getCamera()->accept( iv );
     57                        _camera->accept( iv );
    5758               
    5859                        if ( intersector->containsIntersections() )
     
    9394        if ( !vertices || !selVertices )
    9495                return;
     96       
     97        OSG_NOTIFY(osg::ALWAYS)<<"size of vertices="<<vertices->size()<<std::endl;
     98        OSG_NOTIFY(osg::ALWAYS)<<"size of selVertices="<<selVertices->size()<<std::endl;
    9599
    96100        osg::Vec3 point = result.getWorldIntersectPoint();
    97101        osg::Matrix matrix = osg::computeLocalToWorld( result.nodePath );       // To compute the intersection vertices in world coordinates not in model coordinates
    98         //std::cout << "Intersection-indices: Size=" << result.indexList.size() << std::endl;
     102        OSG_NOTIFY(osg::ALWAYS) << "Intersection-indices: Size=" << result.indexList.size() << std::endl;
    99103        const std::vector<unsigned int>& selIndices = result.indexList;
    100104        {
    101105                double maxRatio = 0.0;
    102106                int closestVertexIndex = 0;
    103                 for ( unsigned int i=0; i<3 && i<result.ratioList.size(); i++ ) //iterate through rations and search for max
     107                for ( unsigned int i=0; i<3 && i<result.ratioList.size(); i++ ) //iterate through rations and search for maxRation=nearestVertex
    104108                {
    105109                        if(result.ratioList[i] > maxRatio)
     
    108112                                closestVertexIndex = result.indexList[i];
    109113                        }
     114                        OSG_NOTIFY(osg::ALWAYS)<<"maxRatio="<<maxRatio<<std::endl;
     115                        OSG_NOTIFY(osg::ALWAYS)<<"closestVertexIndex="<<closestVertexIndex<<std::endl;
    110116                }
     117                OSG_NOTIFY(osg::ALWAYS)<<"nearest vertex: X="<<(*vertices)[closestVertexIndex].x()<<" Y="<<(*vertices)[closestVertexIndex].y()<<" Z="<<(*vertices)[closestVertexIndex].z()<<std::endl;
    111118                osg::Vec3 vertex = (*vertices)[closestVertexIndex] * matrix;
    112                 selVertices->front() = vertex;
     119
     120                selVertices->front() = vertex;         
     121                OSG_NOTIFY(osg::ALWAYS)<<"selected vertice: X="<<vertex.x()<<" Y="<<vertex.y()<<" Z="<<vertex.z()<<std::endl;
    113122        }
    114 
    115123        selVertices->dirty();
    116124        _highlighter->dirtyBound();
  • experimental/distortionNG/distortionNG.h

    r313 r329  
    1616
    1717public:
    18         distortionHandler( osg::Camera* camera )
    19     : _highlighter(0), _camera(camera), _highlightColor( osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f) ) {}
     18        distortionHandler( osg::Camera* camera, osg::Geometry* distortionMesh )
     19    : _highlighter(0), _camera(camera), _distortionMesh(distortionMesh), _highlightColor( osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f) ) {}
    2020
    2121    void computeSelectedVertex( osgUtil::LineSegmentIntersector::Intersection& result );
     
    2727        osg::ref_ptr<osg::Geometry> _highlighter;
    2828    osg::observer_ptr<osg::Camera> _camera;
     29        osg::Geometry* _distortionMesh;
    2930        const osg::Vec4 _highlightColor;
    3031};
  • experimental/distortionNG/extViewer.cpp

    r328 r329  
    11#include "extViewer.h"
    2 
     2#include "distortionNG.h"
     3
     4#include <osg/PolygonOffset>
    35#include<osg/Texture2D>
    46#include<osg/TextureRectangle>
     
    131133        osg::Geode* geode = new osg::Geode();
    132134                //geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 1, 0.45, 0, projectorMatrix));
    133                 geode->addDrawable(createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, projectorMatrix));
     135                osg::Geometry* distortionMesh = createMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), 20, 20, projectorMatrix);
     136                geode->addDrawable(distortionMesh);
    134137
    135138        // new we need to add the texture to the mesh, we do so by creating a
     
    165168
    166169        // add subgraph to render
    167         camera->addChild(geode);
     170        //camera->addChild(geode);
     171
     172                // selector
     173                geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
     174                geode->getOrCreateStateSet()->setAttributeAndModes( new osg::PolygonOffset(1.0f, 1.0f) );
     175                osg::ref_ptr<distortionHandler> selector = new distortionHandler( camera, distortionMesh );
     176                osg::ref_ptr<osg::Group> root = new osg::Group;
     177                root->addChild(geode);
     178                root->addChild(selector->createVertexHighlighter());
     179                addEventHandler( selector.get() );
     180                camera->addChild(root);
     181                // Avoid that the highlighter is culled away
     182                osg::CullSettings::CullingMode mode = camera->getCullingMode();
     183                camera->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) );
     184
    168185
    169186        camera->setName("Dist Cam");
  • experimental/distortionNG/main.cpp

    r327 r329  
    119119        //root->addChild( geode.get() );
    120120        //root->addChild( selector->createVertexHighlighter() );
    121 
    122121        //viewer.addEventHandler( selector.get() );
    123122        //viewer.setSceneData( root.get() );
    124123
    125         //// Avoid that the highlighter is culled away
     124        // Avoid that the highlighter is culled away
    126125        //osg::CullSettings::CullingMode mode = viewer.getCamera()->getCullingMode();
    127126        //viewer.getCamera()->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) );
     
    130129        return viewer.run();
    131130}
     131
     132/*
     133ToDo:
     134 *
     135 * distortionHandler::handle startet Intersections. Da jedoch das distortion Mesh keine Geometry der Scene mehr ist, gibt es keine Intersection
     136 *  -> es muss die intersektion umgestellt werden, um das Distortion Mesh zu intersecten.
     137 * Es muss geprüft werdne, ob bei dne Mausverschiebungen die texturecoordinaten verschoben, oder das Distortion Mesh verschoben wird.
     138
     139
     140
     141
     142
     143*/
Note: See TracChangeset for help on using the changeset viewer.