Other Examples Using Animation

by D.W. Hyatt

Solar System

This program draws several rotating spheres in 3-space. The red sphere is the center of rotation with the yellow and green spheres acting as planets. The blue sphere orbits the yellow sphere as if it were a moon.

Source Code

Animated Tea Pot

This program draws a simple green teapot that rotates in space. The program uses the command glutIdleFunc( ) to switch between a display that rotates and one that does not.

Source Code

Adding a Menu Instead
It is easy to convert the above program into a menu driven one instead of using keyboard and mouse routines. Just replace the references to the mouse function with the following segments of code:

By pressing on the right mouse button, a simple menu will appear on the screen that will allow the user to select an appropriate option. After an item is selected, the the code in the case statement will cause the picture to either spin, stop spinning, or quit by exiting the program.

Source Code: teapot1.c

Adding a Sub-Menu
The following code allows for a sub menu that permits the user to change the speed of the spinning teapot. Here is the appropriate segment of code that creates the sub-menu. Look at the entire program to see how it all works together. Source Code: teapot2.c