View Full Version : create and extrude face from user input
12-30-2005, 11:19 AM
I am very new to OpenGL and am working on my first stand alone application. I am trying to create a build your own kitchen type application. The first step is to create your architecture - which I have a nice little World with a grid for a kind of floor - I have sucessfully created a draw function to describe the walls interior based on left mouse clicks - and even added archs.
Where I am having trouble is in determining if the user has closed his polygon or not? and then once I determine that I have a closed polygon how do I create a face and extrude that face to give the walls some height??
Thanks for the help!
Sounds like it's going to be an all-nighter! ;)
I'm not sure what you mean by closed in this case. If you mean a simple, convex polygon, you can take any edge of the polygon and see if all the other polygon points are on the interior, as defined by the winding direction. One way to do this is to define a plane using the edge and the polygon normal, then test the polygon points in turn against this plane using the signed point-plane distance. Repeat this plane test for each edge until a point is found to be exterior, or you exhaust the point list, in which case your polygon is convex.
Extrusion of a polygon can be accomplished by duplicating the user-defined polygon, reversing the winding direction, offsetting along the normal direction (or any direction for that matter) by the desired distance, then connecting the two faces with triangles/quads around the perimeter. Is that something you're interested in?
Best of luck to you, and a happy new year!
01-03-2006, 04:59 PM
Extrusion of a polygon can be accomplished by duplicating the user-defined polygon, reversing the winding direction, offsetting along the normal direction (or any direction for that matter) by the desired distance, then connecting the two faces with triangles/quads around the perimeter. Is that something you're interested in? Thanks Smiley!
Yes I am intersted. Anyway, I am curious why and how I have to "reverse the winding direction" ?
Also, now when I offset a rectangle to get a cube (for instence) I get 16 edges instead of 12? - Any thoughts?
How should I resolve all the shared points in the polygon when making the faces - so that I don't duplicate edges??
The reverse of the winding direction was just a hint at the need to keep the resulting solid oriented, so all normals are pointing outward (or inward, just be consistent). This is important for things like lighting and back-face culling.
For the 16 edges, it sounds like maybe you're adding an extraneous quad (4 edges)? Don't know for sure, but be careful when adding vertexes and edges so as not to duplicate them. Which brings me to your next concern, shared vertex data.
There are different ways to approach organizing your data. For a model under construction in an editor, performance is probably not the biggest concern, as there's an opportunity to optimize your data later, when you save it out, for instance. But rather, you're probably more interested in organizing your data in a way that makes manipulation the easiest and the most robust. What this all means heavily depends on the overall scheme of things in your world, but indexed vertex arrays are good enough for most folks. And sometimes, plain old glVertex() is just the thing.
Does that make any sense? I'm very fond of graph paper, pencils, and lots of erasers, when I'm in doubt, which unfortunately is all too often the case :D
01-03-2006, 09:24 PM
Have a look at GL Extrusion Library
IRIS, CAIR (email@example.com)
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.