CSC418/2504 : Assignment 1 FAQ

  1. What is GLUT?
  2. How do I get the GLUT library?
  3. How do I drag a vertex?
  4. Can I use code from Q5 for Q6?
  5. What is retracing time?
  6. In Question 2, what is "too much storage"?
  7. In Question 4, do we just draw pictures and try out different cases for those 2 subquestions? Can a quadrilateral be a concave?
  8. What does it mean to drag a vertex?
  9. I still don't get Q6. How do I do it?
  10. Isn't part C of Q6 done for us already?
  11. How can a bunch of (x,y) pairs describe a polygon?
  12. The polygons in data files in2.dat and out2.dat don't make sense!
  13. Q6 bonus: How can I rotate with a single click?
  14. Q6: Should we let the user flip the rectangle over, or drag parts off-screen?
  15. I'm working at home. How can I send my files to CDF?
  1. What is GLUT?

    The openGL library takes care of drawing polygons, but it does not provide for windows and user interaction. The GLUT library takes care of those details.

    If you look the source code for question 6, you'll see that the main program registers five callback functions:

      glutReshapeFunc (handleReshape);
      glutKeyboardFunc(handleKey);
      glutMouseFunc   (handleMouseClick);
      glutMotionFunc  (handleMouseMotion);
      glutDisplayFunc (display);
          
    These tell the GLUT code to call our handleReshape function when the drawing window is resized or exposed, or needs to re-drawn for some reason, to call handleKey when the user presses a key, to call handleMouseClick when they press or release a mouse button, and to call handleMouseMotino when the user moves the mouse with abutton held down ("drags" the mouse). The display function does the actual drawing on the screen, and has all the necessary openGL code in it. You don't call it directly. You have to ask GLUT to call it. You ask GLUT by calling glutPostRedisplay().

  2. How do I get the GLUT library?

    If you're working on CDF, GLUT is already installed. But if you're working on a Windows machine, Microsoft's Visual C includes only the openGL library. You have to get GLUT off the net. The whole compiled library (150Kb) for Windows 95/98/NT is available at SGI's site.

    You will have to install the files yourself. The files should be placed follows, for Windows 98:

    You have to tell Visual C which libraries you're using. This should be set automatically for you if you use the rectangle.dsp file provided. If you don't use it, you'll have to tell VC about the libraries as follows:

  3. How do I drag a vertex?

    You'll need to keep track of what the user did most recently. A finite state machine should help a lot to organize your code. Figure out what the new shape of the rectangle should be, and call glutPostRedisplay to redraw it.

  4. Can I use code from Q5 for Q6?

    You could use the code from Q5, but actually the point-in-polygon problem for a rectangle is a lot simpler: just check if the X and Y of the mouse position is between the left-right bounds of the rectangle, and between the top-bottom bounds.

    Furthermore, you are not just looking for whether the user clicked INSIDE the rectangle, but whether they clicked near a vertex (and which vertex), near an edge (which edge), or somewhere inside.

  5. What is retracing time?

    See the lecture notes on raster graphics off the course web page, to learn how a tv monitor image is created.

  6. In Question 2, what is "too much storage"?

    Too much storage is O(n x n) or O(n) storage. Try to use constant storage.

  7. In Question 4, do we just draw pictures and try out different cases for those 2 subquestions? Can a quadrilateral be a concave?

    Pictures with the worst-case example should be enough for an answer. Assume convex polygons in all cases (no extra points for concave polygons, but you're welcome to answer that problem too).

  8. What does it mean to drag a vertex?

    First, the issue of "nearness": there should be a reasonable neighbourhood of a vertex for the user to click and drag, otherwise it will be very hard to click exactly on the pixel that the vertex covers.

    Secondly, when a vertex is moved, the opposite vertex stays fixed. The moved vertex and the opposite vertex will define a new rectangle. In other words, you have to preserve the rectangular shape. Similarly, when you move an edge, the opposite edge should stay fixed, thus stretching the other two edges with your movement.

  9. I still don't get Q6. How do I do it?

    Think of what's happening from the user's point of view, in detail, when they "drag" a corner:

    1. they click "near" a corner
    2. they move the mouse
    3. they let go the mouse button
    These correspond to the following GLUT calls, respectively:
    1. handleMouseClick (int button, int state, int col, int row),
      with button==GLUT_LEFT_BUTTON,
      and state==GLUT_DOWN.
      col and row tell you where the mouse was when the click happened.
    2. handleMouseMotion (int col, int row),
      repeatedly, every time the mouse moves a bit, to a new position (row,col).
    3. handleMouseClick, with and state==GLUT_UP.
    You have to keep track of these events, and redraw the rectangle every time it changes shape.

  10. Isn't part C of Q6 done for us already?

    Not really. If you click somewhere and let go, the square JUMPS to your mouse position. It's not supposed to do that. You're supposed to be able to move it gradually.

    Another way to look at it is this: if the rectangle was a window on your desktop, you would click the title bar of the window and drag it around. If you clicked in the middle of the title bar, then moved the mouse, the rectangle would still have the mouse pointer in the middle of the title bar.

  11. How can a bunch of (x,y) pairs describe a polygon?

    The convention used is that a list of (x,y) pairs will be considered the vertices of a polygon, as we travel consecutively along the polygon's edges. Implicitly, the last vertex in the list is joined to the first one.

    Thus the list:

    1. (1,2)
    2. (3,4)
    3. (5,6)
    describes a triangle, whose three edges are:
    1. (1,2) to (3,4)
    2. (3,4) to (5,6)
    3. (5,6) to (1,2)

  12. The polygons in data files in2.dat and out2.dat don't make sense!

    Yes they do. They aren't "simple" (their edges cross). The polygon I gave you looks like a bow-tie. Don't worry. It's deliberately like that. It's equivalent to two triangles touching:

    |\     /|
    | \   / |
    |  \ /  |
    | * X   |
    |  / \  |
    | /   \ |
    |/     \|
          
    The asterisk marks the test point, for in2.dat, which is INSIDE the polygon.

  13. Q6 bonus: How can I rotate with a single click?

    Oops! That should read "Click and drag" outside the rectangle to rotate it. Think of a coordinate axis centred on the rectangle, which turns when you drag the mouse. The important thing is:

    and that might be a fair amount of work for one bonus mark.

  14. Q6: Should we let the user flip the rectangle over, or drag parts off-screen?

    Assume the user does not drag vertices or edges outside the window, and does not move vertices or edges past opposite edges, thus flipping the rectangle over.

  15. I'm working at home. How can I send my files to CDF?

    Look here.


Alejo Hausner, Dept of Computer Science, University of Toronto
Last modified: Mon Oct 2 11:53:31 EDT 2000