GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


A Paste by godecho
1
 
subdivisions += subdivisions%4;

static const float PI = 3.1415926535897932384626433832795f;
static const float TWOPI = 2.0f*PI;
static const float PID2 = PI/2.0f;

for(unsigned int j = 0; j < subdivisions/2; ++j)        // generates strips from bottom to top
    {
        offset.y = (j < subdivisions/4) ? -dist : dist;

        theta1 = j * TWOPI / subdivisions - PID2;
        theta2 = (j + 1) * TWOPI / subdivisions - PID2;

        glBegin(GL_QUAD_STRIP);
            for(unsigned int i = 0; i < subdivisions; ++i)    // around the sphere
            {
                
                Point3f p1;
                Point3f p2;
                
                theta3 = i * TWOPI / subdivisions;

                e.x = cos(theta2) * cos(theta3);
                e.y = sin(theta2);
                e.z = cos(theta2) * sin(theta3);
                p1.x = center.x + radius * e.x;
                p1.y = center.y + radius * e.y;
                p1.z = center.z + radius * e.z;

                glNormal3f(e.x, e.y, e.z);
                glTexCoord2f(i/(float)subdivisions, 2*(j+1)/(float)subdivisions);
                glVertex3f(p1.x, p1.y, p1.z);

                e.x = cos(theta1) * cos(theta3);
                e.y = sin(theta1);
                e.z = cos(theta1) * sin(theta3);
                p2.x = center.x + radius * e.x;
                p2.y = center.y + radius * e.y;
                p2.z = center.z + radius * e.z;

                glNormal3f(e.x, e.y, e.z);
                glTexCoord2f(i/(float)subdivisions, 2*j/(float)subdivisions);
                glVertex3f(p2.x, p2.y, p2.z);
                }
            }
        glEnd();
    }