0

我有代码绘制抛物线给定两个端点和下垂/下垂的值来模拟电线。我目前正在使用 GL_LINE_STRIP 来绘制它,但它仅限于像素厚度,并且我需要世界坐标厚度。所以我需要做的是通过一个半径的厚度并在这个抛物线上的每个点上绘制一个圆柱体,它的高度段。在这个坐标系中,+Y 向上。这是我的代码:

const double pPrecision = 50;
double wx1, wy1, wz1, wx2, wy2, wz2, wx3, wy3, wz3;
double wa = gWires[i].Sag;
WorldToLocal(gWires[i].Lat1, gWires[i].Lon1, (gWires[i].El1 * FtToMtrs), &wx1, &wy1, &wz1);
WorldToLocal(gWires[i].Lat2, gWires[i].Lon2, (gWires[i].El2 * FtToMtrs), &wx3, &wy3, &wz3);

double mXZ = (wz3-wz1)/(wx3-wx1);
double mXY = (wy3-wy1)/(wx3-wx1);

wx2 = wx1 + ((wx3 - wx1) / 2.0);
wy2 = (mXY * (wx2 - wx1) + wy1) - wa;
wz2 = (mXZ * (wx2 - wx1) + wz1);

double denom = (wx1 - wx2) * (wx1 - wx3) * (wx2 - wx3);
double A = (wx3 * (wy2 - wy1) + wx2 * (wy1 - wy3) + wx1 * (wy3 - wy2)) / denom;
double B = (wx3*wx3 * (wy1 - wy2) + wx2*wx2 * (wy3 - wy1) + wx1*wx1 * (wy2 - wy3)) / denom;
double C = (wx2 * wx3 * (wx2 - wx3) * wy1 + wx3 * wx1 * (wx3 - wx1) * wy2 + wx1 * wx2 * (wx1 - wx2) * wy3) / denom;

double px = wx1;

//glLineWidth(gWires[i].Thickness);

glColor4f(gWires[i].R, gWires[i].G, gWires[i].B, 1.0f);
glBegin( GL_LINE_STRIP );
    for ( int p = 0; p <= pPrecision; ++p) {
        double thisZ = (mXZ * (px - wx1) + wz1);
        double thisY = (A * (px*px)) + (B * px) + C;
        glVertex3f(px, thisY, thisZ);
        px = px + ((wx3 - wx1) / pPrecision);
    }
glEnd();

如您所见,我有一个 WorldToLocal 将 Lat/Long/El 转换为本地 opengl 坐标...wx1、wy1、wz1 是一个端点,而 wx3、wy3、wz3 是另一个端点。

假设圆柱精度为每段 6 个顶点......我在想由于 GL_TRIANGLE_STRIP 绘图方法,我需要将这些抛物线点添加到数组中并使用它们预先计算,因为我需要知道当前和绘制我的圆柱段时的下一段,对吗?圆柱体不需要在末端加盖。

4

0 回答 0