| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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 |
|
| 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 |
} |