# lehthanis

Member

14

114 Neutral

• Rank
Member
1. ## OpenGL Parabola GL_LINE_STRIP to tube mesh with GL_TRIANGLE_STRIP

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.

3. ## Ionware Tetris Tutorial questions/problems

Hi all, I've been going through IonWare's Tetris tutorial over at [url="http://openglgui.sourceforge.net/tutorials.html"]http://openglgui.sou.../tutorials.html[/url] 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?
4. ## Passing a 2d vector array as a pointer

That seemed to work. Is this what you meant: [code] // 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 } } [/code]
5. ## Passing a 2d vector array as a pointer

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: [code] // 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 } } [/code] 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!!!
6. ## C++ Option Dialog Boxes - low overhead method?

Well, I looked at the Visual Studio dialog box editor...it creates a .rc file. I dunno if that's like I said, and relying too much on the microsoft overhead. I guess what I meant earlier is that when I created my project I did it as an empty project, none of the precompiled headers and all the other things that come in a win32 project. I'm handling all of my opengl window code through a glwindow.cpp and a glxwindow.cpp for linux (from the Beginning OpenGL book samples). I'd like to keep it pretty simple and just call a dialog box without having to dive too deeply into the visual studio wizards. The less I have to do with a wizard the better.
7. ## C++ Option Dialog Boxes - low overhead method?

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. Thanks so much for any help you can give me.
8. ## OpenGL Options dialog box while running OpenGL

I'm using the GLWindow sample code from the book 'Beginning OpenGL Programming Second Edition' and it's working out great for getting started with OpenGL. I've taken what I've learned so far and already applied it to some game code I had written back in my visual basic days. What I'm having a problem with now is having a configuration or options dialog box. I'm kinda crippled here because all the C++ I learned was within an SDK for a flight simulator...so I jumped from C++ for plugins to OpenGL for windows...so I don't know a lot about creating windows in Windows. I was wondering what I would need to do to create a dialog box that I could allow the user to set some options for the program using windows controls. Perhaps when they press a function key, the options menu will pop up. Are there any good tutorials I can read to get me started on adding a dialog box with controls on it to my OpenGL project? Thanks!
9. ## Possibly simple question - How to drop the sign of a float?

That was exactly what I was looking for, thank you!
10. ## Possibly simple question - How to drop the sign of a float?

I have a formula to calculate aspect ratio of a grid in regards to a screen size. The formula works great, but sometimes it returns a negative number, and I'm subtracting it from 0 to pad the left side...which in the case of a negative number ends up adding it to 0 instead. I need to drop the sign of the value of the formula without changing the value. Is there a quick and easy way to do that or will I have to do an if statement? I'm working in C++. I'm fairly new to it, but am learning it super fast, which means I'm probably working on things that may be beyond my means in some cases...such as math. I can't math, lol.
11. ## MaxScript Exporter problems - Vertex Normals/Smooth Groups

Thats my problem! X-Plane DOES support indexed triangles, but I have no idea how to organize/optimize the indices in MaxScript. I'm fairly new to MaxScript, and unfortunately my first need for MaxScript is a big one...so if anyone has any ideas, I'm all for it. As you can see from the above code, I just dump all my vertex records (faces*3, very inefficient) into an array. I then loop through the array and make my index records based on how many vt records I have. very bloated, very inefficient, and probably the source of my problem. I'd love for someone to take a look and maybe make an adjustment for me if anyone has any better ideas.
12. ## MaxScript Exporter problems - Vertex Normals/Smooth Groups

