Results 1 to 8 of 8

Thread: Cylinder arrangements

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Cylinder arrangements

    Hi,

    I need to place cylinder in horizontal location i,e hollow spaces of the cylinder is placed on the top side and bottom side.

    So that i don't want to see the hollow spaces of the cylinder on my window.
    To do this what coordinates i need to use ?

    please sort me from this problem.

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: Cylinder arrangements

    Hi anyone,

    Is it possible to divide the cylinder surface into Triangular strips.

    If possible means How it is ?

    please guide me

    Advance thanks.

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Cylinder arrangements

    Cylinders seem to be all the rage on these forums

    Have a read here, a lot of code available to copy/paste :
    http://www.opengl.org/discussion_boa...6&page=all

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: Cylinder arrangements

    Hi Sir,

    Thanks for the reply.

    The link which you sent is to help how to draw Cylinder using gluCylinder() function.

    Is it possible to draw cylinder Using Triangle strips ?

    or
    Is it possible to do cylinder surface like triangle strips ?

    please Help me.

  5. #5
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Cylinder arrangements

    Yes of course it is possible.
    Does this wireframe image help you to understand how :
    http://blog.thingiverse.com/wp-conte...ktip_05_03.png

    In this picture, quad are used, but with 2 triangles you can easily draw 1 quad.

    For the vertex coordinates, some trigonometry is needed, basically create frist vertex, add a vector v, place second vertex, rotate vector by 180-360/sides degres, etc until all sides are created.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: Cylinder arrangements

    Hi Sir,

    Thanks for your replying.


    As i am new to openGL, will you explain how the vectors are added?

    will you give idea through Snippet of code.

    Please help me from this problem.

  7. #7
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Cylinder arrangements

    The trig part is not really an opengl question, it is classic math.
    Does this pseudo code helps ?
    Code :
    double x = y = z = 0.0;
    double vx = vy = vz = 0.0;
    vx = 1;
    double theta = (180-360.0/SIDES);
    for (int i = 0;i<=SIDES;i++) {
       double theta = i * (180-360.0/SIDES);
       double tempvx = SLENGTH * (vx*cos(theta) + vy*sin(theta));
       double tempvy = SLENGTH * (vy*cos(theta) - vx*sin(theta));
       vx = tempvx;
       vy = tempvy;
       x += vx;
       y += vy;
       glVertex3d(x,y,z);
    }
    First make it work to draw a circle with GL_LINES, then adapt this to store yourself each vertex and build a correct tristrip.

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    20

    Re: Cylinder arrangements

    Hi Sir,

    Thank you so much for reply.

    By using the above pseudo code i wrote the code which is shown below :

    Code :
     
     #include<stdlib.h>
     
    #include<GL/glut.h>
     
    #include<GL/glu.h>
     
    #include<GL/gl.h>
     
    #include<math.h>
     
     
    int angle=0;
     
    void cylinder()
     
    {
     
    GLint SIDES=20,i;
     
    GLfloat SLENGTH=30.0;
    double x, y , z;
     x = y = z = 0.0;
    double vx,vy,vz;
     vx = vy = vz = 0.0;
    vx = 1;
    double theta = (180-360.0/SIDES);
    glBegin(GL_LINES);
    for (i = 0;i<=SIDES;i++) {
     
       double theta = i * (180-360.0/SIDES);
       double tempvx = SLENGTH * (vx*cos(theta) + vy*sin(theta));
       double tempvy = SLENGTH * (vy*cos(theta) - vx*sin(theta));
       vx = tempvx;
       vy = tempvy;
       x += vx;
       y += vy;
       glVertex3d(x,y,z);
    }
     
     
    glEnd();
     
    }
    void display()
    {
     
    glClear(GL_COLOR_BUFFER_BIT);
     
    glLoadIdentity();
     
    gluLookAt(45.0,45.0,25.0,-45.0,-45.0,-40.0,0.0,0.0,10.0);
     
     
    cylinder();
     
    glFlush();
     
    angle+=1;
     
    glutSwapBuffers();
     
    }
     
     
     
    int main(int argc,char **argv)
    {
     
    glutInit(&amp;argc,argv);
     
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
     
    glutInitWindowSize(500,500);
     
    glutInitWindowPosition(100,0);
     
    glutCreateWindow("CYLINDER");
     
    glutDisplayFunc(display);
     
    glMatrixMode(GL_PROJECTION);
     
    glLoadIdentity();
     
    glOrtho(-100.0,100.0,-100.0,100.0,-100.0,100.0);
     
    glMatrixMode(GL_MODELVIEW);
     
    glClearColor(1.0,1.0,1.0,1.0);
     
    glutMainLoop();
     
    }

    This code is not generating the Cylinder with lines. i am not getting the problem

    please help me from this Sir.

Similar Threads

  1. Cylinder out of axis
    By Spaghetti Programmer in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-10-2009, 03:41 AM
  2. cylinder help
    By brett01 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-14-2008, 08:56 AM
  3. create cylinder
    By ms in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-16-2005, 11:29 PM
  4. cylinder problem
    By asingh in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-16-2002, 12:54 AM
  5. 3d cylinder animation
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-07-2000, 10:35 AM

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