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();
}

Thursday, December 6, 2012

Been a while

Sorry, I am a bad blogger always had anyway here is my summatiion for graphics

[code]


void drawModel(objModel_p shape)
{
//put a new matrix on the stack to operate on
glPushMatrix();
//go to return to world space
glTranslatef(shape->center.x, shape->center.y , shape->center.z);
//move to new pos
glTranslatef(shape->position.x, shape->position.y ,shape->position.z);
//scale in local space
glScalef(shape->scale.x,shape->scale.y, shape->scale.z);
//rotate in local space
glRotatef(shape->rotation, 0, 1, 0);
//go to local space
glTranslatef(-shape->center.x, -shape->center.y , -shape->center.z);

//send verts thru that maxtix backwards.
glmDraw(shape->model, GLM_SMOOTH| GLM_TEXTURE);
//remove new matrix and return to worldspace
glPopMatrix();
}

[/code]