#### Archived

This topic is now archived and is closed to further replies.

# Way to draw cylinder from coord to coord?

This topic is 6931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there a way to draw a cylinder by telling it the coordinates of where to start drawing and where to stop, instead of having to draw it, then rotate? Thanks!

##### Share on other sites
i''m sorry, but.. WHAT??

--
Float like a butterfly, bite like a crocodile.

##### Share on other sites
check out the primitives in glut

##### Share on other sites
I''ll eloborate:

Right now, when I use Nehe''s quadratic tutorial to draw cylinders, I have to glTranslatef to somewhere, then draw it. It''s always straight (horizontal) though, so to get it diagonal, I have to rotate it after. I want a way to just say: start drawing at xyz, then finish drawing at xyz. So I can tell it where to draw both ends....

And what''s this about primitives in glut? Thanks!

##### Share on other sites
You mean you''ve given the center line of the cylinder with the end vertices of this line, A and B, and you''ve given the radius r?
I haven''t read Nehe''s tutorial, I don''t know how Nehe draws a cylinder, but I can tell you how I do:
For the parametric cylinder description with the parameters s and t, firstly you need the direction vector of the cylinder, which is v = B-A. Then you''ll need two vectors perpendicular to each other and perpendicular to v. You could get one of the perpendicular vectors, n1, with n1.x=-v.y, n1.y = v.x and n1.z = 0. For the second one, n2, you need the cross product: n2 = v x n1
Now we''ve got the equation: x(s,t) = A + v*s + r*sin(t)*n1 + r*cos(t)*n2
where x(s,t) is a vertex of the cylinder surface. Let s run from 0 to 1 and t from 0 to 2*PI to get the vertices.

GA

##### Share on other sites
I forgot to say that you must normalize n1 and n2:
n1 = n1/sqrt(n1.x^2+n1.y^2+n1.z^2)
n2 = n2/sqrt(n2.x^2+n2.y^2+n2.z^2)

GA

##### Share on other sites
Hmmm, well in Nehe''s tutorial, you just say the length, radius at start, radius at end, and number of faces.... You have to translate to tell it where to draw. So I was wondering if I could tell it coordinates to start and end at instead.... I''ll try to figure out what you said though

• 15
• 13
• 35
• 39
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!