我的代码绘制抛物线,给出两个端点和droop / sag的值来模拟导线。我目前正在使用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绘图方法,我需要将这些抛物线点添加到数组并使用它们预先计算,因为我&# 39;我需要知道当前和下一段,同时绘制我的圆柱段吗?气缸不需要盖在两端。