]> git.mxchange.org Git - flightgear.git/blobdiff - AssemTris/assemtris.c
Code reorganizations. Added a Lib/ directory for more general libraries.
[flightgear.git] / AssemTris / assemtris.c
index 2541da1253be5a1c52b11ea9d764752b7130aef7..5729903865cdb554b64282f66a81e2ade8a1a649 100644 (file)
 
 #include "assemtris.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"
-#include "../../Src/Scenery/tileutils.h"
+#include <Include/fg_constants.h>
+#include <Include/fg_types.h>
+// #include <Math/fg_geodesy.h>
+// #include <Math/mat3.h>
+// #include <Math/polar.h>
+#include <Bucket/bucketutils.h>
 
 
 int nodecount = 0;
 
-float nodes[MAX_NODES][3];
+static double nodes[MAX_NODES][3];
 
 
-struct bucket my_index;
-struct bucket ne_index, nw_index, sw_index, se_index;
-struct bucket north_index, south_index, east_index, west_index;
+struct fgBUCKET my_index;
+struct fgBUCKET ne_index, nw_index, sw_index, se_index;
+struct fgBUCKET north_index, south_index, east_index, west_index;
 
 
 /* return the file base name ( foo/bar/file.ext = file.ext ) */
@@ -108,26 +108,26 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     long int index;
 
     if ( strcmp(ext, ".sw") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.sw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&west_index, scene_path);
-       index = gen_index(&west_index);
+       fgBucketGenBasePath(&west_index, scene_path);
+       index = fgBucketGenIndex(&west_index);
        sprintf(file, "%s/%s/%ld.1.se", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&sw_index, scene_path);
-       index = gen_index(&sw_index);
+       fgBucketGenBasePath(&sw_index, scene_path);
+       index = fgBucketGenIndex(&sw_index);
        sprintf(file, "%s/%s/%ld.1.ne", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&south_index, scene_path);
-       index = gen_index(&south_index);
+       fgBucketGenBasePath(&south_index, scene_path);
+       index = fgBucketGenIndex(&south_index);
        sprintf(file, "%s/%s/%ld.1.nw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -135,26 +135,26 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".se") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.se", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&east_index, scene_path);
-       index = gen_index(&east_index);
+       fgBucketGenBasePath(&east_index, scene_path);
+       index = fgBucketGenIndex(&east_index);
        sprintf(file, "%s/%s/%ld.1.sw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&se_index, scene_path);
-       index = gen_index(&se_index);
+       fgBucketGenBasePath(&se_index, scene_path);
+       index = fgBucketGenIndex(&se_index);
        sprintf(file, "%s/%s/%ld.1.nw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&south_index, scene_path);
-       index = gen_index(&south_index);
+       fgBucketGenBasePath(&south_index, scene_path);
+       index = fgBucketGenIndex(&south_index);
        sprintf(file, "%s/%s/%ld.1.ne", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -162,26 +162,26 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".ne") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.ne", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&east_index, scene_path);
-       index = gen_index(&east_index);
+       fgBucketGenBasePath(&east_index, scene_path);
+       index = fgBucketGenIndex(&east_index);
        sprintf(file, "%s/%s/%ld.1.nw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&ne_index, scene_path);
-       index = gen_index(&ne_index);
+       fgBucketGenBasePath(&ne_index, scene_path);
+       index = fgBucketGenIndex(&ne_index);
        sprintf(file, "%s/%s/%ld.1.sw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&north_index, scene_path);
-       index = gen_index(&north_index);
+       fgBucketGenBasePath(&north_index, scene_path);
+       index = fgBucketGenIndex(&north_index);
        sprintf(file, "%s/%s/%ld.1.se", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -189,26 +189,26 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".nw") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.nw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&west_index, scene_path);
-       index = gen_index(&west_index);
+       fgBucketGenBasePath(&west_index, scene_path);
+       index = fgBucketGenIndex(&west_index);
        sprintf(file, "%s/%s/%ld.1.ne", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&nw_index, scene_path);
-       index = gen_index(&nw_index);
+       fgBucketGenBasePath(&nw_index, scene_path);
+       index = fgBucketGenIndex(&nw_index);
        sprintf(file, "%s/%s/%ld.1.se", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&north_index, scene_path);
-       index = gen_index(&north_index);
+       fgBucketGenBasePath(&north_index, scene_path);
+       index = fgBucketGenIndex(&north_index);
        sprintf(file, "%s/%s/%ld.1.sw", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -216,14 +216,14 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".south") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.south", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&south_index, scene_path);
-       index = gen_index(&south_index);
+       fgBucketGenBasePath(&south_index, scene_path);
+       index = fgBucketGenIndex(&south_index);
        sprintf(file, "%s/%s/%ld.1.north", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -231,14 +231,14 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".north") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.north", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&north_index, scene_path);
-       index = gen_index(&north_index);
+       fgBucketGenBasePath(&north_index, scene_path);
+       index = fgBucketGenIndex(&north_index);
        sprintf(file, "%s/%s/%ld.1.south", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -246,14 +246,14 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".west") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.west", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&west_index, scene_path);
-       index = gen_index(&west_index);
+       fgBucketGenBasePath(&west_index, scene_path);
+       index = fgBucketGenIndex(&west_index);
        sprintf(file, "%s/%s/%ld.1.east", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -261,14 +261,14 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".east") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.east", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
        }
-       gen_base_path(&east_index, scene_path);
-       index = gen_index(&east_index);
+       fgBucketGenBasePath(&east_index, scene_path);
+       index = fgBucketGenIndex(&east_index);
        sprintf(file, "%s/%s/%ld.1.west", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -276,8 +276,8 @@ int shared_object_exists(char *basepath, char *ext, char *file) {
     }
 
     if ( strcmp(ext, ".body") == 0 ) {
-       gen_base_path(&my_index, scene_path);
-       index = gen_index(&my_index);
+       fgBucketGenBasePath(&my_index, scene_path);
+       index = fgBucketGenIndex(&my_index);
        sprintf(file, "%s/%s/%ld.1.body", basepath, scene_path, index);
        if ( file_exists(file) ) {
            return(1);
@@ -315,7 +315,7 @@ void read_nodes(FILE *fp) {
 
     while ( fgets(line, 250, fp) != NULL ) {
        if ( strncmp(line, "gdn ", 4) == 0 ) {
-           sscanf(line, "gdn %f %f %f\n", &nodes[nodecount][0], 
+           sscanf(line, "gdn %lf %lf %lf\n", &nodes[nodecount][0], 
                   &nodes[nodecount][1], &nodes[nodecount][2]);
            /*
            printf("read_nodes(%d) %.2f %.2f %.2f %s", nodecount, 
@@ -372,25 +372,31 @@ void build_node_list(char *basename, char *basepath) {
 
 
 /* dump in WaveFront .obj format */
-void dump_nodes(char *basename, char *basepath) {
+void dump_nodes(char *basename) {
+    char file[256];
     FILE *fp;
-    int i;
-
+    int i, len;
+
+    /* generate output file name */
+    strcpy(file, basename);
+    len = strlen(file);
+    file[len-2] = '\0';
+    strcat(file, ".node");
+    
     /* dump vertices */
-    printf("  writing vertices in .node format\n");
-    /* printf("Creating node file:  %s\n", file);
-    fd = fopen(file, "w"); */
+    printf("Creating node file:  %s\n", file);
+    printf("  writing vertices in .node format.\n");
+    fp = fopen(file, "w");
 
-    printf("%d 2 1 0\n", nodecount);
+    fprintf(fp, "%d 2 1 0\n", nodecount);
 
     /* now write out actual node data */
     for ( i = 0; i < nodecount; i++ ) {
-       printf("%d %.2f %.2f %.2f 0\n", i + 1,
+       fprintf(fp, "%d %.2f %.2f %.2f 0\n", i + 1,
               nodes[i][0], nodes[i][1], nodes[i][2]);
     }
 
-    /* fclose(fd); */
-
+    fclose(fp);
 }
 
 
@@ -415,20 +421,20 @@ int main(int argc, char **argv) {
     }
     tmp_index = atoi(temp);
     printf("%ld\n", tmp_index);
-    parse_index(tmp_index, &my_index);
+    fgBucketParseIndex(tmp_index, &my_index);
 
     printf("bucket = %d %d %d %d\n", 
           my_index.lon, my_index.lat, my_index.x, my_index.y);
     /* generate the indexes of the neighbors */
-    offset_bucket(&my_index, &ne_index,  1,  1);
-    offset_bucket(&my_index, &nw_index, -1,  1);
-    offset_bucket(&my_index, &se_index,  1, -1);
-    offset_bucket(&my_index, &sw_index, -1, -1);
+    fgBucketOffset(&my_index, &ne_index,  1,  1);
+    fgBucketOffset(&my_index, &nw_index, -1,  1);
+    fgBucketOffset(&my_index, &se_index,  1, -1);
+    fgBucketOffset(&my_index, &sw_index, -1, -1);
 
-    offset_bucket(&my_index, &north_index,  0,  1);
-    offset_bucket(&my_index, &south_index,  0, -1);
-    offset_bucket(&my_index, &east_index,  1,  0);
-    offset_bucket(&my_index, &west_index, -1,  0);
+    fgBucketOffset(&my_index, &north_index,  0,  1);
+    fgBucketOffset(&my_index, &south_index,  0, -1);
+    fgBucketOffset(&my_index, &east_index,  1,  0);
+    fgBucketOffset(&my_index, &west_index, -1,  0);
 
     /*
     printf("Corner indexes = %ld %ld %ld %ld\n", 
@@ -441,14 +447,34 @@ int main(int argc, char **argv) {
     build_node_list(basename, basepath);
 
     /* dump in WaveFront .obj format */
-    dump_nodes(basename, basepath);
+    dump_nodes(basename);
 
     return(0);
 }
 
 
 /* $Log$
-/* Revision 1.1  1998/01/15 02:45:26  curt
-/* Initial revision.
+/* Revision 1.7  1998/04/14 02:26:00  curt
+/* Code reorganizations.  Added a Lib/ directory for more general libraries.
 /*
+ * Revision 1.6  1998/04/08 22:54:58  curt
+ * Adopted Gnu automake/autoconf system.
+ *
+ * Revision 1.5  1998/03/03 16:00:52  curt
+ * More c++ compile tweaks.
+ *
+ * Revision 1.4  1998/01/31 00:41:23  curt
+ * Made a few changes converting floats to doubles.
+ *
+ * Revision 1.3  1998/01/27 18:37:00  curt
+ * Lots of updates to get back in sync with changes made over in .../Src/
+ *
+ * Revision 1.2  1998/01/15 21:33:36  curt
+ * Assembling triangles and building a new .node file with the proper shared
+ * vertices now works.  Now we just have to use the shared normals and we'll
+ * be all set.
+ *
+ * Revision 1.1  1998/01/15 02:45:26  curt
+ * Initial revision.
+ *
  */