[osg-users] LineSegmentIntersector NaN warnings on zero-scaled nodes.
Robert Osfield
robert.osfield at gmail.com
Sat Nov 21 08:59:01 PST 2015
HI Jannik,
I haven't had a look at the modified example yet, it's the weekend so I'm
just briefly online. Quick thoughts are:
inverting a zero'd matrix will naturally lead to an invalid matrix.
My inclination is that the case where a zero matrix could be produced is a
special case that needs to be caught higher up in the calling methods
rather than try and implement so lower level workaround.
The actual concept behind the transformations that are being done of the
line segment is transform into the coordinate frame of a subgraph and then
trimming it so that you only test the extents that intersect that subgaph's
bounding volume. If a bounding volume is invalid then you can't do this
test and clip.
For a zero radius bounding sphere, such as a sub-graph that contains just a
single point then this is a special case - the line segment would have to
exactly pass through the centre of the bounding sphere. One approach this
might be to always increase the radius of the sphere by an epsilon so it;'s
not non zero and do the test and clip against this. epsilon's are already
used elsewhere in LineSegmentIntersector, I need to get back to me family
now so can't look further into the topic.
Robert.
On 21 November 2015 at 16:02, Jannik Heller <scrawl at baseoftrash.de> wrote:
> Hi,
>
> The LineSegmentIntersector creates NaN warnings when applied to a node
> with zero scale. I've attached a 3 line change to osgintersection.cpp to
> reproduce the issue.
>
> The NaN's first pop up when OSG tries to invert a zero matrix here:
> https://github.com/openscenegraph/osg/blob/master/src/osgUtil/LineSegmentIntersector.cpp#L294
>
> Check with the following code snippet:
>
> Code:
>
> osg::Matrix zero(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1);
>
> if (zero.invert(zero))
> std::cout << "inverted " << zero << std::endl;
>
>
>
> invert() returns true but the inverted matrix is
>
> inverted {
> -nan -nan -nan 0
> -nan -nan -nan 0
> -nan -nan -nan 0
> nan nan nan 1
> }
>
> This looks like a bug in the Matrix invert function.
>
> However even if the matrix was still zero instead of NaN, there is another
> issue here:
>
> osg::ref_ptr<LineSegmentIntersector> lsi = new
> LineSegmentIntersector(_start * matrix, _end * matrix);
>
> Multiplying a vec3 with a zero matrix will cause NaN's, because there is
> an 1.0 / (mat * vec ...) in the Matrix::preMult(Vec3) function.
>
> Not sure on the best way to fix this. Should we add explicit checks for
> zero scaled matrices in the LineSegmentIntersector, or fix the Matrix and
> Vec classes so they don't produce NaN's under any circumstances for
> (borderline) valid input? The latter seems the cleaner fix but would have a
> performance impact all over OSG.
>
> Thank you!
>
> Cheers,
> Jannik
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=65720#65720
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151121/82ead8c3/attachment-0003.htm>
More information about the osg-users
mailing list