This is G o o g l e's cache of http://ironbark.bendigo.latrobe.edu.au/~fran/int32gp/wk12/tween.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:qHFCROezP-sJ:ironbark.bendigo.latrobe.edu.au/~fran/int32gp/wk12/tween+&hl=en&ie=UTF-8


Google is not affiliated with the authors of this page nor responsible for its content.

<html>
<head>
</head><body><pre>&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;&lt;body&gt;&lt;pre&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&amp;lt;pre&amp;gt;&amp;amp;lt;html&amp;amp;gt;
&amp;amp;lt;head&amp;amp;gt;
&amp;amp;lt;/head&amp;amp;gt;&amp;amp;lt;body&amp;amp;gt;&amp;amp;lt;pre&amp;amp;gt;/*
 * File:				tween.cpp
 * Description:   Demonstrates how to tween between two
 *                images using interpolation.
 * Rev:				1.0
 * Created:			14 August 00
 * Last Update:	15 October 02
 * Author:			Fran Soddell
 * email:			F.Soddell@bendigo.latrobe.edu.au
 */
#include &amp;amp;amp;lt;GL/glut.h&amp;amp;amp;gt;
#include &amp;amp;amp;lt;stdio.h&amp;amp;amp;gt;
#include &amp;amp;amp;lt;math.h&amp;amp;amp;gt;
#define PI 3.14159
#define TRUE 1
#define FALSE 0
#define debug0 1

/*
 * window management
 */
GLint width=350;
GLint height=350;
GLint initialXposition=50;
GLint initialYposition=50;
/*
 * viewport management
 */
GLint vwXorigin;
GLint vwYorigin;
GLint vwWidth;
GLint vwHeight;
/*
 * my world window management
 */
GLdouble myXorigin;
GLdouble myYorigin;
GLdouble myWidth;
GLdouble myHeight;
/*
 * colour management
 */
#define ALPHA 1.0
#define NUM_COLOURS 8
enum {red,green,blue,pink,paleGreen,
      paleBlue,orange,white};
typedef GLfloat colourType[3];
colourType colour[NUM_COLOURS]=
   {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0},
    {1.0,0.75,0.75},{0.75,1.0,0.75},{0.5,0.75,1.0},
    {1.0,0.55,0.0},{1.0,1.0,1.0}
   };
/*
 * data management
 */
#define MAX_VERTICES 360
#define NUM_STAGES 21
#define INCREMENT 0.05;
enum {x,y};
typedef GLdouble vertexType[2];
vertexType firstImage[MAX_VERTICES];
vertexType secondImage[MAX_VERTICES];
vertexType stage[NUM_STAGES][MAX_VERTICES];
int numVertices=0;
int stageNum=0;
int incrementing=TRUE;
/*
 * ********************************************************************
 */
