The purpose of this lab is to make use of an existing class library to implement an application.
In this lab, you will:
You have been asked to design and implement a simple computer animation. You have been given an application framework and a class library of graphic objects. These graphic objects (e.g., a car body) can be arranged in a drawing area; member functions set the size, position, rotation, and color of the objects. The application framework sequences the animation. Your job is to implement a module that defines the graphic objects and controls their behavior. The final animation program might look like this:
Your module must provide the following:
The interfaces to your functions are as follows:
unsigned int SetupAnimation (CDrawArea& draw_area); // Initializes the animation. // Arguments: // draw_area - Drawing area object that will contain drawing elements. // Returns: // Maximum number of frames in the animation. // Side effects: // Adds drawing element objects to the drawing area. void ResetAnimation (); // Resets the drawing elements to their initial states. // Arguments: // None. // Returns: // Nothing. // Side effects: // Initializes drawing element objects to initial states. void DoNextFrame (unsigned int frame); // Modifies drawing elements for next frame of the animation. // Arguments: // frame - Frame number (1 .. n). // Returns: // Nothing. // Side effects: // Modifies drawing element objects for next frame of // animation. |
You can find these interfaces in the file anim2.h and sample definitions in the file anim2.cpp. Your job is to replace the body of the module to create your own unique animation.
The graphic objects you have to work with are as follows:
| Body | The body of a car. |
| Wheel | A car wheel. |
| Ball | A ball (used as a cannonball in lab 4). |
| Cannon | A cannon (previously used in lab 4). |
| plane | The body of a helicopter. |
| propeller | A helicoptor propeller blade. |
| hour_hand | The hour hand of a clock. |
| min_hand | The minute hand of a clock. |
| sec_hand | The second hand of a clock. |
Each of these objects has the following member functions:
int GetXPosition () const; // Gets the x coordinate of an object. // Returns: // The x-coordinate of the object, in pixels, relative to the // left side of the drawing area. |
int GetYPosition () const; // Gets the y coordinate of an object. // Returns: // The y-coordinate of the object, in pixels, relative to the // bottom of the drawing area. |
void SetPosition (int x, int y); // Set object position // Arguments: // x - element x-position (pixels) within drawing area // y - element y-position (pixels) within drawing area |
void Move (int dx, int dy); // Modify object position // Arguments: // dx - distance (pixels) to move in x direction // dy - distance (pixels) to move in y direction |
double GetRotation () const; // Get object rotation // Returns: object rotation (degrees) // Zero degrees is normal orientation; positive angles indicate // clockwise rotation. |
void SetRotation (double ang); // Set object rotation // Arguments: // ang - object rotation (degrees) // Zero degrees is normal orientation; positive angles indicate // clockwise rotation. |
void Rotate (double delta_angle); // Rotate element // Arguments; // delta_angle - element rotation (degrees) // Zero-degree argument leaves rotation unchanged; // positive angles indicate additional clockwise rotation. |
unsigned int GetSize () const; // Get object size // Returns: object "standard" size in pixels |
void SetSize (unsigned int sz); // Set object size // Arguments; // sz - object size (pixels) |
void SetColor (int r, int g, int b); // Set element color // Arguments; // r - red component (0-255) // g - green component (0-255) // b - blue component (0-255) Note: In the current implementation, the Ball and Cannon objects do not make use of the color set by this member function. |
The graphic objects are actually displayed in a drawing area, represented by an object of type CDrawArea. This object has one member function that you will need to use, to incorporate each of your graphics objects into the drawing:
void AddElement (DrawingElement& elem); // Add a graphic object (drawing element) to the // drawing area // Arguments: // elem - element to add to list // This drawing element may be any of the graphic object // types: Ball, Cannon, Body, Wheel. |
An example of how this member function is used can be found in the anim2.cpp sample code, in function SetupAnimation. Objects are drawn in the order you add them to the drawing, so "later" objects are drawn "on top of" the ones that were added first.
If you have difficulties with any part of the lab, consult the instructor for assistance. The basic sequence is:
If you are using an older compiler on another system, the following files contain older versions of this lab. You may be able to do some development with them.
The lab report should consist of the following:
You may submit this report in hard-copy form, or email it to the instructor. If you choose email, it may be convenient to put the textual portion of the report directly in the message, and to attach the source file. 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.
The lab report is due by the beginning of the following lab period, though you are encouraged to submit it sooner if you can. Your grade will depend on quality of design and clarity of the code and documentation, as well as the creativity of your particular animation. If you have any questions, consult the instructor.
In addition to the lab report, please demonstrate your final program to the instructor. This may be done during the lab period, or at another mutually agreed time. The demonstration should be done no later than the first hour of the following lab period.
The animation program is based on an earlier DOS version developed by Professor Sue Fitzgerald of Metropolitan State University.
The plane and clock objects were developed by Dr. Lisa Milkowski.
This page was last updated on September 02, 1997; send comments to Mark Sebern.