• Create Account

We're offering banner ads on our site from just \$5!

# lehthanis

Member Since 05 Nov 2010
Offline Last Active Sep 24 2014 01:33 PM

### Parabola GL_LINE_STRIP to tube mesh with GL_TRIANGLE_STRIP

24 September 2014 - 08:36 AM

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[i].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.

### Need a quick and dirty png loader with libpng...help?!?

10 April 2013 - 10:55 AM

Hi all, sorry for the super noob post...I'm just getting started but I have a very short turnaround time needed for this for my boss.
I'm modifying something in X-Plane, and drawing a really large set of quads that cover the sky...it works....here's the code:
```    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glVertex3f( xt+150000.0f, yt, zt-150000.0f );
glVertex3f( xt+150000.0f, yt, zt+150000.0f );
glVertex3f( xt-150000.0f, yt, zt+150000.0f );
glVertex3f( xt-150000.0f, yt, zt-150000.0f );
glEnd();
glColor4f(0.8f, 0.8f, 0.8f, 0.5f);
glVertex3f( xt+150000.0f, yt+1, zt-150000.0f );
glVertex3f( xt+150000.0f, yt+1, zt+150000.0f );
glVertex3f( xt-150000.0f, yt+1, zt+150000.0f );
glVertex3f( xt-150000.0f, yt+1, zt-150000.0f );
glEnd();
glColor4f(0.5f, 0.5f, 0.5f, 0.2f);
glVertex3f( xt+150000.0f, yt+2, zt-150000.0f );
glVertex3f( xt+150000.0f, yt+2, zt+150000.0f );
glVertex3f( xt-150000.0f, yt+2, zt+150000.0f );
glVertex3f( xt-150000.0f, yt+2, zt-150000.0f );
glEnd();
```
I know, it's the old glBegin method, but that's how the code I have is written for X-Plane...
Anyways...I need to apply a texture to those 3 quads. And I need it to be a png texture.
I've downloaded and compiled libpng, and linked it to my project, but I need a quick and dirty way to load a png file and apply it to the quads.
Is there an easy way to do this without using any additional libraries? Or perhaps a simple header file I could drop in that someone has layign around?
Sorry again for the frantic-ness...once I get a quick and dirty png loader, I'll definitely be able to spend some time learning more about libpng, but for now, I need a quick fix.
Thanks so much to anyone that can help.

### Ionware Tetris Tutorial questions/problems

04 June 2012 - 12:48 PM

Hi all,

I've been going through IonWare's Tetris tutorial over at http://openglgui.sou.../tutorials.html and I'm having some oddities.

First of all, the screen is VERY flickery when the game is running with the provided source code. It seems to respond to my move commands quite well, but the animations seem to be goign super slow, and eliminating full lines seems to be slow also.

I'm also having trouble with loading blocks. It only seems to want to give me the square block...so I can't tell if block rotation is working or anything.

I ended up commenting out all the includes for glaux.h and the sample code compiled with minimal changes (I had to add the int declaration in front of several i=0 statements in the parentheses portions of for loops). Does anyone know how to contact the author of those tutorials and whether or not he intends to finish the series?

### Passing a 2d vector array as a pointer

13 December 2011 - 09:29 AM

I've got a maze generator program I've been working on as a learning tool. I wanted to create a scoring mechanism for user solving, and to do that I need to know in advance what the solution is. I have code that automatically solves the maze. And I am using bitwise logic to store the state of each maze cell in my vector array.

As the user solves the maze, they are storing in the primary array their progress. I wanted to keep that, but make a duplicate vector array that has the computer's solve path's stored in it. So I figured I could pass to the function that solves the maze (and handles pathing) which array to work on via pointer. like this:

```// This is the call for the users pathing in the maze
solveMaze(&glMaze)
// This is the call for the computers pathing in the maze
solveMaze(&glMazeSolution)

// ...

// Here's the function and just the line that I'm getting the error
bool solveMaze(vector<vector<int> > * maze)
{
if (((maze[CurrRow -1][CurrCol] & ALL_PATHS) == 0) && ((maze[CurrRow -1][CurrCol] & ALL_BACKS) == 0)) {
// Do Stuff
}
}
```

The error I'm getting is: binary '&' : 'std::vector<_Ty>' does not define this operator or a conversion to a type acceptable to the predefined operator

So is there a different/better/correct way to pass a multidimensional vector to a function as a pointer that won't cause this problem?

Thanks!!!

### C++ Option Dialog Boxes - low overhead method?

30 November 2011 - 09:09 AM

I am using Visual Studio 2010, and working with OpenGL and want to make an option dialog box where I can set a few options for the render scene. I'm not interested in digging too much into to the "visual" side of visual studio because I've heard there's a lot of overhead in there and it makes cross-platform programming very difficult because the microsoft tools lock you into a microsoft only program. I could be wrong though, feel free to sway me otherwise.

What I'd like is to be able to press, say, F2 to bring up an options dialog box with a few simple controls that set state. Is there a tutorial or sample code for doing something like this available on the net? I don't want to add too many dependencies to my program, so the simplest method available is what I'm looking for.