CS计算机代考程序代写 1

1

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

2

c)

𝐿𝐿 = (0, 1,0)
𝐼𝐼𝑎𝑎 = 0.5
𝐼𝐼𝑙𝑙 = 0.5
𝑘𝑘𝑎𝑎 = 0.1
𝑘𝑘𝑑𝑑 = 0.3
𝑘𝑘𝑠𝑠 = 0.9 𝑛𝑛𝑠𝑠 = 2

𝑉𝑉 = |(100,0,100) − (0,0,0)| = �
1
√2

, 0,
1
√2

𝑁𝑁 = �
1
√2

,
1
√2

, 0�

𝑅𝑅 = 2(𝑁𝑁 ∙ 𝐿𝐿)𝑁𝑁 − 𝐿𝐿 = (1,0,0)

𝐼𝐼 = 𝑘𝑘𝑎𝑎𝐼𝐼𝑎𝑎 + 𝑘𝑘𝑑𝑑𝐼𝐼𝑙𝑙(𝑁𝑁 ∙ 𝐿𝐿) + 𝑘𝑘𝑠𝑠𝐼𝐼𝑙𝑙(𝑉𝑉 ∙ 𝑅𝑅)𝑛𝑛𝑠𝑠

= (0.1)(0.5) + (0.3)(0.5) �
1
√2
� + (0.9)(0.5) �

1
√2

2

= 0.381066017

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
5
𝐼𝐼𝐶𝐶 +

4
5
𝐼𝐼𝐴𝐴 =

1
5

(1.0) +
4
5

(0.5) = 0.6

b)

𝑥𝑥𝐷𝐷 =
1
5
𝑥𝑥𝐶𝐶 +

4
5
𝑥𝑥𝐴𝐴 =

1
5

(10) +
4
5

(0) = 2
𝑥𝑥𝐸𝐸 = 10

𝑁𝑁𝑃𝑃(𝑥𝑥) =
𝑥𝑥 − 2

8
𝑁𝑁𝐸𝐸 +

10 − 𝑥𝑥
8

𝑁𝑁𝐷𝐷 =
(𝑥𝑥 − 1) − 2

8
𝑁𝑁𝐸𝐸 +

10 − (𝑥𝑥 − 1)
8

𝑁𝑁𝐷𝐷 +
𝑁𝑁𝐸𝐸 − 𝑁𝑁𝐷𝐷

8

= 𝑁𝑁𝑃𝑃(𝑥𝑥 − 1) +
(0,1,−1)

8

3

Qn 4

a)

𝑁𝑁 ∙ 𝑉𝑉 = 0.5 > 0 ⟹ Front face

Back face detection (or culling)

b)

i) Since the number of Z buffer operations is proportional to the number of pixels being

projected, the number of Z buffer operations are

(30)(100)(100)(500) = 1.5 × 108

ii) For each of the 2560 × 1440 pixel, we send out a pixel ray and test whether it intersects the

30 spheres, therefore the number of intersection calculations are

(2560)(1440)(30) = 1.10592 × 108

iii) 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