"...ut in omnibus glorificetur Deus."
(...that in all things God may be glorified.)
Rule of St. Benedict (RB 57:9)

      CS 251-Computer Graphics

Homework 3


 
Due: Friday, October 24 Points: 70 points (10 points are for following directions and good documentation)

Written Problems (10 points)

  1. Do practice exercise 4.3.2 (p. 156) 2 points
  2. Do practice exercise 4.3.13 (p. 160) 2 points
  3. Do practice exercise 4.6.14 #1,2 (p. 184) 2 points each
  4. Do practice exercise 4.7.1 part (c) (p. 187) 2 points

Programming Project (60 points)

Complete CASE Study 4.4 on pp. 200-201 with the following, additional stipulations:

  1. Create a Vector2 class with functionality similar to what was on the exam. You should have vector arithmetic, dot products, and perp. You may also encode orthogonal projections and reflections into the vector, if you'd like.
  2. Use your Polygon and Shape classes from HW2.
  3. Add to your Shape and Polygon classes a new function which you will use to determine the hit time of a ray into your Shape. This function will be slightly different from what is described in the book. Its prototype should be the following:
    bool rayHit(Ray thisRay, double &tHit, Vector2 normal);
  4. Modify your Polygon so that it stores the normals to each line segment. You should compute these normals as points are entered. You can compute the first normal after the 2nd point has been entered. Then, the ith line segment will be described in point-normal form by (normals[i], points[i]).
  5. You don't need to understand the entire Cyrus-Beck Clipping algorithm in order to compute the hits. If you'd like to read over it, you should focus on the steps needed in order to find tin for a given ray. That is all described on pp. 190-191 with an example on p. 192.
  6. As a short summary, in your rayHit function, you need to use an auxiliary, private function bool rayHitAux(Ray thisRay, int which, double &tHit); to test each line segment
    1. use eq. 4.59 on p. 186 to find the intersection of thisRay and each line segment in your Polygon.
    2. Check whether it is an incoming intersection or an outgoing intersection with eq. 4.64 on p. 191
    3. If it is an incoming intersection, return the hit time in tHit.
    4. Otherwise return false
    5. Then in rayHit, you must keep track of which incoming hit has the highest (positive) value.
    6. After all have been tested, return the normal and tHit for the highest tHit and true
    7. If there is no positive, incoming hit, return false
  7. As you use rayHit to find the hit time for each polygon, you need to keep track of the lowest (positive) hit time and corresponding normal vector.
  8. Then you may use thisRay's vector and the normal vector to determine the reflection vector.
  9. using tHit in thisRay you may find the point of intersection.
  10. The path of the ray may be stored as a polyline.
  11. You should be able to see the ray in action by pressing some key to advance the ray to its next hit.

EXTRA CREDIT: (only acceptable if all other parts are completed) (up to 20 points)

  1. Add Rectangles in addition to Polygons (10 points)
  2. Add Circles (10 points)
  3. Have the Shape that was just hit fill itself. (10 points)
  4. Any other suggestions will be considered before the assignment is due.

Miscellaneous NOTES:

  1. Create and test your Vector2 in a text program.
  2. Then start by working things out with one polygon. In your myDisplay function, hard-code the sample Polygon by hand. Create the Ray by hand and call the poly's rayHit routine with your sample ray. Once you get that working, then start to generalize.
  3. I will only accept a program that compiles and runs, so make sure you're working incrementally so that you always have a running program that displays what you've done so far.
  4. Your program must be well documented, following the example of the example programs passed out in class.

Turning in your Assignment:

    Hardcopy:
  1. Turn in a sheet with the answers to the written problems.
  2. Do not turn in a print-out of your code.

  3. Softcopy:
  4. Make a directory called "hw3" in your cs251 homework directory.
  5. Place all necessary ".h" and ".cpp" files, as well as the project and workspace files into this directory before class begins (12:30pm).
  6. Create a README file for anything you want to tell me (including what Extra credit you did, if applicable)
  7. As on the syllabus, No Late Assignments are accepted