Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1.  /*scalex - scaling of sphere around x-axis
  2.    scaley - scaling of sphere around y-axis
  3.    r - radius of sphere
  4.   */
  5.  void drawHalfSphere(int scaley, int scalex, GLfloat r) {
  6.    int i, j;
  7.    GLfloat v[scalex*scaley][3];
  8.  
  9.    for (i=0; i<scalex; ++i) {
  10.      for (j=0; j<scaley; ++j) {
  11.        v[i*scaley+j][0]=r*cos(j*2*M_PI/scaley)*cos(i*M_PI/(2*scalex));
  12.        v[i*scaley+j][1]=r*sin(i*M_PI/(2*scalex));
  13.        v[i*scaley+j][2]=r*sin(j*2*M_PI/scaley)*cos(i*M_PI/(2*scalex));
  14.      }
  15.    }
  16.  
  17.    glBegin(GL_QUADS);
  18.      for (i=0; i<scalex-1; ++i) {
  19.        for (j=0; j<scaley; ++j) {
  20.          glVertex3fv(v[i*scaley+j]);
  21.          glVertex3fv(v[i*scaley+(j+1)%scaley]);
  22.          glVertex3fv(v[(i+1)*scaley+(j+1)%scaley]);
  23.          glVertex3fv(v[(i+1)*scaley+j]);
  24.        }
  25.      }
  26.    glEnd();
  27.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement