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

Reply via email to