View Full Version : Cylinder arrangements

Sindhu

12-22-2009, 10:04 PM

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.

Sindhu

01-06-2010, 02:56 AM

Hi anyone,

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

If possible means How it is ?

please guide me

Advance thanks.

ZbuffeR

01-06-2010, 04:06 AM

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_boards/ubbthreads.php?ubb=showflat&Number=267916&page=all

Sindhu

01-06-2010, 10:59 PM

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.

ZbuffeR

01-07-2010, 02:15 AM

Yes of course it is possible.

Does this wireframe image help you to understand how :

http://blog.thingiverse.com/wp-content/uploads/2009/04/blender_quicktip_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.

Sindhu

01-07-2010, 09:02 AM

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.

ZbuffeR

01-07-2010, 01:53 PM

The trig part is not really an opengl question, it is classic math.

Does this pseudo code helps ?

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.

Sindhu

01-10-2010, 11:44 PM

Hi Sir,

Thank you so much for reply.

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

#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(&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.

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.