DrawCylinder

Started by
6 comments, last by Hazem_vb 20 years, 2 months ago
Hello, How to draw a Cylinder starting from (x1,y1,z1) to (x2,y2,z2) in opengl using gluCylinder Function Thanks
Come to visit Egypt (the Land of Civilization)
Advertisement
Crossposts = suck.

-~-The Cow of Darkness-~-
CROSSPOSTING == BAD!


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?"
--------"Do you believe in Ghost?"
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();
}
Come to visit Egypt (the Land of Civilization)
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]
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.
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
Come to visit Egypt (the Land of Civilization)

This topic is closed to new replies.

Advertisement