diff --git a/examples/osgtext3D/osgtext3D.cpp b/examples/osgtext3D/osgtext3D.cpp index 145f85b0b..4dfcf3692 100644 --- a/examples/osgtext3D/osgtext3D.cpp +++ b/examples/osgtext3D/osgtext3D.cpp @@ -31,6 +31,68 @@ extern int main_orig(int, char**); extern int main_test(int, char**); +osg::Vec3 computeIntersectionPoint(const osg::Vec3& a, const osg::Vec3& b, const osg::Vec3& c, const osg::Vec3& d) +{ + float ba_x = b.x()-a.x(); + float ba_y = b.y()-a.y(); + + float dc_x = d.x()-c.x(); + float dc_y = d.y()-c.y(); + + float denominator = (dc_x * ba_y - dc_y * ba_x); + if (denominator==0.0) + { + // line segments must be parallel. + return (b+c)*0.5; + } + + float t = ((a.x()-c.x())*ba_y + (a.y()-c.y())*ba_x) / denominator; + + return c + (d-c)*t; +} + +osg::Vec3 computeBisectorNormal(const osg::Vec3& a, const osg::Vec3& b, const osg::Vec3& c, const osg::Vec3& d) +{ + osg::Vec2 ab(a.x()-b.x(), a.y()-b.y()); + osg::Vec2 dc(d.x()-c.x(), d.y()-c.y()); + float length_ab = ab.normalize(); + float length_dc = dc.normalize(); + float denominator = (ab.x()-dc.x()); + if (denominator==0.0) + { + // ab and cd parallel + return osg::Vec3(ab.y(), -ab.x(), 0.0f); + } + float r = (dc.x()-ab.y())/ denominator; + float ny = 1.0f / sqrtf(r*r + 1.0f); + float nx = r * ny; + + return osg::Vec3(nx,ny,0.0f); +} + +class Boundary +{ + typedef std::vector Points; + typedef std::vector Distances; + typedef std::vector Bisectors; + + struct Segment : public osg::Referenced + { + unsigned int _p1; + unsigned int _p2; + Segment* _left; + osg::ref_ptr _right; + float _distance; + }; + + osg::ref_ptr _head; + + osg::ref_ptr _vertices; + Bisectors _bisectors; + Points _boundary; + Distances _distances; +}; + float computeAngle(osg::Vec3& v1, osg::Vec3& v2, osg::Vec3& v3) { @@ -40,7 +102,6 @@ float computeAngle(osg::Vec3& v1, osg::Vec3& v2, osg::Vec3& v3) v32.normalize(); float dot = v12*v32; float angle = acosf(dot); - OSG_NOTICE<<" v1="<0.0) bisector = -bisector; + OSG_NOTICE<<" bisector normal "<(itr->get()); if (drawArray && drawArray->getMode()==GL_POLYGON) { - new_primitives.push_back(computeBevelEdge(*orig_vertices, drawArray->getFirst(), drawArray->getCount(), *new_vertices)); + osg::DrawArrays* new_drawArray = computeBevelEdge(*orig_vertices, drawArray->getFirst(), drawArray->getCount(), *new_vertices); + removeLoops(*new_vertices, new_drawArray->getFirst(), new_drawArray->getCount()); + new_primitives.push_back(new_drawArray); } } return new_geometry;