Lab 04: Transforming Shapes

This lab is really meant to assist with HW04, but due to scheduling, we’re doing it now. Dr. Wong suggests that you branch your HW02 or HW03 (depending on which is more complete) into Lab 04.

Concepts

  1. In your MVC, the line “import  model…” and “import view…” should only ever appear in the Controller. The line “import controller…” should not appear anywhere in your Model or View.
  2. Basically, we want to turn all shapes into unit-sized entities centered on the origin, as this will most easily permit us to use affine transformations in drawing. For a circle, “unit size” seems pretty clear: unit radius or maybe unit diameter. For a strange shape, however (Dr. Wong draws something that looks like a squashed bug), “unit size” is less  defined. Maybe it is the circle that most tightly encloses it? Maybe it is a circle whose radius is some average of the distances between the points around the perimeter and the geometric center? etc.
  3. It’s important to center your objects around the origin before you start transforming. Otherwise, transformations can easily affect them in drastic and undesired ways.
  4. Dr. Wong suggests trying to load and draw an image as part of Lab 04. Images can be tougher, as images’ origins are in their upper left-hand corners. Dr. Wong suggests using paintCfg(…) to reposition the image somehow to put it at the origin. Keep in mind that you’ll need to maintain the aspect ratio of non-square images when transforming them to unit size. Also, if your image contains a large whitespace border around the content, you may need to use test collision with a shape that is somewhat to substantially smaller than the rectangle of the image. Also, make sure the content of your images is centered within the image :D.
  5. Some of your shapes (including images) will have a non-identity “initial transformation” that will bring them to unit-size at the origin. Then, you can layer other transformations on top of this initial one to draw it wherever you need it. You should do this because you really don’t want to alter image data to bring it to an initial state: scaling images would lose resolution, etc. Instead, just composite multiple transformations to achieve your goal.
  6. Note that all of these transformations are reapplied during every draw; you never permanently alter your images or other shapes, but instead just set up the Graphics2D correctly each frame to draw through the transformations.
  7. If Dr. Wong or another staff member has not yet looked at your MVC design, he urges you to have it looked at to avoid losing points on HW03 and beyond.
After a 25 minute lecture, it looks like we’re now going to have work time for the rest of the lab.

Quotes

  1. “It’s like a never-ending battle, and I’m always losing.” — Dr. Wong on trying to adjust his class schedule year after year.

Resources

  1. Lab 04: http://www.clear.rice.edu/comp310/f12/labs/lab04/