CS318 - Fall 1999
Machine Problem 0


Assigned:
August 27, 1999
Due Date:
September 10, 1999, 10:00am

Description

This is a simple MP to get you acquainted with OpenGL, WindowsNT, and the machines in the Multimedia Lab (1265 DCL). It will give you a chance to learn the Visual C++ development environment if you are not already familiar with it, practice your C skills, and read the OpenGL manual available on the class web page.

You will be using the built-in drawing commands of OpenGL to draw a very simple graphic. Look at the code samples in the OpenGL tutorial to help you generate a program skeleton.


Goals

Upon completion of this MP, you should be able to do the following things:
  1. Login to the NTs and know how to use the windowing environment;
  2. Use Visual C++ to create a C program; and
  3. Know the basics of OpenGL and be able to apply them to a program.


Preparation

Read the Textbook

Read Chapters 1 and 2 in the required text for this class - ``Computer Graphics, C Version, 2nd Edition'' by Hearn & Baker. Chapter 1 contains background material on computer graphics and has lots of pictures. Chapter 2 gives a good introduction to computer graphics systems. Read them now while you have the time. Also, an OpenGL supplement to this textbook is available. You can view it online at http://www-courses.cs.uiuc.edu/~cs318/OpenGL.html.

Get Your Account

If you registered for the class before August 23, 1999, then an account has automatically been set up for you on the multimedia machines (the WindowsNT boxes in 1265 DCL). If you registered for the class after this date, you may not yet have an account. The TA may need to set up an account for you. Send e-mail to cs318ta1@cs.uiuc.edu to make such a request.

Once your account is set up, you need to get the password for your account. Go any lab sitter (in 1235,1245, or 1275 DCL) and show your Student ID. You will receive a password for your CS318 account. Next, go to one of the WindowsNT machines and login. You should change your password when you first log in so that it is easier for you to remember.

Note: When you get your WindowsNT account, you also get an account on the Sun Sparcs. Initially the password you get from the labsitter will work on both accounts. However, the NTs and the Suns have independent password servers, so if you change your password on one platform, it will not change on the other. You have to do this manually for each of the two platforms.

Look at the Class Web Pages

There is extensive information available on the web page for this class. You should look at it to get an idea of the type and scope of information available. This will save you time later when you have questions.

The class web page is at http://www-courses.cs.uiuc.edu/~cs318/. There, you will find links to information about the class, the textbooks you will need, how to compile your programs, etc. As the semester progresses, you may wish to look at these pages for more detailed information.

Learn OpenGL

We will be lecturing on some basic OpenGL commands in class, but there is no substitute for experience. There is no required textbook for OpenGL, but you are still expected to learn OpenGL primarily on your own during this course. There are several ways to do this.
OpenGL has a very large feature set and cannot be learned in one sitting. You should budget your time accordingly. Plan to spend about 2-4 hours reading the introductory material on OpenGL before you begin programming. Also, remember that there are many students in CS318 and only 30 WindowsNT machines. Realize that the machines may be in use full-time as the due date approaches.


Your Assignment

You are to write a program which generates a ``spirograph''. (Some of you may remember this toy from your childhood.) Basically, a spirograph creates circular shapes by connecting many line segments in different patterns. Your program will take two command line arguments: the first specifies the number of line segments to be used in drawing the figure, and the second specifies the ``step size'', or how many vertices to skip when connecting the vertices. Read on for a better explanation.

Name your C source code file mp0.c, and your program will be called mp0.exe when you compile it. The following images would be created with the command lines below them.

\epsfbox {spiro3.eps} \epsfbox {spiro5.eps} \epsfbox {spiro9.eps}
mp0   3   1 mp0   5   2 mp0   9   4

Check for Invalid Input

You need to check to make sure that the user typed in valid input on the command line. There must be two command line arguments. The first argument is the number of vertices. This is an odd integer between 3 and 99 (inclusive). The second argument is the ``step size''. This is an integer greater than 0 and less than the number of vertices. You can use the C function atoi to convert the command line arguments to integers. While this is not perfect (eg. an input of ``34hello'' would be converted to 34 by atoi), it is suitable for our purposes.

