C++ 如何在OpenGL中绘制锥形圆弧(厚度减小的曲线)?

C++ 如何在OpenGL中绘制锥形圆弧(厚度减小的曲线)?,c++,opengl,graphics,geometric-arc,C++,Opengl,Graphics,Geometric Arc,我有以下代码来绘制任意圆弧: void CenteredArc::drawPolygonArc(float radius, float thickness, float startAngle, float arcAngle) { float num_segments = 360.0; float radiusOuter = radius + thickness / 2; float radiusInner = radius - thickness / 2; fl

我有以下代码来绘制任意圆弧:

void CenteredArc::drawPolygonArc(float radius, float thickness, float startAngle, float arcAngle) {
    float num_segments = 360.0;

    float radiusOuter = radius + thickness / 2;
    float radiusInner = radius - thickness / 2;
    float theta = arcAngle / num_segments; 
    float tangetial_factor = tanf(theta);//calculate the tangential factor 

    float radial_factor = cosf(theta);//calculate the radial factor 

    float xxOuter = radiusOuter * cosf(startAngle);
    float yyOuter = radiusOuter * sinf(startAngle);
    float xxInner = radiusInner * cosf(startAngle);
    float yyInner = radiusInner * sinf(startAngle);  

    float prevXXOuter = -1;
    float prevYYOuter = -1;
    float prevXXInner = -1;
    float prevYYInner = -1;

    glPolygonMode(GL_FRONT, GL_FILL);
    for(int ii = 0; ii < num_segments; ii++) 
    { 
        if (prevXXOuter != -1) {
            glBegin(GL_POLYGON);
                glVertex2f(prevXXOuter, prevYYOuter);
                glVertex2f(xxOuter,     yyOuter);
                glVertex2f(xxInner,     yyInner);
                glVertex2f(prevXXInner, prevYYInner);
            glEnd();
        }

        //calculate the tangential vector 
        //remember, the radial vector is (x, y) 
        //to get the tangential vector we flip those coordinates and negate one of them 

        float txOuter = -yyOuter; 
        float tyOuter =  xxOuter; 
        float txInner = -yyInner; 
        float tyInner =  xxInner; 

        //add the tangential vector 

        prevXXOuter = xxOuter;
        prevYYOuter = yyOuter;
        prevXXInner = xxInner;
        prevYYInner = yyInner;

        xxOuter += txOuter * tangetial_factor; 
        yyOuter += tyOuter * tangetial_factor; 
        xxInner += txInner * tangetial_factor; 
        yyInner += tyInner * tangetial_factor; 

        //correct using the radial factor 
        xxOuter *= radial_factor; 
        yyOuter *= radial_factor; 
        xxInner *= radial_factor; 
        yyInner *= radial_factor; 
    }
}
void CenteredArc::drawPolygonArc(浮动半径、浮动厚度、浮动起始角、浮动弧角){
float num_段=360.0;
浮动半径外部=半径+厚度/2;
浮动半径内=半径-厚度/2;
浮点θ=弧角/num_段;
float tangetial_factor=tanf(θ);//计算切向因子
浮点径向系数=cosf(θ);//计算径向系数
float xxOuter=半径outer*cosf(startAngle);
浮动yyOuter=半径OUTER*sinf(星形缠结);
浮点数xxInner=半径inner*cosf(startAngle);
浮动yyInner=半径INNER*sinf(星形缠结);
浮点数prevXXOuter=-1;
浮点数prevYYOuter=-1;
float prevXXInner=-1;
float prevYYInner=-1;
glPolygonMode(GL_前端,GL_填充);
对于(int ii=0;ii
但是,我希望弧的一端以指定的厚度开始,另一端逐渐减小到零厚度。有什么建议吗

编辑:我没有使用
GL\u LINE\u STRIP
,因为我试图避免像这样的重叠线和间隙:


我会使用
线条带
,减少
glLineWidth

这是我的实现,它不会逐渐减小
线宽,但可以修改以减小线宽。对不起,这是我的游戏引擎提供的

for(int i=0;i<arcs().size();i++)
{
        Entities::Arc temp = arcs().at(i);
        glLineWidth(temp.LW.value); // change LWidth

        glColor3f( temp.CL.R, temp.CL.G, temp.CL.B );

        // theta is now calculated from the arc angle instead, the
        // - 1 part comes from the fact that the arc is open
        float theta = temp.A.value*DEG2RAD / float(WW_SPLINE_ACCURACY - 1);

        float tan = tanf(theta);
        float cos = cosf(theta);

        // we are now at the starting angle
        double x = temp.R.value * cosf(temp.A.value*DEG2RAD);
        double y = temp.R.value * sinf(temp.A.value*DEG2RAD);

        // since the arc is not a closed curve, this is a strip now
        glBegin(GL_LINE_STRIP);
        for(int ii = 0; ii < WW_SPLINE_ACCURACY; ii++)
        {
            glVertex2d(x + temp.C.X, y + temp.C.Y);
            double tx = -y;
            double ty = x;
            x += tx * tan;
            y += ty * tan;
            x *= cos;
            y *= cos; //y = ( y + (ty*tan) )*cos;
        }
    glEnd();
    glLineWidth(WW_DEFAULT_LWIDTH); // reset LWidth
}

我不允许发布完整的源代码,因为我是为一家公司写的,但共享一两部分不会伤害任何人:D

什么是
WW_SPLINE_精度?@vulpix它是一个常数,控制每个圆弧将使用多少顶点!我之所以没有使用
GL_LINE_STRIP
,而是绘制多边形,是因为超过5个左右像素的厚度时,渲染效果看起来不太好。你可以在外缘看到缺失的碎片。对,但你将其设置为什么值?恢复我的编辑也是愚蠢的!!该值为
72
,为超平滑,最小值为
32
#define WW_SPLINE_ACCURACY  72 // 72 for extra smooth arcs/circles, 32 minimum
#define WW_BEZIER_ACCURACY  20

/* Math stuff */
#define DEG2RAD 3.14159/180
#define PI  3.1415926535897932384626433832795;

...

glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glEnable (GL_LINE_SMOOTH);
glEnable (GL_BLEND);
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glEnable(GL_POLYGON_SMOOTH);
glClearColor(0.188f, 0.169f, 0.329f, 1.0f); //#302b54