Hi Robert,

I don't think the "if (nodePath.size()>1)" is necessary, since the
nodePath.empty() has already been tested a few lines before.
Plus it looks like it should be "if (!nodePath.empty())", unless
computeLocalToWorld() is known not to work on an empty path.

Could you confirm this?


Cheers,

Tanguy

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Robert Osfield
Sent: Wednesday 10 December 2008 11:01
To: OpenSceneGraph Submissions
Subject: Re: [osg-submissions] FIX: osg::View::computeIntersection with
nodepath

Hi Tanguy,

I've refactored the code ito use compteLocalToWorld, the const NodePath
and the pruning so it now looks like:

    if (!_camera.valid() || nodePath.empty()) return false;

    float local_x, local_y = 0.0;
    const osg::Camera* camera = getCameraContainingPosition(x, y,
local_x, local_y);
    if (!camera) camera = _camera.get();

    osg::Matrixd matrix;
    if (nodePath.size()>1)
    {
        osg::NodePath prunedNodePath(nodePath.begin(),nodePath.end()-1);
        matrix = osg::computeLocalToWorld(prunedNodePath);
    }

    matrix.postMult(camera->getViewMatrix());
    matrix.postMult(camera->getProjectionMatrix());

I've attached the files, could you test it out on your models?

Robert.


On Wed, Dec 10, 2008 at 10:26 AM, Robert Osfield
<[EMAIL PROTECTED]> wrote:
> Hi Tanguy,
>
> I'm just reviewing your changes.  The const changes is good and I'll 
> go ahead an merge this.  The change from to use
> computeLocalWorldToLocal() also looks sounds as the code later does an

> inverse of the associated matrix to get from window coords into local 
> coords.
>
> The pruning of the last element in the nodepath also looks the 
> sensible thing to do, but the way you've coded it doesn't look safe to
> me, as it won't handle the case of nodepath being empty.   I'll
> refactor this code to automatically detect such cases.
>
> The change at line 99 looks redundant - changing from using 
> matrix.preMultScale to preMult(Matrix::scale()), if it it's it 
> suggests a bug in preMultScale that needs to be addressed.  Is this 
> change just an experiment to see if made a difference or did you 
> really see a bug with the original code at line 99?
>
> Robert.
>
> On Fri, Dec 5, 2008 at 2:33 PM, Tanguy Fautre 
> <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> This is based on OSG 2.6.1.
>>
>> bool View::computeIntersections(
>>        float x,float y,
>>        osg::NodePath& nodePath,
>>        osgUtil::LineSegmentIntersector::Intersections& intersections,
>>        osg::Node::NodeMask traversalMask)
>>
>> is currently, as far as I can tell, broken in several ways:
>>
>> - Matrix computation is incorrect, it should be computeLocalToWorld()

>> and not computeWorldToLocal().
>> - Last node of the node path should be ignored; otherwise it can lead

>> to applying a transformation node twice.
>> - nodePath argument should be const
>>
>>
>> I'm attaching an updated version that fixes these 3 issues. I've 
>> tested it on a complex scenegraph featuring several level of 
>> transformations, and it is now working fine.
>>
>>
>> Regards,
>>
>> Tanguy
>>
>>
>> _______________________________________________
>> osg-submissions mailing list
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscen
>> egraph.org
>>
>>
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to