View Full Version : 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.

Centauri

09-13-2005, 11:35 PM

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.

Thank you so much for your advice.

Ehsan Kamrani

09-14-2005, 06:52 AM

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-

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

Dj3hut1

09-15-2005, 10:52 PM

Hello BR,

I haven't test it, but theoratically you can draw a cylinder with the following 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

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.