Changeset 11679 for OpenSceneGraph/trunk/examples/osgtext3D/osgtext3D.cpp
 Timestamp:
 07/17/10 14:03:17 (6 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/examples/osgtext3D/osgtext3D.cpp
r11678 r11679 32 32 extern int main_test(int, char**); 33 33 34 osg::Vec3 computeIntersectionPoint(const osg::Vec3& a, const osg::Vec3& b, const osg::Vec3& c, const osg::Vec3& d) 35 { 36 float ba_x = b.x()a.x(); 37 float ba_y = b.y()a.y(); 38 39 float dc_x = d.x()c.x(); 40 float dc_y = d.y()c.y(); 41 42 float denominator = (dc_x * ba_y  dc_y * ba_x); 43 if (denominator==0.0) 44 { 45 // line segments must be parallel. 46 return (b+c)*0.5; 47 } 48 49 float t = ((a.x()c.x())*ba_y + (a.y()c.y())*ba_x) / denominator; 50 51 return c + (dc)*t; 52 } 53 54 osg::Vec3 computeBisectorNormal(const osg::Vec3& a, const osg::Vec3& b, const osg::Vec3& c, const osg::Vec3& d) 55 { 56 osg::Vec2 ab(a.x()b.x(), a.y()b.y()); 57 osg::Vec2 dc(d.x()c.x(), d.y()c.y()); 58 float length_ab = ab.normalize(); 59 float length_dc = dc.normalize(); 60 float denominator = (ab.x()dc.x()); 61 if (denominator==0.0) 62 { 63 // ab and cd parallel 64 return osg::Vec3(ab.y(), ab.x(), 0.0f); 65 } 66 float r = (dc.x()ab.y())/ denominator; 67 float ny = 1.0f / sqrtf(r*r + 1.0f); 68 float nx = r * ny; 69 70 return osg::Vec3(nx,ny,0.0f); 71 } 72 73 class Boundary 74 { 75 typedef std::vector<unsigned int> Points; 76 typedef std::vector<float> Distances; 77 typedef std::vector<osg::Vec3> Bisectors; 78 79 struct Segment : public osg::Referenced 80 { 81 unsigned int _p1; 82 unsigned int _p2; 83 Segment* _left; 84 osg::ref_ptr<Segment> _right; 85 float _distance; 86 }; 87 88 osg::ref_ptr<Segment> _head; 89 90 osg::ref_ptr<osg::Vec3Array> _vertices; 91 Bisectors _bisectors; 92 Points _boundary; 93 Distances _distances; 94 }; 95 34 96 35 97 float computeAngle(osg::Vec3& v1, osg::Vec3& v2, osg::Vec3& v3) … … 41 103 float dot = v12*v32; 42 104 float angle = acosf(dot); 43 OSG_NOTICE<<" v1="<<v1<<", v2="<<v2<<", v3="<<v3<<", dot_angle="<<osg::RadiansToDegrees(angle)<<std::endl;44 105 return angle; 45 106 } … … 112 173 osg::Vec3 bisector(v32v21); 113 174 175 176 OSG_NOTICE<<"v1="<<v1<<", v2="<<v2<<", v3="<<v3<<", dot_angle="<<osg::RadiansToDegrees(angle)<<std::endl; 177 OSG_NOTICE<<" computeIntersectionPoint() point "<<computeIntersectionPoint(v1,v2,v2,v3)<<std::endl; 178 OSG_NOTICE<<" computeBisectorNormal() normal "<<computeBisectorNormal(v1,v2,v2,v3)<<std::endl; 179 114 180 if (bisector.length()<0.5) 115 181 { … … 124 190 bisector.normalize(); 125 191 192 OSG_NOTICE<<" bisector normal "<<computeBisectorNormal(v1,v2,v2,v3)<<std::endl; 193 126 194 float l = t / sin(angle*0.5); 127 195 … … 137 205 bisector.normalize(); 138 206 if (cross.z()>0.0) bisector = bisector; 207 208 OSG_NOTICE<<" bisector normal "<<computeBisectorNormal(v1,v2,v2,v3)<<std::endl; 139 209 140 210 osg::Vec3 new_vertex = v2 + bisector * l; … … 144 214 } 145 215 146 osg:: PrimitiveSet* computeBevelEdge(osg::Vec3Array& orig_vertices, unsigned int start, unsigned int count, osg::Vec3Array& new_vertices)216 osg::DrawArrays* computeBevelEdge(osg::Vec3Array& orig_vertices, unsigned int start, unsigned int count, osg::Vec3Array& new_vertices) 147 217 { 148 218 OSG_NOTICE<<"computeBoundaryAngles("<<orig_vertices.size()<<", "<<start<<", "<<count<<")"<<std::endl; … … 165 235 166 236 return new osg::DrawArrays(GL_POLYGON, start, count); 237 } 238 239 void removeLoops(osg::Vec3Array& orig_vertices, unsigned int start, unsigned int count) 240 { 167 241 } 168 242 … … 189 263 if (drawArray && drawArray>getMode()==GL_POLYGON) 190 264 { 191 new_primitives.push_back(computeBevelEdge(*orig_vertices, drawArray>getFirst(), drawArray>getCount(), *new_vertices)); 265 osg::DrawArrays* new_drawArray = computeBevelEdge(*orig_vertices, drawArray>getFirst(), drawArray>getCount(), *new_vertices); 266 removeLoops(*new_vertices, new_drawArray>getFirst(), new_drawArray>getCount()); 267 new_primitives.push_back(new_drawArray); 192 268 } 193 269 }