]> git.mxchange.org Git - flightgear.git/blob - Stripe_u/options.c
Initial revision.
[flightgear.git] / Stripe_u / options.c
1 /********************************************************************/
2 /*   STRIPE: converting a polygonal model to triangle strips    
3      Francine Evans, 1996.
4      SUNY @ Stony Brook
5      Advisors: Steven Skiena and Amitabh Varshney
6 */
7 /********************************************************************/
8
9 /*---------------------------------------------------------------------*/
10 /*   STRIPE: options.c
11      This file contains routines that are used to determine the options
12      that were specified by the user
13 */
14 /*---------------------------------------------------------------------*/
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include "options.h"
19 #include "global.h"
20
21 int power_10(int power)
22 {
23         /*      Raise 10 to the power */
24         register int i,p;
25
26         p = 1;
27         for (i = 1; i <= power; ++i)
28                 p = p * 10;
29         return p;
30 }
31
32 float power_negative(int power)
33 {
34      /*   Raise 10 to the negative power */
35
36      register int i;
37      float p;
38      
39      p = (float)1;
40      for (i = 1; i<=power; i++)
41           p = p * (float).1;
42      return p;
43 }
44
45 float convert_array(int num[],int stack_size)
46 {
47         /* Convert an array of characters to an integer */
48         
49         register int counter,c;
50         float temp =(float)0.0;
51
52         for (c=(stack_size-1), counter = 0; c>=0; c--, counter++)
53      {
54           if (num[c] == -1)
55           /*   We are at the decimal point, convert to decimal
56                less than 1
57           */
58           {
59                counter = -1;
60                temp = power_negative(stack_size - c - 1) * temp;
61           }
62           else 
63                temp += power_10(counter) * num[c];
64      }
65                         
66         return(temp);
67 }
68
69 float get_options(int argc, char **argv, int *f, int *t, int *tr, int *group)
70 {
71      char c;
72      int count = 0;
73      int buffer[MAX1];
74      int next = 0;
75      /*    tie variable */
76      enum tie_options tie = FIRST;
77      /*   triangulation variable */
78      enum triangulation_options triangulate = WHOLE;
79      /*   normal difference variable (in degrees) */
80      float norm_difference = (float)360.0;
81      /*   file-type variable */
82      enum file_options file_type = ASCII;
83
84      /*      User has the wrong number of options */
85         if ((argc > 5) || (argc < 2))
86         {
87                 printf("Usage: bands -[file_option][ties_option][triangulation_option][normal_difference] file_name\n");
88                 exit(0);
89         }
90         
91      /* Interpret the options specified */
92         while (--argc > 0 && (*++argv)[0] == '-')
93      {
94           /*   At the next option that was specified */
95           next = 1;
96           while (c = *++argv[0])
97                         switch (c)
98                 {
99                                 case 'f': 
100                                         /*      Use the first polygon we see. */
101                          tie = FIRST;
102                                         break;
103                                 
104                                 case 'r':
105                                         /*      Randomly choose the next polygon */
106                          tie = RANDOM;
107                                         break;
108
109                                 case 'a':
110                                         /*      Alternate direction in choosing the next polygon */
111                          tie = ALTERNATE;
112                                         break;
113
114                                 case 'l':
115                                         /*      Use lookahead to choose the next polygon */
116                          tie = LOOK;
117                                         break;
118
119                                 case 'q':
120                                         /*  Try to reduce swaps */
121                          tie = SEQUENTIAL;
122                                         break;
123
124                                 case 'p':
125                                         /*      Use partial triangulation of polygons */
126                          triangulate = PARTIAL;
127                                         break;
128
129                                 case 'w':
130                                         /*      Use whole triangulation of polygons */
131                          triangulate = WHOLE;
132                                         break;
133
134                     case 'b':
135                          /*      Input file is in binary */
136                          file_type = BINARY;
137                          break;
138
139                     case 'g':
140                          /*   Strips will be grouped according to the groups in 
141                               the data file. We will have to restrict strips to be
142                               in the grouping of the data file.
143                          */
144                          *group = 1;
145                     
146                          /*     Get each the value of the integer */
147                          /*     We have an integer */
148                     default:
149                          if ((c >= '0') && (c <= '9'))
150                          {
151                               /*   More than one normal difference specified, use the last one */
152                               if (next == 1)
153                               {
154                                    count = 0;
155                                    next = 0;
156                               }
157                               buffer[count++] = ATOI(c);
158                          }
159                               /*   At the decimal point */
160                          else if (c == '.')
161                          {
162                               /*   More than one normal difference specified, use the last one */
163                               if (next == 1)
164                               {
165                                    count = 0;
166                                    next = 0;
167                               }
168                               buffer[count++] = -1;
169                          }
170                          else 
171                               break;
172                 }
173      }
174      /*   Convert the buffer of characters to a floating pt integer */
175      if (count != 0) 
176           norm_difference = convert_array(buffer,count);
177      *f = file_type;
178      *t = tie;
179      *tr = triangulate;
180      return norm_difference;
181 }