Results 1 to 8 of 8

Thread: positioning a cylinder in 3d

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    24

    positioning a cylinder in 3d

    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

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    24

    Re: positioning a cylinder in 3d

    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

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    24

    Re: positioning a cylinder in 3d

    plz reply the solution..
    i m still fighting for it

    thanks

  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: positioning a cylinder in 3d

    Quote Originally Posted by somnath
    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
    Am I doing your homework for you?

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    24

    Re: positioning a cylinder in 3d

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

    thanks a lot

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    UAE
    Posts
    3

    Re: positioning a cylinder in 3d

    Hey MaxH, great demo. I really need to know the maths you come around to put all these pieces together, any guidance? Thanks

  7. #7
    Senior Member Regular Contributor
    Join Date
    Mar 2003
    Location
    Los Angeles
    Posts
    374

    Re: positioning a cylinder in 3d

    Quote Originally Posted by msaad
    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

    I start with a vector parallel to the X axis and rotate it in azimuth and elevation to point it in the correct direction.
    Am I doing your homework for you?

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2009
    Location
    UAE
    Posts
    3

    Re: positioning a cylinder in 3d

    Thanks , I am checking it out.

Similar Threads

  1. Relative Positioning
    By JohnBauer in forum OpenGL: GLSL
    Replies: 3
    Last Post: 05-30-2013, 05:24 PM
  2. Near and far plane positioning
    By devdept in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-02-2009, 01:23 AM
  3. text positioning
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-05-2004, 01:06 PM
  4. Light Positioning
    By MrShoe in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-27-2001, 02:37 AM
  5. Positioning the mouse
    By imported_Steve in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-29-2000, 06:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean