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