Debian Codegraph @

utils/Modeller/animassist.c

raw symbols SCIP
1 /*
2 // animassist.c
3 //
4 // Jim Wilson 5/8/2003
5 //
6 // Copyright (C) 2003 Jim Wilson - [email protected]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 //
22 */
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <math.h>
27
28 int main( int argc, char **argv ) {
29 float x1,y1,z1,x2,y2,z2 = 0;
30 float center_x,center_y,center_z,axis_x,axis_y,axis_z;
31 float vector_length;
32
33 if (argc < 7) {
34 printf("animassist - utility to calculate axis and center values for SimGear model animation\n\n");
35 printf("Usage: animassist x1 y1 z1 x2 y2 z2\n\n");
36 printf("Defining two vectors in SimGear coords (x1,y1,z1) and (x2,y2,z2)\n\n");
37 printf("Conversion from model to SimGear:\n");
38 printf("SimGear Coord AC3D Coordinate\n");
39 printf(" X = X\n");
40 printf(" Y = Z * -1\n");
41 printf(" Z = Y\n\n");
42 printf("Note: no normalization done, so please make the 2nd vector the furthest out\n");
43 } else {
44
45 x1 = atof(argv[1]);
46 y1 = atof(argv[2]);
47 z1 = atof(argv[3]);
48 x2 = atof(argv[4]);
49 y2 = atof(argv[5]);
50 z2 = atof(argv[6]);
51
52 center_x = (x1+x2)/2;
53 center_y = (y1+y2)/2;
54 center_z = (z1+z2)/2;
55
56 vector_length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1));
57
58 /* arbitrary axis defined by cos(theta) where theta is angle from x,y or z axis */
59 axis_x = (x2-x1)/vector_length;
60 axis_y = (y2-y1)/vector_length;
61 axis_z = (z2-z1)/vector_length;
62
63 printf("Flightgear Model XML for:\n");
64 printf("Axis from (%f,%f,%f) to (%f,%f,%f)\n", x1,y1,z1,x2,y2,z2);
65 printf("Assuming units in meters!\n\n");
66 printf("<center>\n");
67 printf(" <x-m>%f</x-m>\n",center_x);
68 printf(" <y-m>%f</y-m>\n",center_y);
69 printf(" <z-m>%f</z-m>\n",center_z);
70 printf("</center>\n\n");
71 printf("<axis>\n");
72 printf(" <x>%f</x>\n",axis_x);
73 printf(" <y>%f</y>\n",axis_y);
74 printf(" <z>%f</z>\n",axis_z);
75 printf("</axis>\n\n");
76 }
77
78 return 0;
79 }