Advertisement
Guest User

Untitled

a guest
May 27th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. void draw_cylinder(GLfloat radius,
  2.                    GLfloat height,
  3.                    GLubyte R,
  4.                    GLubyte G,
  5.                    GLubyte B)
  6. {
  7.     GLfloat x              = 0.0;
  8.     GLfloat y              = 0.0;
  9.     GLfloat angle          = 0.0;
  10.     GLfloat angle_stepsize = 0.1;
  11.  
  12.     /** Draw the tube */
  13.     glColor3ub(R-40,G-40,B-40);
  14.     glBegin(GL_QUAD_STRIP);
  15.     angle = 0.0;
  16.         while( angle < 2*PI ) {
  17.             x = radius * cos(angle);
  18.             y = radius * sin(angle);
  19.             glVertex3f(x, y , height);
  20.             glVertex3f(x, y , 0.0);
  21.             angle = angle + angle_stepsize;
  22.         }
  23.         glVertex3f(radius, 0.0, height);
  24.         glVertex3f(radius, 0.0, 0.0);
  25.     glEnd();
  26.  
  27.     /** Draw the circle on top of cylinder */
  28.     glColor3ub(R,G,B);
  29.     glBegin(GL_POLYGON);
  30.     angle = 0.0;
  31.         while( angle < 2*PI ) {
  32.             x = radius * cos(angle);
  33.             y = radius * sin(angle);
  34.             glVertex3f(x, y , height);
  35.             angle = angle + angle_stepsize;
  36.         }
  37.         glVertex3f(radius, 0.0, height);
  38.     glEnd();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement