
Originally Posted by
Kophay
I 'd be interested to know myself if there is a more efficient way but the least you can do is this:
I assume that x,y,z in your code are homogeneous coords. Then add a 4th one, w, let that be your "extra" one and let z be the 3rd coordinate in space.
then
x = r*cos(angle)
y = r*sin(angle)
z = cylinderheight/2
w=(0.0f,0.0f,0.0f,1.0f)
running a loop similar to what you already have
gives you a circle in 3d space that is situated at z=cylinderheight/2, you can instead use
x = r*cos(angle)
y = cylinderheight/2
z = r*sin(angle)
w=(0.0f,0.0f,0.0f,1.0f)
if you wanted your cylinder to sit "upright" instead.
Then run a similar loop again replacing cylinderheight/2 with -cylinderheight/2. That will give you a second circle, so now you have the "top" and "bottom" of the cylinder. So now you can use a line_strip for each of the circles and then connect corresponding points between the circles with line. That gives a convincing representation of a cylinder, but like I said, I 'm not sure if there's a more efficient way. Intuition dictates that it should be possible to do it with just one loop - the one you currently have - , just by "projecting" the circle, just haven't worked out details yet. And there may yet be some more efficient technique I don't know of.
(and of course that's just an example, you can adjust the coords to have the cylinder top and bottom wherever you wish)