2D Drawing and Animation
CS 357 HW1

Due Friday, Sept. 19

 

This is a first assignment using the 2D drawing features of OpenGL. Here you will learn to use a 2D viewport, set up menus, and animate a simple display.

When started your program should open up a window containing the following figure:

 

Note that the inscribed triangles are colored with a gray scale. Triangles with the lightest gray and the darkest gray are opposite each other (this is why all of the options have an even number of sides). In each direction the colors ramp down from darkest to lightest.

Three buttons are available in the control panel:

Your job is to implement this.

 

Part 1: Drawing.

You should draw your figure as an object inscribed in a circle. The x and y coordinates of a point on the unit circle are cos(theta) and sin(theta). If you want points on a circle of radius r centered at (x,y) they are ( x+r*cos(theta), y+r*sin(theta) ). Remember to include the math library (math.h) and to use the -lm flag when you comple. Also remember that the math library trigonometric functions use radian measure; you can convert degrees to radians by multiplying by PI/180.0. The darkest triangle in your object is directly opposite the lightest; the colors should go from dark to light and back to dark as you move around the circle. You get a gray color by choosing the same value for the red, green and blue color chanels. glColor3f(0.0, 0.0, 0.0) gives black, glColor3f(0.5, 0.5, 0.5) gives a fairly dark gray, glColor3f(0.8, 0.8, 0.8) gives a light gray, and glColor3f(1.0, 1.0, 1.0) gives white. Color intensities don't ramp linearly, so you will have to play around a bit with the colors to get a spread that looks nice. You probably don't want to use full white or full black; they tend to overwhelm the picture.

Part 2: Animation

If you draw your objects starting from an initial angle alpha that is stored in a global variable, it is easy to make the object rotate: just increment alpha regularly in your idle function. You will want to put a delay into the rotation or it will zip by too quickly; the following method will pause for "delay" clock ticks:

#include <time.h>

void pause() {
     clock_t t;
     t = clock();
     while (clock() < t+delay)        /* on my laptop I use a "delay" of about 100000 */
          ; /* do nothing, just wait*/
}

You will have to experiment with techniques for getting a smooth rotation at various speeds. You might let your speed controls alter the "delay" value. Alternatively, they could alter the amount the angle of rotation jumps between each step. You should try to find a way to make the rotation smooth at each speed and each number of sides for the polygon.

Part 3: Handing in your work

You should hand in a directory that contains

This should be written in C++, using the OpenGL libraries as we did in class. I should be able to build an executable for your solution for the lab machines (or any other linux machine) by just typing the word "make".

If you feel tempted to add some bells and whistles to this, I suggest that you talk to me before you start adding things. It is not to your advantage to do this unless you have the entire assignment completely working.

This is due by midnight on Friday, Sept. 19.