|
|
 |
CS-321 Lab 4: 2D Graphics
Summer Quarter 1999
Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor
S-331, 277-7339
t a y l o r@m s o e.e d u (remove spaces)
www.msoe.edu/~taylor/
Acknowledgment
This lab was originally developed by Dr. Henry L. Welch.
Purpose
The purpose of this laboratory assignment is to add the following
functionality to your graphics shell: drawing lines and polygons, simple
2D transformations, and color capabilities.
Assignment
Your are to do the following:
- Add a command line command that accepts two points (as x/y pairs) and
draws a line between the to points.
- Update your button pressing code so that you can draw both lines and
polygons using the mouse. (You may remove drawing points using the
mouse, but you should keep points on the command line.) Here are some
issues which you should consider:
- You may find it helpful to differentiate between the two mouse
buttons or to look at the shift key during a button event.
- Keep in mind that separate events will be used for each vertex or
line end. Therefore, state information will have to be shared
between callbacks. Generally speaking, it is better to use
static objects which are local to the member function
than to use a data member of the class since doing so would make
it accessible to other member functions.
- You may want to experiment with pressing/releasing the mouse
button outside of the drawing window. Are the results what you
expected?
- For an additional challenge use the motion event to "draw"
the line or polygon edge in progress; although this is
not a requirement.
- There are a number of dynamic memory challenges involved with storing
objects of varying sizes (polygons, lines, and point objects). Be
sure to review your understanding of dynamic memory allocation.
Depending on how you proceed, this may complicate your memory
recovery operations in some of your destructors.
- Add a command line color command that either accepts RGB values, uses
one of the standard X color names from the standard list in the file
/usr/lib/X11/rgb.txt or by using the Color
class. Once a new color is selected, all subsequent objects should
appear in that color until a new and correct color editor command is
entered. During an exposure redraw each object should appear in the
color in which it was first drawn so you will need to save the color
information (as a GC or pixel value) with the object itself.
Unfortunately, both of these present a problem since both graphical
contexts and pixel values in the colormap are dynamically allocated on
both Torres and the PC. Consequently you will need to keep track of
them and then free them before exiting using either XFreeGC
or XFreeColors respectively (see
additional information). This is probably
best handled in a special member function of the image class or in
the image class destructor.
- Implement support for the following shell buttons by overriding the
appropriate Shell member functions:
- Zoom - Scale by a factor of two about the drawing window center (the
window is 500x350).
- UnZoom - Scale by a factor of 0.5 about the drawing window center.
- Reset - Draw each object as it was originally input (i.e. undo all
transformations done to it).
- Erase - Erase the image and free all dynamic memory associated with
drawing the objects (not undoable).
- Add commands on the command line to:
- Rotate by any angle about any point
- Select any point as the new drawing window center
- Update your help information.
Transformations often present a number of numerical problems to the graphics
programmer. If implemented without thinking carefully the original drawing
data can be corrupted beyond recovery. One of the best methods of doing
this is to always maintain a copy of the original drawing data. As each
transformation is processed have it change the transformation matrix for
that particular graphic entity and then use the composite transformation
on the original data to obtain the current drawing information. This will
prevent the rounding errors that can occur if we, for example, UnZoom and
then Zoom using integer coordinate data. (This will also simplify Reset.)
Note: Reset does not need to "undo" any transformations that occured prior
to the drawing of a shape. It is sufficient to simply have it revert to
the size, orientation, and location in which the object was initially drawn.
Think carefully about which transforms may be local to a shape and which
are global to all shapes.
Also keep in mind that despite the global nature of the transformations
we are really implementing modeling transformations which will affect each
object differently. Consequently you will not be able to complete this
portion of the lab without having each object store its own composite
transformation matrix.
Although not required, you may find it useful to implement the file
reads and writes.
There are plenty of areas for extra credit with this assignment, however
you must complete the basic requirements in order to receive the extra
credit.
NOTE: This is a double credit lab!
Lab report (due 5pm, July 1, 1999)
The lab report should be self-contained. That is, it should be possible
for someone to understand what you did and why without seeing anything other
than your report. Your report should include:
- Purpose
- Problem Statement
- Procedure -- what approach you used to solve the problem
- Documented source code (clearly
identifying any changes made since your last submission)
- Discussion including:
- A tally of the number of new Non-commented Lines Of
Code (NLOC) written for this lab assignment. You may use the
CLC
perl script on your code. If possible, break the NLOC down
into the various features you needed to implement.
- A summary of your activity log indicating how much time you spent
on each phase of the assignment.
- A narrative describing any specific problems you encountered and how
you solved them.
- Conclusions (what you learned, suggestions of how the lab could be
improved, things you would have done differently, etc.)
As with any report you submit, correct spelling and grammar are
required. In addition, your report should be submitted electronically
following the Electronic Submission
Guidelines. (You may wish to consult the
sample report before submitting your
report.) Be sure to keep copies of all your files, in case something
gets lost. It may be wise to keep a diskette backup as well.
If you have any questions, consult the instructor.
This page was created by Dr.
Christopher C. Taylor.
|