PDA

View Full Version : positioning a cylinder in 3d



somnath
03-05-2011, 09:54 AM
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

somnath
03-05-2011, 08:57 PM
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

somnath
03-08-2011, 10:29 PM
plz reply the solution..
i m still fighting for it

thanks

MaxH
03-09-2011, 12:04 AM
plz reply the solution.. i m still fighting for it
I posted a demo that does this a while ago. The source code is at:

Orient Tube Demo - MaxH (http://www.mfwweb.com/OpenGL/Tube.c)

somnath
03-09-2011, 06:20 AM
thank you for ur help.. i m trying now
nd will let u know

thanks a lot

msaad
05-02-2011, 04:00 AM
Hey MaxH, great demo. I really need to know the maths you come around to put all these pieces together, any guidance? Thanks

MaxH
05-02-2011, 01:58 PM
I really need to know the maths you come around to put all these pieces together, any guidance? 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 (http://www.math.montana.edu/frankw/ccp/multiworld/multipleIVP/spherical/learn.htm)

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
05-03-2011, 03:01 PM
Thanks :), I am checking it out.