Text

 


Objectives:  You are expected to learn

OpenGL 2D line drawing

  1.    GLUT menu and mouse/key  input





Tasks:  Write an OpenGL 2D drawing program with the following features:

1. (5 pts) Use mouse and keystrokes to draw lines

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

oWhen ‘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 experiment and find a good D to use.

oWhen ‘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 30 degree for A. Note that you should use radians rather than degrees to the sin and cos functions in your C/C++ program.

After you compute the new u’ and v’, plug them into the formula above to calculate the new x’ and y’.

oWhen ‘S’ is pressed, you scale up the (u,v) vector by 50%, that is:

u’ = 1.5 * u

v’ = 1.5 * v

oWhen ‘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.

  1. 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.


  1. 2.(4 pts) After all the above keystrokes are implemented, you can combine them to generate interesting shapes.  Let us call ‘f’ -> FORWARD, ‘t’ -> TURN, ‘S->SCALEUP, ‘s’->SCALEDOWN,  you can use the following algorithms to generate some patterns automatically:

   

    Polygon (N)

        Repeat N times {

           Forward

           Turn 2 PI/N

        }


   Star (N)  

        Repeat N times {

            Forward

            Turn 4 PI/N

       }


     Spiral(N,A,S) 

          Repeat N times  {

                Forward

                Turn A

                Scale S

          }


Implement all the patterns above and let the user to draw the shape in the following way:

oThe initial position of the shape is defined by a left mouse button click on the screen.

oAfter 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 ready to draw

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.

  1. 3.(1 pt) Allow the user to clear the screen using menu and start all over by typing ‘c’



Submitting Files

What to submit? 

Your program souce files

The Visual Studio solution and project files you use to compile your program.

A simple readme file if you have any instructions 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 later 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:

90%: Correctness and adherence to assignment specification.

10%: Readability, structure of code, use of comments, adherence to lab procedures (submitting, naming conventions, etc.)

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.
 

 

CSE 581 Lab 1

Due: 1/24/2011 11:59 pm