Sunday, December 9, 2012

My first object

I am proud I figured this out

#define PI 3.14159265

void drawCone(int diameter, int height, int numFaces)
{
      //what is the angle
float angle =  360/(float)numFaces;
       //convert to radians
       float radian = (angle * PI)/180;
// get a radius
       float rad  = (float)diameter/2;
       float start = 0;
       //draw CONE
       glBegin(GL_TRIANGLES);
       for (int j  = 0; j < numFaces; j++)
       {
                     glVertex3f(0, 0,(float)height);
                     glVertex3f(cos(start)*rad, sin(start)*rad,0);
start += radian;
                     glVertex3f(cos(start)*rad, sin(start)*rad,0);

       }
       glEnd();
       start = 0;
       //draw BOTTOM
       glBegin(GL_TRIANGLES);
       for ( int k  = 0; k < numFaces; k++){

                     glVertex3f(0,0,0);
                     glVertex3f(cos(start)*rad, sin(start)*rad,0);
                     //reverse to be visible from out side
start -= radian;
                     glVertex3f(cos(start)*rad, sin(start)*rad,0);
       }
       glEnd();
}

No comments:

Post a Comment