If the user did not enter valid command line argments, print out an error message indicating the correct usage, and exit.

It is important that you test your programs for many different input values since you could lose points if your program bombs on some input. For example, test if it works with no command line options, negative values, ``strange'' values such as text, etc.

Implementation

Once you have scanned the command line for valid user input, you need to draw the spirograph. The figure generated should have a radius of 1.0 and be centered about the origin (0,0). Line segments should all be of equal length (ie. the vertices of the spirograph should be equidistant from each other along the perimeter of the unit circle).

You will probably want to use the commands cos and sin to convert polar coordinates to rectangular coordinates. Be sure to include the math.h header file in your source code. Also note that these functions take angles measured in radians, not degrees.

The first point on the spirograph can be anywhere you choose. In the demo, the first point is placed at position (0,1) on the coordinate axes. Subsequent points on the unit circle must be generated at runtime based on the number of line segments entered by the user.

The ``step size'' is used to indicate which vertices are joined by line segments. A step size of 1 would mean that you connect consecutive vertices around the unit circle, forming a basic polygon with the number of sides equal to the number of vertices. A step size of 2 would mean that you ``skip'' a vertex when going around the circle.

For example, let's say the user had entered values for 5 vertices and a step size of 2. Let's label these vertices as 1, 2, 3, 4, and 5 going around the unit circle. Since the step size is 2, we would connect the vertices in the following order: 1, 3, 5, 2, 4. This results in a standard ``5-point star'' as shown in the second example above. A step size of 3 would result in the vertices connected in the following order: 1, 4, 2, 5, 3. Note that this ALSO produces a star, but in a slightly different order. Try running the demo to get a better idea of how ``step size'' is related to ``number of vertices''.

Compiling Your Program

For detailed information on compiling your program on WindowsNT, see the class web page at:
http://www-courses.cs.uiuc.edu/~cs318/compile.html. The following discussion assumes that you are using a DOS shell to compile your program. This is the preferred method, and is also the method that will be used by the graders. Thus, you need to make sure that your program compiles and runs using this method.

First, you need to set up the cs318 class directory so that it corresponds to the G: drive on your NT box. Instructions for doing this can be found at http://www-courses.cs.uiuc.edu/~cs318/winnt.html.

Next, open a DOS shell by double-clicking on the DOSShell shortcut in the G:\ directory. This is a special shell for this class that sets up path information for using the Visual C++ compiler from the command line. From within this DOS shell, navigate to the location of your mp0.c file. (Your program must be named mp0.c and NOT mp0.cpp.)

A special batch file has been set up for you. To compile your code, type the following at a command prompt:

       G:\makewin mp0
This assumes that you have mapped the cs318 class directory to the G: drive. If successful, you will get a file named mp0.exe in the current directory. You can compile other MPs in a similar manner by changing the MP number.


Restrictions

This section lists restrictions that are placed on your program. Please read this section carefully, or you may lose points by implementing something incorrectly.


Hints / Sample Code


Hand-In Procedures

For this and future MPs, we will be using the electronic handin program. Once you have completed your program, logon or telnet to one of the Sun Sparc machines (``handin'' does not work on the WindowsNT machines) and hand in your source code by typing ``handin cs318 mp0 mp0.c''. (For more information on handing in your code, consult the class web page at http://www-courses.cs.uiuc.edu/~cs318/handin.html.) This will send your program to the class directory for grading.

Do not submit your executable program. Also, put all your source code in one file. You must hand in your source code file before 10:00am of the due date, as handin will not accept late assignments. Make sure your name, login, MP#, and date appear at the top of your code listing. See the class web page for a sample file header.

If your program does not run as required, you will be given at most 50% of the total points for the MP. You are responsible for making sure your program compiles on the WindowsNT machines using the makewin batch file.

Late assignments will not be accepted. If you are having problems beyond your control, you must let a TA know at least 24 hours before the due date to arrange for a possible extension. There will be no exceptions!