Changeset 329 for experimental
- Timestamp:
- Mar 3, 2012, 1:22:05 AM (13 years ago)
- Location:
- experimental/distortionNG
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
experimental/distortionNG/distortionNG.cpp
r313 r329 27 27 _highlighter->setUseDisplayList( false ); 28 28 _highlighter->setUseVertexBufferObjects( true ); 29 _highlighter->setVertexArray( new osg::Vec3Array(1) ); 29 _highlighter->setVertexArray( new osg::Vec3Array(1) ); // The highlighter vertex is updated by computeSelectedVertex(..) 30 30 _highlighter->setColorArray( colors.get() ); 31 31 _highlighter->setColorBinding( osg::Geometry::BIND_OVERALL ); … … 54 54 osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY()); 55 55 osgUtil::IntersectionVisitor iv( intersector.get() ); 56 viewer->getCamera()->accept( iv ); 56 //viewer->getCamera()->accept( iv ); 57 _camera->accept( iv ); 57 58 58 59 if ( intersector->containsIntersections() ) … … 93 94 if ( !vertices || !selVertices ) 94 95 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; 95 99 96 100 osg::Vec3 point = result.getWorldIntersectPoint(); 97 101 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; 99 103 const std::vector<unsigned int>& selIndices = result.indexList; 100 104 { 101 105 double maxRatio = 0.0; 102 106 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 104 108 { 105 109 if(result.ratioList[i] > maxRatio) … … 108 112 closestVertexIndex = result.indexList[i]; 109 113 } 114 OSG_NOTIFY(osg::ALWAYS)<<"maxRatio="<<maxRatio<<std::endl; 115 OSG_NOTIFY(osg::ALWAYS)<<"closestVertexIndex="<<closestVertexIndex<<std::endl; 110 116 } 117 OSG_NOTIFY(osg::ALWAYS)<<"nearest vertex: X="<<(*vertices)[closestVertexIndex].x()<<" Y="<<(*vertices)[closestVertexIndex].y()<<" Z="<<(*vertices)[closestVertexIndex].z()<<std::endl; 111 118 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; 113 122 } 114 115 123 selVertices->dirty(); 116 124 _highlighter->dirtyBound(); -
experimental/distortionNG/distortionNG.h
r313 r329 16 16 17 17 public: 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) ) {} 20 20 21 21 void computeSelectedVertex( osgUtil::LineSegmentIntersector::Intersection& result ); … … 27 27 osg::ref_ptr<osg::Geometry> _highlighter; 28 28 osg::observer_ptr<osg::Camera> _camera; 29 osg::Geometry* _distortionMesh; 29 30 const osg::Vec4 _highlightColor; 30 31 }; -
experimental/distortionNG/extViewer.cpp
r328 r329 1 1 #include "extViewer.h" 2 2 #include "distortionNG.h" 3 4 #include <osg/PolygonOffset> 3 5 #include<osg/Texture2D> 4 6 #include<osg/TextureRectangle> … … 131 133 osg::Geode* geode = new osg::Geode(); 132 134 //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); 134 137 135 138 // new we need to add the texture to the mesh, we do so by creating a … … 165 168 166 169 // 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 168 185 169 186 camera->setName("Dist Cam"); -
experimental/distortionNG/main.cpp
r327 r329 119 119 //root->addChild( geode.get() ); 120 120 //root->addChild( selector->createVertexHighlighter() ); 121 122 121 //viewer.addEventHandler( selector.get() ); 123 122 //viewer.setSceneData( root.get() ); 124 123 125 // //Avoid that the highlighter is culled away124 // Avoid that the highlighter is culled away 126 125 //osg::CullSettings::CullingMode mode = viewer.getCamera()->getCullingMode(); 127 126 //viewer.getCamera()->setCullingMode( mode & (~osg::CullSettings::SMALL_FEATURE_CULLING) ); … … 130 129 return viewer.run(); 131 130 } 131 132 /* 133 ToDo: 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.