Sunday, February 10, 2008

Computer Graphic assignment 2(FINAL)

Due to the lack of time, I am unable to clear my draw backs.
The following screenshots are the result of my assignment 2:









Computer Graphic Practical 12

In this practical, we were suppose to create a skybox.

Wednesday, December 26, 2007

Computer Graphic Assignment 2



This is the 'space' that I am going to draw out using openGL. This JPEC picture is supposed to be wrapped around a cube, thus it is not how it suppose to look like.


I am planning to model a chair(which will replace the 2 chairs outside the balcony), the bed as well as a hi-fi set table.

The following chair is used to replace the chair at the balcony as I could not see it properly:




Thursday, December 13, 2007

Computer Graphic Assignment 1

The following picture is my final product for Computer Graphic assignment 1:





FUNCTIONS

'1' - Move Forward
'2' - Move backward
'3' - Shoot bullet and move forward
'4' - Rotate the camera view to right
'5' - Rotate the camera view to left
'6' - Move the cannon upwards
'7' - Move the cannon downwards


DESCRIPTION
I had being using a lot of cylinders draw out the cannon, and a lot of quads to draw the body, Body patterns, as well as my tyre.
DRAW-BACKS
1) I am unable to make it move by its own, where the user suppose to press a key to start animation and press that key again to stop animation.
2) Cannon unable to move on its own axis.

Computer Graphic Practical 7

Monday, December 3, 2007

Computer Graphic Practical 6

We are allowed to start our assignment 1 in week 6 practical, thus I searched through the internet and found the following picture of a toy. I am thinking of drawing the model using 3D glut.





I had began the drawing but it is all in cylinders and cubes. if there is any other way to improve it I would update it. It is not completed though...


Thursday, November 15, 2007

Computer Graphic Practical 5

Question 1 -
How did it arrive with the transformed coordinates?


Answer:

(2 3 1 1) is the transformation and it is alined vertically at the right side of the vertex.

First column:
(4 0 0 2) = (X 0 0 2)

Second column:
(0 4 0 3) = (0 Y 0 3)

Third column:
(0 0 4 1) = (0 0 Z 1)


glBegin();
glVertex3f(0,0,0); ----> [(0 * 4 + 2), (0 * 4 + 3), (0 * 4 + 1) ] ----> (2, 3, 1)
glVertex3f(0,1,0); ----> [(0 * 4 + 2), (1 * 4 + 3), (0 * 4 + 1) ] ----> (2, 7, 1)
glVertex3f(1,1,0); ----> [(1 * 4 + 2), (1 * 4 + 3), (0 * 4 + 1) ] ----> (6, 7, 1)
glVertex3f(1,0,0); ----> [(1 * 4 + 2), (0 * 4 + 3), (0 * 4 + 1) ] ----> (6, 3, 1)
glEnd();

Question 2 -
What is/are the transformation(s) applied?


Answer:

Translation and scaling.

Question 3 -
OpenGL keeps track of only 1 matrix for transformation.
It will be tedious to do transformation for more than 1 mesh/
polygon/objects to different locations.
Why?


Answer:

When having more than 1 transformation, the previous transformation matrix will be overwritten by the others as OpenGL will run the transformation one at a time.

Question 4 -
(a) What is the current operation matrix after this function?

Answer:

Translation and Scaling.

(5 0 0 10)
(0 5 0 2 )
(0 0 5 4 )
(0 0 0 1 )

(b) What is the current operation matrix after this function?

Answer:

Rotation.

(5 0 0 10) * (0 0 5 1) (0 0 5 10)
(0 5 0 2 ) * (0 5 0 1 ) = (0 5 0 2)
(0 0 5 4 ) * (5 0 0 1)
(-5 0 0 4)
(0 0 0 1 ) * (0 0 0 1) (0 0 0 1)

(c) What is the current operation matrix after this function?

Answer:

translation.

(0 0 5 10) (0 0 0 2) (0 0 5 12)
(0 5 0 2) + (0 0 0 2) = (0 5 0 4)
(-5 0 0 4) (0 0 0 2) (-5 0 0 6)
(0 0 0 1) (0 0 0 1) (0 0 0 1)

(d) What is the current operation matrix after this function?

Answer:

scaling of (2, 1, 1)

(0 0 5 10) (2 0 0 1) (0 0 5 10)
(0 5 0 2) * (0 1 0 1) = (0 5 0 2)
(-5 0 0 4) (0 0 1 1) (-5 0 0 4)
(0 0 0 1) (0 0 0 1) (0 0 0 1)

(e) What is the current operation matrix after this function?

Answer:

