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


Strange surface generation by jsjslim
1
 
// Generates the parametric surface
float** calcShape2(int numVerts)
{
    float **vertices = (float**)malloc(sizeof(float*)*numVerts*numVerts);

    int i=0;
    float du = (M_PI*2)/numVerts;
    float dv = (M_PI*2)/numVerts;
    double x,y,z;
    int u,v=0;
    for (u=0; u<numVerts; u++)
    {
        for (v=0; v<numVerts; v++)
        {
            vertices[i] = (float*)malloc(sizeof(float)*3);
            vertices[i][0] = (u*du)*cos(v*dv)/(2*M_PI);
            vertices[i][1] = (u*du)*sin(v*dv)/(2*M_PI);
            vertices[i][2] = (u*du)*sin(v*dv)*sin(u*du)/(2*M_PI);
            i++;
        }
    }
    return vertices;
}

// This goes into the display function
for (i=0; i<pow(numVerts,2)-3; i+=3)
{
    glBegin(GL_POLYGON);
        glVertex3fv(vert[i]);
        glVertex3fv(vert[i+1]);
        glVertex3fv(vert[i+2]);
        glVertex3fv(vert[i+3]);
    glEnd();
}