This page was last updated: September 5, 2022
This project is about performing a keytime animation:
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( );
}
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.
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.
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.
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
Your electronic turnin will be done at http://engr.oregonstate.edu/teach
This is due at 23:59:59 on the listed due date. locally when I run your program.
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 |