工程|EBU7405:3D Graphics Programming Tools

联系我们: 手动添加方式: 微信>添加朋友>企业微信联系人>13262280223 或者 QQ: 1483266981

SOLUTIONS
Module: 3D Graphics Programming Tools
Module Code EBU7405 Paper A
Time allowed 2hrs Filename Solutions_2122_EBU7405_A
Rubric Answer ALL FOUR questions
Examiners Dr Xianhui Che Dr Pengwei Hao
Question 1
a) This question is about OpenGL 2D Drawing.
[13 marks]
i) The following program intends to draw a square using Visual Studio, but it is not producing the correct output. Identify FIVE fatal errors in the program.
#include
void display(){
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2i(-0.5, 0.5);
glVertex2i(-0.5, -0.5);
glVertex2i(0.5, 0.5);
glVertex2i(0.5, -0.5);
glEnd();
int main(int argc, char** argv){
glutInit(&argc, argv);
glCreateWindow(“Square”);
glutDisplayFunc(display);
(10 marks)
Answer:
Error 1: The command should be glVertex2f instead of glVertex2i. [2 marks]
Error 2: There should be a glFlush(); after the glEnd();. [2 marks]
Error 3: The coordinates given by the glVertex commands are in the wrong order. The correct order can be:
(-0.5, -0.5);
(-0.5, 0.5);
(0.5, 0.5);
(0.5, -0.5);
[2 marks]
[Guidance for marking error 3:]
The four coordinates are shown below. Their sequence of appearance must follow either clockwise or anticlockwise order, and there cannot be any disorder.
Error 4: The function glCreateWindow(“Square”) is wrong. It should be a GLUT function. The correct format is glutCreateWindow(“Square”); [2 marks]
Error 5:
There should be a glutMainLoop() function at the end of the main (). [2 marks]
ii) Explain the difference between the following OpenGL primitives. Draw diagrams to aid your discussion.
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP

(3 marks)
Answer:
[The drawing does not have to be identical, as long as the style matches.]

GL_LINES:
It takes coordinates pair by pair and draw straight lines. [1 mark]

GL_LINE_STRIP:
It connects all coordinates with straight lines. [1 mark]

GL_LINE_LOOP:
It connects all coordinates with straight lines, and it also connects the last coordinate with the starting coordinates. [1 mark]

b) This question is about OpenGL Coordinates and Viewing.
[7 marks]

i) Assume Figure 1 shows a display window of 10*10. In order for the coordinates to be used with the values as annotated in Figure 1, explain what must be implemented in the program to make it happen.

Figure 1
(4 marks)

Answer:
The display window is 10*10, so the following code should be used in the main.
glutInitWindowSize(10, 10);
[1 mark]

The following code should be used for initialisation.
glMatrixMode(GL_PROJECTION); [1 mark]
glLoadIdentity(); [1 mark]
gluOrtho2D(0, 10, 0, 10); [1 mark]

ii) Figure 2a shows a display window of 640*480 without using any viewport command. Explain how the program can be changed using viewport to achieve the outcome of Figure 2b.
(3 marks)

(a) (b)
Figure 2
Answer:
glViewport(0, 0, 1280, 960);
[3 marks in total.
Writing the correct command: 1 mark
Giving the right values for the input parameters: 2 marks]

c) This question is about OpenGL 3D Drawing.
[5 marks]

The following coordinates have been used to draw a cube:
GLfloat CubeVertices[][3] = {{-1.0,-1.0,1.0}, {-1.0,1.0,1.0}, {1.0,1.0,1.0}, {1.0,-1.0,1.0}, {-1.0,-1.0,-1.0}, {-1.0,1.0,-1.0}, {1.0,1.0,-1.0}, {1.0,-1.0,-1.0}};

The output is shown in Figure 3a. Explain the reasons for the improper display of the cube, and devise solutions to have an output as shown in Figure 3b.

(a) (b)
Figure 3
Answer:
Reason 1: The cube is currently projected on a 2D screen and only one facet of the cube is shown. [1 mark]
Solution:
Rotation: Use glRotate to spin the cube. [1 mark]
In order to show all the facets like Figure 4b, the cube needs to rotate around all the axis: x, y, and z. [1 mark]

Reason 2: The current cube is too big to fit within the display window. [1 mark]
The solution is either changing the values of the coordinates (make it smaller) or zooming out. [1 mark]

Question 2

a) This question is about OpenGL Events and Animation.
[8 marks]
i) Explain the purpose of glutPostRedisplay() function and its key role in implementing animation.
(5 marks)

Answer:
The display callback is executed whenever GLUT determines that the window should be refreshed. Many events may invoke the display callback function [1 mark]

Can lead to multiple executions of the display callback on a single pass through the event loop. [1 mark]
We can avoid this problem by instead using glutPostRedisplay() which sets a flag. [1 mark]
GLUT checks to see if the flag is set at the end of the event loop. If set then the display callback function is executed. [1 mark]
In animation, this function can be placed inside idle callback. [1 mark]

ii) Explain how to detect that the user has pressed the Shift key.
(3 marks)
Answer:
The callback declaration function is:
glutSpecialFunc(). [1.5 marks]

Inside the callback function, the following condition should be met:
if (glutGetModifiers() == GLUT_ACTIVE_SHIFT) [1.5 marks]

