#### Archived

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

# DrawCylinder

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

## Recommended Posts

Hello, How to draw a Cylinder starting from (x1,y1,z1) to (x2,y2,z2) in opengl using gluCylinder Function Thanks

##### Share on other sites
Crossposts = suck.

##### Share on other sites
Maybe the kid desparately needed help. I''m pretty sure nehe.gamedev.net provides some sort of online tutorial on this situation.

Drawing cylinders or any quadric in OpenGL is quite simple. If you want to alter it''s position you''d have to use the glTranslate function since you can''t really apply a vertex position for quadrics(like you would for Quads, Triangles and other generic polygons).

--------
"Do you believe in Ghost?"

##### Share on other sites
I know what u say but you misunderstand me :-
How to make a Function that Draws A Cylinder Like this

void DrawCylinder(double *p1,double *p2,int raduis)
{
glPushMatrix();
glTranslated(p1[0],p1[1],p1[2]);
//Some transformations Here and this is the question
gluCylinder(...)
glPopMatrix();
}

##### Share on other sites
read up on gluCylinder();

namely on msdn or other such docs.

and read up on glTranslatef()

[edited by - DerAngeD on February 7, 2004 8:43:24 AM]

##### Share on other sites
You guys still arn''t getting him, you need help with the math right.

Your right so far, translate to the first point. Im sure the gluCylinder function takes a height and radius and probably a slices or something parameter. Anyways, height will be the distance between your two points.

sqrt( (p2[0]-p1[0])*(p2[0]-p1[0]) + (p2[1]-p1[1])*(p2[1]-p1[1]) + (p2[2]-p1[2])*(p2[2]-p1[2]))

In order to get your cylinder to point towards the second point your going to have to do some glRotate''s search on how to rotate into the direction of a vector, rotate into p2 - p1. Or use trig and sin-1 and cos-1''s to figure out the angles to rotate.

##### Share on other sites
I could find my answer to question the one who wants to know how this could be done :-

http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm

Bye

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632977
• Total Posts
3009676
• ### Who's Online (See full list)

There are no registered users currently online

×