Hi Sonya,

this method returns IDs. The IDs you are going to assign to anything that
is Pickable (Line, point, triangle mesh). And the result is returned after
rendering with the selection mode GL_SELECT.

The way how I did it, I can not recall the very details though since it is
like years ago, I was having two separate representation of my rendering
"primitive": one for fast drawing, and one for picking and somehow there
was an association between those two. And this can happen on the mouse
click (be careful here with, you should really take care of the rendering
states here yourself to push/pop correctly whatever you change to not
damage the osg states) or you do it with drawables in drawImplementation;

In your case with the grid of lines, I would have the grid as one GL_LINES
primitive for fast rendering, and single GL_LINE for selection.

Having the second method with drawables, maybe you inherit from
osg::Geometry and introduce a pickable Geometry with an ID. This ID has to
be set with glLoadName(ID) before the rendering of the geometry which has
to happen same way. At the beginning of the rendering you set the rendering
mode to glRenderMode(GL_SELECT) and you render the part of the graph with
the pickables (with node masks??) and restore after the render of the frame
to glRenderMode(GL_RENDER). And you have to set the projection matrix to
let say 2x2 pixels around the mouse click point.

This link maybe describe it better:
http://www.unknownroad.com/rtfm/graphics/glselection.html

All you have to do is to either inject rendering of a frame in when your
click happens or do it withing the OSG rendering framework. You have to
investigate this. Was tricky to do but this OpenGL approach is explained on
the web pretty well

Maybe I can help you with a code sample based on my free and boring time
:-). Do the homework first, understand how this selection method works in
OpenGL

Nick


On Sat, Jul 5, 2014 at 3:25 PM, Sonya Blade <[email protected]>
wrote:

> Hi Nick Thanks for the entrypoint,
>
> I usually get intimidated by the these tasks where you are supposed to
> deal
> both with raw OpenGL and OSG codes because you have to be fully familiar
> and
> grasp the terminology behind of them both.
>
> As a next step where am I supposed to place those integrated code portion
> which
> handles picking, into mousemove event handler or something else?
> As further step, picking will return something primitive, data set
> (vertices, normals , name of primitives)
> object, something but will it be known to the OSG-engine in terms of OSG
> arhcitectural terminology?
>
> Regards,
>
> ------------------------------
> Date: Sat, 5 Jul 2014 09:16:58 +0200
> From: [email protected]
> To: [email protected]
> Subject: Re: [osg-users] What is the Object picking criteria in OSG
>
>
> Hi Sonya,
>
> I faced the same challenge while back and was able to resolve it by using
> the OpenGL selection buffer. Here it is described how:
>
> http://www.opengl.org/archives/resources/faq/technical/selection.htm
>
> Nick
>
>
> On Sat, Jul 5, 2014 at 9:00 AM, Sonya Blade <[email protected]>
> wrote:
>
> Dear All,
>
> I noticed that when one tries to pick an object from scene there is a
> critera for that,
> I directly started the example from osgPicking example shown at the
> officail Osg site.
> The code which generates the grids in scene are as follow, problem with
> this is that PickHandler
> doesn't detect each line as individual entity.
>
> I can understand the behaviour of having all the vertices and lines
> stuffed under the
> DrawImplementation to increase the performance and PickHandler not
> detecting them,
> But If you create each line as individual osg::Geometry then PickHandler
> must detect them
> which will result in obvious performance penalty.
>
> I tried both osgUtil::LineSegmentIntersector
> and view->computeIntersections(x,y,intersections)
> functions if any of them intersects with scene objects, but none of them
> worked.
>
> osg::Geode* CreateGrid(osg::Group* gr, int x, int y, int  step)
> {
>    osg::Geode* gode = new osg::Geode();
>
> for (int j=1; j<2000; j++)
> {
>    osg::Geometry* linesGeom = new osg::Geometry();
>     osg::Vec3Array* vertices = new osg::Vec3Array(100 );
>     for (int i=0;i<50 ;i++ )
>     {
>         (*vertices)[2*i].set(-100, step+i*10, 40);
>         (*vertices)[2*i+1].set(100, step+i*10, 40);
>     };
>
>     linesGeom->setVertexArray(vertices);
>     // set the colors as before, plus using the above
>        osg::Vec4Array* colors = new osg::Vec4Array;
>        colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
>        linesGeom->setColorArray(colors);
>        linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
>
>     // set the normal in the same way color.
>     osg::Vec3Array* normals = new osg::Vec3Array;
>     normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
>     linesGeom->setNormalArray(normals);
>     linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
>
>     linesGeom->addPrimitiveSet(new
> osg::DrawArrays(osg::PrimitiveSet::LINES,0,100));
>     gode->addDrawable(linesGeom);
> }
>    return gode;
> }
>
> Regards,
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
>
>
> --
> trajce nikolov nick
>
> _______________________________________________ osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
trajce nikolov nick
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to