# OpenGL Parabola GL_LINE_STRIP to tube mesh with GL_TRIANGLE_STRIP

This topic is 1487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have code that draws a parabola given two end points and a value for droop/sag to simulate a wire.  I'm currently using a GL_LINE_STRIP to draw it, but it's limited to pixel thicknesses, and I need world coordinate thickness.  So what I need to do is pass in a radius for thickness and draw a cylinder with it's segments at each point on this parabola. In this coordinate system +Y is up.  Here's my code:

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();


gWires.Thickness on line 21 will be used as a radius once this is converted.  This code is in a loop of gWires with i being the current wire being drawn...each wire is a parabola with two fixed end points.

As you can see, I have a WorldToLocal that converts Lat/Long/El to local opengl coordinates...wx1, wy1, wz1 is one end point while wx3, wy3, wz3 is the other end point.

Assume a cylinder precision of say 6 vertices per segment...I'm thinking due to the GL_TRIANGLE_STRIP plot method, I'll need to add these parabola points to an array and use them in some form of lofted draw method like a parallel transport frame.  I've seen a bunch of code that calculated parallel transport frames, but nothing that draws them.  I'm limited to immediate mode, so I can't create a VAO or anything, it has to be done in a loop of sorts.

Where do I begin?  I know I need to start by adding the points created on the glVertex3f on line 28 to an array and then calling a whole new set of routines to draw the cylinder but as for the math/drawing, I've no clue.

Edited by lehthanis

1. 1
Rutin
31
2. 2
3. 3
4. 4
5. 5

• 13
• 15
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632962
• Total Posts
3009498
• ### Who's Online (See full list)

There are no registered users currently online

×