/*
 * 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"3dvector.h"
#include"3dpoly.h"

FILE *in, *out;

int gn;



main(int argc, char *argv[]){
	puts("3DNORM.EXE   A dingy normal generator for the 3D engine by Greg");
	puts(" ");

	if((argc != 3) && ((argc != 4) && (*argv[3] != 'a'))){
		puts("Bad parameters");
		puts("Syntax: 3dnorm.exe in.mdl out.mdl [a]");
		puts("The lowercase a indicates that new points should always be created");
		puts("for the normals.");
		exit(1);
	}

	if((argc == 4) && (*argv[3] == 'a')){
		alwaysadd = 1;
	}

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

	readmodel(in);

	if(fclose(in) == EOF){
		perror("Error on closing input file");
	}


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

	printf("Read %d points and %d polygons.\n", pointnum, polynum);
	for(gn = 0; gn < polynum; gn++){
		calculatenormal(gn);
		printf(".");
	}
	printf("\n");

	writemodel(out);
	if(fclose(out) == EOF){
		perror("Error on closing output file");
	}

	return 0;
}
