Info Center

......................................For further queries about Higher Education in USA you are welcome to contact me (Prem Santosh) at: premsantosh@gmail.com. I would be glad to assist in what ever way I can...........................................................Get reviews of the latest Mobile Phones and Computer Games Released......................................

Monday, October 18, 2010

My first animation project

Doing higher studies in computer science can sometimes be real fun and also at times be a real pain in the butt. Computer animation sounded like an interesting course to me and I decided to give it a shot. It was about coding in vc++ using openGL libraries. The good side of the course: Got to learn a lot of things, fun times :)
Bad side: The projects at times take a toll on you.

Our first project was to read a .skel file which contains the coordinates of a certain figure and to render that figure.
You can find the complete question here.

Well, to make things a little simple for some of you guys who might consider taking this course I have placed a sample code snippet below. (P.S: Do not try re-using the same code as it will not work ;) )

void Generate_Tree()
{
char *string213;
int length = 0;
char temp[500], temp1[500], temp2[500];
int j=0, counter =0, counter_temp = 0;
ifstream pointer;
fflush(stdin);
pointer.open("dragon.skel");
if(pointer == NULL)
{
cout<<"File not there\n";
cout<<"Press any key to exit: ";
getch();
exit(1);
}

root->Left = NULL;
root->Right = NULL;
root->Center = NULL;
node = root;
do
{
pointer.getline(temp, MaxLine);
//cout<<
length = strlen(temp);
//cout<<
if(temp[length-2] == '{')
{
// cout<<"After entering the loop: "<
Tree_Node *child = new Tree_Node;
child->nodeNum = number+1;
child->pose[0] = 0;
child->pose[1] = 0;
child->pose[2] = 0;
memset(&child->rotateX,0,sizeof(double)*2);
memset(&child->rotateY,0,sizeof(double)*2);
memset(&child->rotateZ,0,sizeof(double)*2);
if(node->Left == NULL)
{
// cout << "left created"<
node->Left = child;
}

else if(node->Center == NULL)
{
//cout << "center created"<
node->Center = child;
}

else
{
//cout << "right created"<
node->Right = child;
}
child->Left = NULL;
child->Right = NULL;
child->Center = NULL;
child->Prev = node;
node = child;
counter++;
}

else if(temp[length-2] == '}')
{
// cout << "go back " <
node = node->Prev;
counter--;
}
else if(temp[length-2] == ' ')
{
continue;
}

else
{
j = 0;
for(int r = 0;r
{
if(temp[r] != 9)
{
temp2[j] = temp[r];
j++;
}
}
temp2[j] = '\0';
{
string213 = strtok(temp2," ");
//cout<<<"\n";
strcpy(temp1,string213);
if(strcmp(temp1,"offset") == 0)
{
node->offset[0] = atof(strtok(NULL," "));
node->offset[1] = atof(strtok(NULL," "));
node->offset[2] = atof(strtok(NULL," "));
cout<offset[0]<offset[1]<offset[2]<<"\n";
}
else if(strcmp(string213,"boxmin") == 0)
{
node->boxmin[0] = atof(strtok(NULL," "));
node->boxmin[1] = atof(strtok(NULL," "));
node->boxmin[2] = atof(strtok(NULL," "));
//cout<boxmin[0]<<" "<boxmin[1]<<" "<boxmin[2]<<"\n";
}
else if(strcmp(string213,"boxmax") == 0)
{
node->boxmax[0] = atof(strtok(NULL," "));
node->boxmax[1] = atof(strtok(NULL," "));
node->boxmax[2] = atof(strtok(NULL," "));
//cout<boxmax[0]<boxmax[1]<boxmax[2]<<"\n";
}
else if(strcmp(string213,"rotxlimit") == 0)
{
node->rotateX[0] = atof(strtok(NULL," "));
node->rotateX[1] = atof(strtok(NULL," "));
//cout<rotateX[0]<rotateX[1]<<"\n";
}
else if(strcmp(string213,"rotylimit") == 0)
{
node->rotateY[0] = atof(strtok(NULL," "));
node->rotateY[1] = atof(strtok(NULL," "));
}
else if(strcmp(string213,"rotzlimit") == 0)
{
node->rotateZ[0] = atof(strtok(NULL," "));
node->rotateZ[1] = atof(strtok(NULL," "));
}
else if(strcmp(string213,"pose") == 0)
{
node->pose[0] = atof(strtok(NULL," "));
node->pose[1] = atof(strtok(NULL," "));
node->pose[2] = atof(strtok(NULL," "));
}
}
}
//cout<<
}while(counter != 0);
pointer.close();
}

void Read_Tree()
{
int tempNO=0;

int Copy_Flag = 0;
int Visited = 0;
/*root->Left->FlagL = 0;
root->Left->FlagC = 0;
root->Left->FlagR = 0;*/
node = root->Left;
//cout<<"Enter Read Tree"<<"\n";
Queue[front] = node;
rear++;
do
{
node=Queue[front];
//cout<offset[0]<<" "<offset[1]<<" "<offset[2]<
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
glTranslatef(node->offset[0], node->offset[1], node->offset[2]);
if(node->pose[0] <>rotateX[0])
node->pose[0] = node->rotateX[0];
if(node->pose[0] > node->rotateX[1])
node->pose[0] = node->rotateX[1];
if(node->pose[1] <>rotateY[0])
node->pose[1] = node->rotateY[0];
if(node->pose[1] > node->rotateY[1])
node->pose[1] = node->rotateY[1];
if(node->pose[2] <>rotateZ[0])
node->pose[2] = node->rotateZ[0];
if(node->pose[2] > node->rotateZ[1])
node->pose[2] = node->rotateZ[1];

//cout<pose[0]<<" "<pose[1]<<" "<pose[2]<

glRotatef(57.3 * node->pose[0], 1.0, 0.0, 0.0);
glRotatef(57.3 * node->pose[1], 0.0, 1.0, 0.0);
glRotatef(57.3 * node->pose[2], 0.0, 0.0, 1.0);
glGetDoublev(GL_MODELVIEW_MATRIX,node->local);
/*cout<<"Current Local";
for(int d = 0;d<=15;d++)
{
cout<local[d]<<" ";
}*/
//cout<

if(node->Prev == root)
{
//cout<<"I am root \n";
glMatrixMode(GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
glGetDoublev(GL_MODELVIEW_MATRIX,node->world);
}

else
{

//cout<<"I am NOT root \n";
getWorldMatrix(node->Prev->world, node->local, node->world);
/*cout<<"Current World";
for(int d = 1;d<=16;d++)
{
cout<world[d]<<" ";
}*/
}
if(node->Left != NULL)
{
//cout<<"IF condition1"<
tempNO = node->Left->nodeNum;
Insert_Queue(node->Left);
}
if(node->Center != NULL)
{
//cout<<"IF condition2"<
tempNO = node->Center->nodeNum;
Insert_Queue(node->Center);
}
if(node->Right != NULL)
{
//cout<<"IF condition3"<
tempNO = node->Right->nodeNum;
Insert_Queue(node->Right);
}
front++;
//cout<<"Front: "<<<">

}while(front != rear);
}

As you can see I was dumb enough not to use the generic creation of a tree which made my work hell. Anyways, good luck!!

Will be happy to answer queries.

Sunday, October 10, 2010

Back from the grave!!

Hey guys

I know it has been a really long time and I apologize for being dead for the past couple of years. My life was one of the most happening this ever in these past few years. Now that I come to think of it, I regret that time flew and am never going to get those days back again but on the brighter side, there still are a plethora of wonderful events that I would have to face in the future and am very eagerly looking forward for those.

This is just a lame post so just excuse it. I am planing to update this site with all sorts of assorted fun stuff I find. This would be one of those blogs where in you do not look for a particular topic, but the topic looks for you (:P)

Anyways, I would end this by quoting BATMAN:
"Am Back" :P :D