#include <stdio.h>

typedef struct
{
	double x,y,z;
}POINT;

typedef struct
{
	POINT* shape;
	double t;
}KEYFRAME;

#include "blank.dat"
#include "a.dat"
#include "i.dat"
#include "j.dat"
#include "m.dat"
#include "u.dat"
#include "v.dat"

KEYFRAME kf[] =
{
	{l_blank,0},
	{l_a,.1},
	{l_m,.3},
	{l_u,.4},
	{l_v,.45},
	{l_i,.5},
	{l_m,.6},
	{l_u,.7},
	{l_a,.75},
	{l_j,.8},
	{l_a,.9},
	{l_blank,1}
};

int main( int argc, char *argv[] )
{
	float t;
	double ts,te,dur;
	int pat,pt;
	FILE *file;
	POINT l[12*16];
	int f,u,v;
	POINT *s,*e, p1,p2;

	if( argc > 1 )
		sscanf( argv[1],"%f",&t);
	else
		t = .5;

	// which segment?
	ts = kf[0].t;
	s = kf[0].shape;
	te = kf[1].t;
	e = kf[1].shape;
	for( f = 0; t > kf[f].t; f++)
	{
		ts = kf[f].t;
		s = kf[f].shape;
		te = kf[f+1].t;
		e = kf[f+1].shape;
	}
	dur = te-ts;
	t -= ts;
	t /= (dur);

	file = fopen( "lips.inc","wt");
	fprintf( file, "//clock val %f\n",t);
	fprintf( file, "union\n{\n");

	for( pat = 0; pat < 12; pat++ )
	{
		fprintf( file, "\tbicubic_patch\n\t{\n\t\ttype 1 flatness 0 u_steps 3 v_steps 3\n");
		for( pt = 0; pt < 16; pt++ )
		{
			l[pat*16+pt].x = s[pat*16+pt].x * (1-t) + e[pat*16+pt].x * t;
			l[pat*16+pt].y = s[pat*16+pt].y * (1-t) + e[pat*16+pt].y * t;
			l[pat*16+pt].z = s[pat*16+pt].z * (1-t) + e[pat*16+pt].z * t;
			fprintf(file, "\t\t<%f,%f,%f>\n",l[pat*16+pt].x,l[pat*16+pt].y,l[pat*16+pt].z);
		}
		fprintf(file, "\t}\n");
	}
	fprintf(file,"\tpigment {rgb<.7,.3,.3>}\n");
	fprintf(file,"\tfinish {phong 0.9}\n");
	fprintf(file, "}\n");
	return 0;
}

