Wednesday, December 12, 2007

Practical 9

Currently doing my practical 9 now having some problems on the lighting for some reason when i put in the lighting code the viewport became a 2d view like this:

will post more on this if i managed to finish it.

Practical 8

For this practical we were asked to do our assignment one.
I went on to my assignment which was a robot on wheels playing a keyboard
Why this?
I couldnt think of any idea and so I ended up doing this

Wednesday, November 28, 2007

Practical 7







Today in class we were asked to do some lighting on the objects created.







Here are some pictures






Another one on the cylinder


And one on my robot

Here is the code needed to make it work

void init(void)
{
GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 };
GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
glClearColor(0.0, 0.1, 0.1, 0.0);
//Enable Depth test
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
In mydisplay()

GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat low_shininess[] = { 5.0 };
//Clear buffer.
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
In main()
init();


Practical 6

This week we were asked to create an object and code it in such a way that when a certain key is pressed, the object will move in that specific direction

Here's a screenshot of it:

Here is the code used to make this thing move:
In void main
glutKeyboardFunc(Keyboard);
Declared as global are:
int x= 0;
int y=0;
In the KeyboardFunc(Keyboard)

void Keyboard(unsigned char key, int x, int y)
{
switch(key) //check which key is pressed
{
case 'd':
::x++; //add 1 to global x.
break;
case 'a':
::x--; //minus 1 to global x.
break;
case 'w':
::y++;
break;
case 's':
::y--;
break;
}
}
In my display()
glTranslatef(::x,::y,0);

Wednesday, November 21, 2007

Practical 5

On the 5th week of my lab session:



We were asked to do a robot and animate it.

However currently I have only been able to rotate it.

Either way here's a picture of it

Here's a sample code of the creation of the robot

void drawBody()
{
glBegin(GL_QUADS);
glVertex3f(15,5,5);
glVertex3f(15,5,-5);
glVertex3f(15,-20,-5);
glVertex3f(15,-20,5);
glVertex3f(-15,-20,5);
glVertex3f(-15,-20,-5);
glVertex3f(-15,5,-5);
glVertex3f(-15,5,5);
glVertex3f(-15,5,5);
glVertex3f(-15,-20,5);
glVertex3f(15,-20,5);
glVertex3f(15,5,5);
glVertex3f(-15,5,-5);
glVertex3f(-15,-20,-5);
glVertex3f(15,-20,-5);
glVertex3f(15,5,-5);
glVertex3f(-15,5,-5);
glVertex3f(-15,5,5);
glVertex3f(15,5,5);
glVertex3f(15,5,-5);
glVertex3f(-15,-20,-5);
glVertex3f(-15,-20,5);
glVertex3f(15,-20,5);
glVertex3f(15,-20,-5);
glEnd();
}

void head()
{
glutSolidSphere(9,34,23);
}
void drawLimb()
{
glBegin(GL_QUADS);
glVertex3f(5,5,5);
glVertex3f(5,5,-5);
glVertex3f(5,-15,-5);
glVertex3f(5,-15,5);
glVertex3f(5,-15,5);
glVertex3f(5,-15,-5);
glVertex3f(-5,-15,-5);
glVertex3f(-5,-15,5);
glVertex3f(-5,-15,5);
glVertex3f(-5,-15,-5);
glVertex3f(-5,5,-5);
glVertex3f(-5,5,5);
glVertex3f(-5,5,-5);
glVertex3f(-5,5,5);
glVertex3f(5,5,5);
glVertex3f(5,5,-5);
glVertex3f(-5,5,5);
glVertex3f(5,5,5);
glVertex3f(5,-15,5);
glVertex3f(-5,-15,5);
glVertex3f(5,5,5);
glVertex3f(-5,5,5);
glVertex3f(-5,-15,5);
glVertex3f(5,-15,5);
glEnd();
}
void drawRobot()
{
glPushMatrix();
glColor3f(1,0,0);
glTranslatef(-20, 0.0, 0.0);
glRotatef(40.0, 1.0, 0.0, 0.0);
drawLimb(); //draw upper right arm
glPopMatrix();
glPushMatrix();
glColor3f(0,1,0);
glTranslatef(-20, -15.0, -2.0);
glRotatef(-30.0, 1.0, 0.0, 0.0);
drawLimb(); //lower right limb
glPopMatrix();
glPushMatrix();
glColor3f(1,1,1);
glTranslatef(-10, -45.0, 0.0);
glRotatef(0.0, 0.0, 0.0, 0.0);
drawLimb(); // bot left leg
glPopMatrix();
glPushMatrix();
glColor3f(0,1,1);
glTranslatef(10, -45.0, 0.0);
glRotatef(60.0, 1.0, 0.0, 0.0);
drawLimb(); // bot right leg
glPopMatrix();
glPushMatrix();
glColor3f(1,1,1);
glTranslatef(10, -25.0, 0.0);
glRotatef(0.0, 0.0, 0.0, 0.0);
drawLimb(); //top right leg
glPopMatrix();
glPushMatrix();
glColor3f(0,1,1);
glTranslatef(-10, -25.0, 0.0);
glRotatef(0.0, 0.0, 0.0, 0.0);
drawLimb(); //top left leg
glPopMatrix();
glPushMatrix();
//glTranslatef(0, 0.0, 2.5);
glColor3f(0,0,1);
drawBody();
glPopMatrix();
glPushMatrix();
glColor3f(1,0,1);
glTranslatef(0, 12.0, 0.0);
//glTranslatef(20,30.0,20.0);
head();
glPopMatrix();
glPushMatrix();
glColor3f(1,1,0);
glTranslatef(20, 0.0, 0.0);
glRotatef(-40.0, 1.0, 0.0, 0.0);
drawLimb(); //draw upper left arm
glPopMatrix();
glPushMatrix();
glTranslatef(20, -12.5, 7.5);
glRotatef(-90.0, 1.0, 0.0, 0.0);
drawLimb(); //lower left limb
glPopMatrix();
}
And here is code for rotation
In the Display function:
glPushMatrix();
glRotatef(::rot,xx,yy,zz);
drawRobot();
glPopMatrix();

