Sunday, November 11, 2007

Computer Graphic Practical 4

In computer graphic this week, we tried setting up 3D viewing and learn how to draw premitives using openGL.




Firstly, we drew some axes so that it will guild us to draw 3D diagram easier in XYZ directions.




glBegin(GL_LINES); glColor3ub(255,255,255);
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();


We proceeded to draw the sphere, with 1 triangle behind it as well as one triangle in front of it.




glColor3ub(255,0,0);
glBegin(GL_TRIANGLES);
glVertex3f(0.0, 0.0, -10.0);
glVertex3f(10.0, 15.0, -30.0);
glVertex3f(10.0, -15.0, -30.0);
glEnd();
glColor3ub(0,255,255);
glutWireSphere(15,50,50);
glColor3ub(0,255,0);
glBegin(GL_TRIANGLES);
glVertex3f(20.0, 0.0, 20.0);
glVertex3f(-10.0, 15.0, 15.0);
glVertex3f(-10.0, 15.0, 30.0);
glEnd();


And finally, the final exercise which require us to make 4 different quads and collapse each other.





glColor3ub(255,0,0);
glBegin(GL_QUADS);
glVertex3f(-40,20,12);
glVertex3f(-40,25,12);
glVertex3f(40,25,12);
glVertex3f(40,20,12);
glEnd( );

glColor3ub(0,255,0);
glBegin(GL_QUADS);
glVertex3f(-35,-30,11);
glVertex3f(-35,30,11);
glVertex3f(-30,30,11);
glVertex3f(-30,-30,11);
glEnd( );

glColor3ub(255,255,0);
glBegin(GL_QUADS);
glVertex3f(30,-30,13);
glVertex3f(30,30,13);
glVertex3f(35,30,13);
glVertex3f(35,-30,13);
glEnd( );

glColor3ub(0,0,255);
glBegin(GL_QUADS);
glVertex3f(-40,-10,10);
glVertex3f(-40,-10,10);
glVertex3f(40,-10,14);
glVertex3f(40,10,14);
glEnd( );

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

PRACTICAL QUESTIONS
Exercise 1

2) Fill in the empty space in ( ).
Answer:

3) What is the possible window size?
Answer:
A possible window size varies, however 800 x 600 is the best i think, since we always use it.
Exercise 2

1) Find u, v and n.
Answer:
n = eye - look
= (4, 4, 4) - (0, 1, 0)
= (4, 3, 4)
u = up x n
= (0, 1, 0) x (4, 3, 4)
= (4, 0, -4)
v = u x n
= (4, 0, 4) x (4, 3, 4)
= (-12, 32, -12)

2) Repeat for up = (2,1,0).
Answer:
u = up x n
=(2, 1, 0) x (4, 3, 4)
= (-4, 8, -2)

v = u x n
= (-4, 8, -2) x (4, 3, 4)
= (38,-8,-44)
Exercise 3

1) OpenGL stores drawing information in the form of matrices. on the. Can
you briefly describe what does MODEL VIEW matrix and the PROJECTION
matrix does?
Answer:
Modelview matrix is a kind of transformation which include translation, rotation, and scaling of objects, 3D viewing transformation.
Projection matrix is to adjust the position of the "viewing spot" like perspective or orthographic.

2) We can reset the matrix by loading an identity matrix on the top of the
stack. What command is used to reset a matrix?
Answer:
glLoadIdentity() is used.

3) Some parameters have to be set so that our eye can see in the 3D world.
The human eye has a field of view approximately 100°. It also has an
effectively infinite viewing distance. Which command is used to setup
such parameters for the virtual eye?
Answer:

4) The eye can be moved in the world by using the gluLookAt() command.
What do the parameters of the command do?
Answer:
glutLookAt() accepts 9 parameters which have the first 3 as 'eye', another 3 as 'look', and the last 3 as 'up'. Changing the digits will transfer the "eyepoint" to different positions. 'eye' will adjust the position of camera, 'look' is how the eye look at the object, lastly the 'up' is the normal of the object.
Exercise 4

1) What happened to the red triangle?
Answer:
The red triangle did not appear anymore, maybe it is covered by other thing.

2) What do you see now?
Answer:
THE RED TRIANGLE APPEAR AGAIN!!

No comments: