[osg-users] Easy way to pick nearest edge?
Simon Notheis
notheis at ira.uka.de
Tue Sep 2 02:17:53 PDT 2008
Hi Robert,
When i pick e.g. a 3d model of a table my result looks like taht:
intersection.ratio 0.298972
intersection.localIntersectionPoint -37.4626 -162.331 25
intersection.localIntersectionNormal -0 0 1
intersection.getWorldIntersectionPoint() 2187.54 -1787.33 750
intersection.getWorldIntersectionNormal() 0 0 1
intersection.primitiveIndex 11
BUT:
intersection.indexList.size() 0
intersection.ratioList.size() 0
intersection.drawable.library/className osg::Geometry
geometry->getNumPrimitiveSets() 1
geometry->getVertexArray()->getNumPrimitiveSets() 8
Simon
Robert Osfield schrieb:
> Hi Simon,
>
> The LineSegmentIntersector records the indices of the vertices of the
> primitive that has been hit. The
> LineSegmentIntersector::Intersection::indexList and ratioList provide
> the indices and barycentric coords.
>
> Robert.
>
> On Tue, Sep 2, 2008 at 8:54 AM, Simon Notheis <notheis-LzjI1I19FwmELgA04lAiVw at public.gmane.org> wrote:
>> Hi everyone,
>>
>> I want to use mouse events to pick an object of the 3D scene. Instead of
>> working with the intersection point, I want to find the nearest vertex
>> or edge of the polygon that was hit.
>> Until now I used code similar to the following one:
>>
>> // Get the hitlist by using osg::Viewer::computeIntersection(...)
>> const osgUtil::LineSegmentIntersector::Intersection&
>> intersection = *(hitlist.begin())
>> osg::Geometry* geometry = intersection.drawable->asGeometry()
>>
>> Then i used intersection.indexList and the geometry's VertexArray to
>> iterate through all vertices to find the closest vertex (vx) wrt the
>> intersection point.
>> Then I calculated the angles between vx and the both neighbouring
>> vertices in the indexList to determine which one belongs to the closest
>> edge. Finally, the nodePath gave me the local=>world transformation.
>>
>> All of that only worked because we had some bad code to load/convert our
>> own scene format into OSG. This code generated seperate triangles or
>> quads, so actually I always hit a polygon with 3 or 4 vertices, what
>> made it easy to determinie the neighbours of vx.
>>
>> Now that we're using some optimization steps (e.g. triangle strips), I
>> can't use the above code (e.g. the indexList is empty). I tried to use
>> the geometry's IndexArray instead, but the problem is that without
>> knowing the exact primitive type, it is hard to determine which vertices
>> are the neighbouring ones to find the edge. E.g. in case of an triangle
>> strip I would have to check the last 2 and next 2 vertices in the
>> index/vertex list. Also the code won't work if the drawable can't be
>> cast to a Geometry.
>>
>> So my question is, if there's a more easy or flexible way to determine
>> the closest vertex and edge of the intersected polygon/primitve?
>>
>> Looking forward to your ideas or solutions, if something similar was
>> already discussed here.....
>>
>> Simon
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users-ZwoEplunGu0hajLcUbyfC12AsgEQdTeF at public.gmane.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
More information about the osg-users
mailing list