In the KeyboardFunc:

switch(key)
{
case 'x':
if(pressed==0)
{
xx=1;
pressed=1;
}
else if(pressed==1)
{
xx=0;
pressed=0;
}
break;
case 'y':
if(pressed==0)
{
yy=1;
pressed=1;
}
else if(pressed==1)
{
yy=0;
pressed=0;
}
break;
case 'z':
if(pressed==0)
{
zz=1;
pressed=1;
}
else if(pressed==1)
{
zz=0;
pressed=0;
}
break;
}

In my DoMainLoop:

void DoMainLoop()
{
if(::rot>=-90&&::rot<=90&&::set==0) { ::rot++; if(::rot==90) { ::set=1; } } else if(::rot>=-90&&::rot>=-90&&::set==1)
{
::rot--;
if(::rot==-90)
{
::set=0;
}
}
}
Erm i made a mistake on the rotation, somehow i thought it was to rotate the whole body and this code shows that, i will do the rotating of arms later

Wednesday, October 31, 2007

3rd week of my lab

Today what was taught was how to draw simple shape through coding.

For example to draw a triangle you have to type
glBegin(GL_TRIANGLES);
glVertex3f(0.5f, 0.5f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(0.75f,0.5f, 0.0f);
glEnd( );

into the void myDisplay(void) function.

The same goes for quadilaterals but as they have 4 points an additonal

glVertex3f(x.xf,y.yf, 0.0f); is needed

eg
glBegin(GL_QUADS);
glVertex3f(-0.5,-0.5,0);
glVertex3f(0.5,-0.5,0);
glVertex3f(0.5,0.5,0);
glVertex3f(-0.5,0.5,0);
glEnd( );

Also by placing a glColor3f(0.0,0.0f,1.0f); infront of a glBegin(GL_(your shape))

will give you a desired colour with 1 being the strongest i think.

This glColor gives a blue colour.

Now on the show pictures of what was done:
Triangle

2nd week of my lab

On this week I have learnt how to actually draw something onto the computer screen. Also some new abbreviation like CLUT(Colour Look Up Table). I also have discovered the reason for a callback function and its uses over other conventional method.

Here's a sample code of what I did:

void MeltDown()
{
static int lines[800];
for(int i=0;i<800;i++) 10="="0)">600)
lines[i]=0;
}
for(int j=0;j=100&&j<=200) { PlotPixel(i,599-j,0,255,255); } else if(j>200&&j<=300) { PlotPixel(i,599-j,0,255,0); } else if(j>300&&j<=400) { PlotPixel(i,599-j,255,255,0); } else if(j>400&&j<=500) { PlotPixel(i,599-j,255,0,0); } } } }

This is how it looks like

Wednesday, October 17, 2007

Game review


Game title: Warhawk

Game platform: Playstation 3(PS3)

Game genre: Sci-Fi Shooter

Developer: Incognito

Product Model Year: 2007

Game requirements: NIL

Game description: Warhawk is an online game played on the PS3 which allows you to play with up to 31 players. Warhawk also feature 3 different types of gameplay: zones, CTF(Capture The Flag) , DM(DeathMatch) or TDM(Team DeathMatch) and Dogfight where you fight against other player in aircraft and only aircraft.

Game play: The gameplay is mostly like Battlefield series where you have to work as a team to capture certain zones in order to acheive victory. You can either go on foot, ride a vehicle such as a tank or hop into an aircraft and blast the daylights out of your enemies.

Graphics: The graphic are quite nice , smooth and the aircraft and vehicles look quite real to me that is. Have a look at it yourself.

Sound: As for sound, it is quite an important aspect in the game. An example would be that when you are in an aircraft, a buzzing sound will mean that there are homing missles locked on to your aircraft and you will have to take measures to avoid them.

Conculsion: Warhawk is quite a nice game to play and the fun multiplies when you have friends playing together with you online or on the same PS3 console.

Intro and Maths

Yo,
This is my first time blogging, the reason for this is because I am required to do so by my course module.
In this first week's practical, I am supposed to set up a website and maintain it (which is what i am doing now in fact)
Next, I have to post on my website a breif review of my maths and the review of a computer game of my choice.

This week the only lab session I have gone to is the Advanced C++ on tuesday. That session was mostly on recap on the C++ I learnt on the previous semester. An example would be that I had to write a program that shows the abbreivation of the shortform entered by the user.
Eg,
if(state==NCstate==ncstate==nCstate==Nc)
{
cout<<"NC stands for North Carolina.\n";
}
Now on to maths..

Vectors
On vectors, I can mostly understand the questions and how to do. However when the vectors come into the 3d zone I begin to have a little problem on understanding them.

Matrix
On matrix, the only parts I have problems with is finding the determinent of 3x3 matrix and above.

Indices
Not much problems with indices at all

Will there also be dfifferenciation ,intergration and the use of logarithem in CG?
I wonder..