b) This question is about OpenGL Colours and Lighting.
[9 marks]
i) Figure 4a shows the original colour of a certain colour. Explain what types of light effect has been used in Figure 4b, 4c, and 4d. Also explain what function can be used to set up the light effect types and relevant parameters.

(a) (b) (c) (d)
Figure 4

(6 marks)
Answer:
(b) Original + ambient [1.5 marks][The word “Original” is not compulsory.]
(c) Original + ambient + diffuse [1.5 marks] [The word “Original” is not compulsory.]
(d) Original + ambient + diffuse + specular [1.5 marks] [The word “Original” is not compulsory.]
Function: glLight* [1 mark]
It takes three input: light id, parameter name, parameter values. [0.5 mark]

ii) An OpenGL program intends to render a 3D red teapot image in the display window. However, the output is black-and-white colour, as shown in Figure 5. Discuss what may have caused the loss of colour and suggest a fix for the problem.

Figure 5

(3 marks)

Answer:
Reason: When lighting is enabled, a vertex colour is not determined from the colour set by glColor, but by the currently set material colours combined with the light colours using the lighting computations. Therefore glColor is no longer valid. [1.5 marks]
Solution: Use glEnable(GL_COLOR_MATERIAL) to change the material setting before rendering. [1.5 marks]

c) This question is about OpenGL Camera and Transformation.
[8 marks]
Figure 6 presents the isometric view of two 3D cubes and three-dimensional axis. Cube A is centred around the coordinates (0, 0, 0) and has a size of 0.5. Cube B is drawn by transforming from Cube A, without jeopardising the existing matrix. Fill the blank in the code below to achieve the output as shown in Figure 6.

Figure 6

Answer:

Question 3
a) Give four methods for spatial-partitioning representations.
[4 marks]
Solution:
Cell decomposition (voxels)
Spatial occupancy enumeration
Octrees
Binary Space Partition.
(1 mark for each point, total 4 marks)

b) This question is about geometric transformations.
[15 marks]
i)Consider Model A and Model B in Figure 7. Give a chain of the basic transformation matrices for translation, scaling and rotation which, when post-multiplied by the homogeneous coordinates of the vertices of Model A, will transform the vertices of Model A into their corresponding vertices of Model B, such that the vertex at of Model A is transformed to the vertex at of Model B.
(7 marks)

(Model A) (Model B)
Figure 7
Solution:
The matrices can be for translation, for scaling, for rotation , and for translation: (2 marks)
(1 mark) (1 mark)
(2 marks)
(1 mark)
[Total 7 marks]

ii) Compute the composite 2D transformation matrix for the transformations found in question i) above.
(4 marks)
Solution:

(1 mark for each step, total 4 marks)

iii) Give the transformation matrix for the reverse transformation from B to A.
(4 marks)
Solution:

(1 mark for each step, total 4 marks)
c) This question is about colour and lighting.
[6 marks]

i) Give the relations between additive colour spaces and subtractive colour space.
(2 marks)

Solution:
[C,M,Y] = 1 – [R,G,B]
[R,G,B] = 1 – [C,M,Y]
(total 2 marks)

ii) How does the flat shading method work What are the advantages and disadvantages
(4 marks)

Solution:
flat shading: Compute lighting once at one point per polygon and assign the color to the whole polygon. (2 marks)
Advantage: Good for coarse preview of scenes. (1 mark)
Disadvantage: but it has Mach Band Effect. (1 mark)
(total 4 marks)

Question 4
a) This question is about projection.
[15 marks]
i)Give the difference between orthographic, axonometric and oblique projections.
(3 marks)

Solution:
Orthographic (DOP, VPN and coordinate axis are the same)
Axonometric (DOP and VPN are the same)
Oblique (DOP and VPN are not the same)
(1 mark for each, total 3 marks)

ii) In the world coordinate system, if the view plane normal is (2,1,2), the view-up vector is (1,0,1), the view reference point is (3,4,5) for the origin of the view reference coordinate system, and the distance from the centre of projection to the view plane is 2, find the transformation matrix for the perspective projection.
(12 marks)
Solution:
The translation matrix to the view reference point:
(1 mark)
The 3 axis vectors are (1 mark for n, 2 marks for u and 2 marks for v)

The rotation matrix is
(2 marks)
The perspective projection
(1 mark)
The composite transformation matrix is

(3 marks)

(total 12 marks)

b) This question is about rasterisation.
[10 marks]
i) For a line through two points (x0, y0) and (x1, y1), give the explicit and the implicit functions as the line equations, y=f(x) and F(x,y)=0.
(4 marks)

Solution:
Implicit equation: F(x,y) = (y1 – y0)(x – x0) – (x1 – x0)(y – y0) = 0 (2 marks)
Explicit equation: y = f(x) = y0 + (x – x0) (y1 – y0) / (x1 – x0) (2 marks)
(total 4 marks)

ii) Give the normal vector of the line you find in i) and use sketches and formulas to show a point is what half-planes.
(6 marks)

Solution:
The normal vector of the line is [(y1 – y0), –(x1 – x0)]. (2 marks)
In the normal vector positive side is positive: dot product of the normal vector and the vector from a point on the line to a point in the half-plane, F(x,y)>0. (1 mark for the fomula and 1 mark for the corresponding sketch)
In the normal vector negative side is negative: dot product of the normal vector and the vector from a point on the line to a point in the half-plane, F(x,y)<0. (1 mark for the fomula and 1 mark for the corresponding sketch) (total 6 marks)

发表评论

了解 KJESSAY历史案例 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读