Reputation: 12566
I have a set of points, confined to a two dimensional coordinate plane, specifically the first and fourth quadrants (positive x values). I am able to draw a line through these points.
I can also draw these points in 3D space, in another window, as a line. How would I go about sweeping them around an axis, say, Y, so that I can achieve a 3D mesh? I believe the usual example for this is using points to create a line in Maya, to create a goblet or the like.
I can't seem to find much by Googling the term "Sweep Representation", which is what my textbook refers to this process as. I'm just seeking some kind of thought process, or guidelines to, um, guide me!
Upvotes: 0
Views: 2710
Reputation: 10122
There are many ways to do this, but the overriding principle is to rotate the original line around some axis, and then emit vertices from the current line to the next line in order to generate triangles, remembering to "close" the shape by joining the last line with the first.
Personally I would generate a vertex buffer and an index buffer. I would rotate the line N times around the Y axis, storing each rotated line's points into the vertex buffer.
Then, the next part of the algorithm would generate indices for one or more line strips (multiple line strips are easier because otherwise you'd need to create degenerate triangles to go from one strip to the next)
So, given that you have a vertex buffer V, a number of points in your original line P and a number of lines N, you can simply iterate across, generating triangle strips by emitting index I and index I + P, P * N times. You then render N triangle strips given the vertex buffer and index buffer.
If you want to be clever, you can just store an index buffer with a single strips indices in, and add P to the base vertex index each time you render. Be careful with highly tessellated meshes with lots of indices. Some cards have a max vertex index which is 65535, others have one only slightly larger.
I hope that made sense!
Upvotes: 2
Reputation: 4718
not quite sure the final image you want to achieve, but from what i understand, you have a "line" (is this a straight line? a curved "line"? - not clear about this) - and you want to revolve them around some axis so that it creates some sort of 2 dimensional "mesh" like a disc or cone or something?
you could simply try glRotatef(a,x,y,z) where:
"a" is the angle you want to rotate and is the vector around which you are rotating.
thus, if you want to plot the figure 10 times around the y axis then it might look like this:
for(int i = 0; i<10; i++)
{
float da = 2.0*3.14/10.0
plotLine(); // function for plotting the line once in 3 space
glRotatef(da, 0, 1, 0);
}
this will plot the line, rotate the entire figure by a small amount, then plot it again (this will repeat 10 times so that the original line is plotted 10 times around an axis - creating the "mesh" that i believe you are trying to achieve
Upvotes: 0