]> git.mxchange.org Git - flightgear.git/blobdiff - Tri2obj/tri2obj.c
Restructured to split 1deg x 1deg dem's into 64 subsections.
[flightgear.git] / Tri2obj / tri2obj.c
index cc529dd1ddd46034063c5f01a6f00d40fca0aec8..b38b074387bd5e31950dd5d7e8924ca55f497ba4 100644 (file)
@@ -29,8 +29,8 @@
 
 #include "tri2obj.h"
 
-#include "../../Src/constants.h"
-#include "../../Src/types.h"
+#include "../../Src/Include/constants.h"
+#include "../../Src/Include/types.h"
 #include "../../Src/Math/fg_geodesy.h"
 #include "../../Src/Math/mat3.h"
 #include "../../Src/Math/polar.h"
@@ -78,7 +78,7 @@ void calc_normal(struct fgCartesianPoint p1, struct fgCartesianPoint p2,
     MAT3cross_product(normal, v1, v2);
     MAT3_NORMALIZE_VEC(normal,temp);
 
-    /* printf("Normal = %.2f %.2f %.2f\n", normal[0], normal[1], normal[2]); */
+/*  printf("  Normal = %.2f %.2f %.2f\n", normal[0], normal[1], normal[2]); */
 }
 
 
@@ -171,7 +171,7 @@ void triload(char *basename) {
 /* dump in WaveFront .obj format */
 void dump_obj(char *basename) {
     char objname[256];
-    double n1[3], n2[3], n3[3];
+    double n1[3], n2[3], n3[3], norm[3], temp;
     FILE *obj;
     int i, t1, t2, t3, count;
 
@@ -192,11 +192,13 @@ void dump_obj(char *basename) {
     printf("  calculating and writing normals\n");
     /* calculate and generate normals */
     for ( i = 1; i <= nodecount; i++ ) {
+/*     printf("Finding normal\n"); */
+
        find_tris(i, &t1, &t2, &t3);
 
        n1[0] = n1[1] = n1[2] = 0.0;
        n2[0] = n2[1] = n2[2] = 0.0;
-       n3[0] = n3[1] = n3[3] = 0.0;
+       n3[0] = n3[1] = n3[2] = 0.0;
 
        count = 1;
        calc_normal(nodes[tris[t1][0]], nodes[tris[t1][1]], nodes[tris[t1][2]], 
@@ -214,19 +216,25 @@ void dump_obj(char *basename) {
            count = 3;
        }
 
-       fprintf(obj, "vn %.4f %.4f %.4f\n", 
-               ( n1[0] + n2[0] + n3[0] ) / (double)count,
-               ( n1[1] + n2[1] + n3[1] ) / (double)count,
-               ( n1[2] + n2[2] + n3[2] ) / (double)count );
+/*     printf("  norm[2] = %.2f %.2f %.2f\n", n1[2], n2[2], n3[2]); */
+
+       norm[0] = ( n1[0] + n2[0] + n3[0] ) / (double)count;
+       norm[1] = ( n1[1] + n2[1] + n3[1] ) / (double)count;
+       norm[2] = ( n1[2] + n2[2] + n3[2] ) / (double)count;
+       
+/*     printf("  count = %d\n", count); */
+/*     printf("  Ave. normal = %.4f %.4f %.4f\n", norm[0], norm[1], norm[2]);*/
+       MAT3_NORMALIZE_VEC(norm, temp);
+/*     printf("  Normalized ave. normal = %.4f %.4f %.4f\n",  */
+/*            norm[0], norm[1], norm[2]); */
+       
+       fprintf(obj, "vn %.4f %.4f %.4f\n", norm[0], norm[1], norm[2]);
     }
 
     /* dump faces */
     printf("  writing faces\n");
     for ( i = 1; i <= tricount; i++ ) {
-       fprintf(obj, "f %d//%d %d//%d %d//%d\n", 
-               tris[i][0], tris[i][0], 
-               tris[i][1], tris[i][1], 
-               tris[i][2], tris[i][2]);
+       fprintf(obj, "f %d %d %d\n", tris[i][0], tris[i][1], tris[i][2]);
     }
 
     fclose(obj);
@@ -248,9 +256,18 @@ int main(int argc, char **argv) {
 
 
 /* $Log$
-/* Revision 1.3  1997/11/15 18:05:05  curt
-/* minor tweaks ...
+/* Revision 1.6  1998/01/09 23:03:15  curt
+/* Restructured to split 1deg x 1deg dem's into 64 subsections.
 /*
+ * Revision 1.5  1997/12/08 19:17:50  curt
+ * Fixed a type in the normal generation code.
+ *
+ * Revision 1.4  1997/12/02 13:13:32  curt
+ * Fixed problem with averaged vertex normals.
+ *
+ * Revision 1.3  1997/11/15 18:05:05  curt
+ * minor tweaks ...
+ *
  * Revision 1.2  1997/11/14 00:29:13  curt
  * Transform scenery coordinates at this point in pipeline when scenery is
  * being translated to .obj format, not when it is being loaded into the end