i have problem in positioning a cylinder at appropriate pposition in 3d-

in below code i just want to join two sphere by rotating a cylinder firstly with y axis then with x axis.

but my problem is that cylinder is not going to it’s appropriate position or it’s rotating perfectly

my code

glColor3f( 1.0, 0.3, 0.0 );
glutWireSphere( 0.1, 125, 125 );

glPushMatrix();
glTranslatef( 1.0, 1.0, -1.0 );
glColor3f( 1.0, 0.9, 0.7);
glutWireSphere( 0.1, 100, 100);
glPopMatrix();

glRotatef( 45, 1.0, 0.0, 0.0 );
glPushMatrix();
glRotatef( 135, 0.0, 1.0, 0.0 );
glColor3f( 1.0, 1.0, 1.0 );
GLUquadricObj *quadObj = gluNewQuadric();
gluCylinder(quadObj, 0.03, 0.03, 1.732, 20, 10);
glPopMatrix();

should i give the whole code

plz reply me solution …thanks

i have problem in positioning a cylinder at appropriate position in 3d-

in below code i just want to join two sphere by rotating a cylinder firstly with y axis then with x axis.

but my problem is that cylinder is not going to it’s appropriate position or it’s rotating perfectly

my code

glColor3f( 1.0, 0.3, 0.0 );
glutWireSphere( 0.1, 125, 125 );

glPushMatrix();
glTranslatef( 1.0, 1.0, -1.0 );
glColor3f( 1.0, 0.9, 0.7);
glutWireSphere( 0.1, 100, 100);
glPopMatrix();

glRotatef( 45, 1.0, 0.0, 0.0 ); // rotation with x axis
glPushMatrix();
glRotatef( 135, 0.0, 1.0, 0.0 ); //rotation with y axis
glColor3f( 1.0, 1.0, 1.0 );
GLUquadricObj *quadObj = gluNewQuadric();
gluCylinder(quadObj, 0.03, 0.03, 1.732, 20, 10);
glPopMatrix();

should i give the whole code

thanks

plz reply the solution…
i m still fighting for it

thanks

MaxH
March 9, 2011, 12:04am
#4
I posted a demo that does this a while ago. The source code is at:

Orient Tube Demo - MaxH

thank you for ur help… i m trying now
nd will let u know

thanks a lot

msaad
May 2, 2011, 4:00am
#6
Hey MaxH, great demo. I really need to know the maths you come around to put all these pieces together, any guidance? Thanks

MaxH
May 2, 2011, 1:58pm
#7
There are really only 3 lines of math in the demo, where I solve for m, az, and el. These relations are very similar to converting from Cartesian to Spherical coordinates. A diagram explains it best. See the link below …

Cartesian To Spherical Coordinates

I start with a vector parallel to the X axis and rotate it in azimuth and elevation to point it in the correct direction.

msaad
May 3, 2011, 3:01pm
#8
Thanks :), I am checking it out.