标签:
本文主要讨论将线扩展成2d线面的算法
将p0p1这条直线 扩展成面 很简单
Vec2f line = p1 - p0
Vec2f normal = Vec2f( -line.y, line.x).normalized().
void trianglePolyLine( const Vec2f &p0, const Vec2f &p1, const Vec2f &p2, const Vec2f &p3 , PosArray &<span style="font-family:'courier new', courier, monospace;">mesh</span>)
{
if(p1 == p2) return;
Vec2f line = (p2 - p1).normalize();
Vec2f normal = Vec2f(-line.Y, line.X).normalize();
Vec2f tangent1 = (p0 == p1) ? line : ((p1-p0).normalize() + line).normalize();
Vec2f tangent2 = (p2 == p3) ? line : ((p3-p2).normalize() + line).normalize();
Vec2f miter1 = Vec2f(-tangent1.Y, tangent1.X);
Vec2f miter2 = Vec2f(-tangent2.Y, tangent2.X);
float length1 = radius / normal.dotProduct(miter1);
float length2 = radius / normal.dotProduct(miter2);
if(true) {
PUSH(p1 - length1 * miter1);
PUSH(p2 - length2 * miter2 );
PUSH(p1 + length1 * miter1);
PUSH(p2 + length2 * miter2 );
}
}调用代码如下 for(int i = 0;i<vertexes.size();++i) {
int a = ((i-1) < 0) ? 0 : (i-1);
int b = i;
int c = ((i+1) >= vertexes.size()) ? vertexes.size()-1 : (i+1);
int d = ((i+2) >= vertexes.size()) ? vertexes.size()-1 : (i+2);
trianglePolyLine( vertexes[a], vertexes[b], vertexes[c], vertexis[d],<span style="font-family:'courier new', courier, monospace;">mesh</span> );
}vertexes表示多段线,mesh表示构建的顶点数组
讲次数组直接以GL_Lines绘制标签:
原文地址:http://blog.csdn.net/tlglove326/article/details/51330550