/*
 * Copyright 2000 Greg Velichansky
 * released under the GNU General Public License    
 * see the files README and COPYING for details.
 */

#include<stdio.h>
#include<math.h>
#include<process.h>

#include<values.h>

#include"3dvector.h"
#include"3dpoly.h"


int n;
int max, min;
int ave;

FILE *in, *out;

main(int argc, char *argv[]){
	in = fopen(argv[1], "rb");
	if(in == NULL){
		perror("Unable to open input file");
		exit(2);
	}

	readmodel(in);

	fclose(in);

	printf("Read %d points and %d polygons.\n", pointnum, polynum);

	for(n = 0; n < pointnum; ++n){
		points[n].x += 317;
	}
	printf("x had 317 added to it", ave);

	max = -MAXINT;
	min = MAXINT;
	for(n = 0; n < pointnum; ++n){
		if(points[n].y < min) min = points[n].y;
		if(points[n].y > max) max = points[n].y;
	}
	ave = (int) (max + min) / 2;
	for(n = 0; n < pointnum; ++n){
		points[n].y -= ave;
	}
	printf("y was off by %d\n", ave);

	max = -MAXINT;
	min = MAXINT;
	for(n = 0; n < pointnum; ++n){
		if(points[n].z < min) min = points[n].z;
		if(points[n].z > max) max = points[n].z;
	}
	ave = (int) (max + min) / 2;
	for(n = 0; n < pointnum; ++n){
		points[n].z -= ave;
	}
	printf("z was off by %d\n", ave);

	out = fopen(argv[2], "wb");
	if(out == NULL){
		perror("Unable to open output file");
		exit(3);
	}
	writemodel(out);
	fclose(out);
}


