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]

Wednesday, February 8, 2012

Recursion

Here is an interesting fact
When using recursion you must use the pre ++ operator instead of the post ++ operator

function doThis(X)
{
if( x< 10)
doThis(++X);
else
return X;
}

WHY? Well otherwise the recursion call only takes the value and not the incremented value.

FYI
x + 1; does seem to work fine

Saturday, January 21, 2012

Pointers to Pointers

Yes you can have Pointers to Pointers in C. Since everything is passed by copy unless specified than you need to pass a pointer to a pointer for things like linked list

void foo(List **l){
*l = (*l)->next;
}

List L;
List *lP = &L;
foo(&lP);

Thursday, January 12, 2012

C

When creating functions in C you need to declare all your variables before any other function is called

void foo(){
doSomething();
var int; // BAD
}

void foo(){
var int; //GOOD
doSomething();
}

If you want to compile via command line in Windows, find the bin folder of your visual studio via command line

C:\Program Files\Microsoft Visual Studio 8\VC\bin

execute the vcvars32.bat

Now go to the folder where your program is and use CL (compile and link) followed by any files you want to make your exe

CL queue.c queueTest.c

Thursday, January 5, 2012

Tip of the day - Excel

You know how Excel does smart pasting, which will automatically increment rows as you paste? Well what if you wanted something to stay static. You can prevent the incremental behavior by prefixing the column and row with a dollar sign. The cell N12 become $N$12.

Neat!

Tuesday, January 3, 2012

In the beginning . . .

Hello and welcome to 'Learning the Digital World'. This blog is focused on all the things electronic. We will look at programming and electronics and even robotics. Their will be notable mention of game development techniques.