Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. void drawSphere(float r, int lats, int longs) {
  2.     int i, j;
  3.     for(i = 0; i <= lats; i++) {
  4.        float lat0 = PI * (-0.5 + (float) (i - 1) / lats);
  5.        float z0  = sin(lat0);
  6.        float zr0 =  cos(lat0);
  7.  
  8.        float lat1 = PI * (-0.5 + (float) i / lats);
  9.        float z1 = sin(lat1);
  10.        float zr1 = cos(lat1);
  11.  
  12.        glBegin(GL_QUAD_STRIP);
  13.        Material(vert, 0.25, 0.5, 0.0, 1.0, 1.);
  14.  
  15.        for(j = 0; j <= longs; j++) {
  16.            float lng = 2 * PI * (float) (j - 1) / longs;
  17.            float x = cos(lng);
  18.            float y = sin(lng);
  19.  
  20.            glNormal3f(x * zr0, y * zr0, z0);
  21.            glVertex3f(x * zr0, y * zr0, z0);
  22.            glNormal3f(x * zr1, y * zr1, z1);
  23.            glVertex3f(x * zr1, y * zr1, z1);
  24.        }
  25.        glEnd();
  26.    }
  27. }
  28.  
  29. static void bolster(void){
  30.     glPushMatrix();
  31.         glScalef(1.,1.,3.);
  32.         gl_Cylinder(40);
  33.     glPopMatrix();
  34.    
  35.     glPushMatrix();
  36.         glTranslatef(0.,0.,3.);
  37.         drawSphere(1.,40,40);
  38.     glPopMatrix();
  39.    
  40.     glPushMatrix();
  41.         glTranslatef(0.,0.,-3);
  42.         drawSphere(1.,40,40);
  43.     glPopMatrix();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement