]> git.mxchange.org Git - flightgear.git/commitdiff
First revision of a small utility that will build a simple .ac file around
authorcurt <curt>
Mon, 16 Jul 2007 13:47:42 +0000 (13:47 +0000)
committercurt <curt>
Mon, 16 Jul 2007 13:47:42 +0000 (13:47 +0000)
a aerial photo texture.  You need to determine the coordinates of the 4
corners of your image and this utility will use that to build a 3d model
in meters and tell you the information to copy into the proper .stg file.

utils/Modeller/Makefile.am
utils/Modeller/photomodel.cxx [new file with mode: 0644]

index 537a5a8832ed50429fc7872d29d172712b3a13cc..58a47e01b8fb47d4d3a360e36360fed7f2e11cd1 100644 (file)
@@ -1,4 +1,4 @@
-noinst_PROGRAMS = animassist normalmap
+noinst_PROGRAMS = animassist normalmap photomodel
 
 # threedconvert_SOURCES = 3dconvert.cxx
 # threedconvert_LDADD = -lplibssg -lplibsg -lplibul \
@@ -9,3 +9,6 @@ animassist_LDADD = $(base_LIBS)
 
 normalmap_SOURCES = normalmap.cxx
 normalmap_LDADD = -lsgscreen $(opengl_LIBS) $(base_LIBS) -lz
+
+photomodel_SOURCES = photomodel.cxx
+photomodel_LDADD = $(base_LIBS) -lsgbucket -lsgmath -lsgmisc -lsgdebug
diff --git a/utils/Modeller/photomodel.cxx b/utils/Modeller/photomodel.cxx
new file mode 100644 (file)
index 0000000..6526bb8
--- /dev/null
@@ -0,0 +1,126 @@
+#include <stdio.h>
+#include <stdlib.h> // exit()
+
+#include <simgear/bucket/newbucket.hxx>
+#include <simgear/math/sg_geodesy.hxx>
+
+
+int make_model( const char *texture,
+                double ll_lon, double ll_lat,
+                double lr_lon, double lr_lat,
+                double ur_lon, double ur_lat,
+                double ul_lon, double ul_lat,
+                const char *model )
+{
+    // open the output file
+    FILE *out = fopen( model, "w" );
+    if ( out == NULL ) {
+        printf("Error: cannot open %s for writing\n", model);
+        return 0;
+    }
+
+    // compute polygon boundaries in local XY projection
+    double cen_lon = (ll_lon + lr_lon + ur_lon + ul_lon) / 4.0;
+    double cen_lat = (ll_lat + lr_lat + ur_lat + ul_lat) / 4.0;
+
+    double az1, az2, dist;
+    double angle;
+
+    geo_inverse_wgs_84( cen_lat, cen_lon, ll_lat, ll_lon, &az1, &az2, &dist );
+    angle = az1 * SGD_DEGREES_TO_RADIANS;
+    double llx = sin(angle) * dist;
+    double lly = cos(angle) * dist;
+    printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
+            az1, sin(angle) * dist, cos(angle) * dist );
+    
+    geo_inverse_wgs_84( cen_lat, cen_lon, lr_lat, lr_lon, &az1, &az2, &dist );
+    angle = az1 * SGD_DEGREES_TO_RADIANS;
+    double lrx = sin(angle) * dist;
+    double lry = cos(angle) * dist;
+    printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
+            az1, sin(angle) * dist, cos(angle) * dist );
+
+    geo_inverse_wgs_84( cen_lat, cen_lon, ur_lat, ur_lon, &az1, &az2, &dist );
+    angle = az1 * SGD_DEGREES_TO_RADIANS;
+    double urx = sin(angle) * dist;
+    double ury = cos(angle) * dist;
+    printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
+            az1, sin(angle) * dist, cos(angle) * dist );
+
+    geo_inverse_wgs_84( cen_lat, cen_lon, ul_lat, ul_lon, &az1, &az2, &dist );
+    angle = az1 * SGD_DEGREES_TO_RADIANS;
+    double ulx = sin(angle) * dist;
+    double uly = cos(angle) * dist;
+    printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
+            az1, sin(angle) * dist, cos(angle) * dist );
+
+    fprintf( out, "AC3Db\n" );
+    fprintf( out, "MATERIAL \"DefaultWhite\" rgb 1 1 1  amb 1 1 1  emis 0 0 0  spec 0.5 0.5 0.5  shi 64  trans 0\n" );
+    fprintf( out, "OBJECT world\n" );
+    fprintf( out, "kids 1\n" );
+    fprintf( out, "OBJECT poly\n" );
+    fprintf( out, "name \"terrain\"\n" );
+    fprintf( out, "data 9\n" );
+    fprintf( out, "Plane.073\n" );
+    fprintf( out, "texture \"%s\"\n", texture );
+    fprintf( out, "texrep 1 1\n" );
+    fprintf( out, "crease 30.000000\n" );
+    fprintf( out, "numvert 4\n" );
+    fprintf( out, "%.3f 0 %.3f\n", lry, lrx );
+    fprintf( out, "%.3f 0 %.3f\n", lly, llx );
+    fprintf( out, "%.3f 0 %.3f\n", uly, ulx );
+    fprintf( out, "%.3f 0 %.3f\n", ury, urx );
+    fprintf( out, "numsurf 1\n" );
+    fprintf( out, "SURF 0x00\n" );
+    fprintf( out, "mat 0\n" );
+    fprintf( out, "refs 4\n" );
+    fprintf( out, "0 0.0 1.0\n" );
+    fprintf( out, "3 0.0 0.0\n" );
+    fprintf( out, "2 1.0 0.0\n" );
+    fprintf( out, "1 1.0 1.0\n" );
+    fprintf( out, "kids 0\n" );
+
+    fclose( out );
+
+    SGBucket b( cen_lon, cen_lat );
+
+    printf("\n");
+    printf("Model is created as %s\n", model);
+    printf("\n");
+    printf("Now copy the .ac and .rgb file to your Model directory\n");
+    printf("and add the following line to your .stg file:\n");
+    printf("\n");
+    printf("    %s/%s.stg\n",
+           b.gen_base_path().c_str(), b.gen_index_str().c_str());
+    printf("\n");
+    printf("OBJECT_SHARED Models/MNUAV/%s %.6f %.6f ALT_IN_METERS 0.00\n",
+           model, cen_lon, cen_lat);
+    return 1;
+}
+
+
+void usage( char *prog ) {
+    printf("Usage: %s photo.rgb ll_lon ll_lat lr_lon lr_lat ur_lon ur_lat ul_lon ul_lat model.ac\n", prog);
+    printf("Usage: %s photo.rgb left_lon right_lon lower_lat upper_lat model.ac\n", prog);
+
+    exit( 0 );
+}
+
+
+int main( int argc, char **argv ) {
+    if ( argc == 11 ) {
+        make_model( argv[1],
+                    atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]),
+                    atof(argv[6]), atof(argv[7]), atof(argv[8]), atof(argv[9]),
+                    argv[10] );
+    } else if ( argc == 7 ) {
+        make_model( argv[1],
+                    atof(argv[2]), atof(argv[4]), atof(argv[3]), atof(argv[4]),
+                    atof(argv[3]), atof(argv[5]), atof(argv[2]), atof(argv[5]),
+                    argv[6] );
+    } else {
+        usage( argv[0] );
+    }
+    return 0;
+}