Hello Matthew,
Does anyone know how to access the rgba texture values at the point of
intersection in a polygon found using osgUtil::IntersectionVisitor and
osgUtil::LineSegmentIntersector? Ideally I would pass a threshold to the
IntersectionVisitor so that it automatically skips intersecting polygons whose
alpha values at the intersection point fall below the threshold. Since this
functionality does not seem to exist, I am wondering if there is another means
available to find this information. I am hoping that I do not have to write a
new IntersectionVisitor.
I don't think you need to write a new intersector, just filter the
intersections it returns with your criteria. I've never done what you
want to do, but in theory, given what information
osgUtil::LineSegmentIntersector::Intersection gives you, you should be
able to compute the texture coordinates of the hit point (i.e. the hit
point in texture space) and then sample the texture.
The general idea is:
You have the localIntersectionPoint, which is the intersection point in
object space, you have the pointer to the drawable, and you have the
primitiveIndex. Get the primitive's vertex positions and texture
coordinates (there will be 3, 4 or more of each depending on if it's a
triangle, a quad or a polygon - you can always choose to handle only
triangles). Find where the intersection point lines within the primitive
(which will be a linear combination of the 3, 4 or more vertices'
coordinates), and then do a linear combination of the texture
coordinates by the same ratios to find the texture coordinates at the
intersection point.
Then find the texture that's applied to the drawable by starting in the
drawable's stateset and if there's no texture, checking the parent(s)
until you find one. Given that, you can sample the texture at those
coordinates (perhaps filtering 2x2 or something) and you'll have what
you need to make a decision to use that intersection or not. If not,
then move on to the next one.
I wonder if there's any built-in functionality in OSG to do what I
described above. I don't recall any, but I may have just never seen it.
Or perhaps there's some code that does that somewhere in the examples. I
hope in any case that someone can reply with more concrete information,
as what I describe above is pretty general and you'll have to figure out
the math yourself.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay [email protected]
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org