Heres some sample output from the above code: VT -5.688458 -0.184925 4.516189 0.394689 -1.995943 -0.241369 0.258005 0.660901 VT -4.491374 -0.011067 5.177628 0.162206 -0.986106 -0.035846 0.428328 0.554014 VT -4.492776 0.002333 4.922896 0.534238 -3.091060 -0.171475 0.395913 0.535761 VT -4.492776 0.002333 4.922896 0.534238 -3.091060 -0.171475 0.395913 0.535761 VT -5.688458 -0.170515 4.403035 0.230695 -1.153887 -0.146945 0.243681 0.652480 VT -5.688458 -0.184925 4.516189 0.394689 -1.995943 -0.241369 0.258005 0.660901 VT -4.491374 -0.011067 5.177628 0.162206 -0.986106 -0.035846 0.428328 0.554014 VT -3.898806 0.074594 5.507529 0.177333 -1.057912 -0.043833 0.512955 0.501291 VT -3.898806 0.088117 5.181144 0.325549 -1.941949 -0.085238 0.471524 0.477767 VT -3.898806 0.088117 5.181144 0.325549 -1.941949 -0.085238 0.471524 0.477767 VT -4.492776 0.002333 4.922896 0.534238 -3.091060 -0.171475 0.395913 0.535761 VT -4.491374 -0.011067 5.177628 0.162206 -0.986106 -0.035846 0.428328 0.554014 I think its required to be rounded to 6, yes...but it looks like they're way off...i think my biggest problem is understanding the way max handles normals and smoothing versus the way x-plane handles it....
13. ## MaxScript Exporter problems - Vertex Normals/Smooth Groups

Hi all, I've tried this at multiple different forums and haven't gotten much help at all. I'm still VERY new to MaxScript and if I can get past this hurdle I'll be able to work through more of this. I have written an exporter to export from Max to X-Plane. I'm using max 2010 x64. The format that I'm exporting to requires a list of vertex records, and so I export them using the following: for f = 1 to num_faces do ( channel = 1 Face = getFace tmesh f TFace = meshop.getMapFace tmesh channel f TVx = meshop.getMapVert tmesh channel (TFace.x as integer) TVy = meshop.getMapVert tmesh channel (TFace.y as integer) TVz = meshop.getMapVert tmesh channel (TFace.z as integer) for v = 1 to 3 do ( if FaceCCW.state == true then ( case v of ( 3: (curVert = Face.x; curTVert = TVx) 2: (curVert = Face.y; curTVert = TVy) 1: (curVert = Face.z; curTVert = TVz) ) ) else ( case v of ( 1: (curVert = Face.x; curTVert = TVx) 2: (curVert = Face.y; curTVert = TVy) 3: (curVert = Face.z; curTVert = TVz) ) ) Vert = getvert tmesh curVert VertNorm = getNormal tmesh curVert VertX = formattedPrint Vert.x format:".6f" VertY = formattedPrint Vert.y format:".6f" VertZ = formattedPrint Vert.z format:".6f" VertNormX = formattedPrint VertNorm.x format:".6f" VertNormY = formattedPrint VertNorm.y format:".6f" VertNormZ = formattedPrint VertNorm.z format:".6f" VertU = formattedPrint curTVert[1] format:".6f" VertV = formattedPrint curTVert[2] format:".6f" append AryVerts ("VT " + VertX + " " + VertY + " " + VertZ + " " + VertNormX + " " + VertNormY + " " + VertNormZ + " " + VertU + " " + VertV + "\n") ) ) tmesh is a snapshot of my mesh. I loop through each face in my mesh (CCW or CW) and create a record for each vertex. The vertex requires a triplet for X,Y,Z position, and then an X,Y,Z normal (normalized to 1) and then a U, V coordinate. Everything is exporting and displaying properly, except my smooth groups are not showing in the engine, and I get an error for each object that says it has normals of the wrong length. Is there anything I can do in the above code to make sure the normal x,y,z values are normalized to 1 and reflect the smooth groups? The normals also tell X-Plane how to smooth the surfaces, so the normal values should take into account the smooth group choices. My vertex records are NOT optimized...so they currently reflect num_faces * 3. If anyone has any insight into optimizing my vertex records, that would be awesome! Here's the specifics from: http://scenery.x-plane.com/library.php?doc=obj8spec.php Quote:VT <x> <y> <z> <nx> <ny> <nz> <s> <t> This defines a single entry in the triangle vertex table. These are indexed starting from zero based on the record order. The eight numbers represent a triplet coordinate location, a triplet normal, and a pair forming a texture coordinate. This table is only used for triangles. ... Flat/Smooth shading (default is smooth). In flat shading, the entire triangle is drawn with the same brightness. In smooth shading, the corners of the triangle have the shading levels appropriate for their normals, and the interior is interpolated. Note that since flat shading can be simulating via per-vertex normals, it is usually better to only use smooth shading. ... Normals are specified as a triplet of fractions forming a 3-space vector whose length is 1. The vector is interpretted in the same coordinate space as the geometry. Help me get this portion of the exporter working and I'll be set! I think I need some better way to organize the VT records...a more organized array that I can sort through and compare to as I come across vertices. This way when I loop through my faces I can compare to the array and determine whether to add a new record or not...As long as the vertices are set to make faces in a counter clockwise orientation to determine the facing of a face, and all the vertices are represented based on their texture and vertex information I should be good...but I have NO idea how to go about doing that. Thanks in advance for the help!
14. ## MaxScript Exporter problems - Vertex Normals/Smooth Groups

