10 #include <stdlib.h> // exit()
12 #include <simgear/bucket/newbucket.hxx>
13 #include <simgear/math/sg_geodesy.hxx>
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,
23 // open the output file
24 FILE *out = fopen( model, "w" );
26 printf("Error: cannot open %s for writing\n", model);
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;
34 double az1, az2, dist;
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 );
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 );
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 );
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 );
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" );
93 SGBucket b( cen_lon, cen_lat );
96 printf("Model is created as %s\n", model);
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");
101 printf(" %s/%s.stg\n",
102 b.gen_base_path().c_str(), b.gen_index_str().c_str());
104 printf("OBJECT_SHARED Models/MNUAV/%s %.6f %.6f ALT_IN_METERS 0.00\n",
105 model, cen_lon, cen_lat);
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);
118 int main( int argc, char **argv ) {
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]),
124 } else if ( argc == 7 ) {
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]),