CS计算机代考程序代写 Answers to Assignment 3

Answers to Assignment 3
Qn 1
GLdouble XC;
glMatrixMode (GL_MODELVIEW); glLookAt (XC, 0, 100, 20, 0, 20, 0, 1, 0);
void animate ( void )
{
double t;
double operation_time = 2000.0;
t = glutGet (GLUT_ELAPSED_TIME);
XC = 100.0 + 100.0 * (1 – pow(cos ( PI * t/(2.0 * operation_time) ), exponent) );
glutPostRedisplay ( ); }
Qn 2
a)
glEnable (GL_LIGHTING);
GLdouble V1 [ ] = {0.0, 1.0, 0.0, 0.0} GLdouble V2 [ ] = {0.5, 0.5, 0.5, 1.0} glLightfv (GL_LIGHT1, GL_POSITION, V1); glEnable (GL_LIGHT1);
glLightfv (GL_LIGHT1, GL_AMBIENT, V2); glLightfv (GL_LIGHT1, GL_DIFFUSE, V2); glLightfv (GL_LIGHT1, GL_SPECULAR, V2);
b)
GLdouble V3 [ ] = {0.1, 0.1, 0.1, 1.0}
GLdouble V4 [ ] = {0.3, 0.3, 0.3, 1.0}
GLdouble V5 [ ] = {0.9, 0.9, 0.9, 1.0}
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, V3); glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, V4); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, V5); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 2.0);
1

c)
𝐿𝐿 = (0, 1,0)
𝐼𝐼𝑎𝑎 = 0.5
𝐼𝐼𝑙𝑙 = 0.5
𝑘𝑘𝑎𝑎 = 0.1
𝑘𝑘𝑑𝑑 = 0.3
𝑘𝑘𝑠𝑠=0.9 𝑛𝑛𝑠𝑠=2 1 1
𝑉𝑉 = |(100,0,100) − (0,0,0)| = �√2 , 0, √2�
𝑁𝑁 = � 1 , 1 , 0� √2 √2
𝑅𝑅 = 2(𝑁𝑁 ∙ 𝐿𝐿)𝑁𝑁 − 𝐿𝐿 = (1,0,0)
𝐼𝐼 = 𝑘𝑘𝑎𝑎𝐼𝐼𝑎𝑎 + 𝑘𝑘𝑑𝑑𝐼𝐼𝑙𝑙(𝑁𝑁 ∙ 𝐿𝐿) + 𝑘𝑘𝑠𝑠𝐼𝐼𝑙𝑙(𝑉𝑉 ∙ 𝑅𝑅)𝑛𝑛𝑠𝑠
= (0.1)(0.5) + (0.3)(0.5) � 1 � + (0.9)(0.5) � 1 �2 = 0.381066017 √2 √2
d) Phong shading
Because 𝑘𝑘𝑠𝑠 ≫ 𝑘𝑘𝑑𝑑 , 𝑘𝑘𝑎𝑎 , the object is specular. Phong shading will make sure that the specular highlight is not missing. (Or any other reasonable answer.)
Qn 3
a) 1 4 1 4
𝐼𝐼𝐷𝐷 =5𝐼𝐼𝐶𝐶 +5𝐼𝐼𝐴𝐴 =5(1.0)+5(0.5)=0.6
b) 1 4 1 4
𝑥𝑥𝐷𝐷 =5𝑥𝑥𝐶𝐶 +5𝑥𝑥𝐴𝐴 =5(10)+5(0)=2
𝑥𝑥𝐸𝐸 =10 𝑥𝑥−2 10−𝑥𝑥 (𝑥𝑥−1)−2 10−(𝑥𝑥−1) 𝑁𝑁 −𝑁𝑁 𝑁𝑁𝑃𝑃(𝑥𝑥)= 8 𝑁𝑁𝐸𝐸+ 8 𝑁𝑁𝐷𝐷= 8 𝑁𝑁𝐸𝐸+ 8 𝑁𝑁𝐷𝐷+ 𝐸𝐸8 𝐷𝐷
=𝑁𝑁 (𝑥𝑥−1)+(0,1,−1) 𝑃𝑃28

Qn 4
a)
𝑁𝑁∙𝑉𝑉=0.5>0 ⟹ Frontface Back face detection (or culling) b)
i)
ii)
iii)
(30)(100)(100)(500) = 1.5 × 108
For each of the 2560 × 1440 pixel, we send out a pixel ray and test whether it intersects the
Since the number of Z buffer operations is proportional to the number of pixels being projected, the number of Z buffer operations are
30 spheres, therefore the number of intersection calculations are
(2560)(1440)(30) = 1.10592 × 108
For each of the 30 objects, there are 100 × 100 quadrilaterals or 100 × 100 × 2 triangles.
Thus, the number of intersection calculations are
(2560)(1440)(30)(100)(100)(2) = 2.21184 × 1012
3