Results 1 to 6 of 6

Thread: gluCylinder and Ellipsoid

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2005
    Posts
    8

    gluCylinder and Ellipsoid

    Hi. I would like to create a cylinder which the base is not a circle but an oval/elipse, and an ellipsoid. Could anybody tell me how to make it? I found only gluCylinder which only makes a circle-based cylinder. Please help me. Thank you so much.

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2005
    Posts
    4

    Re: gluCylinder and Ellipsoid

    Actually there is no way to straight out make an eliptical cylinder or oval with glu objects. You must either make your own function to draw eliptical cylinders (messy unless you have a good reason to do so) or...

    Transform it with a scale function like,

    glScalef(0.5, 1.0, 1.0);

    this particular one sqaushes it by half on the x axis and keeps the y and z axis as they were. It will produce an elips. Play around with it. Also look up the other simple transformations and play with them,

    glRotatef, glTranslatef

    so you can orientate objects where you want, since the gluCylinder always draws the cylinder with the same orientation.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2005
    Posts
    8

    Re: gluCylinder and Ellipsoid

    Thank you so much for your advice.

  4. #4
    Senior Member Frequent Contributor ehsan2004's Avatar
    Join Date
    Jun 2004
    Location
    Iran
    Posts
    645

    Re: gluCylinder and Ellipsoid

    It's better that you don't use from the glu quadrics. they need heavy transformations and when you use from many glu quadrics, they increase your frame rate. Always use from the objects that consist of the triangles. In these days, most of the models that are loaded in games, consist of the triangles. In this case, hardware helps you to render the objects.
    -Ehsan-

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2005
    Posts
    8

    Re: gluCylinder and Ellipsoid

    Thank you for your advice Ehsan. Could you explain me more about this. I mean, I can easily create a cylinder using gluCylinder(), but how can I make a cylinder or sphere without using glu? Please help me. thank you

  6. #6
    Member Newbie
    Join Date
    Jan 2012
    Posts
    31

    Re: gluCylinder and Ellipsoid

    Hello BR,

    I haven't test it, but theoratically you can draw a cylinder with the following code :

    Code :
    void drawCylinder(int SLICES, int STACKS, float SCALE_X, float SCALE_Y, float SCALE_Z) {
        glEnable(GL_NORMALIZE);
     
        //top of cylinder
        glBegin(GL_TRIANGLE_FAN);
            glNormal3f(0.0f, 0.0f, -1.0f);
            glVertex3f(0.0f, 0.0f, 0.0f)
            for (int i=0; i<=SLICES; ++i) {
                float x = SCALE_X * sin(i*2*M_PI/SLICES);
                float y = SCALE_Y * cos(i*2*M_PI/SLICES);
                glVertex3f(x, y, 0.0f);
            }
        glEnd();
     
        //main part of cylinder
        for (int j=0; j<STACKS; ++j) {
            glBegin(GL_TRIANGLE_STRIP);
                for (int i=0; i<=SLICES; ++i) {
                    float x = SCALE_X * sin(i*2*M_PI/SLICES);
                    float y = SCALE_Y * cos(i*2*M_PI/SLICES);
                    float z = j * SCALE_Z / STACKS;
                    glNormal3f(x, y, 0.0f);
                    glVertex3f(x, y, z);
                    float z = (j+1) * SCALE_Z / STACKS;
                    glVertex3f(x, y, z);
                }
            glEnd();
        }
     
        //bottom of cylinder
        glBegin(GL_TRIANGLE_FAN);
            glNormal3f(0.0f, 0.0f, 1.0f);
            glVertex3f(0.0f, 0.0f, SCALE_Z)
            for (int i=0; i<=SLICES; ++i) {
                float x = SCALE_X * sin(i*2*M_PI/SLICES);
                float y = SCALE_Y * cos(i*2*M_PI/SLICES);
                glVertex3f(x, y, SCALE_Z);
            }
        glEnd();
    }
    dj3hut1

Similar Threads

  1. 3d-Ellipsoid
    By hlewin in forum OpenGL: General
    Replies: 10
    Last Post: 07-25-2013, 02:19 AM
  2. How to draw an ellipsoid with arbitrary axes?
    By dolphinmark in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-10-2003, 09:40 PM
  3. drawing ellipsoid
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-10-2003, 07:43 AM
  4. Ellipsoid. How?
    By jrbcast in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-02-2001, 06:06 AM
  5. Cut an ellipsoid where you need (half, 3/4, y axis,...)
    By Cisne in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-14-2001, 09:53 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