#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();
}