You are on page 1of 2

QATAR UNIVERSITY

College of Engineering
Dept. of Computer Science & Engg

Homework
Date: 13/12/2014 @ 11:59PM
Weight: 10%

Computer Graphics (CMPS 373)


Fall 2014 Semester

ANSWER THE FOLLOWING:

Question1.

[5 marks]

a) Write a function called leftMotif() that draws two arcs inside a


square (see the figure on the right). The arcs are drawn each with
its center at opposite corners of the square (bottom-left corner and
top-right corner) and its radius is equal to the side of the square.
Use the following prototype:
void leftMotif(float side);
To draw the square you may use the ngon() function with the
center point at (
) and
rotation angle to 45 degrees.

. Also set the

b) Write another function called rightMotif() that draws two arcs


inside a square (see the figure on the right). The arcs are drawn
each with its center at opposite corners of the square (bottom-right
corner and top-left corner) and its radius is equal to the side of
the square. Use the following prototype:
void rightMotif(float side);
To draw the square you may use the ngon() function with the
center point at (
) and
rotation angle to 45 degrees.

. Also set the

c) Using leftMotif() and rightMotif()


and a suitable display function draw the
following pattern.

-1/2-

Question2.

[5 marks]

3d
a) Write a C++ function that draws the diamond shown
on the right. The left vertex is at (x0,y0), and the
lengths of its diagonals are d and 3d . The function
prototype is:

y0

void drawDiamond (GLfloat x0, GLfloat y0, GLfloat d)

x0

b) Write another function that uses the above


drawDiamond() function to draw the logo on the
right which consists of three blue diamonds, which
make 120o with each other. The vertices meet at the
point (xc, yc) which is the center of the logo. The
function prototype is:
void drawLogo (GLfloat xc, GLfloat yc, GLfloat d)

[ Hint: repeat the following steps three times:


- draw the horizontal diamond, then
- rotate 120 degrees. ]

c) Write a program that rotates the above logo, centered at (0,0), about the z-axis in an anticlockwise direction, at a speed of 1o per screen redisplay. Use double buffering to reduce
flicker. (Hint: position the origin of the xy-plane in the middle of the window.)
d) Add to your program a keyboard callback function which allows the user to choose the
speed of rotation according to the values given in the following table:
Key
Action

E, e
Stop program

S, s
rotate=0

1
rotate=0.75

2
rotate=1.5

Any other key


rotate=1

Artifacts to submit:
An MS-Word document that contains the source code followed by a screenshot(s) of the graphics output
windows, for each of the above two questions . Please include all the code you used so that we can run it
when your work is assessed. Please do not submit as PDF format.
Please make sure you include a cover sheet that includes your own details and the course and assignment
details.

-2/2-