Hi all, I've tried this at multiple different forums and haven't gotten much help at all. I'm still VERY new to MaxScript and if I can get past this hurdle I'll be able to work through more of this. I have written an exporter to export from Max to X-Plane. I'm using max 2010 x64. The format that I'm exporting to requires a list of vertex records, and so I export them using the following: for f = 1 to num_faces do ( channel = 1 Face = getFace tmesh f TFace = meshop.getMapFace tmesh channel f TVx = meshop.getMapVert tmesh channel (TFace.x as integer) TVy = meshop.getMapVert tmesh channel (TFace.y as integer) TVz = meshop.getMapVert tmesh channel (TFace.z as integer) for v = 1 to 3 do ( if FaceCCW.state == true then ( case v of ( 3: (curVert = Face.x; curTVert = TVx) 2: (curVert = Face.y; curTVert = TVy) 1: (curVert = Face.z; curTVert = TVz) ) ) else ( case v of ( 1: (curVert = Face.x; curTVert = TVx) 2: (curVert = Face.y; curTVert = TVy) 3: (curVert = Face.z; curTVert = TVz) ) ) Vert = getvert tmesh curVert VertNorm = getNormal tmesh curVert VertX = formattedPrint Vert.x format:".6f" VertY = formattedPrint Vert.y format:".6f" VertZ = formattedPrint Vert.z format:".6f" VertNormX = formattedPrint VertNorm.x format:".6f" VertNormY = formattedPrint VertNorm.y format:".6f" VertNormZ = formattedPrint VertNorm.z format:".6f" VertU = formattedPrint curTVert[1] format:".6f" VertV = formattedPrint curTVert[2] format:".6f" append AryVerts ("VT " + VertX + " " + VertY + " " + VertZ + " " + VertNormX + " " + VertNormY + " " + VertNormZ + " " + VertU + " " + VertV + "\n") ) ) tmesh is a snapshot of my mesh. I loop through each face in my mesh (CCW or CW) and create a record for each vertex. The vertex requires a triplet for X,Y,Z position, and then an X,Y,Z normal (normalized to 1) and then a U, V coordinate. Everything is exporting and displaying properly, except my smooth groups are not showing in the engine, and I get an error for each object that says it has normals of the wrong length. Is there anything I can do in the above code to make sure the normal x,y,z values are normalized to 1 and reflect the smooth groups? The normals also tell X-Plane how to smooth the surfaces, so the normal values should take into account the smooth group choices. My vertex records are NOT optimized...so they currently reflect num_faces * 3. If anyone has any insight into optimizing my vertex records, that would be awesome! Here's the specifics from: http://scenery.x-plane.com/library.php?doc=obj8spec.php Quote:VT <x> <y> <z> <nx> <ny> <nz> <s> <t> This defines a single entry in the triangle vertex table. These are indexed starting from zero based on the record order. The eight numbers represent a triplet coordinate location, a triplet normal, and a pair forming a texture coordinate. This table is only used for triangles. ... Flat/Smooth shading (default is smooth). In flat shading, the entire triangle is drawn with the same brightness. In smooth shading, the corners of the triangle have the shading levels appropriate for their normals, and the interior is interpolated. Note that since flat shading can be simulating via per-vertex normals, it is usually better to only use smooth shading. ... Normals are specified as a triplet of fractions forming a 3-space vector whose length is 1. The vector is interpretted in the same coordinate space as the geometry. Help me get this portion of the exporter working and I'll be set! I think I need some better way to organize the VT records...a more organized array that I can sort through and compare to as I come across vertices. This way when I loop through my faces I can compare to the array and determine whether to add a new record or not...As long as the vertices are set to make faces in a counter clockwise orientation to determine the facing of a face, and all the vertices are represented based on their texture and vertex information I should be good...but I have NO idea how to go about doing that. Thanks in advance for the help!