#include "distortionNG.h" #include #include distortionNG::distortionNG() { } distortionNG::~distortionNG() { } osg::Geode* distortionHandler::createVertexHighlighter() { osg::ref_ptr colors = new osg::Vec4Array(1); (*colors)[0] = _highlightColor; _highlighter = new osg::Geometry; _highlighter->setDataVariance( osg::Object::DYNAMIC ); _highlighter->setUseDisplayList( false ); _highlighter->setUseVertexBufferObjects( true ); _highlighter->setVertexArray( new osg::Vec3Array(1) ); // The highlighter vertex is updated by computeSelectedVertex(..) _highlighter->setColorArray( colors.get() ); _highlighter->setColorBinding( osg::Geometry::BIND_OVERALL ); _highlighter->addPrimitiveSet( new osg::DrawArrays(GL_POINTS, 0, 1) ); osg::ref_ptr geode = new osg::Geode; geode->addDrawable( _highlighter.get() ); geode->getOrCreateStateSet()->setAttributeAndModes( new osg::Point(8.0f) ); geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); return geode.release(); } bool distortionHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) { // Only pressing CTRL activates distortion editing if ( !(ea.getModKeyMask()&osgGA::GUIEventAdapter::MODKEY_CTRL) ) return false; // False means not handled. if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH && ea.getButton() == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) { osgViewer::View* viewer = dynamic_cast(&aa); if ( viewer ) { osg::ref_ptr intersector = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), ea.getY()); osgUtil::IntersectionVisitor iv( intersector.get() ); //viewer->getCamera()->accept( iv ); _camera->accept( iv ); if ( intersector->containsIntersections() ) { osgUtil::LineSegmentIntersector::Intersection& result = *(intersector->getIntersections().begin()); computeSelectedVertex( result ); } } } if ( ea.getEventType() == osgGA::GUIEventAdapter::DRAG ) { osg::notify(osg::ALWAYS)<