CSE
581 Lab 1 (10 points)
Due: Thursday, Oct 19th
Objectives: You are expected to learn
Tasks: Write an OpenGL 2D drawing program with the following features:
1. (5 pts) Use mouse and keys to draw polylines
· Use the left mouse button to select a starting position (x,y) inside the window to begin a line
· Use key ‘f’ and ‘t’, ‘S’, and ‘s’ to extend, turn, and scale the line
o When ‘f’ is pressed, connect the current point (x,y) and the next point (x’,y’) with a line segment. The next point is calculated as:
§ x’ = x + D * u
§ y’ = y + D * v where (u,v) is the direction that the line is heading to. The initial value for (u,v) can be (1,0). D is to control the distance between the current and the next point. You can use a default value such as 20 for D.
o When ‘t’ is pressed, you will turn the direction of the line by an angle of A. In other words, you will rotate (u,v) in the following way:
§
u’
= u cos(A) – v sin(A)
§ v’ = u sin(A) + v cos(A). You can use some default value such as 45 degree for A. Note that you should use radians rather than degrees input to the sin and cos functions in your C/C++ program.
§ And then calculate the next point based on the new u and v as in ‘f’
o When ‘S’ is pressed, you scale up the (u,v) vector by 50%, that is:
§ u’ = 1.5 * u
§ v’ = 1.5 * v
o When ‘s’ is pressed, you scale down the (u,v) vector by 50%, that is:
§ u’ = 0.5 * u
§ v’ = 0.5 * v
· Every time when the user clicks the left mouse button at a new location, a new polyline will start.
· Use GLUT pop up menu to select colors for the lines. You can list some fixed colors in the menu for the user to choose.
2. (4 pts) Now, if each of the key strokes above is implemented as a function, for example, ‘F’ -> FORWARD, ‘T’ -> TURN, ‘S’->SCALEUP, ‘s’->SCALEDOWN, then you can use those functions to generate some interesting patterns automatically. Some examples:
Polygon (N) Star (N) Spiral(N,A,S)
Repeat N times { Repeat N times { Repeat N times {
Forward Forward Forward
Turn 2 p/N Turn 4p/N Turn A
} } Scale S
}
· Implement all the patterns above and let the user to draw the shape in the following way:
o The initial position of the shape is defined by a left mouse button click on the screen.
o After the initial position is defined
§ Press key ‘p’ to draw a polygon at the position
§ Press key ‘a’ to draw a star at the position
§ Press key ‘r’ to draw a spiral at the position
· Every time when the user clicks the left mouse button at a new location, a new shape will be drawn after one of the keys is pressed
· Use GLUT pop up menu to select colors for the shapes. You can list some fixed colors in the menu for the user to choose.
3. (1 pt) Allow the user to clear the screen using menu and start all over
4. Bonus point (up to 2 points)
(1 pt) design a way to let the user draw polygons in a similar way as 1 rather than just lines
(1 pt) design some more interesting patterns using a similar method as in 2.
(1 pt) allow the user continue to draw lines or shapes after the window is resized. The lines and shapes should be drawn at
the place the mouse button is pressed on the screen
Submitting Files
What to submit?
§ Your program souce files
§ The Visual Studio (.Net or VC 6.0) solution file you used to compile your program.
§ A readme file about how to compile and use your program.
Do not submit any executable or object files.
In order to submit files for cse581 lab1, use the following command:
submit c581aa lab1 < names of all your files>
(for other labs, replace lab1 by lab2, lab3, etc.)
Important Note about the 'submit' program
The 'submit' program submits all of the files at once, not one at a time, previous submissions for a given lab are completely removed. Or put another way; each time the submit command is issued for a given lab, ALL of the previously submitted files are clobbered.
That means that
submit
c581aa lab1 lab1.c
submit c581aa lab1 readme
will result in ONLY 'readme' remaining in the lab1 submission
You should do the following:
submit
c581aa lab1 lab1.c readme
or
submit c581aa lab1
lab1_dir
Where 'lab1_dir' is a directory containing all of the lab1 files to be submitted, or best of all (for both student and grader) is:
cd lab1_dir
submit c581aa lab1 .
Submit will immediately print submission information to the submitter. Use 'man submit' if you have any other questions.
Late Penalty
You should submit your lab on time. We are on a quarter schedule, which is pretty tight. Being late for one lab could affect the time left for you to complete subsequent labs. All labs are due at 11:59pm of the specified due data, and there is a 10% penalty each day for up to 50%. After that, you get zero.
Grading Criteria
Grading of the labs will be based on the following:
The grader will grade the labs. If you have problems with the grade you received on your lab, see the grader first. If you can't resolve the dispute with the grader, then see me. However, in order to maintain consistent grading for everyone in the class, I am not very inclined to alter grades that are assigned by the grader.
Don't copy labs. Discussion of lab assignments is allowed and
encouraged. However, you need to complete the lab all by yourself. Labs which
are too similar will be handed over to the Committee on Academic
Misconduct and handled by them.