void renderImage(vertexType image[],int mode){
	int i;
   glBegin(mode);
      for(i=0;i&amp;amp;amp;lt;numVertices;i++)
         glVertex2dv(image[i]);
   glEnd();
}
void renderView(){
   glColor3fv(colour[blue]);
   renderImage(stage[stageNum],GL_LINE_LOOP);
}
void display(){
   glClear(GL_COLOR_BUFFER_BIT);

   renderView();
   glutSwapBuffers();
}
void reshapeWindow(int w, int h){
	width=w;
   height=h;

   myXorigin=0.0;
   myYorigin=0.0;
   myWidth=1.0;
   myHeight=1.0;
   glViewport(0,0,(GLsizei)w,(GLsizei)h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluOrtho2D(myXorigin,myWidth,myYorigin,myHeight);
}
void keyboard(unsigned char key,int xMouse,int yMouse){
	switch(key){
   	case 27:
      	exit(0);
      case &amp;amp;#39;t&amp;amp;#39;: if(incrementing){
                  stageNum++;
                  if(stageNum==NUM_STAGES-1)
                     incrementing=FALSE;
                }
                else{
                   stageNum--;
                   if(stageNum==0)
                      incrementing=TRUE;
                }
                break;
      default:
      	printf(&amp;amp;amp;quot;%s%d\n&amp;amp;amp;quot;,&amp;amp;amp;quot;key=&amp;amp;amp;quot;,key);
      	printf(&amp;amp;amp;quot;%s%d\n&amp;amp;amp;quot;,&amp;amp;amp;quot;xMouse=&amp;amp;amp;quot;,xMouse);
      	printf(&amp;amp;amp;quot;%s%d\n&amp;amp;amp;quot;,&amp;amp;amp;quot;yMouse=&amp;amp;amp;quot;,yMouse);
   }
   glutPostRedisplay();
}
void setUpGLUT(int argc,char ** argv){
	glutInit(&amp;amp;amp;amp;argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
   glutInitWindowSize(width,height);
   glutInitWindowPosition(initialXposition,initialYposition);
   glutCreateWindow(&amp;amp;amp;quot;tweening images&amp;amp;amp;quot;);
   /*
    * Register callback functions.
    */
   glutDisplayFunc(display);
   glutReshapeFunc(reshapeWindow);
   glutKeyboardFunc(keyboard);
}
void initialiseGL(){
   glClearColor(colour[white][red],
                colour[white][green],
                colour[white][blue],ALPHA);

}
void interpolate(){
   int i,j,coordinate;
   GLdouble t=0.0,temp1,temp2;

   for(i=0;i&amp;amp;amp;lt;NUM_STAGES;i++){
      for(j=0;j&amp;amp;amp;lt;numVertices;j++){
         for(coordinate=x;coordinate&amp;amp;amp;lt;=y;coordinate++){
            temp1=firstImage[j][coordinate];
            temp2=secondImage[j][coordinate];
            stage[i][j][coordinate]=(1.0-t)*temp1+t*temp2;
         }
      }
      t=t+INCREMENT;
   }
}
int setUpImage(FILE * infile, int imageNum){
   enum {bad,good};
   int status=good;
   int coordinate=x;
   int vertexNum=0;
   GLfloat nextCoord;

   if((fscanf(infile,&amp;amp;amp;quot;%d&amp;amp;amp;quot;,&amp;amp;amp;amp;numVertices))!=1)
      return bad;
   if(numVertices&amp;amp;amp;lt;=0)
      return bad;
   if(numVertices&amp;amp;amp;gt;MAX_VERTICES)
      numVertices=MAX_VERTICES;

   while(vertexNum&amp;amp;amp;lt;numVertices){
      if(fscanf(infile,&amp;amp;amp;quot;%f&amp;amp;amp;quot;,&amp;amp;amp;amp;nextCoord)&amp;amp;amp;lt;0)
         return bad;

      if(imageNum==1)
         firstImage[vertexNum][coordinate]=nextCoord;
      else
         secondImage[vertexNum][coordinate]=nextCoord;
      if(coordinate==x)
         coordinate=y;
      else{
         coordinate=x;
         vertexNum++;
      }
   }
   if((vertexNum!=numVertices)||(coordinate!=x))
      status=bad;
   return status;
}
int processFiles(char ** argv){
   enum {bad,good};
   int status=0;
   FILE * infile1, * infile2;

   if(!(infile1=fopen(argv[1],&amp;amp;amp;quot;r&amp;amp;amp;quot;))){
      fprintf(stderr,&amp;amp;amp;quot;\n%s%s\n&amp;amp;amp;quot;,
              &amp;amp;amp;quot;cannot open &amp;amp;amp;quot;,argv[1]);
      return bad;
   }
   if(!(infile2=fopen(argv[2],&amp;amp;amp;quot;r&amp;amp;amp;quot;))){
      fprintf(stderr,&amp;amp;amp;quot;\n%s%s\n&amp;amp;amp;quot;,
              &amp;amp;amp;quot;cannot open &amp;amp;amp;quot;,argv[2]);
      fclose(infile1);
      return bad;
   }

   status=setUpImage(infile1,1);
   if(status&amp;amp;amp;gt;0)
      status=setUpImage(infile2,2);

   if(fclose(infile1) &amp;amp;amp;lt; 0)
      return bad;
   if(fclose(infile2) &amp;amp;amp;lt; 0)
      return bad;

   return status;
}
int initialise(int argc,char**argv){
   enum {bad,good};
   int status=0;

   if(argc&amp;amp;amp;lt;3){
      fprintf(stderr,&amp;amp;amp;quot;\n%s%s%s\n%s\n%s\n&amp;amp;amp;quot;,
              &amp;amp;amp;quot;Usage: &amp;amp;amp;quot;,argv[0],&amp;amp;amp;quot; infile1 infile2&amp;amp;amp;quot;,
              &amp;amp;amp;quot;Reads in vertices from two files.&amp;amp;amp;quot;,
              &amp;amp;amp;quot;Then tweens the resulting two images.&amp;amp;amp;quot;);
      return bad;
   }
   status=processFiles(argv);
   interpolate();
   return status;
}
int main(int argc,char ** argv){
   int successful;
   successful=initialise(argc,argv);
   if(!successful){
      fprintf(stderr,&amp;amp;amp;quot;\n%s\n\n&amp;amp;amp;quot;,
             &amp;amp;amp;quot;error: exiting program&amp;amp;amp;quot;);
      exit(1);
   }
   setUpGLUT(argc,argv);
   initialiseGL();
   glutMainLoop();
   return 0;
}

&amp;amp;lt;/pre&amp;amp;gt;&amp;amp;lt;/body&amp;amp;gt;&amp;amp;lt;/html&amp;amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</pre></body></html>