Hi Yong,

The simple answer is you can't convert a NULL to Vec3, it simply is
wrong and compiler is right to bark about it.

The best way to write code like is would be to do:

    bool lineintersection(const osg::Vec3f& p1, const osg::Vec3f& p2,
const osg::Vec3f &p3, const osg::Vec3f& p4, osg::Vec3f&
intersectionPoint)
    {
        float x1 = p1.x(), x2 = p2.x(), x3 = p3.x(), x4 = p4.x();
        float y1 = p1.y(), y2 = p2.y(), y3 = p3. y(), y4 = p4.y();

        float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
        if(d==0) return false;

        float p = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4);
        float x = ( p * (x3 - x4) - (x1 - x2) * post ) / d;
        float y = ( p * (y3 - y4) - (y1 - y2) * post ) / d;

        intersectionPoint.set(x, y, 0.0f);
        return true;
   }

Robert.

On 13 May 2013 05:10, Yong Chen <[email protected]> wrote:
> Hi,
>
> The following lines are used to calculate the intersection of two lines in a 
> 2D plane. However, the NULL value cannot be returned because the Visual 
> Studio tells me that "error C2664: cannot convert parameter 1 from 'int' to 
> 'const osg::Vec3f &'". I don't know how to represent a Null value here. Very 
> appreciate if you guys can help me out.
>
> osg::Vec3f lineintersection(osg::Vec3f p1, osg::Vec3f p2, osg::Vec3f p3, 
> osg::Vec3f p4)
> {
>         float x1 = p1.x(), x2 = p2.x(), x3 = p3.x(), x4 = p4.x();
>         float y1 = p1.y(), y2 = p2.y(), y3 = p3. y(), y4 = p4.y();
>
>         float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
>         if(d==0) return NULL; // error occurs here
>
>         float p = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4);
>         float x = ( p * (x3 - x4) - (x1 - x2) * post ) / d;
>         float y = ( p * (y3 - y4) - (y1 - y2) * post ) / d;
>
>         return osg::Vec3f(x, y, 0.0f);
> }
>
> Thank you!
>
> Cheers,
> Yong
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=53991#53991
>
>
>
>
>
> _______________________________________________
> 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

Reply via email to