CS 491 -- Fall Quarter 2022

Project #6: Keytime Animation

100 Points

Due: November 25


This page was last updated: September 5, 2022


Instructions

This project is about performing a keytime animation:

  1. Put this project number and your name in the title bar. You do this by setting the string assigned to WINDOWTITLE.

  2. Do a keytime animation. There need to be at least 2 objects, each with at least 8 keytimes that define the animation.

  3. The objects to be animated are your choice of any 3D geometry. They must have sufficiently-good linework (or polygon-work) in them to be able to tell that they are rotating (a smooth sphere is not a good choice). Being a 3D object, each keytime position is defined by seven numbers: (t,x,y,z,thetax,thetay,thetaz), where t is the time in seconds.

  4. The (t,x,y,z,thetax,thetay,thetaz) values for each keytime are your choice and should be pre-defined in the program.

  5. Animate your objects by smoothly interpolating (x,y,z,thetax,thetay,thetaz) between the keytimes. Use the smooth interpolation C++ class that we discussed. For your convenience, the class methods are re-covered below.

  6. Display the object's keytime positions so you/I can see how well it passes through the keytime positions.

Smooth Interpolation:

The smooth interpolation technique that you will be using employs the Coons cubic curve (end points and end slopes). But, rather than you having to specify all of the slopes, the technique makes a reasonable approximation of them based on the surrounding keytime information.

The methods for the Keytime class are:

void    AddTimeValue( float time, float value );
float   GetFirstTime( );
float   GetLastTime( );
int     GetNumKeytimes( );
float   GetValue( float time );
void    PrintTimeValues( );

Set the values like this:

Keytimes Xpos, Ypos, Zpos;
Keytimes ThetaX, ThetaY, ThetaZ;

	. . .
	Xpos.AddTimeValue(  0.0,  0.000 );
	Xpos.AddTimeValue(  2.0,  0.333 );
	Xpos.AddTimeValue(  1.0,  3.142 );
	Xpos.AddTimeValue(  0.5,  2.718 );
	. . .

In your Animate idle function:

	glutSetWindow( MainWindow );
	glutPostRedisplay( );

In your Display function:

if( AnimationIsOn )
{
	// turn # msec into the cycle ( 0 - MSEC-1 ):
	int msec = glutGet( GLUT_ELAPSED_TIME )  %  MSEC;

	// turn that into a time:
	float nowTime = (float)msec  / 1000.;

	glPushMatrix( );
		glTranslatef( Xpos.GetValue( nowTime ), Ypos.GetValue( nowTime ), Zpos.GetValue( nowTime ) );
		glRotatef( ThetaX.GetValue( nowTime ),  1., 0., 0. );
		glRotatef( ThetaY.GetValue( nowTime ),  0., 1., 0. );
		glRotatef( ThetaZ.GetValue( nowTime ),  0., 0., 1. );
		<< draw the object >>
	glPopMatrix( );
}

Drawing the Keytimes

It is tough to see if your object is going through the keytimes if you can't see the keytimes. Show them somehow. In the sample code, Joe Graphics drew the object as a solid and the keytimes as wireframes, but you can do it however you want. You can use roughly the same code as above:

glPushMatrix( );
	glTranslatef( Xpos.GetValue( ? ), Ypos.GetValue( ? ), Zpos.GetValue( ? ) );
	glRotatef( ThetaX.GetValue( ? ),  1., 0., 0. );
	glRotatef( ThetaY.GetValue( ? ),  0., 1., 0. );
	glRotatef( ThetaZ.GetValue( ? ),  0., 0., 1. );
	<< draw the object >>
glPopMatrix( );
but put it in a for-loop that loops through just the keytimes.

What is This Thing Called an Idle Function?

Graphics programming is often event-based. That is, you set everything up and then the program goes to sleep waiting for something to happen. Part of setting everything up is to tell the GLUT driver what functions to call when certain things happen. This is called nominating a callback. In the wrapper program, it is done at the end of InitGraphics( ) and InitGlui( ).

The "Idle Function" is a special callback function that is called whenever the GLUT driver thinks it has nothing else to do. In the wrapper code, this is called Animate( ) because this is where the program samples the clock, decides what time number it should be displaying, and figures out what the object is doing at that time.

The last two lines in Animate( ) are:

glutSetWindow( MainWindow );
glutPostRedisplay( );

These cause the GLUT driver to force the display callback to be called, which will draw the object at the animation time that you just setup.

Graphics Objects

Your object can be anything you want it to be. But, as a huge favor to humanity, the GLUT library includes some pre-defined 3D objects:

glutSolidSphere( radius, slices, stacks ); glutWireSphere( radius, slices, stacks );
glutSolidCube( size ); glutWireCube( size );
glutSolidCone( base, height, slices, stacks ); glutWireCone( base, height, slices, stacks );
glutSolidTorus( innerRadius, outerRadius, nsides, rings ); glutWireTorus( innerRadius, outerRadius, nsides, rings );
glutSolidDodecahedron( ); glutWireDodecahedron( );
glutSolidTetrahedron( ); glutWireTetrahedron( );
glutSolidIcosahedron( ); glutWireIcosahedron( );
glutSolidTeapot( size ); glutWireTeapot( size );

Dimensions, such as radius, base, height, size, etc., are floats.
Resolutions, such as slices, stacks, nsides, etc., are ints.

If you are interested to see what other magic GLUT can do for you, click here.

Testing and Debugging

You will definitely need to see if your program is working. Here is the file: Keytime2019Wrapper.zip, a graphics wrapper program and all the Visual Studio stuff that goes with it. Just unzip all of this into a separate folder and double click on the .sln file. This file already includes keytime.h and keytime.cpp, but if you want them separately, here they are:
keytime.h
keytime.cpp

Turn-In

Your electronic turnin will be done at http://engr.oregonstate.edu/teach

  1. Your source code file
  2. A one-page PDF with a title, your name, your email address, a nice screen shot from your program, and the link to the Kaltura video demonstrating that your project does what the requirements ask for. If you narrate your video, then you get to tell us what it is doing, and we can grade it more accurately.
    Be sure that your video is flagged as unlisted.
    A good way to test this is to ask a friend to try to open the same video link that you are giving us.
  3. Leave your PDF file out by itself -- do not place it in any zip files.

This is due at 23:59:59 on the listed due date. locally when I run your program.

Grading:

Item Points
Something moves through the keytimes at all 30
Another something moves through the keytimes at all 30
Smooth transition at the keytimes 30
Does it all in 10 seconds 10
Potential Total 100