#include "obj.h"
-#include "../../Src/Math/mat3.h"
+#include <Math/mat3.h>
/* what do ya' know, here's some global variables */
-float nodes[MAXNODES][3];
-float normals[MAXNODES][3];
+static double nodes[MAXNODES][3];
+static double normals[MAXNODES][3];
-int ccw_list[MAXNODES];
+static int ccw_list[MAXNODES];
int ccw_list_ptr;
-int cw_list[MAXNODES];
+static int cw_list[MAXNODES];
int cw_list_ptr;
FILE *in, *out;
list[*list_ptr] = node;
*list_ptr += 1;
- printf("list pointer = %d adding %d\n", *list_ptr, node);
+ /* printf("list pointer = %d adding %d\n", *list_ptr, node); */
}
/* dump header */
fprintf(out, "t %d %d %d\n", list[i], list[i+1], list[i+2]);
- printf("t %d %d %d\n", list[i], list[i+1], list[i+2]);
+ /* printf("t %d %d %d\n", list[i], list[i+1], list[i+2]); */
i += 3;
/* dump rest of strip (until -1) */
/* Load a .obj file */
-void obj_fix(char *basename) {
+void obj_fix(char *infile, char *outfile) {
char line[256];
- char inpath[256], outpath[256];
double dot_prod;
int first, ncount, vncount, n1, n2, n3, n4;
int is_ccw;
- strcpy(inpath, basename);
- strcat(inpath, ".obj");
-
- strcpy(outpath, basename);
- strcat(outpath, ".1.obj");
-
- if ( (in = fopen(inpath, "r")) == NULL ) {
- printf("Cannot open file: %s\n", inpath);
+ if ( (in = fopen(infile, "r")) == NULL ) {
+ printf("Cannot open file: %s\n", infile);
exit(-1);
}
- if ( (out = fopen(outpath, "w")) == NULL ) {
- printf("Cannot open file: %s\n", outpath);
+ if ( (out = fopen(outfile, "w")) == NULL ) {
+ printf("Cannot open file: %s\n", outfile);
exit(-1);
}
ncount = 1;
vncount = 1;
- printf("Reading file: %s\n", inpath);
+ printf("Reading file: %s\n", infile);
while ( fgets(line, 250, in) != NULL ) {
if ( line[0] == '#' ) {
/* save vertex to memory and output to file */
if ( ncount < MAXNODES ) {
/* printf("vertex = %s", line); */
- sscanf(line, "v %f %f %f\n",
+ sscanf(line, "v %lf %lf %lf\n",
&nodes[ncount][0], &nodes[ncount][1], &nodes[ncount][2]);
fprintf(out, "v %.2f %.2f %.2f\n",
nodes[ncount][0], nodes[ncount][1], nodes[ncount][2]);
/* save vertex normals to memory and output to file */
if ( vncount < MAXNODES ) {
/* printf("vertex normal = %s", line); */
- sscanf(line, "vn %f %f %f\n",
+ sscanf(line, "vn %lf %lf %lf\n",
&normals[vncount][0], &normals[vncount][1],
&normals[vncount][2]);
fprintf(out, "vn %.4f %.4f %.4f\n", normals[vncount][0],
printf("new tri strip = %s", line);
sscanf(line, "t %d %d %d %d\n", &n1, &n2, &n3, &n4);
+ /* special cases to handle bugs in our beloved tri striper */
+ if ( (n1 == 4) && (n2 == 2) && (n3 == 2) && (n4 == 1) ) {
+ n2 = 3;
+ }
+ if ( (n1 == 3) && (n2 == 1) && (n3 == 1) && (n4 == 0) ) {
+ n3 = 4;
+ }
+
dot_prod = check_cur_face(n1, n2, n3);
- if ( dot_prod < -0.5 ) {
+ if ( dot_prod < 0.0 ) {
/* this stripe is backwards (CW) */
is_ccw = 0;
printf(" -> Starting a backwards stripe\n");
}
}
} else {
- printf("Unknown line in %s = %s\n", inpath, line);
+ printf("Unknown line in %s = %s\n", infile, line);
}
}
/* $Log$
-/* Revision 1.1 1997/12/08 19:28:54 curt
-/* Initial revision.
+/* Revision 1.9 1998/04/18 04:01:03 curt
+/* Now use libMath rather than having local copies of math routines.
/*
+ * Revision 1.8 1998/04/08 23:19:37 curt
+ * Adopted Gnu automake/autoconf system.
+ *
+ * Revision 1.7 1998/03/19 02:51:41 curt
+ * Added special case handling to compensate for bugs in our beloved tri striper
+ *
+ * Revision 1.6 1998/03/03 15:36:12 curt
+ * Tweaks for compiling with g++
+ *
+ * Revision 1.5 1998/03/03 03:37:03 curt
+ * Cumulative tweaks.
+ *
+ * Revision 1.4 1998/01/31 00:41:25 curt
+ * Made a few changes converting floats to doubles.
+ *
+ * Revision 1.3 1998/01/19 19:51:07 curt
+ * A couple final pre-release tweaks.
+ *
+ * Revision 1.2 1998/01/09 23:03:12 curt
+ * Restructured to split 1deg x 1deg dem's into 64 subsections.
+ *
+ * Revision 1.1 1997/12/08 19:28:54 curt
+ * Initial revision.
+ *
*/