Edges on polygon outlines not always correct

后端 未结 6 1134
梦毁少年i
梦毁少年i 2020-12-01 08:54

I\'m using the algorithm below to generate quads which are then rendered to make an outline like this

http://img810.imageshack.us/img810/8530/uhohz.p

6条回答
  •  青春惊慌失措
    2020-12-01 09:11

    You can not use the offset vectors from the previous segment on the current segment - they are perpendicular to something that has nothing to do with the current segment. Best is to use the same offsets like this:

             p0.x = start.x + perpoffset.x;
             p0.y = start.y + perpoffset.y;
    
             p1.x = start.x - perpoffset.x;
             p1.y = start.y - perpoffset.y;
    
             p2.x = end.x + perpoffset.x;
             p2.y = end.y + perpoffset.y;
    
             p3.x = end.x - perpoffset.x;
             p3.y = end.y - perpoffset.y;
    

    And then put a circle at each vertex to round the corners. If round is not the way you want to go, you'll have to change the amount of ndir you add to the offsets - this is dependent on BOTH segments connecting at a vertex, not just one. You need to identify the intersection of the incomming and outgoing offset lines. Start with the above, and do some zoomed in shots with angles like 90 or 120 degrees to get a feel for this. Sorry, no formula handy right now.

    Lastly, you do not need to normalize the perp vector. The way you calculate it will produce a unit vector anyway.

提交回复
热议问题