|
下面代码是判断2D平面上两直线是否相交。但我写为 return null 时 vs2010 显示以下提示:
error C2664: 'osg::Vec3f::Vec3f(const osg::Vec3f &)' : cannot convert parameter 1 from 'int' to 'const osg::Vec3f &'
请问如果不用NULL 该如何表达返回一个空值?- 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!
- float pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4);
- float x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d;
- float y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d;
- return osg::Vec3f(x, y, 0.0f);
- }
复制代码 |
|