(1 0 0 0) (0 0 0 0) (1 0 0 0)
(0 1 0 0) + (0 0 0 5) = (0 1 0 5)

(0 0 1 0) (0 0 0 0) (0 0 1 0)
(0 0 0 1) (0 0 0 1) (0 0 0 1)

(f) What is the current operation matrix after this function?

Answer:

(0 0 5 12)
(0 5 0 4 ) * =
(-5 0 0 6)
(0 0 0 1)


Exercise 3


Q5) What did you see? Screen shot it and explain why is the 2nd cube appeared at
(0,0,0)?

Answer:

Since the cube had being translated by (5, 0, 0), everything will start at that point. So when
glTranslatef(-5,0,0) is applied, it goes back to (0, 0, 0).
In order to make the 2nd cube to be at the position of (-5, 0, 0), I used the following code:

glPushMatrix();
glTranslatef(5,0,0);
DrawCube();
glPopMatrix();
glTranslatef(-5,0,0);
DrawCube();

glPushMatrix() will allow (0, 0, 0) to be saved. After the translation and a DrawCube() function been called, glPopMatrix() will go back to (0, 0, 0) and carry out another translation of (-5, 0, 0) and call another DrawCube().

I drew the following cube using a function called "drawCube()", and used 4 "glBegin(GL_POLYGON);" for individual sides, and after the translations. I am still unable to back everything starts from (0, 0, 0) and i'm looking into it.




#include "glut.h"


void DrawCube()
{
glColor3ub(255,0,0); // red, back-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();


glColor3ub(0,255,255); // green, back
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(-2.0f, 2.0f, 2.0);
glEnd();


glColor3ub(0,100,100); // dark-green, top
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();


glColor3ub(255,255,0); // yellow, bottom
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(-2.0f, -2.0f, -2.0);
glEnd();


glColor3ub(0,0,255); // blue, front
glBegin(GL_POLYGON);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glEnd();


glColor3ub(255, 100, 0); //orange, front-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(-2.0f, -2.0f, 2.0);
glEnd();
}


void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
glColor3ub(255,255,255);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 100.0);
glVertex3f(0.0f, 0.0f, -10.0);
glVertex3f(100.0f, 0.0f, 0.0);
glVertex3f(-10.0f, 0.0f, 0.0);
glVertex3f(0.0f, 100.0f, 0.0);
glVertex3f(0.0f, -10.0f, 0.0);
glEnd();


glPushMatrix();
glTranslatef(5,0,0);
DrawCube();
glPopMatrix();
glTranslatef(-5,0,0);
DrawCube();
glutSwapBuffers();
}


void Rescale(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
}


void SetupRC()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-64, 64, -48, 48, 1, 100);
gluLookAt(30.0, 30.0, 30.0, 0, 1.0, 0.0, 0.0, 1.0, 0.0);
}


void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 5");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
SetupRC();
glutMainLoop();
}


Exercise 5


1) Yes.


2) Yes.


3) Yes.

Exercise 6

I am still unable to move the cubes, but I still looking into it.


#include "glut.h"


void DrawCube()
{
glColor3ub(255,0,0); // red, back-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();


glColor3ub(0,255,255); // green, back
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(-2.0f, 2.0f, 2.0);
glEnd();


glColor3ub(0,100,100); // dark-green, top
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();


glColor3ub(255,255,0); // yellow, bottom
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(-2.0f, -2.0f, -2.0);
glEnd();


glColor3ub(0,0,255); // blue, front
glBegin(GL_POLYGON);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glEnd();


glColor3ub(255, 100, 0); //orange, front-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(-2.0f, -2.0f, 2.0);
glEnd();
}


void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);


glColor3ub(255,255,255);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 100.0);
glVertex3f(0.0f, 0.0f, -10.0);
glVertex3f(100.0f, 0.0f, 0.0);
glVertex3f(-10.0f, 0.0f, 0.0);
glVertex3f(0.0f, 100.0f, 0.0);
glVertex3f(0.0f, -10.0f, 0.0);
glEnd();


glPushMatrix();
glTranslatef(5,0,0);
DrawCube();
glPopMatrix();
glTranslatef(-5,0,0);
DrawCube();
glutSwapBuffers();
}


void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'w':
y++;
break;
case 's':
y--;
break;
case 'a':
x--;
break;
case 'd':
x--;
break;
}


}
void Rescale(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
}


void SetupRC()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-64, 64, -48, 48, 1, 100);
gluLookAt(30.0, 30.0, 30.0, 0, 1.0, 0.0, 0.0, 1.0, 0.0);
}


void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 5");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
glutKeyboardFunc(keyboard);
SetupRC();
glutMainLoop();
}