CS 371
Computer Graphics
Spring 2005


Program 3: GLUT Galaxy

Due on 4/29/05 before MIDNIGHT

The goal of this assignment is to learn the basics of constructing animations in OpenGL. You are to implement a system that animates a list of GLUT shapes as specified by a scene file.

Program Requirements

Program Organization

A scene class should read and store the scene information. It should contain a list of objects, each of which has some OpenGL functionality, such as materials, planets, spin or orbit information. You should then develop a program which takes the scene and updates and renders it by running through the list (repeatedly), executing the appropriate OpenGL commands.

Key Classes

In addition to Camera and Light classes, you should consider developing a set of classes along the following lines:
NodeGL
An abstract class for representing objects that perform OpenGL operations. This class should contain two methods:
ActionGL
A method to be invoked by your OpenGL display callback function. The derived classes of NodeGL will specify the implementation of ActionGL according to the type of object.
UpdateGL
A method to be invoked by your OpenGL idle callback function. The derived classes of NodeGL will specify the implementation of UpdateGL according to the type of object.
Note: For some Node types, ActionGL does nothing, and for some types, UpdateGL does nothing.
XFormNodeGL Classes
Transform classes extending NodeGL. These push specific types of transforms onto the OpenGL modelview stack (such as translations, orbit transforms, and so on).
PopNodeGL
Removes the top of the modelview stack.
PlanetNodeGL Classes
Derived classes of NodeGL which describe some object to render.
MaterialNodeGL
A derived class of NodeGL describing a material.
With such a set of classes defined, your Scene class need only build an appropriate list of nodes. Your animation then repeatedly runs through the list executing each node's UpdateGL and ActionGL methods.

Help!

Provided Code and Libraries

linAlg
A library providing vector and matrix calculations in 3 and 4 dimensions for both float and double types. While you will be using this to some extent, try to get the OpenGL pipeline to do as much of the matrix multiplication as you can.
samples!
There are many sample OpenGL programs in the sampleProgs/openGL directory. Get to know them!

Enhancements and Extensions

As before, there are countless ways to have fun with this assignment. Here are some:

What to turn in

To turn in your work, create a directory containing all files necessary to make your program run (source code, header files, object code, makefiles, README file, etc). This assignment will have a number of classes, your README file shoulde include brief descriptions of the classes and their functionality, as well as features provided, outstanding issues, etc.

Call your directory yourlastnameProg3 and pack it into a single "tar" file. Then drop the tar file off in the drop-off directory. The files in your directory should be correctly set up so that I can compile and run them without having to make changes.

For more information...

Any news flashes will be added to the course home page. There are also links to the source code for the programs that we have been discussing in class. And, again, there's me.

Scene File Format

A scene file contains all information needed to render the scene. The format is similar to that of the last assignment with some differences/extensions. Shapes (surfaces) are the ones defined by GLUT. Materials are now specified all at once (as opposed to piecemeal); They still apply to all subsequent shapes until another material is defined. Transforms are processed in the following manner: The initial transform is the identity. Subsequent transforms each generate an appropriate type of XFormNodeGL. The keyword "pop" should generate a "PopNodeGL".

Below is a sample scene file, including a full description of the scene file format. If you wish to add features, you should do so in a manner consistent with this format. I have included some examples of the suggested format for optional features. Such lines are commented as optional.

// Here is a sample scene. The keyword // indicates a comment that extends
// the end of the current line.
// Keywords and parameters
// The Scene-------------------------
// numX n
// 	int n is the number of items of type X to be entered, for example
// numLights n
// numSurfaces n
// windowDims (rows, cols)
//	where rows and cols are int
// sceneAmbient (ambient)
//	Point3Df ambient
// Cameras-------------------------
// camera (eye,lookAt,up,viewAngle,near,far)
// 	Point3Dd eye, lookAt, up
//	double viewAngle, aspectRatio, near, far 
//	Note: near and far are given as positive values:  They represent
//	distance from eye along negative n axis.  Angle is in radians
// Lighting-------------------------
// pointLight (location, ambient, diffuse, specular)
//	Point3Df location, ambient, diffuse, specular
// dirLight (direction, ambient, diffuse, specular)
//	Point3Df direction, ambient, diffues, specular
// Materials-------------------------
// A material property applies to all surfaces after it but before the next
// material property
// material (ambient, diffuse, specular, specExp)
//	Point3Df ambient, diffuse, specular
//	double specExp
// Transforms-------------------------
// A transform applies to all surfaces after it but before the next transform
// All rotations are counter-clockwise
// All angles are in DEGREES!  Velocities are in degrees/frame.
// identity
// rotate (angle,direction)  // see text for description
//	double angle (radians); Point3Dd direction
// scale (xscale, yscale, zscale)
//	double xscale, yscale, zscale
// translate (xtranslate, ytranslate, ztranslate)
//	double xtranslate, ytranslate, ztranslate
// transform T // optional
//	Transform4Dd T is an arbitrary transformation
// orbit (startAngle, velocity, distance)
//	double startAngle, velocity, distance
//	orbits are in (local) (x,y)-plane at the given distance from origin.
//	They proceed couunter-clockwise around the (local) z-axis.
//	startAngle gives starting orbital position for object, where
//	startAngle = 0 lies on x-axis.
// spin (axisOfRotation, velocity)
//	Point3Dd axisOfRotation
//	double velocity
//	Any object might spin around some local axis (axisOfRotation)
// orient (fromAxis, toAxis)
//	Point3Dd fromAxis, toAxis
//	Rotate coordinate system so that fromAxis moves to toAxis through
//	the plane they determine (i.e., rotate around fromAxis x toAxis).
// Shapes-------------------------
// sphere (radius, longitudes, latitudes)
// 	double radius, int longitudes, latitudes
// torus (smallRadius, largeRadius, longitudes, latitudes)
// 	double small(and large)Radius, int longitudes, latitudes
// teapot size
//	double size
//----------------------------------
//A sample scene file
windowDims (300,300)
sceneAmbient (0.2,0.2,0.2)
camera ((0,0,6),(0,0,0),(0,1,0),1.04703,1,1,150)
dirLight ((1,1,1),(.1,.1,.1),(.6,.6,.6),(.6,.6,.6))
// pointLight ((5,5,4),(.5,.5,.5),(.7,.7,.7))
material ((0.329412, 0.223529, 0.027451),(0.780392, 0.568627, 0.113725),
(0.992157,0.941176,0.807843),27.8974)
orient ((0,0,1),(1,1,0))
   spin ((0,0,1),1)
      teapot 1
   pop
pop
material ((0.19125, 0.07355, 0.0225),(0.7038, 0.27048, 0.0828),
(0.0256777, 0.137622, 0.086014),12.8)
orient ((0,0,1),(-1,1,0))
   orbit (0, 2, 2)
      spin ((0,1,0),1)
	 sphere	(.4, 15,15)
      pop
      orient ((0,0,1),(0,1,0))
	 orbit (180, 3, 1)
	    sphere	(.2, 10,10)
	 pop
      pop
   pop
pop

lenhart@cs.williams.edu