]> git.mxchange.org Git - flightgear.git/blob - utils/Modeller/photomodel.cxx
Add a generic binary protocol configuration file analyser that outputs the relevant...
[flightgear.git] / utils / Modeller / photomodel.cxx
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #ifdef HAVE_WINDOWS_H
6 #include <windows.h>
7 #endif
8
9 #include <stdio.h>
10 #include <stdlib.h> // exit()
11
12 #include <simgear/bucket/newbucket.hxx>
13 #include <simgear/math/sg_geodesy.hxx>
14
15
16 int make_model( const char *texture,
17                 double ll_lon, double ll_lat,
18                 double lr_lon, double lr_lat,
19                 double ur_lon, double ur_lat,
20                 double ul_lon, double ul_lat,
21                 const char *model )
22 {
23     // open the output file
24     FILE *out = fopen( model, "w" );
25     if ( out == NULL ) {
26         printf("Error: cannot open %s for writing\n", model);
27         return 0;
28     }
29
30     // compute polygon boundaries in local XY projection
31     double cen_lon = (ll_lon + lr_lon + ur_lon + ul_lon) / 4.0;
32     double cen_lat = (ll_lat + lr_lat + ur_lat + ul_lat) / 4.0;
33
34     double az1, az2, dist;
35     double angle;
36
37     geo_inverse_wgs_84( cen_lat, cen_lon, ll_lat, ll_lon, &az1, &az2, &dist );
38     angle = az1 * SGD_DEGREES_TO_RADIANS;
39     double llx = sin(angle) * dist;
40     double lly = cos(angle) * dist;
41     printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
42             az1, sin(angle) * dist, cos(angle) * dist );
43     
44     geo_inverse_wgs_84( cen_lat, cen_lon, lr_lat, lr_lon, &az1, &az2, &dist );
45     angle = az1 * SGD_DEGREES_TO_RADIANS;
46     double lrx = sin(angle) * dist;
47     double lry = cos(angle) * dist;
48     printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
49             az1, sin(angle) * dist, cos(angle) * dist );
50
51     geo_inverse_wgs_84( cen_lat, cen_lon, ur_lat, ur_lon, &az1, &az2, &dist );
52     angle = az1 * SGD_DEGREES_TO_RADIANS;
53     double urx = sin(angle) * dist;
54     double ury = cos(angle) * dist;
55     printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
56             az1, sin(angle) * dist, cos(angle) * dist );
57
58     geo_inverse_wgs_84( cen_lat, cen_lon, ul_lat, ul_lon, &az1, &az2, &dist );
59     angle = az1 * SGD_DEGREES_TO_RADIANS;
60     double ulx = sin(angle) * dist;
61     double uly = cos(angle) * dist;
62     printf( "az1 = %.3f dx = %.3f dy = %.3f\n",
63             az1, sin(angle) * dist, cos(angle) * dist );
64
65     fprintf( out, "AC3Db\n" );
66     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" );
67     fprintf( out, "OBJECT world\n" );
68     fprintf( out, "kids 1\n" );
69     fprintf( out, "OBJECT poly\n" );
70     fprintf( out, "name \"terrain\"\n" );
71     fprintf( out, "data 9\n" );
72     fprintf( out, "Plane.073\n" );
73     fprintf( out, "texture \"%s\"\n", texture );
74     fprintf( out, "texrep 1 1\n" );
75     fprintf( out, "crease 30.000000\n" );
76     fprintf( out, "numvert 4\n" );
77     fprintf( out, "%.3f 0 %.3f\n", lry, lrx );
78     fprintf( out, "%.3f 0 %.3f\n", lly, llx );
79     fprintf( out, "%.3f 0 %.3f\n", uly, ulx );
80     fprintf( out, "%.3f 0 %.3f\n", ury, urx );
81     fprintf( out, "numsurf 1\n" );
82     fprintf( out, "SURF 0x00\n" );
83     fprintf( out, "mat 0\n" );
84     fprintf( out, "refs 4\n" );
85     fprintf( out, "0 0.0 1.0\n" );
86     fprintf( out, "3 0.0 0.0\n" );
87     fprintf( out, "2 1.0 0.0\n" );
88     fprintf( out, "1 1.0 1.0\n" );
89     fprintf( out, "kids 0\n" );
90
91     fclose( out );
92
93     SGBucket b( cen_lon, cen_lat );
94
95     printf("\n");
96     printf("Model is created as %s\n", model);
97     printf("\n");
98     printf("Now copy the .ac and .rgb file to your Model directory\n");
99     printf("and add the following line to your .stg file:\n");
100     printf("\n");
101     printf("    %s/%s.stg\n",
102            b.gen_base_path().c_str(), b.gen_index_str().c_str());
103     printf("\n");
104     printf("OBJECT_SHARED Models/MNUAV/%s %.6f %.6f ALT_IN_METERS 0.00\n",
105            model, cen_lon, cen_lat);
106     return 1;
107 }
108
109
110 void usage( char *prog ) {
111     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);
112     printf("Usage: %s photo.rgb left_lon right_lon lower_lat upper_lat model.ac\n", prog);
113
114     exit( 0 );
115 }
116
117
118 int main( int argc, char **argv ) {
119     if ( argc == 11 ) {
120         make_model( argv[1],
121                     atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]),
122                     atof(argv[6]), atof(argv[7]), atof(argv[8]), atof(argv[9]),
123                     argv[10] );
124     } else if ( argc == 7 ) {
125         make_model( argv[1],
126                     atof(argv[2]), atof(argv[4]), atof(argv[3]), atof(argv[4]),
127                     atof(argv[3]), atof(argv[5]), atof(argv[2]), atof(argv[5]),
128                     argv[6] );
129     } else {
130         usage( argv[0] );
131     }
132  
133     return 0;
134 }